Skip to content

Commit

Permalink
Added calendar example
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedamen committed Jan 8, 2021
1 parent ab3ce65 commit 39ccd7f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ individual data providers)

# Coding log

* 05 Jan 2020
* 08 Jan 2021
* Added extra calendar example
* 05 Jan 2021
* MarketDataRequest accepts parsing of full month names
* 28 Dec 2020
* Spun out Calendar into separate Python script
Expand Down
3 changes: 3 additions & 0 deletions findatapy/market/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,11 @@ def get_base_depos(self, start, end, currencies, tenor, cut="NYC", data_source="
tickers.append("USDFedEffectiveRate")

# For depos there usually isn't a 10AM NYC cut available, so just use TOK data
# Also no BGN tends to available for deposits, so use NYC
if cut == '10AM':
cut = 'TOK'
elif cut == 'BGN':
cut = 'NYC'

market_data_request = MarketDataRequest(
start_date=start, finish_date=end,
Expand Down
10 changes: 6 additions & 4 deletions findatapy/timeseries/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _get_full_cal(self, cal):
holidays_list.append(
[self._get_full_cal(cal[0:3]), self._get_full_cal(cal[3:6]), self._get_full_cal(cal[6:9])])
else:
if cal == 'FX':
if cal == 'FX' or cal == 'NYX':
# Filter for Christmas & New Year's Day
for i in range(1999, 2025):
holidays_list.append(pd.Timestamp(str(i) + "-12-25"))
Expand Down Expand Up @@ -292,11 +292,11 @@ def get_expiry_date_from_horizon_date(self, horizon_date, tenor, cal=None, asset
elif tenor_unit == 'Y':
tenor_digit = tenor_digit * 12

cbd = CustomBusinessDay(n=1, holidays=asset_holidays)

horizon_period_end = horizon_date + CustomBusinessMonthEnd(tenor_digit + 1)
horizon_floating = horizon_date + DateOffset(months=tenor_digit)

cbd = CustomBusinessDay(n=1, holidays=asset_holidays)

delivery_date = []

if isinstance(horizon_period_end, pd.Timestamp):
Expand Down Expand Up @@ -368,7 +368,9 @@ def get_expiry_date_from_delivery_date(self, delivery_date, cal):

hols = self.get_holidays(cal=cal + 'NYD')

return delivery_date - CustomBusinessDay(self._get_settlement_T(cal), holidays=hols)
# cbd = CustomBusinessDay(1, holidays=self.get_holidays(cal=cal))

return delivery_date - CustomBusinessDay(self._get_settlement_T(cal), holidays=hols) # - cbd + cbd

def align_to_NY_cut_in_UTC(self, date_time, hour_of_day=10):

Expand Down
10 changes: 9 additions & 1 deletion findatapy_examples/calendar_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
# run_example = 2 - get FX delivery dates and FX option expiries for various tenors
# run_example = 3 - get number of days between pandas DatetimeIndex
# run_example = 4 - filter time series by EURUSD holidays
# run_example = 4 - option expiries for USDJPY

run_example = 0
run_example = 5

if run_example == 1 or run_example == 0:

Expand Down Expand Up @@ -78,5 +79,12 @@
print(len(df.index))
print(len(df_filtered.index))

if run_example == 5 or run_example == 0:
# Get expiry for USDJPY

# Get 1M expires for these horizon dates - typically would use to get option expiries
print(calendar.get_expiry_date_from_horizon_date(
pd.to_datetime([pd.Timestamp('26 Nov 2008')]), '1M', cal='USDJPY'))



0 comments on commit 39ccd7f

Please sign in to comment.