In the last Blog we demonstrated how we can calculate KPIs with the help of Spark.
We have extended Smart Edgar functionality so that we can implement Calculated KPIs direcltly with the help of formulas. Here is a short demo in Scala which uses
and displays the result in BeakerX Jupyter notebook as tables and charts using the Java API. This functionality is also available as webservice https://pschatzmann.ch/edgar/index.html#/DBService/post_db_companyValues
We install the smart-egar library with the help of Maven
%classpath config resolver maven-public http://software.pschatzmann.ch/repository/maven-public/
%%classpath add mvn
ch.pschatzmann:smart-edgar:LATEST
Added new repo: maven-public
We can use the CompanyEdgarValues class which has been described in the last Blog and extend it with formulas. For BeakerX we ask that the Lists are converted to java.util.ArrayList and the dates to java.utilDate objects.
import ch.pschatzmann.edgar.reporting.company._
val values = new CompanyEdgarValues(new CompanySelection().setTradingSymbol("AAPL"))
.setUseArrayList(true)
.setAddTime(true)
.setFilter(new FilterYearly())
.setParameterNames("NetIncomeLoss","OperatingIncomeLoss","ResearchAndDevelopmentExpense",
"CashAndCashEquivalentsAtCarryingValue","AvailableForSaleSecuritiesCurrent","AccountsReceivableNetCurrent",
"Revenues","SalesRevenueNet","InventoryNet","AssetsCurrent","LiabilitiesCurrent","Assets","EarningsPerShareBasic",
"StockholdersEquity")
.addFormula("Revenue","Edgar.coalesce('Revenues', 'SalesRevenueNet')")
.addFormula("QuickRatio","(CashAndCashEquivalentsAtCarryingValue + AccountsReceivableNetCurrent + AvailableForSaleSecuritiesCurrent) / LiabilitiesCurrent")
.addFormula("CurrentRatio","AssetsCurrent / LiabilitiesCurrent")
.addFormula("InventoryTurnover","Revenue / InventoryNet")
.addFormula("NetProfitMargin","NetIncomeLoss / Revenue")
.addFormula("SalesResearchRatio%","ResearchAndDevelopmentExpense / Revenue *100")
.addFormula("NetIncomeResearchRatio%","ResearchAndDevelopmentExpense / NetIncomeLoss * 100")
.addFormula("NetIncomeChange%", "NetIncomeLoss - Edgar.lag('NetIncomeLoss', -1) / Edgar.lag('NetIncomeLoss', -1) * 100 ")
.addFormula("RevenueChange%", "Edgar.percentChange('Revenue')" )
.addFormula("ResearchAndDevelopmentChange%","Edgar.percentChange('ResearchAndDevelopmentExpense')" )
.removeParameterNames("Revenues","SalesRevenueNet")
val list = values.toList
We need to convert the Java data to a Scala Seq of scala Maps that can be used in a SimpleTimePlot
import scala.collection.JavaConverters._
val scalaValues = values.toList.asScala
.map(_.asScala.toMap)
.toSeq
new SimpleTimePlot {
data = scalaValues
columns = Seq("NetIncomeLoss","ResearchAndDevelopmentExpense")
yLabel = "US $"
timeColumn = "time"
}
new SimpleTimePlot {
data = scalaValues
columns = Seq("QuickRatio","CurrentRatio","SalesResearchRatio%")
}