testing1/drumb.scala
changeset 160 863feeb5c760
parent 144 716042628398
child 161 6ea450e999e2
equal deleted inserted replaced
159:92c31cbb1952 160:863feeb5c760
     4 object CW6c {
     4 object CW6c {
     5 
     5 
     6 
     6 
     7 //two test portfolios
     7 //two test portfolios
     8 
     8 
     9 val blchip_portfolio = List("GOOG", "AAPL", "MSFT", "IBM", "FB", "AMZN", "BIDU", "FOOBAR")
     9 val blchip_portfolio = List("GOOG", "AAPL", "MSFT", "IBM", "FB", "AMZN", "BIDU")
    10 val rstate_portfolio = List("PLD", "PSA", "AMT", "AIV", "AVB", "BXP", "CCI", 
    10 val rstate_portfolio = List("PLD", "PSA", "AMT", "AIV", "AVB", "BXP", "CCI", 
    11                             "DLR", "EQIX", "EQR", "ESS", "EXR", "FRT", "GGP", "HCP") 
    11                             "DLR", "EQIX", "EQR", "ESS", "EXR", "FRT", "GGP", "HCP") 
    12 
    12 
    13 // (1) The function below should obtain the first trading price
    13 // (1) The function below should obtain the first trading price
    14 // for a stock symbol by using the query
    14 // for a stock symbol by using the query
    93     val new_balance = yearly_yield(data, balance, year)
    93     val new_balance = yearly_yield(data, balance, year)
    94     compound_yield(data, new_balance, year + 1)
    94     compound_yield(data, new_balance, year + 1)
    95   }
    95   }
    96 }
    96 }
    97 
    97 
    98 yearly_yield(d, 100, 0)
    98 //yearly_yield(d, 100, 0)
    99 compound_yield(d.take(6), 100, 0)
    99 //compound_yield(d.take(6), 100, 0)
   100 
   100 
   101 //test case
   101 //test case
   102 yearly_yield(d, 100, 0)
   102 //yearly_yield(d, 100, 0)
   103 yearly_yield(d, 225, 1)
   103 //yearly_yield(d, 225, 1)
   104 yearly_yield(d, 246, 2)
   104 //yearly_yield(d, 246, 2)
   105 yearly_yield(d, 466, 3)
   105 //yearly_yield(d, 466, 3)
   106 yearly_yield(d, 218, 4)
   106 //yearly_yield(d, 218, 4)
   107 
   107 
   108 yearly_yield(d, 100, 0)
   108 //yearly_yield(d, 100, 0)
   109 yearly_yield(d, 125, 1)
   109 //yearly_yield(d, 125, 1)
   110 
   110 
   111 def investment(portfolio: List[String], years: Range, start_balance: Long): Long = {
   111 def investment(portfolio: List[String], years: Range, start_balance: Long): Long = {
   112   compound_yield(get_deltas(get_prices(portfolio, years)), start_balance, 0)
   112   compound_yield(get_deltas(get_prices(portfolio, years)), start_balance, 0)
   113 }
   113 }
   114 
   114 
   121 one_full.map(_.flatten).map(_.sum).sum
   121 one_full.map(_.flatten).map(_.sum).sum
   122 two_full.map(_.flatten).map(_.sum).sum
   122 two_full.map(_.flatten).map(_.sum).sum
   123 
   123 
   124 //test cases for the two portfolios given above
   124 //test cases for the two portfolios given above
   125 
   125 
   126 println("Real data: " + investment(rstate_portfolio, 1978 to 1981, 100))
   126 //println("Real data: " + investment(rstate_portfolio, 1978 to 1981, 100))
   127 println("Blue data: " + investment(blchip_portfolio, 1978 to 1981, 100))
   127 //println("Blue data: " + investment(blchip_portfolio, 1978 to 1981, 100))
   128 
   128 
   129 for (i <- 1978 to 2017) {
   129 //for (i <- 1978 to 2017) {
   130   println("Year " + i)
   130 //  println("Year " + i)
   131   println("Real data: " + investment(rstate_portfolio, 1978 to i, 100))
   131 //  println("Real data: " + investment(rstate_portfolio, 1978 to i, 100))
   132   println("Blue data: " + investment(blchip_portfolio, 1978 to i, 100))
   132 //  println("Blue data: " + investment(blchip_portfolio, 1978 to i, 100))
   133 }
   133 //}
       
   134 
   134 //1984
   135 //1984
   135 //1992
   136 //1992
   136 }
   137 }