Skip to content

Commit 9840beb

Browse files
committed
Better documentation, renaming files, update README.md
1 parent 5d7184d commit 9840beb

File tree

4 files changed

+110
-10
lines changed

4 files changed

+110
-10
lines changed

README.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,28 @@ carries all the relevant variables as atributes:
2727
pip install pyacm
2828
```
2929

30-
# Example
31-
The tricky part is getting the correct data format. The model works with
32-
annualized log-yields for zero-coupon bonds, observed at daily or monthly
33-
frequency. Maturities must be equally spaced in monthly frequency and start
34-
at month 1. This means that you need to construct a bootstraped curve for every
35-
date and interpolate it at fixed monthly maturities.
36-
37-
MORE SOON...
30+
31+
# Original Article
32+
> Adrian, Tobias and Crump, Richard K. and Moench, Emanuel,
33+
> Pricing the Term Structure with Linear Regressions (April 11, 2013).
34+
> FRB of New York Staff Report No. 340,
35+
> Available at SSRN: https://ssrn.com/abstract=1362586 or http://dx.doi.org/10.2139/ssrn.1362586
36+
37+
The version of the article that was published by the NY FED is not 100% explicit on how the data is being manipulated,
38+
but I found an earlier version of the paper on SSRN where the authors go deeper into the details on how everything is being estimated:
39+
- Data for zero yields uses monthly maturities starting from month 1
40+
- All principal components and model parameters are estiamted with data resampled to a monthly frequency, averaging observations in each month
41+
- To get daily / real-time estimates, the factor loadings estimated from the monthly frquency are used to transform the daily data
42+
43+
44+
45+
46+
# Usage
47+
The tricky part of using this model is getting the correct data format:
48+
- The model works with annualized log-yields for zero-coupon bonds
49+
- Observations (index) must be in either monthly or daily frequency
50+
- Maturities (columns) must be equally spaced in **monthly** frequency and start at month 1. This means that you need to construct a bootstraped curve for every date and interpolate it at fixed monthly maturities.
51+
- Whichever maturity you want to be the longest, your input data should have one column more. For example, if you want term premium estimate up to the 10-year yield (120 months), your input data should include maturities up to 121 months. This is needed to properly compute the returns.
3852

3953

4054
# Observations

example.py renamed to example_br.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# Read and plot data
1010
yield_curve = pd.read_csv(
11-
"sample_data/di monthly maturities.csv",
11+
"sample_data/di monthly maturities.csv", # TODO change to read from web
1212
index_col=0,
1313
)
1414
yield_curve = yield_curve.iloc[:, :121] # maturities up to 10y

pyacm/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
from pyacm.acm import NominalACM
2+
from pyacm.utils import FRED
23

3-
__all__ = ["NominalACM"]
4+
__all__ = [
5+
"FRED",
6+
"NominalACM",
7+
]

pyacm/acm.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,88 @@ class NominalACM:
2626
month.
2727
- To get daily / real-time estimates, the factor loadings estimated
2828
from the monthly frquency are used to transform the daily data.
29+
30+
Attributes
31+
----------
32+
n_factors: int
33+
number of principal components used
34+
35+
curve: pandas.DataFrame
36+
Raw data of the yield curve
37+
38+
curve_monthly: pandas.DataFrame
39+
Yield curve data resampled to a monthly frequency by averageing
40+
the observations
41+
42+
t: int
43+
Number of observations in the timeseries dimension
44+
45+
n: int
46+
Number of observations in the cross-sectional dimension. Same
47+
as number of maturities available after returns are computed
48+
49+
rx_m: pd.DataFrame
50+
Excess returns in monthly frquency
51+
52+
rf_m: pandas.Series
53+
Risk-free rate in monthly frequency
54+
55+
rf_d: pandas.Series
56+
Risk-free rate in daily frequency
57+
58+
pc_factors_m: pandas.DataFrame
59+
Principal components in monthly frequency
60+
61+
pc_loadings_m: pandas.DataFrame
62+
Factor loadings of the monthly PCs
63+
64+
pc_explained_m: pandas.Series
65+
Percent of total variance explained by each monthly principal component
66+
67+
pc_factors_d: pandas.DataFrame
68+
Principal components in daily frequency
69+
70+
pc_loadings_d: pandas.DataFrame
71+
Factor loadings of the daily PCs
72+
73+
pc_explained_d: pandas.Series
74+
Percent of total variance explained by each monthly principal component
75+
76+
mu, phi, Sigma, v: numpy.array
77+
Estimates of the VAR(1) parameters, the first stage of estimation.
78+
The names are the same as the original paper
79+
80+
a, beta, c, sigma2: numpy.array
81+
Estimates of the risk premium equation, the second stage of estimation.
82+
The names are the same as the original paper
83+
84+
lambda0, lambda1: numpy.array
85+
Estimates of the price of risk parameters, the third stage of estimation.
86+
The names are the same as the original paper
87+
88+
miy: pandas.DataFrame
89+
Model implied / fitted yields
90+
91+
rny: pandas.DataFrame
92+
Risk neutral yields
93+
94+
tp: pandas.DataFrame
95+
Term premium estimates
96+
97+
er_loadings: pandas.DataFrame
98+
Loadings of the expected reutrns on the principal components
99+
100+
er_hist_m: pandas.DataFrame
101+
Historical estimates of expected returns, computed in-sample, in monthly frequency
102+
103+
er_hist_d: pandas.DataFrame
104+
Historical estimates of expected returns, computed in-sample, in daily frequency
105+
106+
z_lambda: pandas.DataFrame
107+
Z-stat for inference on the price of risk parameters
108+
109+
z_beta: pandas.DataFrame
110+
Z-stat for inference on the loadings of expected returns
29111
"""
30112

31113
def __init__(self, curve, n_factors=5):

0 commit comments

Comments
 (0)