全部版块 我的主页
论坛 金融投资论坛 六区 金融学(理论版) 金融工程(数量金融)与金融衍生品
1652 2
2011-01-30
Modify the SmartEurLattice program (as follow) so as to write out the values of the asset prices and their associated option prices side by side for the following parameters: S0=50, K=54, T = 5 months, risk free rate = 3%, and volatility = 30% . Use N= 5. You need to provide both the code as well as the output. The latter can be in form of a 3-column vector, with the first one for the time, the second for the asset price, and the third for the option price.

function price = SmartEurLattice(S0,K,r,T,sigma,N)
% Precompute invariant quantities
deltaT = T/N;
u=exp(sigma * sqrt(deltaT));
d=1/u;
p=(exp(r*deltaT) - d)/(u-d);
discount = exp(-r*deltaT);
p_u = discount*p;
p_d = discount*(1-p);
% set up S values
SVals = zeros(2*N+1,1);
SVals(1) = S0*d^N;
for i=2:2*N+1
SVals(i) = u*SVals(i-1);
end
% set up terminal CALL values
CVals = zeros(2*N+1,1);
for i=1:2:2*N+1
CVals(i) = max(SVals(i)-K,0);
end
% work backwards
for tau=1:N
for i= (tau+1):2:(2*N+1-tau)
CVals(i) = p_u*CVals(i+1) + p_d*CVals(i-1);
end
end
price = CVals(N+1);
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2011-1-31 09:20:06
execute SmartEurLattice(50,54,0.03,5/12,0.3,5)

function out = SmartEurLattice(S0,K,r,T,sigma,N)
% Precompute invariant quantities
deltaT = T/N;
u=exp(sigma * sqrt(deltaT));
d=1/u;
p=(exp(r*deltaT) - d)/(u-d);
discount = exp(-r*deltaT);
p_u = discount*p;
p_d = discount*(1-p);
% set up S values
SVals = zeros(2*N+1,1);
SVals(1) = S0*d^N;
for i=2:2*N+1
SVals(i) = u*SVals(i-1);
end
%============
S_out=[S0;SVals(2*N-3:-2:5);SVals(2*N-2:-2:4);SVals(2*N-1:-2:3);SVals(2*N:-2:2);SVals(2*N+1:-2:1)];
%============
% set up terminal CALL values
CVals = zeros(2*N+1,1);
for i=1:2:2*N+1
CVals(i) = max(SVals(i)-K,0);
end
% work backwards
for tau=1:N
for i= (tau+1):2:(2*N+1-tau)
CVals(i) = p_u*CVals(i+1) + p_d*CVals(i-1);
end
end
%============
P_out= [CVals(2*N-4);CVals(2*N-3:-2:5);CVals(2*N-2:-2:4);CVals(2*N-1:-2:3);CVals(2*N:-2:2);CVals(2*N+1:-2:1)];
Time_out=[0;ones(2,1);2*ones(3,1);3*ones(4,1);4*ones(5,1);5*ones(6,1)];
out=[Time_out S_out P_out];
%============
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-1-31 09:31:17
万分感谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群