In the last Blog we have seen how to calculate the Market Share with the help of Spark. Now we calculate the market share directly with the native Smart EDGAR functionality
%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
import ch.pschatzmann.edgar.reporting.marketshare.MarketShare
import ch.pschatzmann.common.utils._
import ch.pschatzmann.common.table._
import ch.pschatzmann.edgar.reporting.marketshare.MarketShare import ch.pschatzmann.common.utils._ import ch.pschatzmann.common.table._
import scala.collection.JavaConverters._
val marketShare = new MarketShare()
ch.pschatzmann.edgar.reporting.marketshare.MarketShare@554d50b5
import scala.collection.JavaConverters._
val list = marketShare.toList.asScala
.filter(_.get("2017").doubleValue > 0.0)
.sortWith(_.get("2017").doubleValue > _.get("2017").doubleValue)
val plot = new Plot()
plot.add(new Bars {
displayName = "MarketShare%"
y = list.map(r => r.get("2017").doubleValue).toSeq
toolTip = list.map(r => ""+r.get("companyName")+"<br>"+r.get("sicDescription")+"<br>("+r.get("2017").doubleValue+"%)").toSeq
})
We plot the companies as a the Market Share vs Market Share Growth portfolio:
import scala.collection.JavaConverters._
val marketShareGrowth = new TableCalculated(marketShare,new Tuple("Diff2017","($2017 - $2016) / $2016 * 100.0"))
val list = marketShareGrowth.toList.asScala
val plot = new Plot() {
xLabel = "MarketShare%"
yLabel = "MarketShare Growth%"
logY=true
yLogBase = 10
}
plot.add(new Points {
x = list.map(r => r.get("2017").doubleValue).toSeq
y = list.map(r => r.get("Diff2017").doubleValue).toSeq
toolTip = list.map(r => ""+r.get("companyName")+"<br>"+r.get("sicDescription")+"<br>Share: "+r.get("2017")+"%"+"<br>Growth: "+r.get("Diff2017")+"%").toSeq
})
val traded = list.toSeq.filter(r => !r.asInstanceOf[java.util.Map[String,String]].get("tradingSymbol").isEmpty)
val plot = new Plot() {
xLabel = "MarketShare%"
yLabel = "MarketShare Growth%"
logY=true
yLogBase = 10
}
plot.add(new Points {
x = traded.map(r => r.get("2017").doubleValue).toSeq
y = traded.map(r => r.get("Diff2017").doubleValue).toSeq
toolTip = traded.map(r => r.get("companyName").toString+"<br>"+r.get("sicDescription")+"<br>Share: "+r.get("2017")+"%"+"<br>Growth: "+r.get("Diff2017")+"%<br>"+r.get("tradingSymbol")).toSeq
})
We determine the leading company by SIC code
import scala.collection.JavaConverters._
var maxBySIC = traded.map(m => m.asScala)
.groupBy(m => m.get("sicCode").toString)
.map(e => (e._1, e._2.sortWith(_.get("2017").get.doubleValue > _.get("2017").get.doubleValue)(0).asJava))
.map(tuple => tuple._2)
.toSeq
.filter(_.get("2017").doubleValue>0.0)
.sortWith(_.get("2017").doubleValue > _.get("2017").doubleValue)
.asJava
val list = maxBySIC.asScala.toSeq
val plot = new Plot()
plot.add(new Bars {
displayName = "MarketShare%"
y = list.map(r => r.get("2017").doubleValue).toSeq
toolTip = list.map(r => ""+r.get("companyName")+"<br>"+r.get("sicDescription")+"<br>("+r.get("2017")+"%)").toSeq
})