How do I loop a portfolio return calculation for multiple periods in matlab? -
i have next data/sets (simplified version create illustration clear):
3*10
matrix of stocks identified number given period (3 stocks (my portfolio) in rows * 10 days (in columns) named indexbest. 10*10
matrix of returns each period each security in universe named dailyret (my universe of stocks 10). i want create loop able calculate sum returns of each portfolio each period 1 matrix ideally 1*10
or 10*1
(returns * date or vice versa).
i have done single period portfolio, see below: want able automate process instead of doing 10*
on each portfolio each period. please help!
portfolio_1_l= indexbest(:,1); %helps me portfolio constituents period 1 (3 stocks basically). returns_1_l= dailyret(portfolio_1(:,1));%to calculate returns of portfolio period 1 have referenced extraction of returns portfolio constituents. sum_ret_port_1_l=sum(returns_1_l); %sum homecoming of portfolio period 1
how loop process other 9 periods?
use for
loop , utilize index variable in place of hardcoded 1
in illustration code. index output store result each day.
for day = 1:10 portfolio_1_l = indexbest(:,day); returns_1_l = dailyret(portfolio_1_l); sum_ret_port_1_l(day) = sum(returns_1_l); end
matlab loops finance portfolio
No comments:
Post a Comment