main_marking1/drumb.scala
changeset 421 864107857d27
parent 388 0f7ed23161f9
child 460 f5c0749858fd
equal deleted inserted replaced
420:a6db2b70abdd 421:864107857d27
     1 // Main Part about a really dumb investment strategy
     1 // Main Part 1 about a really dumb investment strategy
     2 //======================================================
     2 //=====================================================
     3 
     3 
     4 object CW6b {
     4 
       
     5 // generate jar with
       
     6 //   > scala -d drumb.jar  drumb.scala
       
     7 
       
     8 
       
     9 object M1 { 
     5 
    10 
     6 
    11 
     7 //two test portfolios
    12 //two test portfolios
     8 
    13 
     9 val blchip_portfolio = List("GOOG", "AAPL", "MSFT", "IBM", "FB", "AMZN", "BIDU")
    14 val blchip_portfolio = List("GOOG", "AAPL", "MSFT", "IBM", "FB", "AMZN", "BIDU")
    17 //     It should read the corresponding CSV-file and reads the January 
    22 //     It should read the corresponding CSV-file and reads the January 
    18 //     data from the given year. The data should be collected in a list of
    23 //     data from the given year. The data should be collected in a list of
    19 //     strings for each line in the CSV-file.
    24 //     strings for each line in the CSV-file.
    20 
    25 
    21 def get_january_data(symbol: String, year: Int) : List[String] = 
    26 def get_january_data(symbol: String, year: Int) : List[String] = 
    22   Source.fromFile(symbol ++ ".csv")("ISO-8859-1").getLines.toList.filter(_.startsWith(year.toString))
    27   Source.fromFile(symbol ++ ".csv")("ISO-8859-1").getLines().toList.filter(_.startsWith(year.toString))
    23 
    28 
    24 
    29 
    25 //test cases
    30 //test cases
    26 //blchip_portfolio.map(get_january_data(_, 2018))
    31 //blchip_portfolio.map(get_january_data(_, 2018))
    27 //rstate_portfolio.map(get_january_data(_, 2018))
    32 //rstate_portfolio.map(get_january_data(_, 2018))
   162 
   167 
   163 
   168 
   164 
   169 
   165 //test cases for the two portfolios given above
   170 //test cases for the two portfolios given above
   166 
   171 
   167 //println("Real data: " + investment(rstate_portfolio, 1978 to 2019, 100))
   172   println("Real data: " + investment(rstate_portfolio, 1978 to 2019, 100))
   168 //println("Blue data: " + investment(blchip_portfolio, 1978 to 2019, 100))
   173   println("Blue data: " + investment(blchip_portfolio, 1978 to 2019, 100))
       
   174 
   169 
   175 
   170 }
   176 }
   171 
   177 
   172 
   178 
   173 
   179 
       
   180 
       
   181 
       
   182 
       
   183 
       
   184 
       
   185 
       
   186 
       
   187 
       
   188 
       
   189 
       
   190 
       
   191 
       
   192 
       
   193 
       
   194 
       
   195 
       
   196