# MATHEMATICAL AND COMPUTATIONAL FINANCE

ASSIGNMENT (VERSION 4):

This is an individual assignment. Group discussions are healthy and encouraged

BUT the work you submit must be your own and NOT collaboratively prepared.

Aims

• To provide practical and robust computational solutions to realistic problems drawn from

financial mathematics.

• To coordinate and unify the theoretical and algorithmic formulations of problems in mathematical finance.

Learning outcomes

On successful completion of this assignment students will be able to:

• formulate algorithmic solutions to financial mathematics problems of real-world relevance.

• Generate, modify, enhance, debug and demonstrably verify robust and effective computer

software for problems in finance.

Remarks

This assignment counts 30% towards your assessment for MA3667.

All symbols have their usual meanings.

1

1 Rules of engagement

The computing assignment for MA3667 is detailed below.

A hard copy of the assignment report must be submitted to the Maths General Office

(Room JNCK101), with a completed Assignment Cover Sheet, on or before

3:30 PM Monday 15 February 2016 (week 22)

Your submission must consist of:

• A hard copy of a typeset report, prepared using Microsoft Word or L ATEX2ε, containing no more than four A4 pages with font size no

smaller than 11 point and

margins no smaller than 25mm on all four edges. These limits are STRICT and

documents that do not comply will attract ZERO marks.

• An email sent to Simon.Shaw@brunel.ac.uk with a back up copy also sent to

Shashank.Virmani@brunel.ac.uk with ’MA3667 submission’ in the subject

line and the following files included in a single zip file attachment:

– The typeset report either as:

∗ a single word document

∗ or as a L ATEX source file with the resulting PDF file and one imported

graphics file as required by task 2.

– Two matlab files, task1.m and task2.m.

No other files must be submitted because they may be rejected by the email

system as potential virus files.

To create this zip file first create a new folder with the name taken from your

student number. For example, if your student number is 0736154 then this should

be the name of the folder. Place both of the matlab files and all of the report files

in this folder and then, in Windows 7, right click on the folder’s icon and select

Send to and then Compressed (zipped) folder. This creates a single file

called ‘0736154.zip’ (but, depending your settings, you may not see the ‘.zip’ at

the end) and it is this that should be attached to the email.

Important Notes

• The same deadline applies to the email submission as to the hard copy submission. You will receive an emailed acknowledgement of

receipt of your email from

Simon Shaw within 36 hours. If you do not receive that email then contact Simon

Shaw as a matter of urgency.

• All submitted materials should bear your name, your Brunel email address and

your student number. You are completely responsible for the integrity of all the

material you submit. In particular do not submit any virus-infected electronic

files.

• The university policy on late submissions will apply to this assignment.

2

2 Marking scheme

The marks for this assignment are partitioned as follows.

57% for the written report, made up as follows:

– 27% on the technical content of Task 1 (excluding the matlab code), plus 5%

on written style, grammar, punctuation;

– 20% on the technical content of Task 2 (excluding the matlab code), plus 5%

on written style, grammar, punctuation.

18% for the matlab implementation and coding for Task 1.

25% for the matlab implementation and coding for Task 2.

You should ensure that your codes are well commented and user friendly, and you

should program defensively (for example: test for errors and print warnings; reject invalid input; don’t divide by zero; don’t take the

square root of negative numbers unless

you are sure you intend to; check your output …and so on). Marks will be awarded

for the cogent demonstration of these skills.

3 Remarks

You should appreciate that very similar advice applies to the creation of this written

document as for the Final Year Project. Accordingly you should feel free to use the

Final Year Project learning resource materials, as well as Dr Greenhow’s study skills

guide at

http://people.brunel.ac.uk/˜mastmmg/ssguide/sshome.htm

to inform your report writing. Also, although aimed at L ATEX users, the book [2] contains a lot of helpful tips on how to write

mathematical text.

4 Plagiarism

This is an individual assignment. Group discussions are healthy and encouraged, but

the work you submit must be your own and NOT collaboratively prepared. In this

regard you are reminded of the definition of plagiarism: To take and use as one’s own the

thoughts, writings or inventions of another (Oxford English Dictionary). See here:

http://www.brunel.ac.uk/services/library/learning/plagiarism

for a useful discussion. Your submission will be subjected to plagiarism detection software and will also be visually inspected. You

should be aware that it is extremely

difficult to successfully disguise duplicated work. If you hand in such work it will be

detected and you will face the consequences.

3

5 Assessment and support

The deadline given above refers to the submission of solutions to both of the tasks

outlined below. However, there are two earlier and optional opportunities for you to

receive advice and feedback on a draft of Task 1. These are:

• See Simon Shaw in JC302 on a drop-in, first-come, first-served basis on Tuesday

12 January 2016 during 12noon — 3:30pm, Wednesday 13 January 2016 during

12:30 — 5pm; or Thursday 14 January 2016 during 10am — 5pm.

• Hand in a hard copy draft of your attempt at Task 1 by 3:30 PM on Monday

25 January 2016. The pages must be stapled together, marked with your name,

Brunel email address and student number and then handed in to the maths general office, marked FOR THE ATTENTION OF SIMON SHAW.

The purpose of this draft submission stage is to give you an opportunity to receive

formative feedback on your work. No marks will be awarded but you will receive

advice on your work’s weaknesses and strengths. Also no codes will be run as part of

this exercise. You may however present a print out of your Task 1 matlab for advice on

design and layout.

There are two reasons for the change in the original arrangement and date. First, the

original date of 15 January is at the end of the Final Year Project presentation week and

it is recognised that some people might prefer to spend time on that. Second, Shaw

has an off-site engagement during the week of 18 January which would mean that

all feedback would have to be given electronically, which is not ideal, and may also

be subject to delay. The new arrangements avoid these problems and give you more

opportunities for formative feedback.

In terms of support for this assignment recall that regular matlab surgeries are run by

the department and you are advised to make full use of them. Note however that the

staff running these sessions may not be able to help on the details of the financial maths

part of these tasks.

Because of this the assignment coordinator, Dr Simon Shaw (Room JNCK 302), will

host the following support sessions:

• Task 1 and 2 support seminar from 3:00—4:00pm on Tuesday 24 November in

LC263

• Office hour drop-in sessions with Simon Shaw — To Be Announced.

The overview lectures will contain help and advice on how to address each task, and

will contain a question and answer session. The drop-in sessions will be on a firstcome, first-served basis. In the drop-ins you will

be able to obtain individually tailored

help and advice.

4

Task 1:

Yield to Maturity of Bonds (5qual+27tech+18code marks)

The motivation behind this task is that working out the yield to maturity of a bond

involves working out the roots of a polynomial, a task that can in most cases only be

done by computer.

Context

Suppose that the time now is t = 0, and you have just paid price P for a bond that

promises you:

1. coupon payments of c after one year, two years etc, until the bond matures after

T years;

2. a final additional payment after T years of the face value of the Bond, F.

The entire cashflow can hence be summarised as:

{−P,c,c,c,c,…,c + F }

where −P represents the amount you pay now for the bond, the c’s represent your

coupon payments each year, and the F represents the face value payment after the T

year maturity period. In lectures you have met the idea that the yield to maturity of

the bond is defined as the internal rate of return of this cashflow. In other words it is

the interest rate R that would make the discounted value of the cashflow zero, so that

R solves:

0 = −P + c

1 + R

+

c

(1 + R)2 +

c

(1 + R)3 + … +

c + F

(1 + R)T .

It is easier to work with a different variable,

x =

1

1 + R,

and then in order to work out the yield to maturity we must solve

0 = −P + cx + cx2 + cx3 + … + (c + F )xT

for x, and then rearrange to get R. To proceed we define the polynomial f(x) as

f(x) = −P + cx + cx2 + cx3 + … + (c + F )xT,

and so to find the yield of the bond we seek a root of f. Note that there may be

many roots but, for our current purposes, we need only to find the unique positive

root, which we know exists for such cashflows from the discussion in the lectures.

We cannot solve f(x) = 0 analytically but we can approximate the root numerically

by using Newton’s method. So, if x0 is an initial guess for the root then the Newton

iteration1,

xi = xi−1 −

f(xi−1)

f ′(xi−1) (for i > 0),

1Ref: MA2715 matlab lab notes with Dr Mike Warby.

5

will, if certain conditions are met, converge to the exact root: xi → x. In practice this

iteration would be halted once |f(xi)| < ϵ for some user-specified tolerance ϵ.

Tasks 1: sub-tasks

You are required to complete the following tasks.

1. Work out f ′(x) for the cashflow above. [1 mark]

2. Show that if x ̸= 1 then

f(x) = −(P + c) + FxT + c(1 − xT +1)

1 − x

.

[2 marks]

3. Explain why there is exactly one positive solution when F, P > 0 and c > 0. [2 marks]

4. Show that if P = F + Tc then the unique solution is R = 0. [3 marks]

5. Implement Newton’s method as described above in the form of a matlab function

in a file called task1.m (note that Windows usually adds the last part, ‘.m’, for

you). This function should provide the estimate for R in return for appropriate

inputs—one of which should be an initial guess x0. Make sure that the commenthelp functionality is used to tell the user how to use the

function. For example,

this is a skeleton of how such a matlab function might look: [18 marks]

function [R x fx] = task1(PR,FV,c,T,x0,epsilon)

%

% Use Newton’s method to find the internal rate of

% return of a bond that costs PR now, returns c per

% year, and has a face value of FV when it matures in

% T years’ time. The value x=1/(1+R) is calculated as

% a root of a T-degree polynomial and R is recovered

% from this as R = (1-x)/x. This R, the value of x,

% and the value fx of the polynomial at that x are

% returned as a check on the results.

%

% Examples:

% [R x fx] = task1(1000,1500,45,50,1,1.0e-11)

% [R x fx] = task1(1500+45*50,1500,45,50,1,1.0e-11)

%

xnew=x0; criterion = 2*epsilon;

while criterion > epsilon

x = xnew;

% get f=f(x) and df=f’(x)

xnew = x – f/df;

6

criterion = abs(f);

end

end

Take the second, fourth and fifth from last digits in your student ID number and

call them u, v and w in that order. For example, if your ID number is 0736154 then

this becomes 07wv1u4 so that in this case u = 5, v = 6 and w = 3. In your report

give the yield to maturity implied by the values: [1 mark]

P = 5uvw, c = 10uv, T = 10 + w and F = 5uvw.

For the ID number example given above we would have P = 5563, c = 1056,

T = 13 and F = 5563. State clearly in your report the values that you used.

You should use the comment line help functionality, as illustrated above, to explain how this function is to be used.

Remark: the choice of starting value, x0, is left to you. You may proceed simply

by trial and error, or you may choose to use matlab to plot f(x) against x and

determine an approximate root by inspection. Your report should give the details.

6. For the remainder of this task we let f represent an arbitrary function, of which

the polynomial from earlier is just an example.

Suppose that x = x∗ is a solution of the equation f(x) = 0. Show that: [1 mark]

0 = f(x) + ∫xx∗ f ′(ξ) dξ for arbitrary x

and, hence, show that, [2 marks]

0 = f(x) + (x∗ − x)f ′(x) + ∫xx∗(x∗ − ξ)f ′′(ξ) dξ. (1)

Furthermore, show first that [2 marks]

xi − x∗ = xi−1 − x∗ + f(x∗) − f(xi−1)

f ′(xi−1)

and second that, [1 mark]

f(x∗) − f(xi−1) = (x∗ − xi−1)f ′(xi−1) + ∫xix − ∗1(x∗ − ξ)f ′′(ξ) dξ.

Conclude that if f ′(xi−1) ̸= 0 then we have the error equation, [2 marks]

xi − x∗ = 1

f ′(xi−1) ∫xix − ∗1(x∗ − ξ)f ′′(ξ) dξ.

Assuming that there are positive constants m and M such that |f ′′(x)| 6 M and

|f ′(x)| > m for all x near the root x∗ show that, [4 marks]

|xi − x∗| 6 C M

m

|xi−1 − x∗|2

for some positive constant C. Discuss the following:

7

• what are the limitations of this result? [2 marks]

• Newton’s method is said to converge quadratically. Why? [2 marks]

• if xi−1 has three digits of accuracy then how many would you expect xi to

have? How about xi+1? Explain your answers. [2 marks]

7. Up to five marks will also be awarded for high quality written style, grammar,

structure and presentation. You may use the ‘draft hand in’ opportunity to obtain

feedback on this aspect of the assignment. [5 marks]

Task 2:

Monte-Carlo Option Pricing (5qual+20tech+25code marks)

This exercise uses the observation that an option price can be calculated as a discounted

risk-neutral expectation; it is based closely on material in Higham’s book, [1].

Context

This observation suggests that we could value an option by sampling many thousands,

M say, of possible asset prices, at time T, calculating the payoffs, taking their average

and discounting this at the risk-free rate to today in order to estimate the option’s

current value. This game of chance does in fact work and in this task you will see how.

It is an example of a simple Monte Carlo method: so-called because games of chance

form an important part of Monaco’s economy.

You have seen in lectures that the asset price Ito process, ˆ dS = rS dt + σS dX for dX ∼

N(0, dt) with X(0) = 0 and S(0) = S0, has at expiry, t = T with X(T ) ∼ N(0, T ), the

solution S(T ) = S0 exp ((r − σ2/2)T + σX(T )). In what follows we let V be the payoff

function for a plain vanilla European-style option written on a non-dividend paying

underlying asset. In particular, if S is the underlying asset’s price at expiry then V (S)

will give the value of the option at that same time.

Task 2: sub-tasks

First make sure you know what the central limit theorem says. Then complete the following tasks.

1. Let Z1, Z2, Z3, . . . be a sequence of independent and identically distributed (i.i.d.)

random variables each with mean ν and variance ζ2. Define the sample mean,

SM = 1

M

M∑ i

=1

Zi

.

In your report explain why, as M gets large, we have: [4 marks]

SM − ν

ζ/√M ∼ N(0, 1) and Prob (S ζ/ M√ − M ν 6 x) → N(x).

8

Remark: you should be aware of the distinction between N(x) and N(ν, ζ2), but

if you aren’t then please ask.

2. Let ν and ζ2 be the exact (and unknown) mean and variance of the discounted

payoff functions, the pricing algorithm is as follows:

• for i = 1,2,3, . . . , M

• Si = S0 exp((r − σ2/2)T + σX(T))

• Vi = exp(−rT)V (Si)

• Next i.

• Estimate ν by V ¯ = M 1 ∑M i=1 Vi.

• Estimate ζ2 by V ˆ 2 = M1 −1 ∑M i=1(Vi − V ¯)2.

• Output approximate price V ¯ and approximate standard deviation V ˆ

This part of your assignment should be completed by creating a matlab function

in a file with the name task2.m (again, note that Windows usually adds the

last part, ‘.m’, for you). You should use the comment line help functionality, as

illustrated above for Task 1, to explain how this function is to be used.

Take the last three digits from your student ID number and call them x, y and z in

that order. For example, if your ID number is 0736154 then this becomes 0736xyz

so that in this case x = 1, y = 5 and z = 4. Now apply the following algorithm to

find out which version of this task you should implement:

• If y is smaller than x then do Version A.

• Otherwise, if z is smaller than y then do Version B.

• Otherwise, do Version C.

For the ID number example given above we see that y is not smaller than x but

z is smaller than y, so we would do Version B. State clearly in your report the

values that you have and the version that you chose. In the following replace

each occurence of x, y and z with the corresponding digit.

Version A:

A Bull Spread is formed by buying a call with exercise price K1 and writing

a call with exercise price K2 > K1. Both have the same underlying asset and

expiry date. Implement this algorithm in matlab to price a European version

of this derivative with the data [25 marks]

S = £1.0y, K1 = £0.75, K2 = £1.2x, σ = 0.1x, r = 0.03y, T = 0.25.

Version B:

A Straddle is formed by buying a call and a put with the same exercise price

K, underlying asset and expiry date. Implement this algorithm in matlab to

price a European version of this derivative with the data [25 marks]

S = £2.z0, K = £2.y0, σ = 0.2z, r = 0.05y, T = 0.15.

9

Version C:

A Strangle is formed by buying a put with exercise price K1 and buying a

call with exercise price K2 > K1. Both have the same underlying assest and

expiry date. Implement this algorithm in matlab to price a European version

of this derivative with the data [25 marks]

S = £1.4x, K1 = £1.2y, K2 = £1.5z, σ = 0.18, r = 0.04x, T = 0.35.

Take M ∈ {100, 1000, 10000, 100000} and tabulate (in your report) the resulting

prices. Give the exact value and assess the quality of your computed value. [1 mark]

3. Use matlab’s graphical functions to improve the code’s output. In particular plot

a histogram of computed values to give a visual impression of probability density function of the discounted payoff function. Include a

single sample of these

graphics in your report. (HINT: look up the ‘hist’ command.) [1 mark]

4. The statement V ¯ ∼ N(ν, ζ2/M) for the estimated option price becomes more accurate as M → ∞ (the central limit theorem). Explain why

you can infer from

this that the standard deviation of the estimate decreases like M −1/2 as M → ∞.

Explain how and why we can expect that,

Prob (ν − 1 √ .96 Mζ 6 V ¯ 6 ν + 1 √ .96 Mζ ) = 95%.

and show that this may also be written as,

Prob (V ¯ − 1 √ .96 Mζ 6 ν 6 V ¯ + 1 √ .96 Mζ ) = 95%

and, hence, explain why [V ¯ − 1√ .96 M V ˆ , V ¯ + 1√ .96 M V ˆ ] is an approximate 95% confidence

interval for the true option price. [4 marks]

5. Alter your matlab code so that it also prints out a 95% confidence interval for the

computed price. Include these confidence intervals in your tabulated results. [2 marks]

6. Suppose that in matlab we generate N random normal variates with the statement X(1:N) = randn(N,1). Explain why, when we issue the

subsequent

statement, X(N+1:2*N) = -X(1:N) we will then have produced 2N random

normal variates for the price of only N random number generations. This leads to

the technique of variance reduction by antithetic variables. Look these terms up and

briefly comment in your report on the effect this has on the confidence intervals

and the probability distribution of the payoff function. Explain what the benefit

of this variance reduction technique is. NOTE: no extra coding is required. [4 marks]

7. Investigate the so-called curse of dimensionality: suppose for M = 10, 000 a matlab

program took one minute to give a Monte-Carlo price, V ¯, of an option with a 95%

confidence interval [0.38, 0.42] of width 4p. Estimate how large M would have to

be to reduce the width of this interval by a factor of ten to 0.4p. Estimate how

long the matlab code would now take to run. [4 marks]

10

8. Up to five marks will also be awarded for high quality written style, grammar,

structure and presentation. You may use the ‘draft hand in’ opportunity to obtain

feedback on this aspect of the assignment. [5 marks]

Recommended Reading

[1] Desmond J. Higham. An introduction to financial option valuation; mathematics,

stochastics and computation. Cambridge University Press, New York, 2004.

[2] Nicholas J. Higham. Handbook of writing for the mathematical sciences. SIAM, 1998.

11

TAKE ADVANTAGE OF OUR PROMOTIONAL DISCOUNT DISPLAYED ON THE WEBSITE AND GET A DISCOUNT FOR YOUR PAPER NOW!

**Category**: Essay