Hello everybody,
I face this streange problem
i try to find opportunity cost measure for my portfolio and i run this code:
function [opcost] = expopportcost(Retwv,Retnv,g)
i = 0;
exponential_utility_wv = -exp(-(1+Retwv).*g)./g;
expected_utility_wv = sum(exponential_utility_wv)/length(Retwv);
for theta = -0.5:0.0001:0.5
exponential_utility_nv = -exp(-(1+Retnv+theta).*g)./g;
i = i+1;
objective_function(i) = abs(expected_utility_wv - sum(exponential_utility_nv/length(Retwv)));
end
[val, position] = min(objective_function);
theta = -0.5 + 0.0001*(position-1);
opcost = theta;
end
Its for exponential utility and Retwv = xlsread("file1.xlsx") and Retnv=xlsread("file2.xlsx") ......the returns for two assets and g=2 (risk averse coefficient) i define the g.
when i run the code with monthly retuns = 38 monthly observations everything is fine!
but when i run the code with daily returns = 755 daily observations always the "val = NaN" and the result is -0.5 which is wrong!!!
i change only the returns in excel files ....i tried to change the format of values in excel but i think this is not problem...
Why this happend? i need help immidiately!
thanks in advance!!

댓글 수: 4

Walter Roberson
Walter Roberson 2019년 4월 16일
-0.5 exactly or that minus 0.0001?
Panos Raptis
Panos Raptis 2019년 4월 16일
-0.5
because val = NaN and position = 1
so theta=-0.5
thanks for the reply
Walter Roberson
Walter Roberson 2019년 4월 17일
Can you attach the files?
Panos Raptis
Panos Raptis 2019년 4월 17일
im sorry for the delay response
i attach the files with returns monthly and daily for two assets
g=2
if you run monthly everything its fine
but when you run daily val=NaN and position=1 and theta = -0.5

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

 채택된 답변

Walter Roberson
Walter Roberson 2019년 4월 17일

1 개 추천

Line 265 of your Retnv_daily.xls file contains 'RP' instead of a number and so is being replaced with NaN.
You might want to add the 'omitnan' flag to your sum() calls.

댓글 수: 3

Panos Raptis
Panos Raptis 2019년 4월 17일
yes my wrong when i copy the values, but its same the result is -0.5.....i substitute the rp with number
Walter Roberson
Walter Roberson 2019년 4월 17일
With the revised file, I get 0.0025 for the daily.
Panos Raptis
Panos Raptis 2019년 4월 17일
yes you are right ....i will check it again beacuse i have many files with returns and i had the same result.
thanks a lot for your time!!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

질문:

2019년 4월 16일

댓글:

2019년 4월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by