How to Perform iteration with conditions? Help Please!!

1 view (last 30 days)
I have the following arrays with which i need to work with, been working on this the whole day and haven't got anything out of it. Help would greatly be appreciated. Thanks.
I have these two variables in the attached excel file. Wgt, LgRet
%%Step 1 - Find the Beta using the Wgt and LgRet
Port_ret = LgRet*Wgt;
Beta = zeros(1,N);
for w = 1:N
Beta(w) = regress(LgRet(:,w),Port_ret);
end
%%Step 2 Check the property LHS == RHS
LHS = Beta.*Wgt';
RHS = (1/N)*ones(1,N);
% if LHS == RHS then the Wgt satisfies the property, if not perform iteration, by increasing the Wgt if LHS < RHS and decrease Wgt if LHS > RHS, and use the new Wgt to find Beta by repeating Step 1 until the equality LHS == RHS is obtained.
--------------------------------------------------------------------
% Here
% N is scalar
% Wgt is N-by-1 vector
% LgRet is M-by-N matrix
% Port_ret is M-by-1 vector
% Beta is 1-by-N vector
% LHS is 1-by-N vector
% RHS is 1-by-N vector
% However to get the correct Wgt,
% the condition LHS == RHS must satisfy.
% The problem needs to
% Increase Wgt if Beta.*Wgt' < RHS
% Decrease Wgt if Beta.*Wgt' > RHS
% And then perform *Setp 1* again, do this iteration until LHS == RHS
% *Note that sum of Wgt at all time must equal 1*
% in this exercise i use N as 100
% M as 1051

Answers (0)

Categories

Find more on MATLAB 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!