Skip to content

Commit

Permalink
fix(exchanges): calculate_sigma_it_squared
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakl committed Mar 20, 2024
1 parent 40576bc commit 8df6f9d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions exchanges/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def main():
calculate_wij = Processing().calculate_wij(
otm_final, interpolate_implied_interest_rates_near_term
)
calculate_sigma_it_squared = Processing().calculate_sigma_it_squared(
calculate_wij, otm_final
)
calculate_sigma_it_squared.to_csv("calculate_sigma_it_squared.csv", index=False)
calculate_wij.to_csv("calculate_wij.csv", index=False)

interpolate_implied_interest_rates_near_term.to_csv(
Expand Down
17 changes: 16 additions & 1 deletion exchanges/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ def filter_and_sort_options(df, Fimp):

return otm_final

# w_{i,j} = e^{r_i T_i} * (ΔK_j) / (K_j)^2,
@staticmethod
def calculate_wij(strike_prices_df, interest_rates_df):
interest_rates_df["expiry"] = pd.to_datetime(interest_rates_df["expiry"])
Expand All @@ -168,6 +167,22 @@ def calculate_wij(strike_prices_df, interest_rates_df):

return merged_df[["expiry", "strike", "w_ij"]]

@staticmethod
def calculate_sigma_it_squared(w_ij_df, option_prices_df):
option_prices_df["expiry"] = pd.to_datetime(option_prices_df["expiry"])
option_prices_df.sort_values(by=["expiry", "strike"], inplace=True)

merged_df = w_ij_df.merge(
option_prices_df, on=["expiry", "strike"], how="left", suffixes=("_x", "_y")
)

merged_df["sigma_it_squared"] = (1 / merged_df["years_to_expiry"]) * (
0.5 * (merged_df["w_ij"] * merged_df["mid_price"]).sum()
- (merged_df["Fimp"] / merged_df["KATM"] - 1) ** 2
)

return merged_df[["expiry", "strike", "sigma_it_squared"]]

@staticmethod
def find_missing_expiries(options_df, futures_df):
options_expiries = options_df["expiry"].unique()
Expand Down

0 comments on commit 8df6f9d

Please sign in to comment.