【代码】Asian arithmetic Option

对算术平均亚式期权Matlab代码的阅读;

Payoff of Asian arithmetic’s is

输入参数

  • r = risk free rate
  • u , d : $S_1(up)=S_0u, S_1(down)=S_0d$
  • strike = strike price (K)
  • s0 = $S_0$
  • imax = T or periods
1
2
3
r = 0.03; u = 1.1; d = 0.9; 
strike = 9.5; S0 = 9;
imax = 3;

初始化

  • rnp = $\frac{1+r-d}{u-d}$ , risk neutral probability
  • SS : 初始化价格树,因为不同于欧式需要记录每一步,即$S_0ud$和$S_0du$的平均价格不等,因此需要$2^{imax}$种情况
1
2
3
rnp = (1+r-d)/(u-d);
SS = zeros(2^imax,imax+1);
SS(:,1) = S0;
output:

​ SS = (2^imax,imax+1)

建立up-down组合表

  • matr : 将所有可能排成$2^{imax}$行
1
2
3
4
5
6
7
8
matr=[];
for i = 1:imax
v1 = ones(2^(i-1),1);
v2 = -v1;
vc = repmat([v1;v2],2^(imax-i),1);
% repmat : 将矩阵[v1;v2]重复到2^(imax)×1块排列中
matr = [vc,matr]; %类似+=,从左加
end
output:

​ matr = (2^imax,imax)

补充价格树

  • 按照matr的组合对SS进行补充
1
2
3
4
5
6
7
8
for z = 1:2^imax
for k = 2:imax+1
SS(z,k)=SS(z,k-1)*u;
if matr(z,k-1)<0
SS(z,k)=SS(z,k-1)*d;
end
end
end
output:

​ SS = (2^imax,imax+1)

计算收益

  • 按照公式计算收益
1
2
payoff = max(sum(SS,2)/(imax+1)-strike,0); % Asian arithmetic's
%payoff = max(prod(SS,2)^(imax+1)-strike,0); % Asian geometric's
output:

​ payoff = (2^imax,1)

计算每个up-down组合up的次数

1
2
3
4
5
6
7
8
9
for i=1:2^imax
ind1 = 0;
for j =1:imax
if matr(i,j)>0
ind1=ind1+1;
end
end
pp(i)=ind1;
end
output:

​ pp = (1,2^imax)

计算期望值

  • rnp_payoff = $rnp ^{pp}*(1-rnp)^{imax-pp}$
  • option_price = $\frac{E_{rnp}[payoff]}{(1+r)^{imax}}$
1
2
rnp_payoff=(rnp.^pp).*(1-rnp).^(imax-pp);
option_price=sum(payoff.*rnp_payoff')/((1+r)^imax);
output:

​ rnp_payoff = (1,2^imax)

​ rnp_payoff = (1,1)


【代码】Asian arithmetic Option
http://achlier.github.io/2021/02/17/Asian_arithmetic_Option_With_MatlabCode/
Author
Hailey
Posted on
February 17, 2021
Licensed under