Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about a formula implementation and how to extract the term premium #1

Open
skienthu opened this issue Oct 6, 2018 · 20 comments

Comments

@skienthu
Copy link

skienthu commented Oct 6, 2018

Hi;
The fitted yield is quite good , have a question about this code snippet

for i in range(0, n_maturities - 1):
A[0, i+1] = A[0, i] + B[:, i].T @ (mu - lambda0) + 1/2 * (B[:, i].T @ Sigma @ B[:, i] + 0 * sigmasq_ret) - delta0
B[:, i+1] = B[:, i] @ (phi - lambda1) - delta1
why are we multiplying "sigmasq_ret" with 0 here, looking at the paper this should be 0.5 .

Als how would you go about calculating the term premium, with this code.

@skienthu skienthu changed the title Question about how to extract the term premium from this Question about a formula implementation and how to extract the term premium Oct 7, 2018
@vilelalucas
Copy link

Thank you for the code. It worked for fitted yields perfectly. I tried to calculate term premium setting lamda0 and lamda1 to zero but it didnt work. How do you calculate the term premium? Best

@JCMBarros
Copy link

Hi,

i have the same problem as skienthu and vilelalucas. Both of you arealdy calculate de term premium? I tried a lof thing but nothing till now. Could you help me?

@urskabele
Copy link

hello,
i am coding in R and have the same problem. The yield fit is fine, but setting lambdas to 0 gives completely unsensible results. If anyone managed to solve the problem, I would appreciate a hint.
thanks

@decmarcin
Copy link

I believe there is an issue with scaling of the original raw yields. Should one add: rawYields=rawYields/100 just after uploading the xls file, everything is fine and the lambdas have good magnitude therefore the term premia are OK after zeroing out the lambdas

@skienthu
Copy link
Author

Yes I think that is very well spotted it works !!!.
Now in real world we don't have monthly liquid tradeable instruments. We need to rely on market quotes which will be for 1M, 3M, ... 1Y, 2Y, ... 5Y etc . In the example we do all operations on maturities 1M apart from 1M to 10Y ,
I tried to reduce the resolution and took only 1M, 3M, 6M, 1Y,2Y,3Y,4Y,5Y,5Y,7Y,10Y to see the results and there are not at all close to what the results we when we use 120 maturities. Has some one tried this combination ? if so would be good to know how this should be approached.

@muntumdwara
Copy link

Can you share the the update code for the term premia

@andreioanceanew
Copy link

After dividing by 100, still don't work proper. The risk neutral yields are far more lower than public data from FED and that makes the term premium bigger. Anyone know what is the problem?

@radaryl
Copy link

radaryl commented Jul 20, 2021

Dear Team,

Hey , the yields obtained using NSS parameters has to be continuously compounded. I have been checking the code on Indian data ( by estimating ZCYC yields across maturities using NSS parameter. The NSS parameters can be obtained from CCIL website)
Without continuous compounding there is huge mismatch between model fitted yield and observed yield. However for US one will not find the same mismatch. But one gets an abnormal term premium for US markets.

When using continuous compounding the problem associated with term premium for US market is resolved and the mismatch observed in Indian market is also addressed.

In load_gsw file only one correction is to be done.
return np.log(1+ 0.01*(Beta0 + Beta1 * (1 - np.exp(-n / Tau1)) / (n / Tau1) +
Beta2 * ((1 - np.exp(-n/Tau1))/(n/Tau1) - np.exp(-n/Tau1)) +
Beta3 * ((1 - np.exp(-n/Tau2))/(n/Tau2) - np.exp(-n/Tau2))))

and small correction in lamda0 line : lambda0 = np.linalg.pinv(beta.T) @ (a + 1/2 * (BStar @ vec(Sigma) + sigmasq_ret))
0 was multiplied to the sigmasq_ret term.
Hope the same solves the problem for you all

Thanks Michael Abrahams for providing the replication codes.
Regards
Arnab Biswas

Hi Arnab,

I tried your modification but the issue still not fixed when I applied to Fed data, did you solve it when plotting term premium? Can you share your code if possible?

Thank you very much!

@arnab13061989
Copy link

Dear Team,
Hey , the yields obtained using NSS parameters has to be continuously compounded. I have been checking the code on Indian data ( by estimating ZCYC yields across maturities using NSS parameter. The NSS parameters can be obtained from CCIL website)
Without continuous compounding there is huge mismatch between model fitted yield and observed yield. However for US one will not find the same mismatch. But one gets an abnormal term premium for US markets.
When using continuous compounding the problem associated with term premium for US market is resolved and the mismatch observed in Indian market is also addressed.
In load_gsw file only one correction is to be done.
return np.log(1+ 0.01*(Beta0 + Beta1 * (1 - np.exp(-n / Tau1)) / (n / Tau1) +
Beta2 * ((1 - np.exp(-n/Tau1))/(n/Tau1) - np.exp(-n/Tau1)) +
Beta3 * ((1 - np.exp(-n/Tau2))/(n/Tau2) - np.exp(-n/Tau2))))
and small correction in lamda0 line : lambda0 = np.linalg.pinv(beta.T) @ (a + 1/2 * (BStar @ vec(Sigma) + sigmasq_ret))
0 was multiplied to the sigmasq_ret term.
Hope the same solves the problem for you all
Thanks Michael Abrahams for providing the replication codes.
Regards
Arnab Biswas

Hi Arnab,

I tried your modification but the issue still not fixed when I applied to Fed data, did you solve it when plotting term premium? Can you share your code if possible?

Thank you very much!

Yes I plotted the term premium , US FRED estimates the term premium using three factor model , The whole idea of the paper was using five factors one has more accuracy in pricing yields , Term premium estimates may be different by few basis points . The codes are same , and I have used NSS parameters from GSW paper .
Second , one will have to apply small sample bias correction as recommender by Baur et al 2012 for more robust results.

@radaryl
Copy link

radaryl commented Jul 20, 2021

Dear Team,
Hey , the yields obtained using NSS parameters has to be continuously compounded. I have been checking the code on Indian data ( by estimating ZCYC yields across maturities using NSS parameter. The NSS parameters can be obtained from CCIL website)
Without continuous compounding there is huge mismatch between model fitted yield and observed yield. However for US one will not find the same mismatch. But one gets an abnormal term premium for US markets.
When using continuous compounding the problem associated with term premium for US market is resolved and the mismatch observed in Indian market is also addressed.
In load_gsw file only one correction is to be done.
return np.log(1+ 0.01*(Beta0 + Beta1 * (1 - np.exp(-n / Tau1)) / (n / Tau1) +
Beta2 * ((1 - np.exp(-n/Tau1))/(n/Tau1) - np.exp(-n/Tau1)) +
Beta3 * ((1 - np.exp(-n/Tau2))/(n/Tau2) - np.exp(-n/Tau2))))
and small correction in lamda0 line : lambda0 = np.linalg.pinv(beta.T) @ (a + 1/2 * (BStar @ vec(Sigma) + sigmasq_ret))
0 was multiplied to the sigmasq_ret term.
Hope the same solves the problem for you all
Thanks Michael Abrahams for providing the replication codes.
Regards
Arnab Biswas

Hi Arnab,
I tried your modification but the issue still not fixed when I applied to Fed data, did you solve it when plotting term premium? Can you share your code if possible?
Thank you very much!

Yes I plotted the term premium , US FRED estimates the term premium using three factor model , The whole idea of the paper was using five factors one has more accuracy in pricing yields , Term premium estimates may be different by few basis points . The codes are same , and I have used NSS parameters from GSW paper .
Second , one will have to apply small sample bias correction as recommender by Baur et al 2012 for more robust results.

Would you mind sharing your whole code that estimate term premium, either publicly or privately, with me? Working a project of term premium and really need that part to estimate TP. I would really appreciate it if that works for you!

@arnab13061989
Copy link

arnab13061989 commented Sep 27, 2021 via email

@arnab13061989
Copy link

arnab13061989 commented Sep 30, 2021

Hi Peter ,
I checked the output from the code using US nss parameters and compared with Tobias Adrian result , little difference is coming because the unconditional mean of the VAR equation is not taken zero , Tobias Adrian has done the analysis on demeaned yields , so the unconditional mean of VAR will be zero , so you will find around 2005 the TP touching zero and negative post 2011 . This extra thing has to be implemented in the code , over and above the continuous compounding which I had mentioned earlier
I have attached the TP plot of 10 year without setting unconditional mean to zero , you will find the difference due to the same between the result given in the paper and the same. The sample period is same as that taken in the code snippet.
I will share the basic revised codes soon.

Regards
Arnab

without unconditional mean to zero

@arnab13061989
Copy link

arnab13061989 commented Sep 30, 2021 via email

@arnab13061989
Copy link

arnab13061989 commented Sep 30, 2021

If one is using the cc yields from US FRED , please divide by 100 before proceeding . Second my initial comments were wrong, divide the yield using nss parameter by 100 , as nss also gives cc yield

@Hampton89
Copy link

If one is using the cc yields from US FRED , please divide by 100 before proceeding

Hey thank you for your code, I experienced some technical problems in implementing your code in R, but I tried your code in Python but didnt get the same result.

One problem I have when looking at your code is:

Run Bond Pricing recursion

A = rep(0,n_maturities)
B = matrix(rep(0,n_maturities),K,n_maturities)
mat =rbind(rep(1,ncol(v)),x[,1:(ncol(x)-1)])
delta = t(rf)%% pinv(mat)
delta0 = delta[1]
delta1 = delta[,2:ncol(delta)]
A[1]= -delta0
B[,1] = -delta1
for(i in 2:(n_maturities))
{
A[i] = A[i-1]+ t(B[,i-1])%
%(-lambda0) +0.5*(t(B[,i-1])%% Sigma %% B[,i-1]+ sigmasq_ret)-delta0
B[,i] = t(B[,i-1])%*%(phi-lambda1)-t(delta1)
}

You calculate the A[i] without adding the 'mu' term, I think the correct version should be:

A[i] = A[i-1]+ t(B[,i-1])%%(mu-lambda0) +0.5(t(B[,i-1])%% Sigma %% B[,i-1]+ sigmasq_ret)-delta0

Correct me if I am wrong, thank you very much.

@arnab13061989
Copy link

arnab13061989 commented Oct 12, 2021 via email

@arnab13061989
Copy link

arnab13061989 commented Oct 12, 2021 via email

@NoDuffman
Copy link

Has anyone managed to rebuild the Abrahams and ACM model done on TIPS?

@arnab13061989
Copy link

Has anyone managed to rebuild the Abrahams and ACM model done on TIPS?

I think the process will be same , One will get the expected real rates and real risk premium using the same set of codes from TIPS yields . One can referer "Pricing TIPS and Treasuries with Linear Regressions" by same authors for details

@NoDuffman
Copy link

I tried running this code with TIPS and was unable to recreate the authors output. I’ll have to look closer at their paper. Thank you for sharing your code btw, it is very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests