| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Wed, 02 Nov 2022 21:49:42 +0000 | |
| changeset 427 | 2a0ddb392d2b | 
| parent 425 | 6e990ae2c6a3 | 
| child 467 | 1b879b3e704e | 
| permissions | -rw-r--r-- | 
| 396 | 1 | // Main Part 1 about a really dumb investment strategy | 
| 266 | 2 | //=================================================== | 
| 129 | 3 | |
| 396 | 4 | object M1 {
 | 
| 129 | 5 | |
| 6 | //two test portfolios | |
| 7 | ||
| 144 | 8 | val blchip_portfolio = List("GOOG", "AAPL", "MSFT", "IBM", "FB", "AMZN", "BIDU")
 | 
| 9 | val rstate_portfolio = List("PLD", "PSA", "AMT", "AIV", "AVB", "BXP", "CCI", 
 | |
| 199 | 10 | "DLR", "EQIX", "EQR", "ESS", "EXR", "FRT", "HCP") | 
| 129 | 11 | |
| 135 | 12 | import io.Source | 
| 13 | import scala.util._ | |
| 132 | 14 | |
| 425 
6e990ae2c6a3
updated solutions and templates
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
396diff
changeset | 15 | // ADD YOUR CODE BELOW | 
| 
6e990ae2c6a3
updated solutions and templates
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
396diff
changeset | 16 | //====================== | 
| 
6e990ae2c6a3
updated solutions and templates
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
396diff
changeset | 17 | |
| 
6e990ae2c6a3
updated solutions and templates
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
396diff
changeset | 18 | |
| 
6e990ae2c6a3
updated solutions and templates
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
396diff
changeset | 19 | // (1) | 
| 347 | 20 | def get_january_data(symbol: String, year: Int) : List[String] = ??? | 
| 132 | 21 | |
| 135 | 22 | |
| 425 
6e990ae2c6a3
updated solutions and templates
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
396diff
changeset | 23 | // (2) | 
| 347 | 24 | def get_first_price(symbol: String, year: Int) : Option[Double] = ??? | 
| 129 | 25 | |
| 26 | ||
| 425 
6e990ae2c6a3
updated solutions and templates
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
396diff
changeset | 27 | // (3) | 
| 347 | 28 | def get_prices(portfolio: List[String], years: Range) : List[List[Option[Double]]] = ??? | 
| 135 | 29 | |
| 129 | 30 | |
| 31 | ||
| 425 
6e990ae2c6a3
updated solutions and templates
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
396diff
changeset | 32 | // (4) | 
| 347 | 33 | def get_delta(price_old: Option[Double], price_new: Option[Double]) : Option[Double] = ??? | 
| 129 | 34 | |
| 199 | 35 | |
| 36 | ||
| 425 
6e990ae2c6a3
updated solutions and templates
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
396diff
changeset | 37 | // (5) | 
| 347 | 38 | def get_deltas(data: List[List[Option[Double]]]) : List[List[Option[Double]]] = ??? | 
| 135 | 39 | |
| 425 
6e990ae2c6a3
updated solutions and templates
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
396diff
changeset | 40 | // (6) | 
| 347 | 41 | def yearly_yield(data: List[List[Option[Double]]], balance: Long, index: Int) : Long = ??? | 
| 135 | 42 | |
| 129 | 43 | |
| 425 
6e990ae2c6a3
updated solutions and templates
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
396diff
changeset | 44 | // (7) | 
| 347 | 45 | def compound_yield(data: List[List[Option[Double]]], balance: Long, index: Int) : Long = ??? | 
| 129 | 46 | |
| 347 | 47 | def investment(portfolio: List[String], years: Range, start_balance: Long) : Long = ??? | 
| 129 | 48 | |
| 49 | ||
| 50 | ||
| 199 | 51 | |
| 52 | //Test cases for the two portfolios given above | |
| 129 | 53 | |
| 266 | 54 | //println("Real data: " + investment(rstate_portfolio, 1978 to 2019, 100))
 | 
| 55 | //println("Blue data: " + investment(blchip_portfolio, 1978 to 2019, 100))
 | |
| 129 | 56 | |
| 199 | 57 | |
| 281 | 58 | } |