main_templates1/drumb.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Sat, 23 Sep 2023 23:49:44 +0100
changeset 470 86a456f8cb92
parent 428 cdfa6a293453
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
396
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
     1
// Main Part 1 about a really dumb investment strategy
266
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
     2
//===================================================
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
396
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
     4
object M1 {
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
//two test portfolios
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
144
716042628398 updated
Christian Urban <urbanc@in.tum.de>
parents: 135
diff changeset
     8
val blchip_portfolio = List("GOOG", "AAPL", "MSFT", "IBM", "FB", "AMZN", "BIDU")
716042628398 updated
Christian Urban <urbanc@in.tum.de>
parents: 135
diff changeset
     9
val rstate_portfolio = List("PLD", "PSA", "AMT", "AIV", "AVB", "BXP", "CCI", 
199
54befaf23648 updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    10
                            "DLR", "EQIX", "EQR", "ESS", "EXR", "FRT", "HCP") 
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
135
077e63e96287 updated
Christian Urban <urbanc@in.tum.de>
parents: 132
diff changeset
    12
import io.Source
077e63e96287 updated
Christian Urban <urbanc@in.tum.de>
parents: 132
diff changeset
    13
import scala.util._
132
2ca6db82d207 updated
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
    14
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
    15
// ADD YOUR CODE BELOW
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
    16
//======================
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
    17
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
    18
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
    19
// (1) 
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 281
diff changeset
    20
def get_january_data(symbol: String, year: Int) : List[String] = ???
132
2ca6db82d207 updated
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
    21
135
077e63e96287 updated
Christian Urban <urbanc@in.tum.de>
parents: 132
diff changeset
    22
470
86a456f8cb92 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
    23
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
    24
// (2) 
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 281
diff changeset
    25
def get_first_price(symbol: String, year: Int) : Option[Double] = ???
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
    28
// (3) 
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 281
diff changeset
    29
def get_prices(portfolio: List[String], years: Range) : List[List[Option[Double]]] = ???
135
077e63e96287 updated
Christian Urban <urbanc@in.tum.de>
parents: 132
diff changeset
    30
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
    33
// (4) 
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 281
diff changeset
    34
def get_delta(price_old: Option[Double], price_new: Option[Double]) : Option[Double] = ???
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
199
54befaf23648 updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    36
54befaf23648 updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    37
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
    38
// (5) 
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 281
diff changeset
    39
def get_deltas(data: List[List[Option[Double]]]) :  List[List[Option[Double]]] = ???
135
077e63e96287 updated
Christian Urban <urbanc@in.tum.de>
parents: 132
diff changeset
    40
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
    41
// (6) 
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 281
diff changeset
    42
def yearly_yield(data: List[List[Option[Double]]], balance: Long, index: Int) : Long = ???
135
077e63e96287 updated
Christian Urban <urbanc@in.tum.de>
parents: 132
diff changeset
    43
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
    45
// (7) 
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 281
diff changeset
    46
def compound_yield(data: List[List[Option[Double]]], balance: Long, index: Int) : Long = ???
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 281
diff changeset
    48
def investment(portfolio: List[String], years: Range, start_balance: Long) : Long = ???
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
199
54befaf23648 updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    52
54befaf23648 updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    53
//Test cases for the two portfolios given above
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
266
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    55
//println("Real data: " + investment(rstate_portfolio, 1978 to 2019, 100))
ca48ac1d3c3e updated to 2.13
Christian Urban <urbanc@in.tum.de>
parents: 199
diff changeset
    56
//println("Blue data: " + investment(blchip_portfolio, 1978 to 2019, 100))
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
199
54befaf23648 updated
Christian Urban <urbanc@in.tum.de>
parents: 145
diff changeset
    58
281
87b9e3e2c1a7 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    59
}