• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Stopping times in Matlab

  • Thread starter Thread starter figo
  • Start date Start date
Joined
4/15/11
Messages
1
Points
11
Hi all,

for my project at uni I wanted to implement a modified binomial approach to price barrier options in Matlab.

In the first step I am approximating the price process by a step function Z with jumps at random times r_n. Z(t) jumps if and only if the price process Y changes by delta.

For a given accuracy delta we can define a step function according to:

r_0 = 0
r_n = inf{t \in [0,T] | t > r_(n-1), |Y(t) - Y(r_(n-1))| >delta}

Z(t) = \sum{n=0}{\infty} Y(r_n)*1_{r_n, r_(n+1)}(t)

I am struggling with the matlab implementation. I started learning Matlab 2 days ago and still are not really familiar with it.

I have problems to implement the stopping times. I want to be able to get the values r_n since i need to calculations with them at a later point.

Could you help me here?
Thank you!



I modelled the price process like this:

function X = binomialbarrier(delta,rate,vola,barrier,T,spot,K)

%Binomial Tree
N=90
t = (0:1:N)'/N; % t is the column vector [0 1/N 2/N ... 1]

W = [0; cumsum(randn(N,1))]/sqrt(N); % S is running sum of N(0,1/N) variables

t = t*T;
W = W*sqrt(T);

Y = log(spot)+(rate-(vola^2)/2)*t + vola * W; %geometric brownian motion


trans.gif
 
Judging from some code posted on wiki.
Does the following work?
Code:
dY = [0 diff(Y)];
jumps = (abs(dY) > delta);
Z = cumsum(Y .* jumps);
First line calculates the changes in Y.
(the left-concatenation of 0 is because diff(Y) has array length is one less than that of Y)
The second line is the signal of all indices at which Y jumped by more than dY in either direction.
The last line cumulatively adds up these jumps, using Y as the magnitude of the jump.
If you need to also switch whether the jump is positive or negative, instead use "cumsum(Y .* sign(dY) .* jumps)"

EDIT: Oops, necro'd, shame on me.
 
Back
Top