Hi everybody,
i want to find lambda (single value) that determines the maturity at which the function achieves its max
((1-exp(-lambda*gmaturities))./(lambda*gmaturities)-exp(-lambda*gmaturities))
my code is
F=@(lambda)[((1-exp(-lambda*gmaturities))./(lambda*gmaturities)-exp(-lambda*gmaturities))];
lambda0=0.0609;
lambda=fsolve(F,lambda0)
and i got lambda = 1.005283084116551e+03,i know this is not correct
could you please help me?
gmaturities=[6;12;24;36;48;60;72;84;96;108;120;180;240]

 채택된 답변

Walter Roberson
Walter Roberson 2020년 5월 16일

0 개 추천

gmaturities = [6;12;24;36;48;60;72;84;96;108;120;180;240]
F = @(lambda) -(((1-exp(-lambda*gmaturities))./(lambda*gmaturities)-exp(-lambda*gmaturities)));
lambda0 = 0.0609;
lambda = gamultiobj(F, lambda0)
The result will be a vector of values, because you are trying to maximize 13 equations at the same time -- each of the values of gmaturies effectively defines another equation, so you are asking to maximize the equations simultaneously.
I suspect you want something more like
gmaturities = [6;12;24;36;48;60;72;84;96;108;120;180;240];
lambda0 = 0.0609;
lambda = arrayfun(@(GM) fminsearch(@(lambda) -(((1-exp(-lambda*GM))./(lambda*GM)-exp(-lambda*GM))), lambda0), gmaturities);

댓글 수: 3

masoumeh solgi
masoumeh solgi 2020년 5월 16일
편집: masoumeh solgi 2020년 5월 16일
thank you for your reply.
lamda should be a single value that determines the maturity at which the function achieves its max
Walter Roberson
Walter Roberson 2020년 5월 16일
Your function has 13 values because your maturities is a vector. No one lambda can maximize it all simultaneously.
The code I posted second optimizes for each individual maturity value.
masoumeh solgi
masoumeh solgi 2020년 5월 16일
Thank you

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2020년 5월 16일

댓글:

2020년 5월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by