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