sum(W)==1 used in a function does not work with the exact number
조회 수: 22 (최근 30일)
이전 댓글 표시
I have used "if sum(W)==1" in a function and the function does not work as it should. If I change it to "sum(W)<=1" it starts to work.
I have checked multiple times sum(W) is in fact equal to 1. I have tried several iterations e.g. increasing the value of W to more than 1 OR using "sum(W)>=1" In all iterations the conclusion is that something is getting lost in summation process and MATLAB thinks the sum is smaller than 1.
So my question what do I need to do for MATLAB to see that the sum of W is in fact 1 (and not less than 1).
The code (that works)is as follows:
function RARV=RARvariance1(A,B,C,D,E,F,G,H,W)
T=length(A); %Time period, the same for all assets
SW=sum(W);
if SW<=1
DD=[A-mean(A), B-mean(B), C-mean(C), D-mean(D), E-mean(E), F-mean(F), G-mean(G), H-mean(H)]; %Temporal, needed for covariances
Cov=DD'*DD/T;
V=W(1,:)*Cov*W(1,:)';
%Portfolio expected returns
ER=[mean(A), mean(B), mean(C), mean(D), mean(E), mean(F), mean(G), mean(H)]*W(1,:)';
%(Negative) risk adjusted return
RARV=-(ER)/sqrt(V); %Change V to sqrt(V) for semi-standard deviation
else
end
*I need the code to work with SW==1 *
Thanks
댓글 수: 2
Image Analyst
2013년 7월 20일
This should have been continued from your duplicate question. What is the value for W?
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Java Package Integration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!