CPT206 CW2

CPT206 Computer Programming for Financial Mathematics: Coursework 2 Task Specification
The aim of this coursework is to implement the Brennan-Schwartz model, a two factors model that simulates the dynamics of short and long term interest rates. The model was first introduced by Michael Brennan and Eduardo Schwarz in 1982, and has been widely used as a financial model of interest rates since then. It has also been used to model apparently unrelated phenomena, such as population growth rates. As part of this task, you will also produce a report documenting your design choices, detailed in Section 4.
1 Model dynamics
The model is a two factors model of both short-term and long-term interest rates over a given time period. We write r(t) for the short-term rate, also called the spot rate, and l(t) for the long-term rate, also called the consol rate. The dynamics of the model are given by the following equations:
dr(t) = 􏰀a1 + b1(l(t) − r(t))􏰁dt + r(t)σ1dW1(t) (1) dl(t) = l(t)􏰀a2 − b2r(t) + c2l(t))􏰁dt + l(t)σ2dW2(t) (2)
where:
• a1, b1, σ1, a2, b2, c2 and σ2 are all constants, usually obtained through callibration techniques; • W1(t) and W2(t) are standard Brownian motions with correlation factor ρ (here ρ is another
constant of the model).
See https://quant.stackexchange.com/questions/24472/two-correlated-brownian-motions for an indication on how to simulate the two random variables dW1(t) and dW2(t). For simplicity, we will choose the values supplied by Brennan and Schwartz in their original paper for the constants of the model, given in the table below.
a1 b1 σ1 a2 b2 c2 σ2 ρ -0.01 0.1102 0.1133 0.0089 0.00358 -0.0037 0.0298 0.2063
1

2 Task description (60 marks)
You will write a Java program that simulates the Brennan-Schwarz model over a given time period. Your Java program should be written in a single Main class called BrennanSchwarz. As well as the constants above, your program should take the following input paramters:
• initial rates r0, l0 > 0;
• a time period T > 0 and a positive integer n indicating the number of increment intervals.
The idea is to break down the time period [0, T ] into n increment intervals of length dt = Tn ,
and apply the Euler method to Equations (1) and (2) to simulate the model over that time period.
Inotherwords,weshouldhave: r(t=0)=r0 andl(t=0)=l0,andforanygiventimet= kT for n
some k ∈ {0,…,n−1}, r(t+dt) = r(t)+dr(t) and l(t+dt) = l(t)+dl(t), where the increments dr(t) and dl(t) are is given by Equations (1) and (2).
On executing, your program should calculate and display the following information:
1. the values of the rate functions r(t) and l(t) over the chosen time period (i.e. should show
the values of r(t) and l(t) for all t of the form t = kT as above); n
2. the minimum and maximum values of the rate functions, and the time(s) at which these are achieved;
3. the maximum displacements ∆r and ∆l of the rate functions over all intervals of length dt1, and the time period(s) in which these are achieved;
4. the average values of the rate functions.
The display should be readable, and informative. Values should be rounded to a sensible length
(e.g. five digits after the decimal point).
3 Code quality (20 marks)
The remaining marks (20) for the coding part will be awarded for general code quality as seen in the course materials to date. Here is some guidance.
4
• • • •
Keep your code neat and tidy; make sure it is properly indented throughout.
Choose suitable names for variables and methods.
Comment your code as needed.
Split your code into separate methods as appropriate; code in the main method should be kept to a minimum; methods overall should not be too long.
Report (20 marks)
You will write a short report (no more than three pages in length) providing some details on how you designed and implemented your program, as described in Section 2. You should explain the design choices you made for your Java program. You should consider the following questions.
• What are the different members (class variables or methods) of your Java class? What is their purpose?
• How did you proceed in implementing the model’s dynamics as described by Equations (1) and (2)? How did you calculate the various statistics associated with the rate functions?
1 The displacement of a function f over an interval [t1 , t2 ] is simply the absolute value |f (t2 ) − f (t1 )|. 2

5 Submission instructions
In the dedicated “Coursework 2 submission” Assignment activity on the Learning Mall Online, you will need to submit the following two (2) documents.
• A plaintext .txt file, into which you have copied the source code of your entire BrennanSchwarz Java class. This file should be named “CPT206 CW2 Code studentId.txt”.
• Your report from Section 4, typed into for instance a Word document, and converted into a PDF file. This file should be named “CPT206 CW2 Report studentId.pdf”.
This assignment is individual work. Plagiarism (e.g. copying materials from other sources without proper acknowledgement) is a serious academic offence. Plagiarism and collusion will not be tolerated and will be dealt with in accordance with the University Code of Practice on Academic Integrity. Submitting work created by others, whether paid for or not, is a serious offence, and will be prosecuted vigorously. Individual students may be invited to explain parts of their code in person during a dedicated BBB session, and if they fail to demonstrate an understanding of the code, no credit will be given for that part of the code.
Late submissions. The standard University policy on late submissions will apply: 5% of the total marks available for the component shall be deducted from the assessment mark for each working day after the submission date, up to a maximum of five working days, so long as this does not reduce the mark below the pass mark (40%); submissions more than five working days late will not be accepted.
Good luck!
3