Using macro to compute yield to maturity

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Using macro to compute yield to maturity

Postby parantap » Thu Jul 20, 2017 7:29 pm

Hi all,
I am on a learning curve on macro processor.
I am trying to calculate yield to maturity (ytm) formula as follows based on a consumption CAPM model. The goal is to plot ytm against i. I tried this code.

....


@#define J=30
@#for i in 1:J

ytm=betta^-1*(c(+i)/c)^(1/i);

@#endfor
...............................

I get an error message.
Symbol c is being treated as if it were a function (i.e., takes an argument that is not an integer).

I must be doing something silly.
parantap
 
Posts: 31
Joined: Tue Oct 01, 2013 11:58 pm

Re: Using macro to compute yield to maturity

Postby StephaneAdjemian » Thu Jul 20, 2017 7:46 pm

Hi,

You should read the section devoted to the macro language in the reference manual:

http://www.dynare.org/manual/index_37.h ... g-language

If you rewrite the statement inside the loop as

Code: Select all
ytm = (c(@{i})/c)^(1/@{i})/betta;


it should work better... You cannot use directly use the index i, you have to include it in @{}, as in other macro expression.

Best,
Stéphane.
Stéphane Adjemian
Université du Maine, GAINS and DynareTeam
https://stepan.adjemian.eu
StephaneAdjemian
 
Posts: 429
Joined: Wed Jan 05, 2005 4:24 pm
Location: Paris, France.

Re: Using macro to compute yield to maturity

Postby parantap » Thu Jul 20, 2017 8:12 pm

Thank you Stephanne. Yes I am reading it. i am on a steep learning curve on this. The complication now is that it creates 435 auxiliary variables and thus number Of eqns far exceeds the number of variables. I believe I have to now declare all these new variables at the top usung macro processor.
parantap
 
Posts: 31
Joined: Tue Oct 01, 2013 11:58 pm

Re: Using macro to compute yield to maturity

Postby StephaneAdjemian » Thu Jul 20, 2017 8:29 pm

Sorry, I didn't really think about what is in the loop. Here you put an equation in the loop, so you create thousands of equation. I am quite sure that this is not what you intend. The equal sign should not be in the loop. I suppose you want to use this loop to write a product (or a sum) of terms in an equation. Perhaps it would be easier if you write what you want to compute...

Best,
Stéphane.
Stéphane Adjemian
Université du Maine, GAINS and DynareTeam
https://stepan.adjemian.eu
StephaneAdjemian
 
Posts: 429
Joined: Wed Jan 05, 2005 4:24 pm
Location: Paris, France.

Re: Using macro to compute yield to maturity

Postby parantap » Thu Jul 20, 2017 9:13 pm

Dear Stephane,
Here is what I want to do. I would like to research what happens to ytm of various maturities. with respect to some monetary policy shock? That is why I wanted to create an array of ytm and then run an irf for each.

I can easily create manually 10 or 15 ytm variables and do this experiment. But I wanted to use the macro processor. But doing so, it gives rise to 400 auxiliary variables.
PB
parantap
 
Posts: 31
Joined: Tue Oct 01, 2013 11:58 pm

Re: Using macro to compute yield to maturity

Postby StephaneAdjemian » Thu Jul 20, 2017 9:38 pm

I still don't understand and would need to look at the equations. With this loop you add equations without adding variables, so obviously it cannot work. Do you mean that you need different variables on the left hand side (this would work)? To do that, you could try something like:

Code: Select all
ytm_@{i} = (c(@{i})/c)^(1/@{i})/betta;


assuming that you have another loop in the list of declared endogenous variables (to declare ytm_1, ytm_2, ...).

Best,
Stéphane.
Stéphane Adjemian
Université du Maine, GAINS and DynareTeam
https://stepan.adjemian.eu
StephaneAdjemian
 
Posts: 429
Joined: Wed Jan 05, 2005 4:24 pm
Location: Paris, France.


Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 6 guests

cron