templates1/drumb.scala
changeset 266 ca48ac1d3c3e
parent 199 54befaf23648
child 281 87b9e3e2c1a7
equal deleted inserted replaced
265:59779ce322a6 266:ca48ac1d3c3e
     1 // Part 2 and 3 about a really dumb investment strategy
     1 // Main Part about a really dumb investment strategy
     2 //======================================================
     2 //===================================================
     3 
     3 
     4 
     4 
     5 //two test portfolios
     5 //two test portfolios
     6 
     6 
     7 val blchip_portfolio = List("GOOG", "AAPL", "MSFT", "IBM", "FB", "AMZN", "BIDU")
     7 val blchip_portfolio = List("GOOG", "AAPL", "MSFT", "IBM", "FB", "AMZN", "BIDU")
     8 val rstate_portfolio = List("PLD", "PSA", "AMT", "AIV", "AVB", "BXP", "CCI", 
     8 val rstate_portfolio = List("PLD", "PSA", "AMT", "AIV", "AVB", "BXP", "CCI", 
     9                             "DLR", "EQIX", "EQR", "ESS", "EXR", "FRT", "HCP") 
     9                             "DLR", "EQIX", "EQR", "ESS", "EXR", "FRT", "HCP") 
    10 
    10 
    11 
    11 
    12 // (1) The function below takes a stock symbol and a year as arguments.
    12 // (1) The function below takes a stock symbol and a year as arguments.
    13 //     It should read the corresponding CSV-file and reads the January 
    13 //     It should read the corresponding CSV-file and then extract the January 
    14 //     data from the given year. The data should be collected in a list of
    14 //     data from the given year. The data should be collected in a list of
    15 //     strings for each line in the CSV-file.
    15 //     strings (one entry for each line in the CSV-file).
    16 
    16 
    17 import io.Source
    17 import io.Source
    18 import scala.util._
    18 import scala.util._
    19 
    19 
    20 //def get_january_data(symbol: String, year: Int) : List[String] = ...
    20 //def get_january_data(symbol: String, year: Int) : List[String] = ...
    21 
    21 
    22 
    22 
    23 // (2) From the output of the get_january_data function, the next function 
    23 // (2) From the output of the get_january_data function, the next function 
    24 //     should extract the first line (if it exists) and the corresponding
    24 //     should extract the first line (if it exists) and the corresponding
    25 //     first trading price in that year with type Option[Double]. If no line 
    25 //     first trading price in that year with type Option[Double]. If no line 
    26 //     is generated by get_january_data then the result is None; Some if 
    26 //     is generated by get_january_data then the result is None; and Some if 
    27 //     there is a price.
    27 //     there is a price.
    28 
    28 
    29 
    29 
    30 //def get_first_price(symbol: String, year: Int) : Option[Double] = ...
    30 //def get_first_price(symbol: String, year: Int) : Option[Double] = ...
    31 
    31 
    36 //     stock symbols and the outer list for the years.
    36 //     stock symbols and the outer list for the years.
    37 
    37 
    38 
    38 
    39 //def get_prices(portfolio: List[String], years: Range) : List[List[Option[Double]]] = ...
    39 //def get_prices(portfolio: List[String], years: Range) : List[List[Option[Double]]] = ...
    40 
    40 
    41 
       
    42 
       
    43 
       
    44 //==============================================
       
    45 // Do not change anything below, unless you want 
       
    46 // to submit the file for the advanced part 3!
       
    47 //==============================================
       
    48 
    41 
    49 
    42 
    50 // (4) The function below calculates the change factor (delta) between
    43 // (4) The function below calculates the change factor (delta) between
    51 //     a price in year n and a price in year n + 1. 
    44 //     a price in year n and a price in year n + 1. 
    52 
    45 
    82 
    75 
    83 
    76 
    84 
    77 
    85 //Test cases for the two portfolios given above
    78 //Test cases for the two portfolios given above
    86 
    79 
    87 //println("Real data: " + investment(rstate_portfolio, 1978 to 2018, 100))
    80 //println("Real data: " + investment(rstate_portfolio, 1978 to 2019, 100))
    88 //println("Blue data: " + investment(blchip_portfolio, 1978 to 2018, 100))
    81 //println("Blue data: " + investment(blchip_portfolio, 1978 to 2019, 100))
    89 
    82 
    90 
    83