Reference to non-existent field

1 visualización (últimos 30 días)
Jony Bench
Jony Bench el 11 de Mayo de 2021
Comentada: Image Analyst el 11 de Mayo de 2021
Hello i'm new to matlab, this is my error "Reference to non-existent field 'sigmaV'."
This is my code:
%Script tests the particle filter
%simulation parameters
%[sigma sigmaN mu F/V_end]
param_real=[.25 0.0001 .18 1];
sigma=param_real(1); %asset volatility
delta=param_real(2); %measurement noise
mu=param_real(3); %asset drift
F0=1; %debt
V_end=F0/param_real(4); %end-of-sample pseudo-leverage
r=.05; %riskfree rate
dt=1/250; %observation frequency
T=10; %beginning maturity
t=9; %end-of-sample maturity
%number of simulated paths
Npath=1;
randn('state',0);
%%%%%%%%%%%%%%%%
%Simulate paths%
%%%%%%%%%%%%%%%%
for m=1:Npath
[S(:,m),AssetValue(:,m),mat]=SimMerton_Equity(V_end,dt,mu,r,sigma,F0,T,t,delta);
end
%%%%%%%%%%%%%%%%%%%%%%%
%set filter parameters%
%%%%%%%%%%%%%%%%%%%%%%%
samplesize=length(mat);
F=ones(samplesize,1)*F0;
modelparam.dt=dt;
modelparam.r=r;
modelparam.sigma=sigma/20;
modelparam.mu=mu;
modelparam.delta=delta;
%number of particles
M=1000;
R=1000;
%random number seed to filter
seed=0;
%generate prior
Prior=log(AssetValue(1))+randn(M,1)*.1;
%%%%%%%%%%%%
%Run Filter%
%%%%%%%%%%%%
tic
[L,V]=feval('LocalizedFilter',modelparam,Prior,R,seed,S(1:100),F(1:100),mat(1:100));
toc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%loglikelihood from transformed data method%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
L3=Merton_loglvec([modelparam.sigmaV modelparam.mu],S(1:100),r,F(1:100),mat(1:100),modelparam.dt);

Respuesta aceptada

Image Analyst
Image Analyst el 11 de Mayo de 2021
I see you assigned
modelparam.sigma=sigma/20;
but where exactly did you assign
modelparam.sigmaV = ?????????????????????
I'm not seeing it. You need to assign it some value. Or maybe you want to use modelparam.sigma instead of modelparam.sigmaV???
  3 comentarios
Jony Bench
Jony Bench el 11 de Mayo de 2021
and these are the functions GetV and Merton_Loglvec
function [V,d]=GetV(S_observed,r,sigmaV,F,mat,MAXITER,tol)
V_low=S_observed;
V_high=S_observed+F;
%compute equity values from Merton's model
iter=0;
stopcrit=1;
if nargin<7
tol=.00000001;
end
if nargin<6
MAXITER=1000;
end
while (stopcrit>0 & iter<MAXITER)
V_new=(V_low+V_high)/2;
%evaluate S at V_new
d=(log(V_new)-log(F)+(r+sigmaV^2/2).*mat)./(sigmaV*sqrt(mat));
S=V_new.*normcdf(d)-F.*exp(-r.*mat).*normcdf(d-sigmaV*sqrt(mat));
k1=find(S<S_observed);
V_low(k1)=V_new(k1);
k2=find(S>=S_observed);
V_high(k2)=V_new(k2);
stopcrit=max(abs(V_high-V_low))>tol;
iter=iter+1;
end
if (iter==MAXITER)
warning('MAXITER reached in GetV')
end
V=V_new;
---------------------
function [logl_vec,lnV]=Merton_loglvec(param,S_observed,r,F,mat,dt)
%PURPOSE: returns vector of loglikelihood values for Merton's model using transformed data method
sigmaV=param(1);
mu=param(2);
[V,d]=GetV(S_observed,r,sigmaV,F,mat);
samplesize=length(S_observed);
lnV=log(V);
logl=-1/2*log(2*pi)-1/2*log(sigmaV^2*dt)...
-(lnV(2:end)-lnV(1:end-1)-(mu-sigmaV^2/2)*dt).^2/(2*sigmaV^2*dt);
%get determinant of jacobian
detJ=-log(normcdf(d(2:end)))-lnV(2:end)+log(S_observed(2:end));
logl_vec=logl+detJ;
Image Analyst
Image Analyst el 11 de Mayo de 2021
Evidently S_observed and F don't have the same lengths. It says that. What does it say in the workspace that their lengths are?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Particle & Nuclear Physics en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by