s0=41350;
npath=10000;
nstep=252;
sigma=0.2;
r=0.05;
sk=35000;
f=0.0001;
t=1;
rx=randn(npath,nstep);
deltat=t/nstep;
s=[s0*ones(npath,1) zeros(npath,nstep-1)];
for i=1:nstep-1
s(:,i+1)=s(:,i)+s(:,i)*r*deltat+sigma*deltat^0.5*(s(:,i).*rx(:,i));
end;
for m=1:nstep
[cdelt(:,m),pdelt(:,m)]=blsdelta(s(:,m),sk,r,1-(m-1)*deltat,sigma,0);
end;
% 产生现货持仓头寸
tc=ones(npath,nstep);
tcc(:,k)=1200*tc(:,k);
%每天需对冲头寸
dc=round(tcc.*pdelt);
%期货合约的价值
hyjz=(dc.*s*5);
bzj= hyjz*0.05*-1;
bzjMax = max(bzj')';
%头寸变化
dcb=[0*ones(npath,1) zeros(npath,nstep-1)];
for i=1:nstep-1
dcb(:,i+1)=(dc(:,i+1)-dc(:,i));
end
%手续费
zx=zeros(npath,nstep);
for m=1:nstep
zx(:,m)=exp(-r*(m-1)*deltat);
end
sxf=[abs(hyjz(:,1))*fzeros(npath,nstep-1)];
for i=1:nstep-1
sxf(:,i+1)=abs(dcb(:,i+1)).*s(:,i+1)*5*f.*zx(:,i+1);
end
zsxf=[sxf(:,1), zeros(npath,nstep-1)];
for i=1:nstep-1
zsxf(:,i+1)=zsxf(:,i)+sxf(:,i+1);
end
%平仓盈亏
pc=zeros(npath,nstep);
for i=1:npath
for j=1:nstep
if (dcb(i,j)>0 )
pc(i,j)=dcb(i,j)*(-1);
else
pc(i,j)=0;
end
end
end
%平仓盈亏的价格变化
jgbh=zeros(npath,nstep);
for i=1:nstep-1
jgbh(:,i+1)=s(:,i+1)-s(:,i);
end
pcyk=pc.*jgbh.*zx*5;
zpcyk=[pcyk(:,1), zeros(npath,nstep-1)];
for i=1:nstep-1
zpcyk(:,i+1)=zpcyk(:,i)+pcyk(:,i+1);
end
%持仓收益
cc=zeros(npath,nstep);
for m=1:npath
for j=1:nstep
if (dcb(m,j)<0 )
cc(m,j)=dc(m,j)-dcb(m,j);
else
cc(m,j)=dc(m,j);
end
end
end
ccyk=cc.*jgbh.*zx*5;
>> zccyk=[ccyk(:,1), zeros(npath,nstep-1)];
for i=1:nstep-1
zccyk(:,i+1)=zccyk(:,i)+ccyk(:,i+1);
end
%所有盈亏
zyk1=zeros(npath,5);
zyk1(:,1)=zsxf(:,nstep)*-1;
zyk1(:,2)=zpcyk(:,nstep);
zyk1(:,3)=zccyk(:,nstep);
zyk1(:,4)=zyk1(:,1)+zyk1(:,2)+zyk1(:,3);
zyk1(:,5)= bzjMax;
%期权复制平均成本
fzcb=mean(zyk1(:,4));
sig=std(zyk1(:,4))/npath^0.5;