A matlab function is not running. Can someone help me?
1 view (last 30 days)
Show older comments
Andrea Miceli
on 14 Jan 2022
Edited: John D'Errico
on 14 Jan 2022
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)
0 Comments
Accepted Answer
John D'Errico
on 14 Jan 2022
Edited: John D'Errico
on 14 Jan 2022
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 Comments
John D'Errico
on 14 Jan 2022
Edited: John D'Errico
on 14 Jan 2022
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. :)
More Answers (0)
See Also
Categories
Find more on Test Execution 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!