progs/drumb_sol.scala
author Christian Urban <urbanc@in.tum.de>
Wed, 08 Nov 2017 02:06:54 +0000
changeset 129 b1a51285de7e
parent 82 28c8e17ab83a
child 131 1fb90f5d53ee
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
     1
// Advanvced Part 3 about a really dumb investment strategy
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
     2
//==========================================================
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
     3
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
     4
object CW6c {
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
     5
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
//two test portfolios
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
     9
val blchip_portfolio = List("GOOG", "AAPL", "MSFT", "IBM", "FB", "AMZN", "BIDU")
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    10
val rstate_portfolio = List("PLD", "PSA", "AMT", "AIV", "AVB", "BXP", "CCI", 
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
                            "DLR", "EQIX", "EQR", "ESS", "EXR", "FRT", "GGP", "HCP") 
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
26
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    13
// (1) The function below should obtain the first trading price
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    14
// for a stock symbol by using the query
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    15
//
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    16
//    http://ichart.yahoo.com/table.csv?s=<<symbol>>&a=0&b=1&c=<<year>>&d=1&e=1&f=<<year>> 
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    17
// 
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    18
// and extracting the first January Adjusted Close price in a year.
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    20
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
import io.Source
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
import scala.util._
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    24
def get_january_data(symbol: String, year: Int) : List[String] = 
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    25
  Source.fromFile(symbol ++ ".csv")("ISO-8859-1").getLines.toList.filter(_.startsWith(year.toString))
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    26
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    27
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    28
get_trading_data("FB", 2015)
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    29
get_trading_data("GOOG", 2010).head
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    30
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    31
def get_first_price(symbol: String, year: Int) : Option[Double] = {
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    32
  val data = Try(Some(get_january_data(symbol, year).head)) getOrElse None 
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    33
  data.map(_.split(",").toList(1).toDouble)
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
}
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    36
get_first_price("GOOG", 1980)
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    37
get_first_price("GOOG", 2010)
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    38
get_first_price("FB", 2014)
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
26
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    40
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    41
// Complete the function below that obtains all first prices
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    42
// for the stock symbols from a portfolio for the given
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    43
// range of years
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    44
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
def get_prices(portfolio: List[String], years: Range): List[List[Option[Double]]] = 
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  for (year <- years.toList) yield
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
    for (symbol <- portfolio) yield get_first_price(symbol, year)
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
26
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    49
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    50
// test case
62
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
    51
val p_fb = get_prices(List("FB"), 2012 to 2014)
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    52
val p = get_prices(List("GOOG", "AAPL"), 2010 to 2012)
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
82
28c8e17ab83a updated
Christian Urban <urbanc@in.tum.de>
parents: 81
diff changeset
    54
val tt = get_prices(List("IBM", "BIDU"), 2004 to 2008)
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
26
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    56
// (2) The first function below calculates the change factor (delta) between
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    57
// a price in year n and a price in year n+1. The second function calculates
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    58
// all change factors for all prices (from a portfolio).
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    59
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    60
def get_delta(price_old: Option[Double], price_new: Option[Double]) : Option[Double] = {
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  (price_old, price_new) match {
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
    case (Some(x), Some(y)) => Some((y - x) / x)
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
    case _ => None
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
  }
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
}
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
def get_deltas(data: List[List[Option[Double]]]):  List[List[Option[Double]]] =
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  for (i <- (0 until (data.length - 1)).toList) yield 
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
    for (j <- (0 until (data(0).length)).toList) yield get_delta(data(i)(j), data(i + 1)(j))
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
26
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    71
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    72
// test case using the prices calculated above
52
7a4fe3f6b188 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
    73
val d = get_deltas(p)
82
28c8e17ab83a updated
Christian Urban <urbanc@in.tum.de>
parents: 81
diff changeset
    74
val ttd = get_deltas(tt)
26
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    75
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    76
// (3) Write a function that given change factors, a starting balance and a year
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    77
// calculates the yearly yield, i.e. new balanace, according to our dump investment 
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    78
// strategy. Another function calculates given the same data calculates the
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    79
// compound yield up to a given year. Finally a function combines all 
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    80
// calculations by taking a portfolio, a range of years and a start balance
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    81
// as arguments.
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    82
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
    83
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
def yearly_yield(data: List[List[Option[Double]]], balance: Long, year: Int): Long = {
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  val somes = data(year).flatten
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  val somes_length = somes.length
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  if (somes_length == 0) balance
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  else {
62
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
    89
    val portion: Double = balance.toDouble / somes_length.toDouble
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
    balance + (for (x <- somes) yield (x * portion)).sum.toLong
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  }
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
}
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    94
yearly_yield(d, 100, 0)
82
28c8e17ab83a updated
Christian Urban <urbanc@in.tum.de>
parents: 81
diff changeset
    95
yearly_yield(ttd, 100, 1)
28c8e17ab83a updated
Christian Urban <urbanc@in.tum.de>
parents: 81
diff changeset
    96
yearly_yield(ttd, 100, 2)
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    97
yearly_yield(ttd, 100, 3) 
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    98
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
    99
assert((yearly_yield(ttd, 100, 0) - 107).abs <= 2)
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
   100
assert((yearly_yield(ttd, 100, 1) - 85).abs <= 2)
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
   101
assert((yearly_yield(ttd, 100, 2) - 156).abs <= 2)
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
   102
assert((yearly_yield(ttd, 100, 3) - 210).abs <= 2)
82
28c8e17ab83a updated
Christian Urban <urbanc@in.tum.de>
parents: 81
diff changeset
   103
28c8e17ab83a updated
Christian Urban <urbanc@in.tum.de>
parents: 81
diff changeset
   104
28c8e17ab83a updated
Christian Urban <urbanc@in.tum.de>
parents: 81
diff changeset
   105
26
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
   106
//test case
52
7a4fe3f6b188 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   107
yearly_yield(d, 100, 0)
7a4fe3f6b188 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   108
yearly_yield(d, 225, 1)
7a4fe3f6b188 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   109
yearly_yield(d, 246, 2)
7a4fe3f6b188 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   110
yearly_yield(d, 466, 3)
7a4fe3f6b188 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   111
yearly_yield(d, 218, 4)
7a4fe3f6b188 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   112
yearly_yield(d, 469, 5)
7a4fe3f6b188 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   113
yearly_yield(d, 587, 6)
26
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
   114
//yearly_yield(d, 100, 0)
52
7a4fe3f6b188 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   115
//yearly_yield(d, 125, 1)
26
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
   116
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
def compound_yield(data: List[List[Option[Double]]], balance: Long, year: Int): Long = {
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  if (year >= data.length) balance else {
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
    val new_balance = yearly_yield(data, balance, year)
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
    compound_yield(data, new_balance, year + 1)
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  }
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
}
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
52
7a4fe3f6b188 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   124
compound_yield(d.take(6), 100, 0)
7a4fe3f6b188 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   125
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
def investment(portfolio: List[String], years: Range, start_balance: Long): Long = {
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
  compound_yield(get_deltas(get_prices(portfolio, years)), start_balance, 0)
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
}
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
52
7a4fe3f6b188 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 39
diff changeset
   130
investment(List("GOOG", "AAPL"), 2005 to 2009, 100)
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
26
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
   132
//test cases for the two portfolios given above
a7afc2540a88 updated
Christian Urban <urbanc@in.tum.de>
parents: 18
diff changeset
   133
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
   134
println("Real data: " + investment(rstate_portfolio, 1978 to 2017, 100))
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
   135
println("Blue data: " + investment(blchip_portfolio, 1978 to 2017, 100))
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
82
28c8e17ab83a updated
Christian Urban <urbanc@in.tum.de>
parents: 81
diff changeset
   137
28c8e17ab83a updated
Christian Urban <urbanc@in.tum.de>
parents: 81
diff changeset
   138
investment(List("IBM", "BIDU"), 2004 to 2008, 100)
28c8e17ab83a updated
Christian Urban <urbanc@in.tum.de>
parents: 81
diff changeset
   139
62
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   140
val p_fb = get_prices(List("FB"), 2011 to 2016)
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   141
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   142
// prices 2011 - 2016
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   143
//    
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   144
List(List(None), List(None), List(Some(28.0)), 
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   145
     List(Some(54.709999)), List(Some(78.449997)), 
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   146
     List(Some(102.220001)))
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   147
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   148
// deltas 2011 - 2016
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   149
val d_fb = get_deltas(p_fb)
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   150
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   151
List(List(None), List(None), List(Some(0.9539285357142858)), 
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   152
     List(Some(0.4339242996513305)), List(Some(0.30299560113431234)))
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   153
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   154
yearly_yield(d_fb, 100, 0)   //2011  => 100
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   155
yearly_yield(d_fb, 100, 1)   //2012  => 100
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   156
yearly_yield(d_fb, 100, 2)   //2013  => 195
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   157
yearly_yield(d_fb, 195, 3)   //2014  => 279   
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   158
yearly_yield(d_fb, 279, 4)   //2015  => 363
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   159
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   160
investment(List("FB"), 2011 to 2012, 100)  // => 100
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   161
investment(List("FB"), 2011 to 2013, 100)  // => 100
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   162
investment(List("FB"), 2011 to 2014, 100)  // => 195
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   163
investment(List("FB"), 2011 to 2015, 100)  // => 279
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   164
investment(List("FB"), 2011 to 2016, 100)  // => 363
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   165
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   166
64
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   167
val rs_p = get_prices(rstate_portfolio, 1978 to 2016)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   168
val bl_p = get_prices(blchip_portfolio, 1978 to 2016)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   169
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   170
val rs_d = get_deltas(rs_p)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   171
val bl_d = get_deltas(bl_p)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   172
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   173
rs_p(0)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   174
    <-
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   175
rs_p(1)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   176
    <- 
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   177
rs_p(2)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   178
    <- 
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   179
rs_p(3)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   180
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   181
rs_d(0)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   182
rs_d(1)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   183
rs_d(2)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   184
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   185
yearly_yield(rs_d, 100, 0)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   186
yearly_yield(rs_d, 96, 1)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   187
yearly_yield(rs_d, 95, 2)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   188
yearly_yield(rs_d, 134, 3)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   189
yearly_yield(rs_d, 126, 4)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   190
yearly_yield(rs_d, 169, 5)
d6f97b562424 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   191
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 82
diff changeset
   192
}