Skip to main content

Market and exchange trading calendars for pandas

Project description

pandas_market_calendars

Market calendars to use with pandas for trading applications.

https://badge.fury.io/py/pandas-market-calendars.svg https://travis-ci.org/rsheftel/pandas_market_calendars.svg?branch=master https://coveralls.io/repos/github/rsheftel/pandas_market_calendars/badge.svg?branch=master Documentation Status

Documentation

http://pandas_market_calendars.readthedocs.io/en/latest/

Overview

The Pandas package is widely used in finance and specifically for time series analysis. It includes excellent functionality for generating sequences of dates and capabilities for custom holiday calendars, but as an explicit design choice it does not include the actual holiday calendars for specific exchanges or OTC markets.

The pandas_market_calendars package looks to fill that role with the holiday, late open and early close calendars for specific exchanges and OTC conventions. pandas_market_calendars also adds several functions to manipulate the market calendars and includes a date_range function to create a pandas DatetimeIndex including only the datetimes when the markets are open. Additionally the package contains product specific calendars for future exchanges which have different market open, closes, breaks and holidays based on product type.

This package is a fork of the Zipline package from Quantopian and extracts just the relevant parts. All credit for their excellent work to Quantopian.

As of v1.0 this package only works with Python3. This is consistent with Pandas dropping support for Python2.

As of v1.4 this package now has the concept of a break during the trading day. For example this can accommodate Asian markets that have a lunch break, or futures markets that are open 24 hours with a break in the day for trade processing.

Source location

Hosted on GitHub: https://github.com/rsheftel/pandas_market_calendars

Installation

pip install pandas_market_calendars

Arch Linux package available here: https://aur.archlinux.org/packages/python-pandas_market_calendars/

Quick Start

import pandas_market_calendars as mcal

# Create a calendar
nyse = mcal.get_calendar('NYSE')

# Show available calendars
print(mcal.get_calendar_names())
early = nyse.schedule(start_date='2012-07-01', end_date='2012-07-10')
early
                  market_open             market_close
=========== ========================= =========================
 2012-07-02 2012-07-02 13:30:00+00:00 2012-07-02 20:00:00+00:00
 2012-07-03 2012-07-03 13:30:00+00:00 2012-07-03 17:00:00+00:00
 2012-07-05 2012-07-05 13:30:00+00:00 2012-07-05 20:00:00+00:00
 2012-07-06 2012-07-06 13:30:00+00:00 2012-07-06 20:00:00+00:00
 2012-07-09 2012-07-09 13:30:00+00:00 2012-07-09 20:00:00+00:00
 2012-07-10 2012-07-10 13:30:00+00:00 2012-07-10 20:00:00+00:00
mcal.date_range(early, frequency='1D')
DatetimeIndex(['2012-07-02 20:00:00+00:00', '2012-07-03 17:00:00+00:00',
               '2012-07-05 20:00:00+00:00', '2012-07-06 20:00:00+00:00',
               '2012-07-09 20:00:00+00:00', '2012-07-10 20:00:00+00:00'],
              dtype='datetime64[ns, UTC]', freq=None)
mcal.date_range(early, frequency='1H')
DatetimeIndex(['2012-07-02 14:30:00+00:00', '2012-07-02 15:30:00+00:00',
               '2012-07-02 16:30:00+00:00', '2012-07-02 17:30:00+00:00',
               '2012-07-02 18:30:00+00:00', '2012-07-02 19:30:00+00:00',
               '2012-07-02 20:00:00+00:00', '2012-07-03 14:30:00+00:00',
               '2012-07-03 15:30:00+00:00', '2012-07-03 16:30:00+00:00',
               '2012-07-03 17:00:00+00:00', '2012-07-05 14:30:00+00:00',
               '2012-07-05 15:30:00+00:00', '2012-07-05 16:30:00+00:00',
               '2012-07-05 17:30:00+00:00', '2012-07-05 18:30:00+00:00',
               '2012-07-05 19:30:00+00:00', '2012-07-05 20:00:00+00:00',
               '2012-07-06 14:30:00+00:00', '2012-07-06 15:30:00+00:00',
               '2012-07-06 16:30:00+00:00', '2012-07-06 17:30:00+00:00',
               '2012-07-06 18:30:00+00:00', '2012-07-06 19:30:00+00:00',
               '2012-07-06 20:00:00+00:00', '2012-07-09 14:30:00+00:00',
               '2012-07-09 15:30:00+00:00', '2012-07-09 16:30:00+00:00',
               '2012-07-09 17:30:00+00:00', '2012-07-09 18:30:00+00:00',
               '2012-07-09 19:30:00+00:00', '2012-07-09 20:00:00+00:00',
               '2012-07-10 14:30:00+00:00', '2012-07-10 15:30:00+00:00',
               '2012-07-10 16:30:00+00:00', '2012-07-10 17:30:00+00:00',
               '2012-07-10 18:30:00+00:00', '2012-07-10 19:30:00+00:00',
               '2012-07-10 20:00:00+00:00'],
              dtype='datetime64[ns, UTC]', freq=None)

Contributing

All improvements and additional (and corrections) in the form of pull requests are welcome. This package will grow in value and correctness the more eyes are on it.

To add new functionality please include tests which are in standard pytest format.

Use pytest to run the test suite.

Future

This package is open sourced under the MIT license. Everyone is welcome to add more exchanges or OTC markets, confirm or correct the existing calendars, and generally do whatever they desire with this code.

Merger with Quantopian Trading-Calendars

Work has begun to merge this project with the Quantopian trading-calendars project that it was originally forked from. The end-state is to have one unified project that brings together the superset of all funcationality in this project and trading-calendars, and to have one source for all market calendars.

The process of this merger will be updated in #120, everyone is welcome to comment or provide their input

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pandas_market_calendars-1.6.0.tar.gz (42.9 kB view details)

Uploaded Source

Built Distribution

pandas_market_calendars-1.6.0-py3-none-any.whl (57.9 kB view details)

Uploaded Python 3

File details

Details for the file pandas_market_calendars-1.6.0.tar.gz.

File metadata

  • Download URL: pandas_market_calendars-1.6.0.tar.gz
  • Upload date:
  • Size: 42.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for pandas_market_calendars-1.6.0.tar.gz
Algorithm Hash digest
SHA256 3bd83d3e7dfa0f9b981d2dba62d26eabe9c59a98c6a8ee537adb490c058cf598
MD5 f922bd6eff38aa2303a358a474a5b2e9
BLAKE2b-256 cacf072c4531a832ae849371982ba75833d6b517a7d4e487d0a004c321b67ef9

See more details on using hashes here.

File details

Details for the file pandas_market_calendars-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: pandas_market_calendars-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 57.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for pandas_market_calendars-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 629f3e80d25778cf3dfd49bbb3076e8b899c58534320ffca799af873bae709c7
MD5 e3d3146b2ba82961c35b9333bf7f3f8a
BLAKE2b-256 a2b7c4bb6a81b33558a4cb1be5513333094e9130eecfc39adf5ca764f3dbd39c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page