cws/cw01.tex
author Christian Urban <urbanc@in.tum.de>
Sat, 03 Nov 2018 11:07:44 +0000
changeset 195 fc3ac7b70a06
parent 192 a112e0e2325c
child 196 c50b074b3047
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
\documentclass{article}
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
     2
\usepackage{../style}
195
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
     3
\usepackage{disclaimer}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
%%\usepackage{../langs}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
\begin{document}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
9
48a477fdef21 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 6
diff changeset
     8
\section*{Coursework 6 (Scala)}
31
d0caa12ab8d8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 30
diff changeset
     9
 
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
    10
This coursework is about Scala and is worth 10\%. The first and second
195
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    11
part are due on 15 November at 11pm, and the third part on 20 December
29
fde9223a5301 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 28
diff changeset
    12
at 11pm. You are asked to implement three programs about list
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    13
processing and recursion. The third part is more advanced and might
195
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    14
include material you have not yet seen in the lecture.
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
    15
Make sure the files you submit can be processed by just calling
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
    16
\texttt{scala <<filename.scala>>}.\bigskip
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
    17
195
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    18
\IMPORTANT{}
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    19
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    20
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
    21
\noindent
195
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    22
Also note that the running time of each part will be restricted to a
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    23
maximum of 60 seconds on my laptop.
28
f50c6a61a3a2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 24
diff changeset
    24
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
    25
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
    26
\subsection*{Disclaimer}
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
    27
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
    28
It should be understood that the work you submit represents
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
    29
your own effort. You have not copied from anyone else. An
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
    30
exception is the Scala code I showed during the lectures or
195
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    31
uploaded to KEATS, which you can freely use. If you want to
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    32
look up anything from the Scala library, the link to the api
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    33
is
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    34
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    35
\begin{center}
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    36
\url{http://www.scala-lang.org/api/current/}
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    37
\end{center}  
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    38
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    39
\noindent
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    40
I usually google for things like \texttt{scala} \texttt{library} \texttt{groupBy}
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    41
and click on the link about the Scala Standard Library for more information.
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    42
\bigskip
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    45
\subsection*{Part 1 (3 Marks)}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
    47
This part is about recursion. You are asked to implement a Scala
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    48
program that tests examples of the \emph{$3n + 1$-conjecture}, also
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    49
called \emph{Collatz conjecture}. This conjecture can be described as
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    50
follows: Start with any positive number $n$ greater than $0$:
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    51
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    52
\begin{itemize}
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    53
\item If $n$ is even, divide it by $2$ to obtain $n / 2$.
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    54
\item If $n$ is odd, multiply it by $3$ and add $1$ to obtain $3n +
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    55
  1$.
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    56
\item Repeat this process and you will always end up with $1$.
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    57
\end{itemize}
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    58
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    59
\noindent
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    60
For example if you start with $6$, respectively $9$, you obtain the
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    61
series
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
    62
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
    63
\[
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
    64
\begin{array}{@{}l@{\hspace{5mm}}l@{}}
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    65
6, 3, 10, 5, 16, 8, 4, 2, 1 & \text{(= 9 steps)}\\
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    66
9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1  & \text{(= 20 steps)}\\
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
    67
\end{array}
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
    68
\]
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
    69
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
    70
\noindent
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
    71
As you can see, the numbers go up and down like a roller-coaster, but
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    72
curiously they seem to always terminate in $1$. The conjecture is that
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    73
this will \emph{always} happen for every number greater than
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    74
0.\footnote{While it is relatively easy to test this conjecture with
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    75
  particular numbers, it is an interesting open problem to
195
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    76
  \emph{prove} that the conjecture is true for \emph{all} numbers
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    77
  ($> 0$). Paul Erd\"o{}s, a famous mathematician you might have hard
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    78
  about, is quoted to have said about this conjecture: ``Mathematics
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    79
  is not yet ripe enough for such questions.''  and also offered a
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    80
  \$500 cash prize for its solution. Jeffrey Lagarias, another
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    81
  mathematician, claimed that based only on known information about
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    82
  this problem, ``this is an extraordinarily difficult problem,
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    83
  completely out of reach of present day mathematics.'' There is also
fc3ac7b70a06 updated
Christian Urban <urbanc@in.tum.de>
parents: 192
diff changeset
    84
  a \href{https://xkcd.com/710/}{xkcd} cartoon about this conjecture
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    85
  (click \href{https://xkcd.com/710/}{here}). If you are able to solve
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    86
  this conjecture, you will definitely get famous.}\bigskip
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    87
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
    88
\newpage
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    89
\noindent
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    90
\textbf{Tasks (file collatz.scala):}
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    91
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    92
\begin{itemize}
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    93
\item[(1)] You are asked to implement a recursive function that
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    94
  calculates the number of steps needed until a series ends
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    95
  with $1$. In case of starting with $6$, it takes $9$ steps and in
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    96
  case of starting with $9$, it takes $20$ (see above). In order to
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    97
  try out this function with large numbers, you should use
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    98
  \texttt{Long} as argument type, instead of \texttt{Int}.  You can
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
    99
  assume this function will be called with numbers between $1$ and
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   100
  $1$ million. \hfill[2 Marks]
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   101
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   102
\item[(2)] Write a second function that takes an upper bound as
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   103
  argument and calculates the steps for all numbers in the range from
20
07860dd35c2b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 18
diff changeset
   104
  1 up to this bound. It returns the maximum number of steps and the
31
d0caa12ab8d8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 30
diff changeset
   105
  corresponding number that needs that many steps.  More precisely
24
66b97f9a40f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 20
diff changeset
   106
  it returns a pair where the first
66b97f9a40f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 20
diff changeset
   107
  component is the number of steps and the second is the
66b97f9a40f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 20
diff changeset
   108
  corresponding number. \hfill\mbox{[1 Mark]}
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   109
\end{itemize}
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
   110
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
   111
\noindent
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   112
\textbf{Test Data:} Some test ranges are:
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
   113
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
   114
\begin{itemize}
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   115
\item 1 to 10 where $9$ takes 20 steps 
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   116
\item 1 to 100 where $97$ takes 119 steps,
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   117
\item 1 to 1,000 where $871$ takes 179 steps,
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   118
\item 1 to 10,000 where $6,171$ takes 262 steps,
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   119
\item 1 to 100,000 where $77,031$ takes 351 steps, 
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   120
\item 1 to 1 million where $837,799$ takes 525 steps
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   121
  %%\item[$\bullet$] $1 - 10$ million where $8,400,511$ takes 686 steps
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   122
\end{itemize}\bigskip
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   123
  
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
   124
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
   125
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   126
\subsection*{Part 2 (4 Marks)}
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   127
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   128
This part is about list processing---it's a variant of
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   129
``buy-low-sell-high'' in Scala. It uses the online financial data
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   130
service from Yahoo.\bigskip 
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   131
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   132
\noindent
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   133
\textbf{Tasks (file trade.scala):}
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   134
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   135
\begin{itemize}
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   136
\item[(1)] Given a list of prices for a commodity, for example
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
   137
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   138
\[
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   139
\texttt{List(28.0, 18.0, 20.0, 26.0, 24.0)}
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   140
\]
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
   141
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   142
\noindent
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   143
you need to write a function that returns a pair of indices for when
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   144
to buy and when to sell this commodity. In the example above it should
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   145
return the pair $\texttt{(1, 3)}$ because at index $1$ the price is lowest and
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   146
then at index $3$ the price is highest. Note the prices are given as
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   147
lists of \texttt{Double}s.\newline \mbox{} \hfill[1 Mark]
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   148
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   149
\item[(2)] Write a function that requests a comma-separated value (CSV) list
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   150
  from the Yahoo websevice that provides historical data for stock
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   151
  indices. For example if you query the URL
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   152
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   153
\begin{center}
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   154
\url{http://ichart.yahoo.com/table.csv?s=GOOG}
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   155
\end{center}
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
   156
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   157
\noindent where \texttt{GOOG} stands for Google's stock market symbol,
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   158
then you will receive a CSV-list of the daily stock prices since
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   159
Google was listed. You can also try this with other stock market
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   160
symbols, for instance AAPL, MSFT, IBM, FB, YHOO, AMZN, BIDU and so
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   161
on. 
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   162
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   163
This function should return a List of strings, where each string
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   164
is one line in this CVS-list (representing one day's
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   165
data). Note that Yahoo generates its answer such that the newest data
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   166
is at the front of this list, and the oldest data is at the end.
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   167
\hfill[1 Mark]
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   168
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   169
\item[(3)] As you can see, the financial data from Yahoo is organised in 7 columns,
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   170
for example
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   171
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   172
{\small\begin{verbatim}
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   173
Date,Open,High,Low,Close,Volume,Adj Close
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   174
2016-11-04,750.659973,770.359985,750.560974,762.02002,2126900,762.02002
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   175
2016-11-03,767.25,769.950012,759.030029,762.130005,1914000,762.130005
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   176
2016-11-02,778.200012,781.650024,763.450012,768.700012,1872400,768.700012
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   177
2016-11-01,782.890015,789.48999,775.539978,783.609985,2404500,783.609985
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   178
....
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   179
\end{verbatim}}
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   180
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   181
\noindent
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   182
Write a function that ignores the first line (the header) and then
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   183
extracts from each line the date (first column) and the Adjusted Close
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   184
price (last column). The Adjusted Close price should be converted into
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   185
a \texttt{Double}. So the result of this function is a list of pairs where the
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   186
first components are strings (the dates) and the second are doubles
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   187
(the adjusted close prices).\newline\mbox{}\hfill\mbox{[1 Mark]}
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   188
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   189
\item[(4)] Write a function that takes a stock market symbol as
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   190
  argument (you can assume it is a valid one, like GOOG or AAPL). The
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   191
  function calculates the \underline{dates} when you should have
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   192
  bought the corresponding shares (lowest price) and when you should
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   193
  have sold them (highest price).\hfill\mbox{[1 Mark]}
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   194
\end{itemize}
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
   195
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
   196
\noindent
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   197
\textbf{Test Data:}
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   198
In case of Google, the financial data records 3077 entries starting
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   199
from 2004-08-19 until 2016-11-04 (which is the last entry on the day
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   200
when I prepared the course work...namely on 6 November; remember stock
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   201
markets are typically closed on weekends and no financial data is
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   202
produced then; also I did not count the header line). The lowest
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   203
shareprice for Google was on 2004-09-03 with \$49.95513 per share and the
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   204
highest on 2016-10-24 with \$813.109985 per share.\bigskip
127
b4def82f3f9f updated
Christian Urban <urbanc@in.tum.de>
parents: 125
diff changeset
   205
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   206
\subsection*{Advanced Part 3 (3 Marks)}
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   207
35
9fea5f751be4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 31
diff changeset
   208
A purely fictional character named Mr T.~Drumb inherited in 1978
9fea5f751be4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 31
diff changeset
   209
approximately 200 Million Dollar from his father. Mr Drumb prides
20
07860dd35c2b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 18
diff changeset
   210
himself to be a brilliant business man because nowadays it is
07860dd35c2b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 18
diff changeset
   211
estimated he is 3 Billion Dollar worth (one is not sure, of course,
35
9fea5f751be4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 31
diff changeset
   212
because Mr Drumb refuses to make his tax records public).
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   213
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   214
Since the question about Mr Drumb's business acumen remains, let's do a
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   215
quick back-of-the-envelope calculation in Scala whether his claim has
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   216
any merit. Let's suppose we are given \$100 in 1978 and we follow a
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   217
really dumb investment strategy, namely:
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   218
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   219
\begin{itemize}
24
66b97f9a40f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 20
diff changeset
   220
\item We blindly choose a portfolio of stocks, say some Blue-Chip stocks
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   221
  or some Real Estate stocks.
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   222
\item If some of the stocks in our portfolio are traded in January of
24
66b97f9a40f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 20
diff changeset
   223
  a year, we invest our money in equal amounts in each of these
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   224
  stocks.  For example if we have \$100 and there are four stocks that
24
66b97f9a40f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 20
diff changeset
   225
  are traded in our portfolio, we buy \$25 worth of stocks
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   226
  from each.
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   227
\item Next year in January, we look how our stocks did, liquidate
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   228
  everything, and re-invest our (hopefully) increased money in again
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   229
  the stocks from our portfolio (there might be more stocks available,
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   230
  if companies from our portfolio got listed in that year, or less if
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   231
  some companies went bust or de-listed).
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   232
\item We do this for 38 years until January 2016 and check what would
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   233
  have become out of our \$100.
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   234
\end{itemize}\medskip  
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
   235
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   236
\noindent
42
a5106bc13db6 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
   237
\textbf{Tasks (file drumb.scala):}
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   238
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   239
\begin{itemize}
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   240
\item[(1.a)] Write a function that queries the Yahoo financial data
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   241
  service and obtains the first trade (adjusted close price) of a
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   242
  stock symbol and a year. A problem is that normally a stock exchange
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   243
  is not open on 1st of January, but depending on the day of the week
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   244
  on a later day (maybe 3rd or 4th). The easiest way to solve this
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   245
  problem is to obtain the whole January data for a stock symbol as
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   246
  CSV-list and then select the earliest entry in this list. For this
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   247
  you can specify a date range with the Yahoo service. For example if
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   248
  you want to obtain all January data for Google in 2000, you can form
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   249
  the query:\mbox{}\\[-8mm]
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   250
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   251
  \begin{center}\small
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   252
    \mbox{\url{http://ichart.yahoo.com/table.csv?s=GOOG&a=0&b=1&c=2000&d=1&e=1&f=2000}}
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   253
  \end{center}
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   254
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   255
  For other companies and years, you need to change the stock symbol
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   256
  (\texttt{GOOG}) and the year \texttt{2000} (in the \texttt{c} and
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   257
  \texttt{f} argument of the query). Such a request might fail, if the
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   258
  company does not exist during this period. For example, if you query
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   259
  for Google in January of 1980, then clearly Google did not exists yet.
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   260
  Therefore you are asked to return a trade price as
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   261
  \texttt{Option[Double]}.
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   262
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   263
\item[(1.b)] Write a function that takes a portfolio (a list of stock symbols),
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   264
  a years range and gets all the first trading prices for each year. You should
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   265
  organise this as a list of lists of \texttt{Option[Double]}'s. The inner lists
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   266
  are for all stock symbols from the portfolio and the outer list for the years.
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   267
  For example for Google and Apple in years 2010 (first line), 2011
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   268
  (second line) and 2012 (third line) you obtain:
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
   269
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   270
\begin{verbatim}
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   271
  List(List(Some(313.062468), Some(27.847252)), 
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   272
       List(Some(301.873641), Some(42.884065)),
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   273
       List(Some(332.373186), Some(53.509768)))
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   274
\end{verbatim}\hfill[1 Mark]
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   275
 
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   276
\item[(2.a)] Write a function that calculates the \emph{change factor} (delta)
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   277
  for how a stock price has changed from one year to the next. This is
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   278
  only well-defined, if the corresponding company has been traded in both
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   279
  years. In this case you can calculate
11
417869f65585 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
   280
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   281
  \[
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   282
  \frac{price_{new} - price_{old}}{price_{old}}
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   283
  \]
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   284
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   285
  
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   286
\item[(2.b)] Write a function that calculates all change factors
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   287
  (deltas) for the prices we obtained under Task 1. For the running
24
66b97f9a40f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 20
diff changeset
   288
  example of Google and Apple for the years 2010 to 2012 you should
66b97f9a40f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 20
diff changeset
   289
  obtain 4 change factors:
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   290
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   291
\begin{verbatim}  
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   292
  List(List(Some(-0.03573991820699504), Some(0.5399747522663995))
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   293
          List(Some(0.10103414428290529), Some(0.24777742035415723)))
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   294
\end{verbatim}
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   295
24
66b97f9a40f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 20
diff changeset
   296
  That means Google did a bit badly in 2010, while Apple did very well.
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   297
  Both did OK in 2011.\hfill\mbox{[1 Mark]}
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   298
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   299
\item[(3.a)] Write a function that calculates the ``yield'', or
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   300
  balance, for one year for our portfolio.  This function takes the
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   301
  change factors, the starting balance and the year as arguments. If
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   302
  no company from our portfolio existed in that year, the balance is
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   303
  unchanged. Otherwise we invest in each existing company an equal
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   304
  amount of our balance. Using the change factors computed under Task
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   305
  2, calculate the new balance. Say we had \$100 in 2010, we would have
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   306
  received in our running example
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   308
  \begin{verbatim}
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   309
  $50 * -0.03573991820699504 + $50 * 0.5399747522663995
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   310
                                         = $25.211741702970222
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   311
  \end{verbatim}
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   312
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   313
  as profit for that year, and our new balance for 2011 is \$125 when
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   314
  converted to a \texttt{Long}.
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   315
  
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   316
\item[(3.b)] Write a function that calculates the overall balance
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   317
  for a range of years where each year the yearly profit is compounded to
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   318
  the new balances and then re-invested into our portfolio.\mbox{}\hfill\mbox{[1 Mark]}
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   319
\end{itemize}\medskip  
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   320
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   321
\noindent
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   322
\textbf{Test Data:} File \texttt{drumb.scala} contains two portfolios
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   323
collected from the S\&P 500, one for blue-chip companies, including
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   324
Facebook, Amazon and Baidu; and another for listed real-estate companies, whose
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   325
names I have never heard of. Following the dumb investment strategy
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   326
from 1978 until 2016 would have turned a starting balance of \$100
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   327
into \$23,794 for real estate and a whopping \$524,609 for blue chips.\medskip
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   328
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   329
\noindent
24
66b97f9a40f8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 20
diff changeset
   330
\textbf{Moral:} Reflecting on our assumptions, we are over-estimating
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   331
our yield in many ways: first, who can know in 1978 about what will
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   332
turn out to be a blue chip company.  Also, since the portfolios are
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   333
chosen from the current S\&P 500, they do not include the myriad
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   334
of companies that went bust or were de-listed over the years.
35
9fea5f751be4 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 31
diff changeset
   335
So where does this leave our fictional character Mr T.~Drumb? Well, given
18
87e55eb309ed updated
Christian Urban <urbanc@in.tum.de>
parents: 11
diff changeset
   336
his inheritance, a really dumb investment strategy would have done
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   337
equally well, if not much better.
129
b1a51285de7e updated
Christian Urban <urbanc@in.tum.de>
parents: 127
diff changeset
   338
135
077e63e96287 updated
Christian Urban <urbanc@in.tum.de>
parents: 129
diff changeset
   339
192
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   340
About rounding errors: \url{https://www.youtube.com/watch?v=pQs_wx8eoQ8}
a112e0e2325c updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   341
(PBS Infinity Series).
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
\end{document}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
%%% Local Variables: 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
%%% mode: latex
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
%%% TeX-master: t
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   347
%%% End: