Who can help me to run this code in matlab?

  • MATLAB
  • Thread starter xuej1112
  • Start date
  • Tags
    Code Matlab
In summary, the conversation revolves around a problem with running a code in MATLAB for the Vasicek model. The result obtained is different from the one shown in the book, with an increase curve in the book and a decrease curve in the result. The code is provided and there is speculation that there may be typos or errors in the code.
  • #1
xuej1112
18
0
who can help me to run this code in matlab? I run it in my computer but the result is totally different from the book! In the book,the image is a increase curve,but my result is a decrease curve.So, is there something wrong of my MATLAB?

code:

syms r P A B t;
P = exp(A+B*r);
disp('first derivative of P with respect to r')
diff(P,r)
disp('second derivative of P with respect to r')
diff(diff(P,r))

syms f B A s k m p r t DA DB
f1=0.5*B^2*s^2+B*(k*(m-r)-p*s)-DA-DB*r-r
collect(f1,r)

dsolve('-B*k-DB-1=0','B(0)=0')
B = -1/k+exp(-k*t)/k;
f2=1/2*B^2*s^2+B*(k*m-p*s)-DA
dsolve('1/2*(-1/k+exp(-k*t)/k)^2*s^2+(-1/k+exp(-k*t)/k)*(k*m-p*s)-DA=0','A(0)=0')

tau=(1:1:60)';
nTau=length(tau);
p=0.20;s=0.25;k=0.30;theta=5;r=6;
% Calculate A, B and the yield curve;
B=(exp(-k.*tau)-1)./k;
A=B.*(((p*s)/k)-theta)-theta.*tau+(p.*s.*tau)./k+(s^2/(4*k)).*(-(B.^2)+(2*exp(-k.*tau)-2)./(k^2)+(2.*tau)./k);
y=-(1./tau).*(A+B.*r);
figure;
plot(tau,y)
 
Physics news on Phys.org
  • #2
I would say change the sign of the exponential, it increases. There is no way that anybody can help you on this unless you state more precisely what the problem is.
 
  • #3
thank you! the problem is about a example of Vasicek model.it is in the book"Strategic Asset Allocation in Fixed Income Markets A Matlab based user's guide",page 77.It wants to solve a PDE of Vasicek model for bond pricing.
 
  • #5
Well, the code is running properly, and I don't have the book so my guess goes with some typos in the code... Try to comment some of the portions of the code and check by hand
 

1. Who can help me run my code in MATLAB?

There are several resources available to help you with running your code in MATLAB. You can reach out to your colleagues, classmates, or professors for assistance. You can also seek help from online forums or communities dedicated to MATLAB programming. Additionally, MATLAB offers technical support through email, phone, or chat.

2. How do I find someone to help me run my code in MATLAB?

If you are unable to find help from your immediate network, you can post your question on online forums such as MathWorks community, Stack Overflow, or MATLAB Central. You can also reach out to MATLAB technical support for assistance.

3. Do I need any specific qualifications to help someone run their code in MATLAB?

While having a background in MATLAB programming can be beneficial, there are no specific qualifications required to help someone run their code in MATLAB. As long as you have a good understanding of the software and its functions, you can assist others in running their code.

4. What should I do if I am stuck while trying to run my code in MATLAB?

If you encounter any difficulties while running your code in MATLAB, you can refer to the software's documentation or search for solutions on online forums. You can also reach out to MATLAB technical support for assistance.

5. Can I get help in running my code in MATLAB for free?

Yes, there are several free resources available to help you run your code in MATLAB. You can seek help from online forums, communities, or MATLAB technical support. However, some resources may require a subscription or membership fee for advanced assistance.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
951
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
505
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
Back
Top