|
貌似好像函数a、b、c里面不认r、sigma的值 不知道怎么弄,新人求助,谢谢
rm(list=ls())
triA=function(Smin=0,Smax,T=1,N=10,M=10,K,r=0.05,sigma=0.01)
{Dt=T/N;Ds=Smax/M;
#系数aa、bb、cc
a=function(j){1/2*r*j*Dt-1/2*sigma^2*j^2*Dt}
b=function(j){1+sigma^2*j^2*Dt+r*Dt}
c=function(j){-1/2*r*j*Dt-1/2*sigma^2*j^2*Dt}
aa=sapply(0:M,a);bb=sapply(0:M,b);cc=sapply(0:M,c)
#矩阵A
A=matrix(0,M-1,M-1)
for (i in 1M-1)){
A[i,i]=bb(i)
if (i>1)
A[i,i-1]=aa(i)
if (i<M)
A[i,i+1]=cc(i)
}
A
}
|
|