Hello, I am developing a code that will need to use forecast future prices using _n-1 observation. For example, I if I am forecasting the prices on day 33, my equation would use the price of day 32 in the equation. My current code is as follows:
S0=2809;
K=2750;
for j=1:252;
for c=1:1000
S(c,j)=S0*exp((.0295-.5*(.2^2))*.004+.0295*sqrt(.004)*eps(c,j));
end
end
Right now I have every cell being priced with S0. My confusion is how do I keep one variable, S, and still reference, for column , S0, but for columns 2 through 252 I reference S_n-1.

댓글 수: 1

Are you using only (n-1)th observation? If so isn't it stored in S(c,j-1)?
S0=2809;
K=2750;
%for S(c,1)
for c=1:1000
S(c,1)=S0*exp((.0295-.5*(.2^2))*.004+.0295*sqrt(.004)*eps(c,1));
end
for j=2:252;
for c=1:1000
S(c,j)=S(c,j-1)*exp((.0295-.5*(.2^2))*.004+.0295*sqrt(.004)*eps(c,j));
end
end

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2019년 5월 21일

댓글:

2019년 5월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by