首页 >
> 详细

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
- 微信：codehelp

- 代写dataset留学生作业、代做c++,Java，Python程序语言作业 2020-04-01
- Comp 8042作业代做、代写c/C++程序语言作业、代做g++课程设计作 2020-04-01
- 代写cs304留学生作业、代做c++编程设计作业、代写c/C++课程作业、D 2020-04-01
- Cs544留学生作业代做、Programming作业代写、R编程设计作业代做 2020-04-01
- Csc73010作业代写、代做programming作业、Java语言作业代 2020-04-01
- Logistic Regression作业代做、代写java，Python语 2020-04-01
- Envx3002作业代写、代做statistics课程作业、代做r语言作业、 2020-03-31
- 代做cs2034留学生作业、代写data Analytics作业、Pytho 2020-03-31
- Csi3131作业代做、Java编程设计作业调试、Java语言作业代做、代写 2020-03-31
- Webcms3作业代写、代做data Service作业、C/C++语言作业 2020-03-31
- Stat7017 Final Project 2020-03-29
- Cs3214 Spring 2020 Project 1 - “Extens 2020-03-29
- Co3090/Co7090 Distributed Systems And ... 2020-03-29
- Hw2: Sql 2020-03-29
- Hw1: 5 Points Entity-Relational (Er) 2020-03-29
- Math 104A Homework #3 2020-03-29
- Comp 250 Assignment 2 2020-03-29
- Cs 570课程作业代写、Program作业代做、C++语言作业代写、代做j 2020-03-29
- Comp-424作业代做、代写intelligence作业、Python，C 2020-03-29
- Database作业代做、代写cap Theorem作业、代写java程序语 2020-03-29