首页 >
> 详细

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.

联系我们

- QQ：99515681
- 邮箱：99515681@qq.com
- 工作时间：8:00-23:00
- 微信：codinghelp

- 代做csci 4155作业、代做python课程作业、代写date留学生作业 2020-02-21
- 代写csi4142作业、代做electrical作业、Sql编程语言作业代做 2020-02-21
- Cse 482作业代做、代写data Analysis作业、代写java语言 2020-02-21
- Sample Prediction作业代做、代写data课程作业、代写r编程 2020-02-20
- 代写lr留学生作业、代做r程序设计作业、代写sample Predictio 2020-02-20
- Stats 102A作业代做、代做r课程设计作业、代写r程序语言作业、代写s 2020-02-19
- 625.664留学生作业代做、代写python语言作业、代做java，C/C 2020-02-19
- 代做csi 410留学生作业、代写database Systems作业、代做 2020-02-18
- 代写computer Networks作业、Python编程设计作业调试、P 2020-02-18
- Sta490y L0201 2020-02-17
- Comp 3005作业代写、代写c++语言作业、代做database作业、C 2020-02-16
- Beng0019作业代做、代写java编程设计作业、代做c/C++，Pyth 2020-02-16
- Macm 316 – Computing Assignment 2 2020-02-17
- Reverse Polish Notation (Or Postfix No... 2020-02-17
- Price Predictions Project 2020-02-17
- Ug3 Operating Systems 2020-02-16
- Homework 1 Use Marching Cubes Algori... 2020-02-16
- Module Ics-33 Quiz #2: File Reading, E... 2020-02-16
- S&As: Stat1603 Introductory Statistics 2020-02-16
- Fit5145 - Introduction To Data Scienc... 2020-02-16