Borrar filtros
Borrar filtros

Unable to perform assignment because value of type 'sym' is not convertible to 'double'.

32 visualizaciones (últimos 30 días)
function [U]=timerpathCALLfinite(s0,v0,sigma,kappa,K,B)%varibles
s0=100;
v0=0.001;
K=100;
T=2;
steptime=256;
dt=T/256;
B=0.001;
r=0.01;
sigma=0.25;% not larger then 0.1
kappa=0.1;
rho=0.5;
v=zeros(T*steptime);%volatility price
v(1)=v0;%initial price;
zpath(1)=(2*sqrt(v0))/sigma;
deta=(4*kappa)/(sigma^2); % Bessel process parameter
nu=deta/2-1; % bessel model index
sum(1)=0;
p(1)=0;
for j=1:steptime*T% search stopping time
v(j+1)=v0*exp((kappa-0.5*sigma^2)*(j*dt)-sigma*sqrt(j*dt)); %volatility
sum=sum+dt*((v(j)+v(j+1))/2);% cumulation volitility
if sum>=B
tau=j+1;
br=tau*dt;
break;
end
end
if sum>=B % at stopping time exercise
syms ztau R
%%insert expectation
d=sqrt((1-rho^2)*B);
vaps=-rho*(2*kappa/(sigma^2)-0.5).*(0.5*(1./ztau+1/zpath(1)).*B)+(r.*br)-(B/2)+rho.*(ztau-zpath(1));
d1=((log(s0/K)+vaps+(1-rho^2)*B))./d;
d2=d1-d;
infi=s0.*exp(vaps-r.*br).*normcdf(d1)-K.*exp(-r.*br).*normcdf(d2); %inner expectation
%%intervsion laplace transform to density
alpha=18.4/(2*B); % laplace parameter
sh=sinh(R.*sqrt(alpha./2)); % large value
pe=besseli(sqrt(alpha),2.*sqrt(2.*alpha.*zpath(1).*ztau)./sh);%bessel function
LAP=real(pe.*sqrt(2.*alpha).*(ztau.^(nu+1))./(sh.*8*(zpath(1)^(nu))).*exp(-((nu^2)*br*(sigma^2))/8-((zpath(1)+ztau).*sqrt(2*alpha).*coth(R.*sqrt(alpha/2)))));
%%% DOUBLE integral outer expectation
U=trapz(0:1,trapz(0:1,infi.*inverlap1(LAP,alpha,R,ztau,br),2));
function[disthree]=inverlap1(LAP,alpha,R,ztau,br)
v0=0.001;
B=0.001;
sigma=0.25;% not larger then 0.1
kappa=0.1;
v(1)=v0;%initial price;
zpath(1)=(2*sqrt(v0))/sigma;
deta=(4*kappa)/(sigma^2); % Bessel process parameter
nu=deta/2-1; % bessel model index
H2=LAP/2;
for t=1:1:15
alphaP=complex(alpha,(t*pi)/B);
sh1=sinh(R.*sqrt(alphaP/2));
pe1=besseli(sqrt(alpha+(t*pi)/B),2.*sqrt(2.*alphaP.*zpath(1).*ztau)./sh1);
H2=H2+((-1)^t).*real(pe1.*sqrt(2.*alphaP).*(ztau.^(nu+1))./(sh1.*8.*(zpath(1)^(nu))).*exp(-((nu^2).*br.*(sigma^2))./8-((zpath(1)+ztau).*sqrt(2.*alphaP).*coth(R.*sqrt(alphaP./2)))));
end
SU=zeros(12);
SU(1)=H2;
for I=1:12
NT=15+I;
alpha2=complex(alpha,(NT*pi)/B);
sh2=sinh(R.*sqrt(alpha2/2));
pe2=besseli(sqrt(alpha+(NT*pi)/B),2.*sqrt(2.*alpha2.*zpath(1).*ztau)./sh2);
SU(I+1)=SU(I)+((-1)^NT).*real(pe2.*sqrt(2.*alpha2).*(ztau.^(nu+1))./(sh2.*8.*(zpath(1).^(nu))).*exp(-((nu^2).*br.*(sigma^2))./8-((zpath(1)+ztau).*sqrt(2.*alpha2).*coth(R.*sqrt(alpha2./2)))));
end
AVGSU=0;
C=[1,11,55,165,330,462,462,330,165,55,11,1];
for J=1:12
AVGSU=AVGSU+C(J)*SU(J);
end
U=exp(18.4/2)/B;
disthree=(U.*AVGSU)./2048;
end
  2 comentarios
Cris LaPierre
Cris LaPierre el 15 de Abr. de 2023
Please share the full error message (all the red text).
Note that the code you have shared here cannot be run due to syntax errors.
JICHAO ZHANG
JICHAO ZHANG el 16 de Abr. de 2023
Error using trapz (line 66)
Point spacing must be a scalar specifying uniform spacing or a vector of x-coordinates for each data point.
Error in timerCALLfinite (line 46)
U=trapz(0:0.001:1,trapz(0:0.001:1,infi.*inverlap1(LAP,alpha,R,ztau,br),2));

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 15 de Abr. de 2023
Are you 100% sure you need symbolic variables? Why can't you do it numerically with regular double variables? Try it.

Categorías

Más información sobre Numbers and Precision en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by