Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
In [3]:
import pandas as pd
import pandas_market_calendars as mcal
pd.options.display.max_rows = 500
In [11]:
markets_all = mcal.get_calendar_names()
In [12]:
markets_lumibot = [
'MarketCalendar',
'ASX',
'BMF',
'CFE',
'NYSE',
'stock',
'NASDAQ',
'BATS',
'CME_Equity',
'CBOT_Equity',
'CME_Agriculture',
'CBOT_Agriculture',
'COMEX_Agriculture',
'NYMEX_Agriculture',
'CME_Rate',
'CBOT_Rate',
'CME_InterestRate',
'CBOT_InterestRate',
'CME_Bond',
'CBOT_Bond',
'EUREX',
'HKEX',
'ICE',
'ICEUS',
'NYFE',
'JPX',
'LSE',
'OSE',
'SIX',
'SSE',
'TSX',
'TSXV',
'BSE',
'TASE',
'TradingCalendar',
'ASEX',
'BVMF',
'CMES',
'IEPA',
'XAMS',
'XASX',
'XBKK',
'XBOG',
'XBOM',
'XBRU',
'XBUD',
'XBUE',
'XCBF',
'XCSE',
'XDUB',
'XFRA',
'XETR',
'XHEL',
'XHKG',
'XICE',
'XIDX',
'XIST',
'XJSE',
'XKAR', 'XKLS',
'XKRX',
'XLIM',
'XLIS',
'XLON',
'XMAD',
'XMEX',
'XMIL',
'XMOS',
'XNYS',
'XNZE',
'XOSL',
'XPAR',
'XPHS',
'XPRA',
'XSES',
'XSGO',
'XSHG',
'XSTO',
'XSWX',
'XTAE',
'XTAI',
'XTKS',
'XTSE',
'XWAR',
'XWBO',
'us_futures',
'24/7',
'24/5',
]
In [20]:
markets_both = list(set(markets_all) & set(markets_lumibot))
In [21]:
set(markets_lumibot) - set(markets_all)
Out[21]:
In [22]:
open_times = [
mcal.get_calendar(market).open_time.strftime("%H:%M:%S %Z")
for market in markets_both
]
In [23]:
def get_close_time(market):
try:
return mcal.get_calendar(market).close_time.strftime("%H:%M:%S %Z")
except:
return None
In [24]:
close_times = [
get_close_time(market) for market in markets_both
]
In [25]:
df = pd.DataFrame(data={
"markets": markets_both,
"open_times": open_times,
"close_times": close_times,
})
df
Out[25]:
In [6]:
c.market_times
Out[6]:
In [8]:
c.open_time
Out[8]:
In [23]:
c.close_time
Out[23]:
In [9]:
c.open_close_map
Out[9]:
In [10]:
c.regular_market_times
Out[10]:
In [14]:
from datetime import datetime, timedelta, timezone
In [17]:
dt_now_utc = datetime.now(timezone.utc)
date = dt_now_utc
trading_hours = c.schedule(start_date=date, end_date=date + timedelta(weeks=1)).head(2)
In [18]:
trading_hours
Out[18]: