Trading Calendar

Trading calendar is a frequently used tool for data analysis, which helps to quickly obtain exchange calendars and perform calculations based on trading calendars. Starting from version 2.00.9/1.30.21, DolphinDB provides built-in trading calendars of more than fifty exchanges.

This tutorial describes how to use and customize trading calendars in DolphinDB. Specifically: check trading days; perform calculations based on trading calendars; create your own trading calendars; update trading calendars.

Use Trading Calendars

The built-in trading calendars can be used for various scenarios.

Check Trading Days

You can use function getMarketCalendar(marketName, [startDate], [endDate]) to get trading days of the corresponding exchange in the date range determined by startDate and endDate.

To check the trading days of New York Stock Exchange (XNYS) between 2022.1.1 and 2022.1.10:

getMarketCalendar("XNYS",2022.01.01, 2022.01.10)

#output
[2022.01.03,2022.01.04,2022.01.05,2022.01.06,2022.01.07,2022.01.10]

Create the DateOffset of Trading Days

To shift a trading day forward or backward, you can use function temporalAdd(date, duration, exchangeId).

Take XNYS for example, we add two trading days to the dates between 2023.1.1 and 2023.1.6:

dates=[2023.01.01, 2023.01.02, 2023.01.03, 2023.01.04, 2023.01.05, 2023.01.06]
temporalAdd(dates,2,"XNYS")

#output
[2023.01.04,2023.01.04,2023.01.05,2023.01.06,2023.01.09,2023.01.10]

Obtain the Closest Trading Day

You can get the closest trading day of a certain day with function transFreq(X,rule).

For example, specify parameter rule as XNYS. We can get the closest trading days of each date between 2023.1.1 and 2023.1.6:

dates=[2023.01.01, 2023.01.02, 2023.01.03, 2023.01.04, 2023.01.05, 2023.01.06]
dates.transFreq("XNYS")

#output
[2022.12.30,2022.12.30,2023.01.03,2023.01.04,2023.01.05,2023.01.06]

Data Sampling Based on Trading Days

You can choose functions asFreq(X,rule) or resample(X,rule,func) to sample data on trading days. The only difference of the two lies in whether data can be aggregated.

Function asFreq(X,rule) will return the result by trading days. If there are multiple records in the same trading day, only the first value will be taken. If there is no data in a trading day, it will be filled with NULL.

The following example obtains the stock prices of XNYS in trading days from 2022.12.30 to 2023.1.6:

timestampv = [2022.12.30T23:00:00.000,2023.01.01T00:00:00.000,2023.01.03T00:10:00.000,2023.01.03T00:20:00.000,2023.01.04T00:20:00.000,2023.01.04T00:30:00.000,2023.01.06T00:40:00.000]
close = [100.10, 100.10, 100.10, 78.89, 88.99, 88.67, 78.78]
s=indexedSeries(timestampv, close)
s.asFreq("XNYS")

#output
           #0                 
           ------
2022.12.30|100.10
2023.01.03|100.10
2023.01.04|88.99 
2023.01.05|                   
2023.01.06|78.78

Function resample(X,rule,func) will return the aggregated result of data sampled by trading days.

In the following example, we obtain the closing prices of XNYS stocks in trading days from 2022.12.30 to 2023.1.6:

timestampv = [2022.12.30T23:00:00.000,2023.01.01T00:00:00.000,2023.01.03T00:10:00.000,2023.01.03T00:20:00.000,2023.01.04T00:20:00.000,2023.01.04T00:30:00.000,2023.01.06T00:40:00.000]
close = [100.10, 100.10, 100.10, 78.89, 88.99, 88.67, 78.78]
s=indexedSeries(timestampv, close)
s.resample("XNYS", last)

#output
           #0                 
           ------
2022.12.30|100.10
2023.01.03|78.89
2023.01.04|88.67 
2023.01.05|                   
2023.01.06|78.78

Customize Trading Calendars

DolphinDB also allows administrators to customize trading calendars with built-in functions.

Add a New Trading Calendar

Suppose there is an exchange named "DDB", function addMarketHoliday(marketName, holiday) can be used to add a new DDB calendar. A DDB.csv file will be added to the /marketHoliday/ directory. Weekends are recognized as holidays in DolphinDB by default, therefore, only weekday holidays need to be filled in the file.

Once a new trading calendar has been generated, functions such as getMarketCalendar can be used directly based on the new calendar:

//set 2023.01.03 (Tue.) and 2023.01.04 (Wed.) as holidays
holiday = 2023.01.03 2023.01.04  
//user login
login(`admin,`123456)
//generate a trading calendar
addMarketHoliday("DDB",holiday)

//get the trading days of the new calendar in a date range
getMarketCalendar("DDB",2023.01.01, 2023.01.10)
#output
[2023.01.02,2023.01.05,2023.01.06,2023.01.09,2023.01.10]

temporalAdd(2023.01.01,2,"DDB")
#output
2023.01.05

Note: The newly added trading calendar is only valid on the current node. Execute function addMarketHoliday on other nodes for it to take effect on those nodes.

Update the Trading Calendar

If you want to update the existing calendar of DDB exchange, function updateMarketHoliday(marketName, holiday) can be used to reset the holidays.

Note: The file will be overwritten. The original holidays will be replaced with the holidays specified by this function.

The following example resets the dates 2023.03.07 and 2023.03.08 as holidays for the DDB calendar. Check the next trading day after 2022.01.01 with function temporalAdd:

//set 2023.03.07 (Tue.) and 2023.03.08 (Wed.) as holiday
updateMarketHoliday("DDB",2023.03.07 2023.03.08)

//the original holidays 2023.01.03 and 2023.01.04 are no longer holidays
getMarketCalendar("DDB",2023.01.01, 2023.01.10)
#output
[2023.01.02,2023.01.03,2023.01.04,2023.01.05,2023.01.06,2023.01.09,2023.01.10]

//As holidays, 2023.03.07 and 2023.03.08 are not included in the trading calendar
getMarketCalendar("DDB",2023.03.01, 2023.03.10)
#output
[2023.03.01,2023.03.02,2023.03.03,2023.03.06,2023.03.09,2023.03.10]

Calendar Support

All exchange calendars supported are listed below.

Note that calendars are updated according to the holidays announced on the official website of each exchange and the local governments.

  • Major Stock Exchanges

ISO CodeExchangeCountryExchange WebsiteCSV File PathStarting from
AIXKAstana International ExchangeKazakhstanhttps://aix.kz/trading/trading-calendar/marketHoliday/AIXK.csv2017
ASEXAthens Stock ExchangeGreecehttps://www.athexgroup.gr/market-alternative-holidaysmarketHoliday/ASEX.csv2004
BVMFBMF BovespaBrazilhttps://www.b3.com.br/en_us/solutions/platforms/puma-trading-system/for-members-and-traders/trading-calendar/holidays/marketHoliday/BVMF.csv2004
CMESChicago Mercantile ExchangeUSAhttps://www.cmegroup.com/tools-information/holiday-calendar.html#cmeGlobexmarketHoliday/CMES.csv2004
IEPAICE USUShttps://www.theice.com/holiday-hours?utm_source=website&utm_medium=search&utm_campaign=spotlightmarketHoliday/IEPA.csv2004
XAMSEuronext AmsterdamNetherlandshttps://www.euronext.com/en/trade/trading-hours-holidaysmarketHoliday/XAMS.csv2004
XASXAustrialian Securities ExchangeAustraliahttps://www2.asx.com.au/markets/market-resources/asx-24-trading-calendarmarketHoliday/XASX.csv2004
XBKKStock Exchange of ThailandThailandhttps://www.set.or.th/en/about/event-calendar/holiday?year=2023marketHoliday/XBKK.csv2004
XBOGColombia Securities ExchangeColombiahttps://www.bvc.com.co/non-business-market-daysmarketHoliday/XBOG.csv2004
XBOMBombay Stock ExchangeIndiahttps://www.bseindia.com/static/markets/marketinfo/listholi.aspxmarketHoliday/XBOM.csv2004
XBRUEuronext BrusselsBelgiumhttps://www.euronext.com/en/trade/trading-hours-holidays#:~:text=Calendar%20of%20business%20days%202023%20%20%20Euronext:%20%20Closed%20%2012%20more%20rows%20marketHoliday/XBRU.csv2004
XBSEBucharest Stock ExchangeRomaniahttps://www.bvb.ro/TradingAndStatistics/TradingSessionSchedulemarketHoliday/XBSE.csv2004
XBUDBudapest Stock ExchangeHungaryhttps://www.bse.hu/Products-and-Services/Trading-information/trading-calendar-2023marketHoliday/XBUD.csv2004
XBUEBuenos Aires Stock ExchangeArgentinamarketHoliday/XBUE.csv2004
XCBFCBOE FuturesUSAhttps://www.cboe.com/about/hours/us-futures/marketHoliday/XCBF.csv2004
XCSECopenhagen Stock ExchangeDenmarkhttps://www.nasdaqomxnordic.com/tradinghours/marketHoliday/XCSE.csv2004
XDUBIrish Stock ExchangeIrelandhttps://www.euronext.com/en/trade/trading-hours-holidaysmarketHoliday/XDUB.csv2004
XETRXetraGermanyhttps://www.xetra.com/xetra-en/newsroom/trading-calendarmarketHoliday/XETR.csv2004
XFRAFrankfurt Stock ExchangeGermanyhttps://www.boerse-frankfurt.de/en/know-how/trading-calendarmarketHoliday/XFRA.csv2004
XHELHelsinki Stock ExchangeFinlandhttps://www.nasdaqomxnordic.com/tradinghours/XHELmarketHoliday/XHEL.csv2004
XHKGHong Kong ExchangesHong Kong, Chinahttps://www.hkex.com.hk/News/HKEX-Calendar?sc_lang=zh-HK&defaultdate=2023-02-01marketHoliday/XHKG.csv2004
XICEIceland Stock ExchangeIcelandhttps://www.nasdaqomxnordic.com/tradinghours/marketHoliday/XICE.csv2004
XIDXIndonesia Stock ExchangeIndonesiahttps://idx.co.id/en/about-idx/trading-holiday/marketHoliday/XIDX.csv2004
XISTIstanbul Stock ExchangeTürkiyehttps://borsaistanbul.com/en/sayfa/3631/official-holidaysmarketHoliday/XIST.csv2004
XJSEJohannesburg Stock ExchangeSouth Africahttps://www.jse.co.za/marketHoliday/XJSE.csv2004
XKARPakistan Stock ExchangePakistanhttps://www.psx.com.pk/psx/exchange/general/calendar-holidaysmarketHoliday/XKAR.csv2004
XKLSMalaysia Stock ExchangeMalaysiahttps://www.bursamalaysia.com/about_bursa/about_us/calendarmarketHoliday/XKLS.csv2004
XKRXKorea ExchangeRepublic of Koreahttp://global.krx.co.kr/contents/GLB/05/0501/0501110000/GLB0501110000.jspmarketHoliday/XKRX.csv2004
XLIMLima Stock ExchangePeru marketHoliday/XLIM.csv2004
XLISEuronext LisbonPortugalhttps://www.euronext.com/en/trade/trading-hours-holidaysmarketHoliday/XLIS.csv2004
XLONLondon Stock ExchangeEnglandhttps://www.londonstockexchange.com/securities-trading/trading-access/business-daysmarketHoliday/XLON.csv2004
XMADEuronext LisbonPortugalhttps://www.euronext.com/en/trade/trading-hours-holidaysmarketHoliday/XMAD.csv2004
XMEXMexican Stock ExchangeMexicohttps://www.bmv.com.mx/en/bmv-group/holiday-schedulemarketHoliday/XMEX.csv2004
XMILBorsa ItalianaItalyhttps://www.borsaitaliana.it/borsaitaliana/calendario-e-orari-di-negoziazione/calendario-borsa-orari-di-negoziazione.en.htmmarketHoliday/XMIL.csv2004
XMOSMoscow ExchangeRussiahttps://www.moex.com/en/tradingcalendar/marketHoliday/XMOS.csv2004
XNYSNew York Stock ExchangeUSAhttps://www.nyse.com/markets/hours-calendarsmarketHoliday/XNYS.csv2004
XNZENew Zealand ExchangenNew Zealandhttps://www.nzx.com/services/nzx-trading/hours-boardsmarketHoliday/XNZE.csv2004
XOSLOslo Stock ExchangeNorwayhttps://www.euronext.com/en/trade/trading-hours-holidaysmarketHoliday/XOSL.csv2004
XPAREuronext ParisFrancehttps://www.euronext.com/en/trade/trading-hours-holidaysmarketHoliday/XPAR.csv2004
XPHSPhilippine Stock ExchangePhilippineshttps://www.pse.com.ph/investing-at-pse/#investing2marketHoliday/XPHS.csv2004
XPRAPrague Stock ExchangeCzech Republichttps://www.pse.cz/en/trading/trading-information/trading-calendarmarketHoliday/XPRA.csv2004
XSESSingapore ExchangeSingaporehttps://www.mom.gov.sg/employment-practices/public-holidaysmarketHoliday/XSES.csv2004
XSGOSantiago Stock ExchangeChilehttps://www.euronext.com/en/trade/trading-hours-holidaysmarketHoliday/XSGO.csv2004
XSHEShenzhen Stocak ExchangeChinahttp://www.szse.cn/disclosure/index.htmlmarketHoliday/XSHE.csv1992
XSHGShanghai Stock ExchangeChinahttp://www.sse.com.cn/market/view/marketHoliday/XSHG.csv1991
XSTOStockholm Stock ExchangeSwedenhttps://www.nasdaqomxnordic.com/tradinghours/marketHoliday/XSTO.csv2004
XSWXSIX Swiss ExchangeSwitzerlandhttps://www.six-group.com/en/products-services/the-swiss-stock-exchange/market-data/news-tools/trading-currency-holiday-calendar.html#/marketHoliday/XSWX.csv2004
XTAITaiwan Stock Exchange CorpTaiwan, Chinahttps://www.twse.com.tw/en/holidaySchedule/holidaySchedulemarketHoliday/XTAI.csv2004
XTKSTokyo Stock ExchangeJapanhttps://www.jpx.co.jp/english/corporate/about-jpx/calendar/marketHoliday/XTKS.csv2004
XTSEToronto Stock ExchangeCanadahttps://www.tsx.com/trading/calendars-and-trading-hours/calendarmarketHoliday/XTSE.csv2004
XWARPoland Stock ExchangePoland marketHoliday/XWAR.csv2004
XWBOWiener BorseAustriahttps://www.wienerborse.at/en/trading/trading-information/trading-calendar/marketHoliday/XWBO.csv2004
  • Exchanges in Mainland, China

ISO CodeExchangeCountryExchange WebsiteCSV File PathStarting from
SSEShanghai Stock ExchangeChinahttp://www.sse.com.cn/market/view/marketHoliday/SSE.csv1991
SZSEShenzhen Stocak ExchangeChinahttp://www.szse.cn/disclosure/index.htmlmarketHoliday/SZSE.csv1991
CFFEXChina Finacial Futures ExchangeChinahttp://www.cffex.com.cn/jyrl/marketHoliday/CFFEX.csv2007
SHFEShanghai Futures ExchangeChinahttps://www.shfe.com.cn/bourseService/businessdata/calendar/marketHoliday/SHFE.csv1992
CZCEZhengzhou Commodity ExchangeChinahttp://www.czce.com.cn/cn/jysj/jyyl/H770313index_1.htmmarketHoliday/CZCE.csv1991
DCEDalian Commodity ExchangeChinahttp://big5.dce.com.cn:1980/SuniT/www.dce.com.cn/DCE/TradingClearing/Exchange%20Notice/1516085/index.htmlmarketHoliday/DCE.csv1994
INEShanghai International Energey ExchangeChinahttps://www.ine.cn/en/news/notice/6598.htmlmarketHoliday/INE.csv2017