main_testing1/drumb.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Thu, 04 Nov 2021 12:20:12 +0000
changeset 395 e0a82c9f1d21
parent 363 9f481fd7c613
child 402 72e43cb53c13
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
282
2d290b79fc73 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     1
// Core Part 6 about a really dumb investment strategy
2d290b79fc73 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     2
//=====================================================
2d290b79fc73 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     3
208
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
282
2d290b79fc73 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     5
// generate jar with
2d290b79fc73 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     6
//   > scala -d drumb.jar  drumb.scala
2d290b79fc73 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     7
2d290b79fc73 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     8
2d290b79fc73 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     9
object CW6b { 
208
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
//two test portfolios
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
val blchip_portfolio = List("GOOG", "AAPL", "MSFT", "IBM", "FB", "AMZN", "BIDU")
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
val rstate_portfolio = List("PLD", "PSA", "AMT", "AIV", "AVB", "BXP", "CCI", 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
                            "DLR", "EQIX", "EQR", "ESS", "EXR", "FRT", "HCP") 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
import io.Source
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
import scala.util._
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
// (1) The function below takes a stock symbol and a year as arguments.
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
//     It should read the corresponding CSV-file and reads the January 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
//     data from the given year. The data should be collected in a list of
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
//     strings for each line in the CSV-file.
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
def get_january_data(symbol: String, year: Int) : List[String] = 
347
0b727d1a8184 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 329
diff changeset
    27
  Source.fromFile(symbol ++ ".csv")("ISO-8859-1").getLines().toList.filter(_.startsWith(year.toString))
208
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
//test cases
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
//blchip_portfolio.map(get_january_data(_, 2018))
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
//rstate_portfolio.map(get_january_data(_, 2018))
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
//get_january_data("GOOG", 1980)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
//get_january_data("GOOG", 2010)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
//get_january_data("FB", 2014)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
//get_january_data("PLD", 1980)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
//get_january_data("EQIX", 2010)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
//get_january_data("ESS", 2014)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
// (2) From the output of the get_january_data function, the next function 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
//     should extract the first line (if it exists) and the corresponding
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
//     first trading price in that year with type Option[Double]. If no line 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
//     is generated by get_january_data then the result is None; Some if 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
//     there is a price.
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
def get_first_price(symbol: String, year: Int) : Option[Double] = {
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  val data = Try(Some(get_january_data(symbol, year).head)) getOrElse None 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  data.map(_.split(",").toList(1).toDouble)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
}
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
//test cases
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
//get_first_price("GOOG", 1980)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
//get_first_price("GOOG", 2010)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
//get_first_price("FB", 2014)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
/*
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
for (i <- 1978 to 2018) {
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  println(blchip_portfolio.map(get_first_price(_, i)))
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
}
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
for (i <- 1978 to 2018) {
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  println(rstate_portfolio.map(get_first_price(_, i)))
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
}
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
*/ 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
// (3) Complete the function below that obtains all first prices
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
//     for the stock symbols from a portfolio (list of strings) and 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
//     for the given range of years. The inner lists are for the
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
//     stock symbols and the outer list for the years.
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
def get_prices(portfolio: List[String], years: Range): List[List[Option[Double]]] = 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  for (year <- years.toList) yield
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
    for (symbol <- portfolio) yield get_first_price(symbol, year)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
//test cases
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
266
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    82
//println("Task 3 data from Google and Apple in 2010 to 2012")
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    83
//val goog_aapl_prices = get_prices(List("GOOG", "AAPL"), 2010 to 2012)
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    84
//println(goog_aapl_prices.toString ++ "\n")
208
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
266
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    86
//val p_fb = get_prices(List("FB"), 2012 to 2014)
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    87
//val tt = get_prices(List("BIDU"), 2004 to 2008)
208
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
// (4) The function below calculates the change factor (delta) between
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
//     a price in year n and a price in year n + 1. 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
def get_delta(price_old: Option[Double], price_new: Option[Double]) : Option[Double] = {
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  (price_old, price_new) match {
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
    case (Some(x), Some(y)) => Some((y - x) / x)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
    case _ => None
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  }
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
}
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
// (5) The next function calculates all change factors for all prices (from a 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
//     portfolio). The input to this function are the nested lists created by 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
//     get_prices above.
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
def get_deltas(data: List[List[Option[Double]]]):  List[List[Option[Double]]] =
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
  for (i <- (0 until (data.length - 1)).toList) yield 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
    for (j <- (0 until (data(0).length)).toList) yield get_delta(data(i)(j), data(i + 1)(j))
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
229
cfcaf4a5e5b4 updated
Christian Urban <urbanc@in.tum.de>
parents: 208
diff changeset
   110
208
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
// test case using the prices calculated above
266
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   112
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   113
//println("Task 5 change prices from Google and Apple in 2010 and 2011")
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   114
//val goog_aapl_deltas = get_deltas(goog_aapl_prices)
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   115
//println(goog_aapl_deltas.toString ++ "\n")
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   116
208
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
//val ttd = get_deltas(tt)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
// (6) Write a function that given change factors, a starting balance and an index,
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
//     calculates the yearly yield, i.e. new balance, according to our dumb investment 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
//     strategy. Index points to a year in the data list.
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
def yearly_yield(data: List[List[Option[Double]]], balance: Long, index: Int): Long = {
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  val somes = data(index).flatten
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
  val somes_length = somes.length
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  if (somes_length == 0) balance
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
  else {
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
    val portion: Double = balance.toDouble / somes_length.toDouble
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
    balance + (for (x <- somes) yield (x * portion)).sum.toLong
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
  }
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
}
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
266
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   134
// test case using the deltas calculated above
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   135
//println("Task 6 yield from Google and Apple in 2010 with  balance 100")
208
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
266
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   137
//val d0 = goog_aapl_deltas(0)(0)
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   138
//val d1 = goog_aapl_deltas(0)(1)
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   139
//println(s"50 * ${d0.get} + 50 * ${d1.get} = ${50.toDouble * d0.get + 50.toDouble * d1.get}")
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   140
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   141
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   142
//val goog_aapl_yield = yearly_yield(goog_aapl_deltas, 100, 0)
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   143
//println("Rounded yield: " ++ goog_aapl_yield.toString ++ "\n")
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   144
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   145
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   146
//yearly_yield(get_prices(rstate_portfolio, 2016 to 2018), 100, 2) 
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   147
//get_prices(rstate_portfolio, 2016 to 2018)(2).flatten.sum
229
cfcaf4a5e5b4 updated
Christian Urban <urbanc@in.tum.de>
parents: 208
diff changeset
   148
cfcaf4a5e5b4 updated
Christian Urban <urbanc@in.tum.de>
parents: 208
diff changeset
   149
208
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
// (7) Write a function compound_yield that calculates the overall balance for a 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
//     range of years where in each year the yearly profit is compounded to the new 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
//     balances and then re-invested into our portfolio. For this use the function and 
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
//     results generated under (6). The function investment calls compound_yield
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
//     with the appropriate deltas and the first index.
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
def compound_yield(data: List[List[Option[Double]]], balance: Long, index: Int): Long = {
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
  if (index >= data.length) balance else {
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
    val new_balance = yearly_yield(data, balance, index)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
    compound_yield(data, new_balance, index + 1)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
  }
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
}
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
def investment(portfolio: List[String], years: Range, start_balance: Long): Long = {
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
  compound_yield(get_deltas(get_prices(portfolio, years)), start_balance, 0)
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
}
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
363
9f481fd7c613 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
   170
9f481fd7c613 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
   171
investment(List("AAPL"), 2000 to 2001, 100)
9f481fd7c613 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
   172
val aapl_prices = get_prices(List("AAPL"), 2000 to 2002)
9f481fd7c613 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
   173
val aapl_deltas = get_deltas(aapl_prices)
9f481fd7c613 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
   174
208
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
//test cases for the two portfolios given above
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
266
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   177
//println("Real data: " + investment(rstate_portfolio, 1978 to 2019, 100))
31e5218f43de updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   178
//println("Blue data: " + investment(blchip_portfolio, 1978 to 2019, 100))
208
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
}
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
ab0ccbc8271f updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183