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