--- a/progs/drumb_sol.scala Thu Nov 17 16:21:56 2016 +0000
+++ b/progs/drumb_sol.scala Fri Nov 18 18:47:02 2016 +0000
@@ -42,7 +42,7 @@
// test case
-val p = get_prices(List("FB"), 2012 to 2014)
+val p_fb = get_prices(List("FB"), 2012 to 2014)
val p = get_prices(List("GOOG", "AAPL"), 2005 to 2012)
@@ -79,7 +79,7 @@
val somes_length = somes.length
if (somes_length == 0) balance
else {
- val portion: Double = (balance.toDouble) / somes_length
+ val portion: Double = balance.toDouble / somes_length.toDouble
balance + (for (x <- somes) yield (x * portion)).sum.toLong
}
}
@@ -115,3 +115,30 @@
println("Real data: " + investment(rstate_portfolio, 1978 to 2016, 100))
println("Blue data: " + investment(blchip_portfolio, 1978 to 2016, 100))
+val p_fb = get_prices(List("FB"), 2011 to 2016)
+
+// prices 2011 - 2016
+//
+List(List(None), List(None), List(Some(28.0)),
+ List(Some(54.709999)), List(Some(78.449997)),
+ List(Some(102.220001)))
+
+// deltas 2011 - 2016
+val d_fb = get_deltas(p_fb)
+
+List(List(None), List(None), List(Some(0.9539285357142858)),
+ List(Some(0.4339242996513305)), List(Some(0.30299560113431234)))
+
+yearly_yield(d_fb, 100, 0) //2011 => 100
+yearly_yield(d_fb, 100, 1) //2012 => 100
+yearly_yield(d_fb, 100, 2) //2013 => 195
+yearly_yield(d_fb, 195, 3) //2014 => 279
+yearly_yield(d_fb, 279, 4) //2015 => 363
+
+investment(List("FB"), 2011 to 2012, 100) // => 100
+investment(List("FB"), 2011 to 2013, 100) // => 100
+investment(List("FB"), 2011 to 2014, 100) // => 195
+investment(List("FB"), 2011 to 2015, 100) // => 279
+investment(List("FB"), 2011 to 2016, 100) // => 363
+
+