cws/cw01.tex
changeset 26 a7afc2540a88
parent 24 66b97f9a40f8
child 30 bb8c3dd8c75c
equal deleted inserted replaced
25:6253f4681451 26:a7afc2540a88
    78   $1$ million. \hfill[2 Marks]
    78   $1$ million. \hfill[2 Marks]
    79 
    79 
    80 \item[(2)] Write a second function that takes an upper bound as
    80 \item[(2)] Write a second function that takes an upper bound as
    81   argument and calculates the steps for all numbers in the range from
    81   argument and calculates the steps for all numbers in the range from
    82   1 up to this bound. It returns the maximum number of steps and the
    82   1 up to this bound. It returns the maximum number of steps and the
    83   corresponding number that needs that many steps.  More precisely
    83   corresponding number that needs that many steps.  More precisely,
    84   it returns a pair where the first
    84   it returns a pair where the first
    85   component is the number of steps and the second is the
    85   component is the number of steps and the second is the
    86   corresponding number. \hfill\mbox{[1 Mark]}
    86   corresponding number. \hfill\mbox{[1 Mark]}
    87 \end{itemize}
    87 \end{itemize}
    88 
    88 
   120 \noindent
   120 \noindent
   121 you need to write a function that returns a pair of indices for when
   121 you need to write a function that returns a pair of indices for when
   122 to buy and when to sell this commodity. In the example above it should
   122 to buy and when to sell this commodity. In the example above it should
   123 return the pair $\texttt{(1, 3)}$ because at index $1$ the price is lowest and
   123 return the pair $\texttt{(1, 3)}$ because at index $1$ the price is lowest and
   124 then at index $3$ the price is highest. Note the prices are given as
   124 then at index $3$ the price is highest. Note the prices are given as
   125 lists of \texttt{Float}s.\newline \mbox{} \hfill[1 Mark]
   125 lists of \texttt{Double}s.\newline \mbox{} \hfill[1 Mark]
   126 
   126 
   127 \item[(2)] Write a function that requests a comma-separated value (CSV) list
   127 \item[(2)] Write a function that requests a comma-separated value (CSV) list
   128   from the Yahoo websevice that provides historical data for stock
   128   from the Yahoo websevice that provides historical data for stock
   129   indices. For example if you query the URL
   129   indices. For example if you query the URL
   130 
   130 
   181 shareprice for Google was on 2004-09-03 with \$49.95513 per share and the
   181 shareprice for Google was on 2004-09-03 with \$49.95513 per share and the
   182 highest on 2016-10-24 with \$813.109985 per share.\bigskip
   182 highest on 2016-10-24 with \$813.109985 per share.\bigskip
   183 
   183 
   184 \subsection*{Advanced Part 3 (3 Marks)}
   184 \subsection*{Advanced Part 3 (3 Marks)}
   185 
   185 
   186 A purely fictional character named Mr T.~Drump inherited in 1978
   186 A purely fictional character named Mr T.~Drumb inherited in 1978
   187 approximately 200 Million Dollar from his father. Mr Drump prides
   187 approximately 200 Million Dollar from his father. Mr Drumb prides
   188 himself to be a brilliant business man because nowadays it is
   188 himself to be a brilliant business man because nowadays it is
   189 estimated he is 3 Billion Dollar worth (one is not sure, of course,
   189 estimated he is 3 Billion Dollar worth (one is not sure, of course,
   190 because Mr Drump refuses to make his tax records public).
   190 because Mr Drumb refuses to make his tax records public).
   191 
   191 
   192 Since the question about Mr Drump's business acumen remains, let's do a
   192 Since the question about Mr Drumb's business acumen remains open, let's do a
   193 quick back-of-the-envelope calculation in Scala whether his claim has
   193 quick back-of-the-envelope calculation in Scala whether his claim has
   194 any merit. Let's suppose we are given \$100 in 1978 and we follow a
   194 any merit. Let's suppose we are given \$100 in 1978 and we follow a
   195 really dump investment strategy, namely:
   195 really dump investment strategy, namely:
   196 
   196 
   197 \begin{itemize}
   197 \begin{itemize}
   210 \item We do this for 38 years until January 2016 and check what would
   210 \item We do this for 38 years until January 2016 and check what would
   211   have become out of our \$100.
   211   have become out of our \$100.
   212 \end{itemize}\medskip  
   212 \end{itemize}\medskip  
   213 
   213 
   214 \noindent
   214 \noindent
   215 \textbf{Tasks (file drump.scala):}
   215 \textbf{Tasks (file drumb.scala):}
   216 
   216 
   217 \begin{itemize}
   217 \begin{itemize}
   218 \item[(1.a)] Write a function that queries the Yahoo financial data
   218 \item[(1.a)] Write a function that queries the Yahoo financial data
   219   service and obtains the first trade (adjusted close price) of a
   219   service and obtains the first trade (adjusted close price) of a
   220   stock symbol and a year. A problem is that normally a stock exchange
   220   stock symbol and a year. A problem is that normally a stock exchange
   308 \textbf{Moral:} Reflecting on our assumptions, we are over-estimating
   308 \textbf{Moral:} Reflecting on our assumptions, we are over-estimating
   309 our yield in many ways: first, who can know in 1978 about what will
   309 our yield in many ways: first, who can know in 1978 about what will
   310 turn out to be a blue chip company.  Also, since the portfolios are
   310 turn out to be a blue chip company.  Also, since the portfolios are
   311 chosen from the current S\&P 500, they do not include the myriad
   311 chosen from the current S\&P 500, they do not include the myriad
   312 of companies that went bust or were de-listed over the years.
   312 of companies that went bust or were de-listed over the years.
   313 So where does this leave our fictional character Mr T.~Drump? Well, given
   313 So where does this leave our fictional character Mr T.~Drumb? Well, given
   314 his inheritance, a really dumb investment strategy would have done
   314 his inheritance, a really dumb investment strategy would have done
   315 equally well, if not much better.
   315 equally well, if not much better.
   316 \end{document}
   316 \end{document}
   317 
   317 
   318 %%% Local Variables: 
   318 %%% Local Variables: