Using a Loop That Uses _n-1 obs.
显示 更早的评论
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 个评论
vidhathri bhat
2019-5-29
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 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!