Using a Loop That Uses _n-1 obs.
Show older comments
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 Comment
vidhathri bhat
on 29 May 2019
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
Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!