diff -r a057dc4457fc -r 87b9e3e2c1a7 testing1/drumb.scala --- a/testing1/drumb.scala Tue Oct 29 11:11:44 2019 +0000 +++ b/testing1/drumb.scala Tue Oct 29 14:12:24 2019 +0000 @@ -1,7 +1,7 @@ -// Part 2 and 3 about a really dumb investment strategy +// Main Part about a really dumb investment strategy //====================================================== -//object CW6b { // for purposes of generating a jar +object CW6b { //two test portfolios @@ -73,16 +73,13 @@ //test cases -//val p_fb = get_prices(List("FB"), 2012 to 2014) -//val p = get_prices(List("GOOG", "AAPL"), 2010 to 2012) - -//val tt = get_prices(List("BIDU"), 2004 to 2008) +//println("Task 3 data from Google and Apple in 2010 to 2012") +//val goog_aapl_prices = get_prices(List("GOOG", "AAPL"), 2010 to 2012) +//println(goog_aapl_prices.toString ++ "\n") -//============================================== -// Do not change anything below, unless you want -// to submit the file for the advanced part 3! -//============================================== +//val p_fb = get_prices(List("FB"), 2012 to 2014) +//val tt = get_prices(List("BIDU"), 2004 to 2008) // (4) The function below calculates the change factor (delta) between @@ -105,8 +102,13 @@ for (j <- (0 until (data(0).length)).toList) yield get_delta(data(i)(j), data(i + 1)(j)) + // test case using the prices calculated above -//val d = get_deltas(p) + +//println("Task 5 change prices from Google and Apple in 2010 and 2011") +//val goog_aapl_deltas = get_deltas(goog_aapl_prices) +//println(goog_aapl_deltas.toString ++ "\n") + //val ttd = get_deltas(tt) @@ -124,6 +126,21 @@ } } +// test case using the deltas calculated above +//println("Task 6 yield from Google and Apple in 2010 with balance 100") + +//val d0 = goog_aapl_deltas(0)(0) +//val d1 = goog_aapl_deltas(0)(1) +//println(s"50 * ${d0.get} + 50 * ${d1.get} = ${50.toDouble * d0.get + 50.toDouble * d1.get}") + + +//val goog_aapl_yield = yearly_yield(goog_aapl_deltas, 100, 0) +//println("Rounded yield: " ++ goog_aapl_yield.toString ++ "\n") + + +//yearly_yield(get_prices(rstate_portfolio, 2016 to 2018), 100, 2) +//get_prices(rstate_portfolio, 2016 to 2018)(2).flatten.sum + // (7) Write a function compound_yield that calculates the overall balance for a // range of years where in each year the yearly profit is compounded to the new @@ -147,21 +164,10 @@ //test cases for the two portfolios given above -//println("Real data: " + investment(rstate_portfolio, 1978 to 2018, 100)) -//println("Blue data: " + investment(blchip_portfolio, 1978 to 2018, 100)) +//println("Real data: " + investment(rstate_portfolio, 1978 to 2019, 100)) +//println("Blue data: " + investment(blchip_portfolio, 1978 to 2019, 100)) -//} +} -//val ds = get_deltas(get_prices(List("GOOG", "AAPL"), 2010 to 2012)) -//yearly_yield(ds, 100, 0) => 125 -//yearly_yield(ds, 100, 1) => 117 -//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2000, 100) // => 100 -//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2001, 100) // => 27 -//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2002, 100) // => 42 -//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2003, 100) // => 27 -//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2004, 100) // => 38 -//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2005, 100) // => 113 -//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2006, 100) // => 254 -//investment(List("GOOG", "AAPL", "BIDU"), 2000 to 2007, 100) // => 349