Skip to content

Commit

Permalink
ran RTL update Oct 23
Browse files Browse the repository at this point in the history
  • Loading branch information
bbcho committed Oct 23, 2023
1 parent d9c29f4 commit ff727df
Show file tree
Hide file tree
Showing 20 changed files with 1,108 additions and 567 deletions.
978 changes: 978 additions & 0 deletions notebooks/datapulltest.ipynb

Large diffs are not rendered by default.

614 changes: 102 additions & 512 deletions notebooks/scratchpad.ipynb

Large diffs are not rendered by default.

File renamed without changes.
45 changes: 8 additions & 37 deletions pytest/test_risktools.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def test_swap_irs():
# a = 85085.84
# b = round(1.015174, 4)

# ac = _load_json("swapIRS.json")
# ac = _load_json("./data/swapIRS.json")
# ac.dates = pd.to_datetime(ac.dates)

# usSwapCurves = rt.data.open_data("usSwapCurves")
Expand Down Expand Up @@ -443,46 +443,17 @@ def test_stl_decomposition():


def test_get_eia_df():
pass
# ac = _load_json("eia2tidy1.json")
# ac = ac[["date", "value"]].set_index("date").sort_index().value
# ts = rt.get_eia_df("PET.MCRFPTX2.M", key=up["eia"])
# ts = ts[["date", "value"]].set_index("date").sort_index().value
# ts = ts[ac.index.min() : ac.index.max()]

# # assert ac.equals(ts), "get_eia_df Test 1 failed"
# pd.testing.assert_series_equal(ac, ts)

# ac = _load_json("eia2tidy2.json")
# ac = ac.set_index(["series", "date"]).sort_index().value
# ts = rt.get_eia_df(
# ["PET.W_EPC0_SAX_YCUOK_MBBL.W", "NG.NW2_EPG0_SWO_R48_BCF.W"], key=up["eia"]
# )
# ts.date = pd.to_datetime(ts.date)
# ts.table_name = ts.table_name.map(
# {
# "Cushing, OK Ending Stocks excluding SPR of Crude Oil, Weekly": "CrudeCushing",
# "Weekly Lower 48 States Natural Gas Working Underground Storage, Weekly": "NGLower48",
# }
# )
ts = rt.get_eia_df("PET.MCRFPTX2.M", key=up["eia"])

# ts = (
# ts.rename({"table_name": "series"}, axis=1)
# .set_index(["series", "date"])
# .sort_index()
# .value
# )
assert ts.shape[0] > 0, "get_eia_df Test 1 failed"

# cmin = ac["CrudeCushing"].index.min()
# cmax = ac["CrudeCushing"].index.max()
ts = rt.get_eia_df(
["PET.W_EPC0_SAX_YCUOK_MBBL.W", "NG.NW2_EPG0_SWO_R48_BCF.W"], key=up["eia"]
)

# nmin = ac["NGLower48"].index.min()
# nmax = ac["NGLower48"].index.max()
assert ts.shape[0] > 0, "get_eia_df Test 2 failed"

# ts = ts.loc[("CrudeCushing", slice(cmin, cmax))].append(
# ts.loc[("NGLower48", slice(nmin, nmax))]
# )
# pd.testing.assert_series_equal(ac, ts)
assert ts.shape[1] == 4, "get_eia_df Test 3 failed"


def test_chart_spreads():
Expand Down
2 changes: 0 additions & 2 deletions src/risktools/_main_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def ir_df_us(quandl_key=None, ir_sens=0.01, date=None):
sdt = edt - _pd.DateOffset(days=30)

fedsfund = _quandl.get("FED/RIFSPFF_N_D", start_date=sdt, end_date=edt).dropna()
# print(fedsfund)
fedsfund["FedsFunds0"] = _np.log((1 + fedsfund.Value / 360) ** 365)
fedsfund.drop("Value", axis=1, inplace=True)

Expand Down Expand Up @@ -634,7 +633,6 @@ def npv(
)

if break_even == True:
print("test")
disc_factors["yield"] = be_yield
disc_factors["discountfactor"] = _np.exp(
-disc_factors["yield"] * disc_factors.maturity
Expand Down
2 changes: 1 addition & 1 deletion src/risktools/_sims.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ def _fitOU_MLE(spread):
- 2 * mu * (1 - a) * (Sy - a * Sx)
+ (n - 1) * mu**2 * (1 - a) ** 2
) / (n - 1)
print((sigmah2) * 2 * theta / (1 - a**2))
# print((sigmah2) * 2 * theta / (1 - a**2))
sigma = _np.sqrt((sigmah2) * 2 * theta / (1 - a**2))
theta = {"theta": theta, "mu": mu, "annualized_sigma": sigma}

Expand Down
2 changes: 1 addition & 1 deletion src/risktools/_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def swap_irs(
/ 365, # calc days to maturity from trade_date
}
)
print(df)

disc = _interpolate.splrep(disc_curve["times"], disc_curve["discounts"])
df["disc"] = _interpolate.splev(df.times, disc)

Expand Down
8 changes: 6 additions & 2 deletions src/risktools/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def _norm_df(fn):
cf = _pd.DataFrame()
for sec_key in tmp[key].keys():
tf = _pd.DataFrame.from_records(tmp[key][sec_key])
tf.columns = tf.columns.str.replace("\.+", "_", regex=True)
cols = list(tf.columns)
tf['assay'] = sec_key
tf = tf[['assay', *cols]]
Expand All @@ -176,6 +177,7 @@ def _load_data(fn):
try:
df = _pd.DataFrame.from_records(dd)
df = _try_dates(df)
df.columns = df.columns.str.replace("\.+", "_", regex=True)
return df
except:
pass
Expand All @@ -184,11 +186,13 @@ def _load_data(fn):

try:
dd[key] = _pd.DataFrame.from_records(dd[key])
dd[key].columns = dd[key].columns.str.replace("\.+", "_", regex=True)
except:
pass

try:
dd[key] = _pd.DataFrame(dd[key])
dd[key].columns = dd[key].columns.str.replace("\.+", "_", regex=True)
except:
pass

Expand All @@ -199,7 +203,7 @@ def _load_data(fn):
# dd[key] = _np.array(dd[key])
# except:
# pass

# dd.columns = dd.columns.str.replace("\.+", "_", regex=True)
return dd


Expand All @@ -225,7 +229,7 @@ def _read_curves(fn):
dd[key] = _np.array(dd[key])

if isinstance(dd[key], dict) == True:
print(dd[key])
# print(dd[key])
for k in dd[key].keys():
dd[key][k] = _np.array(dd[key][k])

Expand Down
2 changes: 1 addition & 1 deletion src/risktools/data/dflong.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/risktools/data/dfwide.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/risktools/data/eiaStocks.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/risktools/data/fizdiffs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/risktools/data/fxfwd.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/risktools/data/steo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/risktools/data/stocks.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/risktools/data/test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.10.12"
},
"orig_nbformat": 4,
"vscode": {
Expand Down
2 changes: 1 addition & 1 deletion src/risktools/data/tradeprocess.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/risktools/data/tsQuotes.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"d1w":[0.053],"d1m":[0.0531],"d3m":[0.0538],"s2y":[0.0482],"s3y":[0.0449],"s5y":[0.0417],"s7y":[0.0405],"s10y":[0.0398],"s15y":[0.0397],"s30y":[0.037],"fut1":[94.7625],"fut2":[94.68],"fut3":[94.6375],"fut4":[94.6],"fut5":[94.575],"fut6":[94.58],"fut7":[94.62],"fut8":[94.66]}
{"d1w":[0.053],"d1m":[0.0534],"d3m":[0.0541],"s2y":[0.0496],"s3y":[0.0473],"s5y":[0.0459],"s7y":[0.0457],"s10y":[0.0457],"s15y":[0.0461],"s30y":[0.0437],"fut1":[94.6625],"fut2":[94.6525],"fut3":[94.625],"fut4":[94.6],"fut5":[94.575],"fut6":[94.575],"fut7":[94.6],"fut8":[94.665]}
2 changes: 1 addition & 1 deletion src/risktools/data/usSwapCurves.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/risktools/data/usSwapCurvesPar.json

Large diffs are not rendered by default.

0 comments on commit ff727df

Please sign in to comment.