New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Add tutorial on creating a custom TradingCalendar #2035

Merged
merged 3 commits into from Dec 21, 2017

Conversation

Projects
None yet
3 participants
@freddiev4
Contributor

freddiev4 commented Dec 1, 2017

With the addition of the csvdir bundle, and having the option to pass a trading calendar via the CLI with --trading-calendar, we've seen quite a few instances where people would like to use data on assets outside of the NYSE exchange calendar, such as an exchange in India, London, and a Bitcoin exchange. This little tutorial is meant to help people use that data by also having a trading calendar that fits the date range, holidays, timing, etc of their data.

@coveralls

This comment has been minimized.

coveralls commented Dec 1, 2017

Coverage Status

Coverage remained the same at 87.372% when pulling 792ed59 on trading-calendar-tutorial into 42b3200 on master.

@freddiev4 freddiev4 requested a review from abhijeetkalyan Dec 11, 2017

@abhijeetkalyan

@freddiev4 this looks great overall - had a few small suggestions

~~~~~~~~~~~~~~~~~~~~~~~~~~~
A trading calendar represents the timing information of a single market exchange. The timing information is made up of two parts: sessions, and opens/closes. This is represented by the Zipline :class:`~zipline.utils.calendars.trading_calendar.TradingCalendar` class, and is used as the parent class for all new ``TradingCalendar`` s.
A session represents a contiguous set of minutes, and has a label that is midnight UTC. It is important to note that a session label should not be considered a specific point in time, and that midnight UTC is just being used for convenience.

This comment has been minimized.

@abhijeetkalyan

abhijeetkalyan Dec 14, 2017

Member

Should we add an example here? Perhaps demonstrating what the typical sessions, opens and closes look like for the average NYSE day?

Why Should You Care About Trading Calendars?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Let's say you want to buy a share of some equity on Tuesday, and then sell it on Saturday. If the exchange in which you're trading that equity is not open on Saturday, then in reality it would not be possible to trade that equity at that time, and you would have to wait until some other number of days past Saturday. It would then be unreasonable to allow your trading algorithm to also place a trade on Saturday.

This comment has been minimized.

@abhijeetkalyan

abhijeetkalyan Dec 14, 2017

Member

Maybe we can reword the last line?

"Since you wouldn't be able to place the trade in reality, it would also be unreasonable for your backtest to place a trade on Saturday."

- Timezone
- Open Time
- Close Time
- Regular & Adhoc Holidays

This comment has been minimized.

@abhijeetkalyan

abhijeetkalyan Dec 14, 2017

Member

'Adhoc' -> 'ad hoc'

.. code-block:: python
class TFSExchangeCalendar(TradingCalendar):
"""

This comment has been minimized.

@abhijeetkalyan

abhijeetkalyan Dec 14, 2017

Member

This is super minor, but should we add periods to the end of each of these docstrings?

You can create the ``Holiday`` objects mentioned in ``def regular_holidays(self)` through the `pandas <http://pandas.pydata.org/pandas-docs/stable/>`__ module, ``pandas.tseries.holiday.Holiday``, and also take a look at the `LSEExchangeCalendar <https://github.com/quantopian/zipline/blob/master/zipline/utils/calendars/exchange_calendar_lse.py>`__ code as an example.
Building a Custom Trading Calendar

This comment has been minimized.

@abhijeetkalyan

abhijeetkalyan Dec 14, 2017

Member

This section looks great - I'd just add a bit about how to create custom holidays on the trading calendar, for completeness

@freddiev4 freddiev4 force-pushed the trading-calendar-tutorial branch from 792ed59 to e590335 Dec 21, 2017

@freddiev4

This comment has been minimized.

Contributor

freddiev4 commented Dec 21, 2017

@abhijeetkalyan made changes to reflect your suggestions.

@coveralls

This comment has been minimized.

coveralls commented Dec 21, 2017

Coverage Status

Coverage remained the same at 87.554% when pulling e590335 on trading-calendar-tutorial into dbd504a on master.

@abhijeetkalyan

This comment has been minimized.

Member

abhijeetkalyan commented Dec 21, 2017

:shipit: lgtm

@freddiev4 freddiev4 merged commit 2b07334 into master Dec 21, 2017

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@freddiev4 freddiev4 deleted the trading-calendar-tutorial branch Dec 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment