Professional Documents
Culture Documents
COURSEWORK 1
2020/21
CST2330
This assignment is worth 50% of the overall grade. The submission date is Week
12, Friday, 19:00 January 8, 2021.
Contents
1 The net present value (NPV) problem (10%) 1
https://rstudio.com/products/rstudio/
Note, however, that all tasks in this coursework can be implemented in other
languages (e.g. Python, Common Lisp, Julia or even more visual projects, such as
KNIME or RapidMiner), and you can use them, if you feel more comfortable.
A specific dataset is required for Task 3 as well as the tasks in Coursework 2.
It is available on My Learning in the Data folder of the CST2330 page.
This function should modify the table by adding columns showing the net
returns, the numbers of years to discount, the present value factors and the
discounted returns. Your function must be able to take different cashflow
tables and discount rates as the input, print the modified cashflow table and
return the (total) net present value (NPV) for the investment. Include your
code into the report. 5 marks
3. Calculate the NPV for discount rates of 2%, 3%, 4% and 5%, giving your
answers to two decimal places. 1 mark
4. Plot NPV against the discount rates ranging from 0% to 5%. 1 mark
5. Use your graph to estimate the discount rate that would give an NPV of
zero. What is the significance of this discount rate? (Hint: What happens
at discount rates lower and higher than this figure?) 2 marks
• The logistics and warehouse facilities do not allow for production of more
than 750 vehicles per day in total (i.e. both conventional and EVs).
3. Plot or draw the feasible region and the isoprofit line. 3 marks
CST2330, COURSEWORK 1, 2020/21 3
4. Find the optimal numbers of conventional cars and EVs to be produced (the
solution) in order to achieve the maximum profit (the optimal value). 2 marks
3. Use the lpSolve library in R to find the solution (an optimal combination
of three types of cars) and the optimal value (the maximum profit) to this
problem. Include your code into the report. 5 marks
crypto-candles.csv
crypto-candles.db
The first is a comma separated values (csv) file, and the second is an SQLite
database. You can read the csv file with the read.csv command. Alternatively,
you can connect to the database and read table candles from the db file using the
dbReadTable command. You should assign the result to a variable, which you may
call candles. Note that if you read data from the database, then the timestamps
have to be converted into dates by the command:
as . POSIXct ( candles $ TIMESTAMP , origin = " 1970 -01 -01 " )
Regardless of which method you use, you should now have the same dataset, the
first 6 rows of which are:
CST2330, COURSEWORK 1, 2020/21 4
The column SYMBOL contains names of the trading pairs (e.g. tBTCUSD is the ex-
change rate between Bitcoin and the US Dollar). Thus, each row of the dataset
contains a record of the prices (open, close, high, low) and volume data on a spec-
ified date (given by the TIMESTAMP) and for each trading pair (given by SYMBOL).
The goal of this task is to make several transformations of this dataset into
other formats, so that it is ready for further analysis in Coursework 2.
12000 12000
10000 10000
8000 8000
6000 6000
4000 4000
To do this, you will need to select subsets from the data corresponding to the
trading pairs of your choice (e.g. tETHUSD, tETHBTC, tIOTBTC, tEOSJPY), and then
selecting columns TIMESTAMP and CLOSE. Note that before plotting the subset, you
can convert it into the extensible timeseries format (xts) using the command:
as . xts ( < data >[ , " CLOSE " ] , order . by = < data >[ , " TIMESTAMP " ])
Note that the table above shows only some of the columns for just a few pairs (i.e.
"tAAABBB", "tBTCUSD", etc). The dataset contains more than 270 trading pairs.
One possible way of converting the candles is as follows:
• Create a list (or vector) all_pairs of all trading pair names. This can
be done by selecting the SYMBOL column from the data, and then removing
duplicates using function unique.
• Create an empty variable prices that will be used to assemble closing prices
for all pairs.
1. Select TIMESTAMP and CLOSE columns from a subset for the pair and
assign the result into a temporary table (e.g. call it temp).
2. Convert the result into class xts using CLOSE as data and order by
TIMESTAMP (see the commands in Task 3.1).
3. Add the result into the prices table using the cbind function:
prices <- cbind ( prices , temp )
In your report, you should print the dimensions of the resulting table using
command dim(prices) and show the first 10 rows and randomly chosen 5 columns
using the command:
head ( prices [ , sample (1: ncol ( prices ) , 5) ] , 10)
10 marks
CST2330, COURSEWORK 1, 2020/21 6
1. Fill in the NA values by the last observations (i.e. most recent available
prices). This is equivalent to assuming that the price remained the same
rather than missing, and so log-return will be zero rather than NA.
2. In the cases when no more recent prices were observed (e.g. a pair was not
traded before certain date), then fill in the NA values by the next observations.
This means that log-returns will also be zero in this case rather than NA.
If the prices table is in the xts (timeseries) format, then both operations above
can be performed by the function na.locf and using its argument fromLast to
control the direction of the operations.
After filling in the NA values, convert the prices table into log_returns, as
described above. In your report, you should print the dimensions of the resulting
table using command dim(log_returns) and show the first 10 rows and randomly
chosen 5 columns using the command:
head ( log _ returns [ , sample (1: ncol ( log _ returns ) , 5) ] , 10)
In addition, include a couple of plots of log-returns for some of the pairs (e.g. those
used in Task 3.1). For example, below is the plot of log-returns of tBTCUSD:
CST2330, COURSEWORK 1, 2020/21 7
0.1 0.1
0.0 0.0
−0.1 −0.1
−0.2 −0.2
−0.3 −0.3
−0.4 −0.4
5 marks
Presentation
Your report should be well presented. A good guide is the Publication Manual of
the American Psychological Association (e.g. see http://www.apastyle.org/).
At the very least, your report should be clear, typed or nicely hand-written doc-
ument with good spelling, grammar and easy to understand English. There is no
word limit, but a useful report should be just long enough to describe the work.
A sensible limit is about 10 pages of typed text. Beyond this, you are probably
being a bit too verbose. Tables, graphs, careful labelling and numbering are all
well established and effective presentation tools.
Things to avoid are:
• Including images or diagrams that you did not create yourself or did not
obtain the permission to use from the author (even if the image is from the
Internet).
Assignment Submissions
Submit your report online using My Learning by Week 12, Friday, 19:00 Jan-
uary 8, 2021.