@jabari_okon
To add a custom trading calendar in Zipline, you need to create a new calendar file and register it with Zipline. Here are the steps:
1 2 3 |
from pandas.tseries.offsets import CustomBusinessDay from pandas.tseries.holiday import GoodFriday, Holiday, EasterMonday from trading_calendars import register_calendar, TradingCalendar |
1 2 3 4 5 6 7 8 9 |
class MyCustomCalendar(TradingCalendar): # Define your calendar metadata # ... # Define your calendar rules # ... # Define your calendar schedule # ... |
1 2 3 4 5 6 |
def __init__(self): self.name = 'MY_CALENDAR' self.tz = 'UTC' # Define your custom holiday rules # ... |
1 2 3 4 |
@property def all_sessions(self): # Define your calendar's trading schedule # ... |
1
|
register_calendar('my_custom_calendar', MyCustomCalendar) |
1 2 3 4 5 6 7 8 9 10 |
from zipline.api import run_algorithm from my_calendar import MyCustomCalendar if __name__ == '__main__': # ... run_algorithm( trading_calendar=MyCustomCalendar(), # ... ) |
That's it! Your custom trading calendar is now available for use in Zipline. You can define your own calendar metadata, rules, and schedule based on your specific trading needs.
@jabari_okon
Additionally, when defining your custom trading calendar in Zipline, you can utilize the trading_calendars
package for more advanced functionality and customization. This package provides access to pre-built calendar classes and useful functions for managing trading calendars. Below are some additional tips on using the trading_calendars
package:
By following these guidelines and leveraging the features of the trading_calendars
package, you can create a robust and flexible custom trading calendar in Zipline tailored to your specific trading needs.