필터 지우기
필터 지우기

Indexing in a for loop

조회 수: 5 (최근 30일)
civs
civs 2014년 8월 12일
댓글: civs 2014년 8월 12일
This is a code for daily portfolio rebalancing. I would like to rebalance every 10 days instead. How can I do that? Thanks!
.......................................................................
Rets=data(:,[2,3,4,5,6]); % All returns for the period under research
n= length(Rets);
% i represents the day number in the loop
% Amount invested is 1000 USD which is fixed at day 1001
for i= 1001:n-1
% Determine weights of global min-var portfolio
wmin_var{i-1000}= mean_var_portopt2(-10, Rets (i-1000:i-1,:));
PR_min_var(i+1)= Rets(i+1,:)* wmin_var{i-1000};
% Compute tomorrow's portfolio value as
V_min_var(1001)=1000; % first value is fixed
V_min_var(i+1)= V_min_var(i)*(PR_min_var(i+1)+1);
end

답변 (1개)

Joakim Magnusson
Joakim Magnusson 2014년 8월 12일
I'm not sure i understand but maybe this will work for you:
for i= 1001:10:n-1
  댓글 수: 1
civs
civs 2014년 8월 12일
Thanks! yeah I was thinking the same, I need to try that. In that case I would also have to change the index inside the loop to:
% Determine weights of global min-var portfolio
wmin_var{i-1000}= mean_var_portopt2(-10, Rets (i-1000:i-1,:));
PR_min_var(i+10)= Rets(i+10,:)* wmin_var{i-1000};
% Compute tomorrow's portfolio value as
V_min_var(1001)=1000; % first value is fixed
V_min_var(i+10)= V_min_var(i)*(PR_min_var(i+10)+1);
I am running the code for the daily rebalancing and it's taking some time. As soon as it finishes running I will try your suggestion. Thanks Joakim!

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

카테고리

Help CenterFile Exchange에서 Portfolio Optimization and Asset Allocation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by