diff -r d58954a96ec1 -r 077e63e96287 templates/drumb.scala --- a/templates/drumb.scala Wed Nov 08 16:08:16 2017 +0000 +++ b/templates/drumb.scala Wed Nov 08 20:27:56 2017 +0000 @@ -1,4 +1,4 @@ -// Advanvced Part 3 about a really dumb investment strategy +// Advanced Part 3 about a really dumb investment strategy //========================================================== object CW6c { @@ -11,68 +11,66 @@ "DLR", "EQIX", "EQR", "ESS", "EXR", "FRT", "GGP", "HCP") -// (1.a) The function below takes a stock symbol and a year as argument. -// It should read the corresponding CSV-file and read the january -// data from that year. The data should be collected in a list of -// strings for each line in the CSV file. +// (1.a) The function below takes a stock symbol and a year as arguments. +// It should read the corresponding CSV-file and read the January +// data from the given year. The data should be collected in a list of +// strings for each line in the CSV-file. + +import io.Source +import scala.util._ //def get_january_data(symbol: String, year: Int) : List[String] = ... -// -// http://ichart.yahoo.com/table.csv?s=<>&a=0&b=1&c=<>&d=1&e=1&f=<> -// -// and extracting the first January Adjusted Close price in a year. -// + // (1.b) From the output of the get_january_data function, the next function // should extract the first line (if it exists) and the corresponding // first trading price in that year as Option[Double]. If no line is -// given -// +// generated by get_january_data then the result is None + //def get_first_price(symbol: String, year: Int) : Option[Double] = ... -// Complete the function below that obtains all first prices -// for the stock symbols from a portfolio for the given -// range of years +// (1.c) Complete the function below that obtains all first prices +// for the stock symbols from a portfolio (list of strings) and +// for the given range of years. The inner lists are for the +// stock symbols and the outer list for the years. -//def get_prices(portfolio: List[String], years: Range): List[List[Option[Double]]] = ... -// test case -//val p = get_prices(List("GOOG", "AAPL"), 2010 to 2012) +//def get_prices(portfolio: List[String], years: Range) : List[List[Option[Double]]] = ... + // (2) The first function below calculates the change factor (delta) between -// a price in year n and a price in year n+1. The second function calculates -// all change factors for all prices (from a portfolio). - -//def get_delta(price_old: Option[Double], price_new: Option[Double]): Option[Double] = ... +// a price in year n and a price in year n + 1. The second function calculates +// all change factors for all prices (from a portfolio). The input to this +// function are the nested lists created by get_prices above. -//def get_deltas(data: List[List[Option[Double]]]): List[List[Option[Double]]] = ... +//def get_delta(price_old: Option[Double], price_new: Option[Double]) : Option[Double] = ... -// test case using the prices calculated above -//val d = get_deltas(p) +//def get_deltas(data: List[List[Option[Double]]]) : List[List[Option[Double]]] = ... + // (3) Write a function that given change factors, a starting balance and a year -// calculates the yearly yield, i.e. new balanace, according to our dump investment -// strategy. Another function calculates given the same data calculates the -// compound yield up to a given year. Finally a function combines all -// calculations by taking a portfolio, a range of years and a start balance -// as arguments. +// calculates the yearly yield, i.e. new balance, according to our dump investment +// strategy. Another function calculates given the same data calculates the +// compound yield up to a given year. Finally a function combines all +// calculations by taking a portfolio, a range of years and a start balance +// as arguments. + -//def yearly_yield(data: List[List[Option[Double]]], balance: Long, year: Int): Long = ... +//def yearly_yield(data: List[List[Option[Double]]], balance: Long, year: Int) : Long = ... + +//def compound_yield(data: List[List[Option[Double]]], balance: Long, year: Int) : Long = ... -//test case -//yearly_yield(d, 100, 0) +//def investment(portfolio: List[String], years: Range, start_balance: Long) : Long = ... -//def compound_yield(data: List[List[Option[Double]]], balance: Long, year: Int): Long = ... -//def investment(portfolio: List[String], years: Range, start_balance: Long): Long = ... //test cases for the two portfolios given above -//investment(rstate_portfolio, 1978 to 2016, 100) -//investment(blchip_portfolio, 1978 to 2016, 100) +//investment(rstate_portfolio, 1978 to 2017, 100) +//investment(blchip_portfolio, 1978 to 2017, 100) }