aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/analytics/curve_trades.py10
-rw-r--r--python/notebooks/Curve Trades.ipynb28
2 files changed, 33 insertions, 5 deletions
diff --git a/python/analytics/curve_trades.py b/python/analytics/curve_trades.py
index 73afaa0f..6c20994d 100644
--- a/python/analytics/curve_trades.py
+++ b/python/analytics/curve_trades.py
@@ -66,8 +66,10 @@ def theta_matrix_by_series(index="IG", rolling=6):
return theta_matrix[["3yr", "5yr", "7yr", "10yr"]]
-def ratio_within_series(index="IG", rolling=6, param="duration"):
+def ratio_within_series(index="IG", rolling=6, param="duration", max_series=None):
otr = on_the_run(index)
+ if max_series is not None:
+ otr = max_series
df = get_index_quotes(
index, list(range(otr - rolling, otr + 1)), tenor=["3yr", "5yr", "7yr", "10yr"]
).unstack()
@@ -187,9 +189,9 @@ def forward_loss(index="IG"):
df["fwd_loss_rate"] = df.indexel.diff(2) / df.duration.diff(2)
-def curve_model(tenor_1="5yr", tenor_2="10yr", index="IG"):
+def curve_model(tenor_1="5yr", tenor_2="10yr", index="IG", max_series=None):
# OLS model
- df = ratio_within_series(index, param="close_spread")
+ df = ratio_within_series(index, param="close_spread", max_series=max_series)
df = pd.concat(
[
df.duration[tenor_1],
@@ -204,7 +206,7 @@ def curve_model(tenor_1="5yr", tenor_2="10yr", index="IG"):
)
df = np.log(df)
ols_model = smf.ols(
- "ratio ~ close_spread + duration1 + theta1 + theta2", data=df
+ "ratio ~ np.log(close_spread) + np.log(duration1) + theta1 + theta2", data=df
).fit()
return df, ols_model
diff --git a/python/notebooks/Curve Trades.ipynb b/python/notebooks/Curve Trades.ipynb
index 4165bd98..1695b412 100644
--- a/python/notebooks/Curve Trades.ipynb
+++ b/python/notebooks/Curve Trades.ipynb
@@ -11,6 +11,7 @@
"import numpy as np\n",
"import graphics as g\n",
"import globeop_reports as go\n",
+ "import analytics.curve_trades as ct\n",
"\n",
"from ipywidgets import widgets\n",
"from analytics.scenarios import run_curve_scenarios\n",
@@ -220,7 +221,7 @@
"metadata": {},
"outputs": [],
"source": [
- "model = ct.curve_model('5yr', '10yr', index='IG')\n",
+ "model = ct.curve_model('5yr', '10yr', index='IG', max_series=33)\n",
"model_results = ct.curve_model_results(model[0], model[1])"
]
},
@@ -240,6 +241,24 @@
"metadata": {},
"outputs": [],
"source": [
+ "model_results.iloc[-1]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "model[1].summary()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
"#Do the same regression for Itrxx\n",
"model = ct.curve_model('5yr', '10yr', index='EU')\n",
"model_results = ct.curve_model_results(model[0], model[1])"
@@ -492,6 +511,13 @@
"metadata": {},
"outputs": [],
"source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"metadata": {