Home Page > > Details

Help With PROGRAMMING Assignment,C++ Programming AssignmentDebug ,C++ Course Assignment Debug Matlab Programming| Java Programming

Problem Sheet 2, 4CMP Spring Term 2019/20
PROBLEM SHEET 2
4CMP, SPRING TERM, PART 2: PROGRAMMING IN C++
Weighting: This problem sheet counts 15% to your final grade for the spring part of 4CMP. Only the
best two out of the problem sheets 1,2,3 count towards your degree.
INSTRUCTIONS FOR THE SUBMISSION:
Submit your code on Canvas twice: first upload a single zip file containing all code files for each
problem, and then upload the individual source files. Each problem sheet should be implemented in
source code files that are named as follows: Each program contains a main_X.cpp. Here, X is the
number of the problem. For example, main_P1.cpp. Further files should be implemented if
appropriate. Recall the conventions discussed during the lecture. Main should be slim and not
contain too much code. Implement code in separate files that are logically named.
The reason for this double-submission is that Canvas internally renames files. Therefore, the
individual files cannot be compiled unless they are renamed back (which would create a lot of work
for the marker). If a zip file is submitted, that zip file is renamed, but not the files within that zip file.
However, comments on Canvas can only be given on text/word/pdf files, which is why you have to
additionally submit the individual source files.
If requested, also submit a pdf with explanations of your results.
The source files should compile without errors or warnings on Visual Studio 2017 as installed on the
clusters, and the resulting executable should run without problems. You do not have to submit the
executable. If you use another compile than Visual Studio, you should take your final code and
compile it on Visual Studio on our clusters. Unfortunately, different compilers follow slightly
different rules, and even a small difference may cause the code to fail on Visual Studio.
The source code should also be well formatted. This means that opening and closing brackets should
be aligned in a readable way, and we will discuss such styles briefly in the lectures. Also, it is crucial
that you comment your code well. For this first problem sheet, this means that you should explain
every single line of code with a comment
PLAGIARISM:
Obviously, you are not allowed to plagiarise. This means that you are not allowed to directly copy
the code from any online sources or any of your fellow students. Direct group work is also not
allowed. What this means is that while you are allowed (and even encouraged) to discuss the
contents of this module (including problem sheets) with your fellow students, every one of you
needs to write their own code.
PROBLEM 1: TIME SERIES
Write a class TimeSeries that is used to store a time series of share prices, and that can compute the
following information: The mean and standard deviation of the share prices, and the mean and
standard deviation of the increments. Moreover, the class should be able to add an additional share
price/date at the end of the time series (i.e. write a function that takes a date and a share price as an
input. Add both to the stored values.) The class should also have a constructor to initialise member
variables, where the input is given by two vectors: one for the share prices, and one for the
corresponding dates. Finally, the class should have a function that allow us to print all share prices
for all given days, and a function that allows us to print all increments that occur on any given day.
For simplicity, we will label the dates by unsigned integers. This is how, for example, Excel stores
dates. You can see this in Excel by entering 1 into a spreadsheet field, and then formatting this field
as a date. You will see that ‘day 1’ corresponds to the 1/1/1900, and all following days are labelled
by subsequent integers (only that Excel apparently has a mistake with one of the leap years).
In main, create the two vectors (with appropriate data types)
sharePrices = {23.3, 24.3, 24.1, 25.0, 22.1};
dates = {1,2,3,4,5};
Then, create an object of TimeSeries that is initialised with this data.
Next, call member functions of the class that print all share prices for all days 1-5 on the command
line, and also the daily increments of the share prices (obviously, you only have increments for days
2-5). Finally compute and print on the command line the mean and standard deviation of the share
prices as well as of their increments.
Then, on day 6, the share price is 22.8. Add this information to your TimeSeries object.
Finally, repeat printing all the information as requested above for days 1-5 again, now for days 1-6
(i.e. share prices, increments, mean and standard deviation).
Hints:
The class TimeSeries will store two vectors of equal length, one containing the share prices and one
that contains the corresponding dates. You can store the increments in a third vector, or compute
them with a function (both are fine for this problem, and we will later discuss in the lectures what
advantage one of the two options has over the other).
Write member functions that can calculate mean and standard deviations of the share price as well
as of the increment. Write a constructor that initialises all the member variables with input data.
Write a function that takes a date and a share price as input and then pushes these values back to
the member variables that store share prices and dates, respectively.
Make sure functions have checks for reasonable input.
PROBLEM 2: BOND PRICING
Write a class that represents bonds. The bonds should be defined by coupon payments at given
dates, a principle and the date of expiry.
The bond class should implement constructors to initialise an object with reasonable input. Write at
least two constructors: The first takes coupon payments and dates on which these occur, the
principle, and the date of maturity, as inputs. The second only takes the maturity and principle as
input, assuming it’s a zero-coupon bond (i.e. one that only pays back the principle at expiry, but
makes no other interest payments before expiry).
Write a member function that prices the bond where the input is the interest rate for each coupon
payment day, and the day of expiry.
Problem Sheet 2, 4CMP Spring Term 2019/20
Advanced: Implement a function that calculates the yield for a given bond price. This advanced
question cannot be solved with methods that we discussed in the lecture so far, and will only count
10% of this problem sheet.
Simplifying assumptions: We can measure all days as (unsigned) integers and consider the present
day of pricing to be the day 0. We may assume all interest rates are continuously compounded, and
are based on years with 365 days. We can also assume that the time of expiry always coincides with
the last coupon day (unless it is a zero coupon bond), so that the list of interest rates required for
pricing the bond always contains the correct interest rates for the required coupon days.
In main, create the following bonds:
Bond 1: $100, time to expiry 2 years, bi-annual coupons of $3 paid on days 182, 365, 547, 730
Bond 2: $100, time to expiry 2 years, zero coupon
Assume an interest rate of 5%, 5.8%, 6.4%, 6.8% at days 182, 365, 547, 730, respectively. Price the
bonds and calculate the yields. Output the results on the command line.
Extra task: Implement an advanced code where the bond pricing function is supplied with a general
time series for the interest rates. The program then automatically extracts the correct interest rates
at the coupon days (and gives an error message if the time series does not contain rates for the days
where a coupon is paid). Solving this extra task will count up to 5 bonus points, but is not required to
achieve 100% for this problem sheet.

Contact Us - Email:99515681@qq.com    WeChat:codinghelp
Programming Assignment Help!