diff -r ff8d075842d5 -r 28c8e17ab83a progs/drumb_sol.scala --- a/progs/drumb_sol.scala Thu Dec 01 22:08:00 2016 +0000 +++ b/progs/drumb_sol.scala Fri Dec 02 16:45:31 2016 +0000 @@ -45,7 +45,7 @@ val p_fb = get_prices(List("FB"), 2012 to 2014) val p = get_prices(List("GOOG", "AAPL"), 2005 to 2012) -get_prices(List("BIDU"), 2004 to 2008) +val tt = get_prices(List("IBM", "BIDU"), 2004 to 2008) // (2) The first function below calculates the change factor (delta) between // a price in year n and a price in year n+1. The second function calculates @@ -65,7 +65,7 @@ // test case using the prices calculated above val d = get_deltas(p) - +val ttd = get_deltas(tt) // (3) Write a function that given change factors, a starting balance and a year // calculates the yearly yield, i.e. new balanace, according to our dump investment @@ -85,6 +85,16 @@ } } +yearly_yield(ttd, 100, 0) +yearly_yield(ttd, 100, 1) +yearly_yield(ttd, 100, 2) +yearly_yield(ttd, 100, 3) assert((yearly_yield(ttd, 100, 0) - 107).abs <= 2) + assert((yearly_yield(ttd, 100, 1) - 85).abs <= 2) + assert((yearly_yield(ttd, 100, 2) - 156).abs <= 2) + assert((yearly_yield(ttd, 100, 3) - 210).abs <= 2) + + + //test case yearly_yield(d, 100, 0) yearly_yield(d, 225, 1) @@ -116,6 +126,9 @@ println("Real data: " + investment(rstate_portfolio, 1978 to 2016, 100)) println("Blue data: " + investment(blchip_portfolio, 1978 to 2016, 100)) + +investment(List("IBM", "BIDU"), 2004 to 2008, 100) + val p_fb = get_prices(List("FB"), 2011 to 2016) // prices 2011 - 2016