-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_stock.m
31 lines (26 loc) · 933 Bytes
/
run_stock.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function [stock f_surface] = run_stock(p, prev, i, Z)
if isempty(prev.S(i).f_surface)
if isempty(p.S(i).fixedSigma)
% calulate local vol surface
surface = local_vol_surface(p.S(i), p.r);
f_surface = @(t,s) local_vol(surface, t, s);
else
% use a constant vol surface
f_surface = @(t,s) p.S(i).fixedSigma;
end
else
f_surface = prev.S(i).f_surface;
end
stock = euler_simulation(p.S(i).x_0, p.T, f_surface, Z, p.r);
end
% from: run_put
function sigma = local_vol(surface, t, s)
t_index = floor(t / surface.dT);
s_index = floor(s / surface.dK);
% clamp our volatility on the bottom and top level
t_index(t_index < 1) = 1;
t_index(t_index > numel(surface.maturities)) = numel(surface.maturities);
s_index(s_index < 1) = 1;
s_index(s_index > numel(surface.strikes)) = numel(surface.strikes);
sigma = surface.surface(t_index, s_index)';
end