A matlab function is not running. Can someone help me?

조회 수: 3 (최근 30일)
Andrea Miceli
Andrea Miceli 2022년 1월 14일
편집: John D'Errico 2022년 1월 14일
Hello evreone, I am trying to run this code, but I get this error:' Invalid expression. Check for missing or extra characters.'
The error isn't the code but the funcion " mertonmodel" because I can't even run the code showed into the documentation (https://it.mathworks.com/help/risk/mertonbytimeseries.html)
I tried to reinstall the matlab license and I have already checked the the tools.
What's strange for me is the fact that the function "mertonByTimeSeries " that is from the same ToolBox is working.
Can someone explain me how to proceed? Or maybe you can see if with my code is working with your matlab and show me the plot: plot(Equity, PD).
Thankyou in advance.
EquityVol2 = 0.198;
Liability2 = 66.547;
Rate2 = 0.009;
Maturity2 = 5;
Equity2=7000/10000;
EquityVol = zeros(1,10000);
Liability = zeros(1,10000);
Rate = zeros(1,10000);
Maturity = zeros(1,10000);
Equity=zeros(1,10000);
EquityVol(:) = EquityVol2;
Liability(:) = Liability2;
Rate(:) = Rate2;
Maturity(:) = Maturity2;
Equity(1)=Equity2;
for i=2:size(Equity,2)
Equity(i)=Equity(i-1)+Equity2;
end
[PD,DD,A,Sa] = mertonmodel(Equity,EquityVol,Liability,Rate,'Maturity',Maturity);
plot(Equity, PD)

채택된 답변

John D'Errico
John D'Errico 2022년 1월 14일
편집: John D'Errico 2022년 1월 14일
No problem. It runs fine, using EXACTLY the code you posted.
I will point out that when you report an error, please report the ENTIRE error message, not just what you think is important about that message. So show EVERYTHING in red.
Anyway, I pasted in the code you show, and I get this:
EquityVol2 = 0.198;
Liability2 = 66.547;
Rate2 = 0.009;
Maturity2 = 5;
Equity2=7000/10000;
EquityVol = zeros(1,10000);
Liability = zeros(1,10000);
Rate = zeros(1,10000);
Maturity = zeros(1,10000);
Equity=zeros(1,10000);
EquityVol(:) = EquityVol2;
Liability(:) = Liability2;
Rate(:) = Rate2;
Maturity(:) = Maturity2;
Equity(1)=Equity2;
for i=2:size(Equity,2)
Equity(i)=Equity(i-1)+Equity2;
end
[PD,DD,A,Sa] = mertonmodel(Equity,EquityVol,Liability,Rate,'Maturity',Maturity);
plot(Equity, PD)
Kind of a boring plot, IMHO, but that is not relevant. :) This was run in R2021b, since it ran using the online version. (I don't have the necessary toolbox myself, but Answers does.)
You will need to be careful that you did not edit code from that toolbox.
You will need to be sure you did not save a file with the same name as a function from that toolbox.
  댓글 수: 2
Andrea Miceli
Andrea Miceli 2022년 1월 14일
"You will need to be sure you did not save a file with the same name as a function from that toolbox." this was the problem thank you
John D'Errico
John D'Errico 2022년 1월 14일
편집: John D'Errico 2022년 1월 14일
Ah. That seems to be a common mistake made by users. That gets MATLAB terribly confused. And we really don't want confused computers running around these days. They might decide to take over the world. :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Agriculture에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by