Donald Trump is the best, smartest, most beautiful, richest, youngest ... President that was ever elected in the USA.
He is also the best that could happen to the profites of the companies which are located in the US.
But is this actually true ?
We use the values from the Edgar database to analyse the profits of the filing US companies over time.
We load the neccessary libraries with the help of Maven
%classpath config resolver maven-public http://software.pschatzmann.ch/repository/maven-public/
%%classpath add mvn
ch.pschatzmann:smart-edgar:1.0.3-SNAPSHOT
ch.pschatzmann:jupyter-jdk-extensions:1.0.0
And we import the packages that we want to use
import ch.pschatzmann.common.table._
import ch.pschatzmann.edgar.reporting._
import ch.pschatzmann.edgar.utils._
import ch.pschatzmann.display._
import scala.collection.JavaConverters._
import java.util.Arrays
import ch.pschatzmann.common.table._ import ch.pschatzmann.edgar.reporting._ import ch.pschatzmann.edgar.utils._ import ch.pschatzmann.display._ import scala.collection.JavaConverters._ import java.util.Arrays <console>:6: error: Class ch.pschatzmann.stocks.errors.UniverseException not found - continuing with a stub. lazy val $print: String = { ^
To make sure that the Edgar Table is displayed as table in BaekerX we use a custom Displayer...
Displayers.setup()
true
In my first posts, I was using webservices to query the Smart EDGAR database. In this example - since we use Scala - we can directly use the underlying Java query classes:
We also only use 10K filings and for the parameter name we select "NetIncomeLoss". We restrict the selection on USD values and we take the values for the period from 2005 up to 2018.
We exclude 2019 because we do not have all the filings yet.
var model = new EdgarModel()
model.create()
// set filter values
model.getNavigationField("values", "parametername").setFilterValues(Arrays.asList("NetIncomeLoss"))
model.getNavigationField("values", "numberofmonths").setFilterValues(Arrays.asList("12"))
model.getNavigationField("values", "form").setFilterValues(Arrays.asList("10-K","10-K/A"))
model.getNavigationField("values", "unitref").setFilterValues(Arrays.asList("USD"))
model.getNavigationField("values", "segment").setFilterValues(Arrays.asList(""))
model.getNavigationField("values", "segmentdimension").setFilterValues(Arrays.asList(""))
values.segmentDimension
// define the result table
var tableIncome = new ch.pschatzmann.edgar.reporting.Table()
tableIncome.setValueField(model.getTable("values").getValueField())
tableIncome.addColumn(model.getNavigationField("states","country","location").setFilterValues(Arrays.asList("USA")))
tableIncome.addRow(model.getNavigationField("values","year",null).setFilterRange(2005,2018))
tableIncome.execute(model)
// we double check the generated SQL query
new TableFormatterSQL(model).format(tableIncome)
SELECT states.country, to_char(date,'yyyy') AS year, SUM(value) AS value FROM values INNER JOIN company ON (values.identifier = company.identifier ) INNER JOIN states ON (company.location = states.id ) WHERE values.parameterName IN ('NetIncomeLoss') AND values.numberOfMonths IN ('12') AND values.form IN ('10-K','10-K/A') AND values.segment IN ('') AND values.segmentDimension IN ('') AND values.unitRef IN ('USD') AND to_char(date,'yyyy') IN ('2005','2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018') AND states.country IN ('USA') GROUP BY states.country, year
tableIncome
Now we are raeady to plot the result. I have marked the election year of
val plot = new Plot
plot.add(new Line { x = tableIncome.getValues("year").asScala.toSeq; y = tableIncome.getValues("USA").asScala.toSeq })
plot.add(new ConstantLine {
x = 2009 // Obama
y = 0
style = StrokeType.DOT
color = Color.blue
})
plot.add(new ConstantLine {
x = 2017 // Trump
y = 0
style = StrokeType.DOT
color = Color.red
})
Well, the result is not very conclusive. One might argue that Trump is just riding the upturn that was created by Obama. But there is no denying that the profits were rising to record levels.
So let's have a quick look into the Revenues and Reasearch & Development. A high R&D should lead to high future profits:
// define the result table
model.getNavigationField("values", "parametername").setFilterValues(Arrays.asList("Revenues"))
var tableRevenue = new ch.pschatzmann.edgar.reporting.Table()
tableRevenue.setValueField(model.getTable("values").getValueField())
tableRevenue.addColumn(model.getNavigationField("states","country","location").setFilterValues(Arrays.asList("USA")))
tableRevenue.addRow(model.getNavigationField("values","year",null).setFilterRange(2005,2018))
tableRevenue.execute(model)
val plot = new Plot
plot.add(new Line { x = tableRevenue.getValues("year").asScala.toSeq; y = tableRevenue.getValues("USA").asScala.toSeq })
plot.add(new ConstantLine {
x = 2009
y = 0
style = StrokeType.DOT
color = Color.blue
})
plot.add(new ConstantLine {
x = 2017
y = 0
style = StrokeType.DOT
color = Color.red
})
We can see that the Revenues of the Companies are actually declining with Trump. So the higher profits are not created because the companies were sellimg more!
model.getNavigationField("values", "parametername").setFilterValues(Arrays.asList("ResearchAndDevelopmentExpense"))
// define the result table
var tableRD = new ch.pschatzmann.edgar.reporting.Table()
tableRD.setValueField(model.getTable("values").getValueField())
tableRD.addColumn(model.getNavigationField("states","country","location").setFilterValues(Arrays.asList("USA")))
tableRD.addRow(model.getNavigationField("values","year",null).setFilterRange(2005,2018))
tableRD.execute(model)
val plot = new Plot
plot.add(new Line { x = tableRD.getValues("year").asScala.toSeq; y = tableRD.getValues("USA").asScala.toSeq })
plot.add(new ConstantLine {
x = 2009
y = 0
style = StrokeType.DOT
color = Color.blue
})
plot.add(new ConstantLine {
x = 2017
y = 0
style = StrokeType.DOT
color = Color.red
})
This finally looks very promising: Companies are spending more on R&D then ever!