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);

 채택된 답변

Image Analyst
Image Analyst 2021년 5월 11일

0 개 추천

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

This is the code from an author, so i really dont know what's the problem, i forgot to say i removed V from sigmaV and i got these errors:
Error using +
Matrix dimensions must agree.
Error in GetV (line 4)
V_high=S_observed+F;
Error in Merton_loglvec (line 8)
[V,d]=GetV(S_observed,r,sigmaV,F,mat);
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 2021년 5월 11일
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?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Scope Variables and Generate Names에 대해 자세히 알아보기

제품

질문:

2021년 5월 11일

댓글:

2021년 5월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by