| 39 |      1 | // Advanvced Part 3 about really dumb investing strategy
 | 
| 26 |      2 | //=======================================================
 | 
| 18 |      3 | 
 | 
|  |      4 | //two test portfolios
 | 
|  |      5 | 
 | 
|  |      6 | val blchip_portfolio = List("GOOG", "AAPL", "MSFT", "IBM", "FB", "YHOO", "AMZN", "BIDU")
 | 
|  |      7 | val rstate_portfolio = List("PLD", "PSA", "AMT", "AIV", "AVB", "BXP", "CBG", "CCI", 
 | 
| 133 |      8 |                             "DLR", "EQIX", "EQR", "ESS", "EXR", "FRT", "GGP", "HCP") 
 | 
| 18 |      9 | 
 | 
|  |     10 | 
 | 
| 26 |     11 | // (1) The function below should obtain the first trading price
 | 
|  |     12 | // for a stock symbol by using the query
 | 
|  |     13 | //
 | 
|  |     14 | //    http://ichart.yahoo.com/table.csv?s=<<symbol>>&a=0&b=1&c=<<year>>&d=1&e=1&f=<<year>> 
 | 
|  |     15 | // 
 | 
|  |     16 | // and extracting the first January Adjusted Close price in a year.
 | 
| 18 |     17 | 
 | 
| 19 |     18 | def get_first_price(symbol: String, year: Int): Option[Double] = ...
 | 
| 18 |     19 | 
 | 
| 26 |     20 | // Complete the function below that obtains all first prices
 | 
|  |     21 | // for the stock symbols from a portfolio for the given
 | 
|  |     22 | // range of years
 | 
|  |     23 | 
 | 
| 19 |     24 | def get_prices(portfolio: List[String], years: Range): List[List[Option[Double]]] = ...
 | 
| 18 |     25 | 
 | 
| 26 |     26 | // test case
 | 
|  |     27 | //val p = get_prices(List("GOOG", "AAPL"), 2010 to 2012)
 | 
|  |     28 | 
 | 
| 18 |     29 | 
 | 
| 26 |     30 | // (2) The first function below calculates the change factor (delta) between
 | 
|  |     31 | // a price in year n and a price in year n+1. The second function calculates
 | 
|  |     32 | // all change factors for all prices (from a portfolio).
 | 
| 18 |     33 | 
 | 
| 19 |     34 | def get_delta(price_old: Option[Double], price_new: Option[Double]): Option[Double] = ...
 | 
| 18 |     35 | 
 | 
| 19 |     36 | def get_deltas(data: List[List[Option[Double]]]):  List[List[Option[Double]]] = ...
 | 
| 18 |     37 | 
 | 
| 26 |     38 | // test case using the prices calculated above
 | 
| 19 |     39 | //val d = get_deltas(p)
 | 
| 18 |     40 | 
 | 
|  |     41 | 
 | 
| 26 |     42 | // (3) Write a function that given change factors, a starting balance and a year
 | 
|  |     43 | // calculates the yearly yield, i.e. new balanace, according to our dump investment 
 | 
|  |     44 | // strategy. Another function calculates given the same data calculates the
 | 
|  |     45 | // compound yield up to a given year. Finally a function combines all 
 | 
|  |     46 | // calculations by taking a portfolio, a range of years and a start balance
 | 
|  |     47 | // as arguments.
 | 
| 18 |     48 | 
 | 
| 19 |     49 | def yearly_yield(data: List[List[Option[Double]]], balance: Long, year: Int): Long = ... 
 | 
|  |     50 | 
 | 
| 26 |     51 | //test case
 | 
| 19 |     52 | //yearly_yield(d, 100, 0)
 | 
|  |     53 | 
 | 
|  |     54 | def compound_yield(data: List[List[Option[Double]]], balance: Long, year: Int): Long = ... 
 | 
|  |     55 | 
 | 
|  |     56 | def investment(portfolio: List[String], years: Range, start_balance: Long): Long = ...
 | 
|  |     57 | 
 | 
|  |     58 | 
 | 
| 26 |     59 | //test cases for the two portfolios given above
 | 
| 19 |     60 | //investment(rstate_portfolio, 1978 to 2016, 100)
 | 
|  |     61 | //investment(blchip_portfolio, 1978 to 2016, 100)
 | 
|  |     62 | 
 |