aboutsummaryrefslogtreecommitdiffstats
path: root/python/exploration
diff options
context:
space:
mode:
Diffstat (limited to 'python/exploration')
-rw-r--r--python/exploration/dispersion.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/python/exploration/dispersion.py b/python/exploration/dispersion.py
index c9f219cf..c7bc33d9 100644
--- a/python/exploration/dispersion.py
+++ b/python/exploration/dispersion.py
@@ -119,18 +119,25 @@ def create_models(conn, df) -> (pd.DataFrame, float):
return (df, model)
-def create_models_v2(conn, df) -> (pd.DataFrame, float):
+def create_models_v2(conn, df, weights=None) -> (pd.DataFrame, float):
# Takes the output of get_tranche_data
attach_max = df.index.get_level_values("attach").max()
bottom_stack = df[df.index.get_level_values("attach") != attach_max]
- model = smf.ols(
+ if weights is None:
+ weights = np.ones(len(bottom_stack))
+ else:
+ weights.name = "resids"
+ bottom_stack = bottom_stack.merge(weights, left_index=True, right_index=True)
+ weights = np.array(bottom_stack.resids)
+ model = smf.wls(
"logit(tranche_loss_per) ~ "
- "np.log(index_duration) + "
- "np.log(moneyness) * gini + "
- "np.log(index_expected_loss)* gini + "
- "expit(att_moneyness) +"
- "expit(det_moneyness)",
+ "np.log(index_duration) * np.log(gini)+ "
+ "np.log(moneyness) * np.log(gini) + "
+ "I(np.log(gini)**2) +"
+ "expit(att_moneyness) + I(expit(att_moneyness)**2) +"
+ "expit(det_moneyness) + I(expit(det_moneyness)**2)",
data=bottom_stack,
+ weights=weights,
)
f = model.fit()
df.loc[