Skip to content
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

fix: generalize values for before_trading_start_minutes #222

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/zipline/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from collections import namedtuple
from copy import copy
import warnings
from datetime import tzinfo, time, timezone
from datetime import tzinfo, time, timezone, timedelta, date, datetime
import logging
import pytz
import pandas as pd
Expand Down Expand Up @@ -516,11 +516,18 @@ def _create_clock(self):
execution_closes = market_closes
execution_opens = market_closes

# FIXME generalize these values
# Default to 8:45am if trading_calendar doesn't have valid open_time
before_trading_time = time(8,45)
for open_time in self.trading_calendar.open_times:
if open_time[0] is None and open_time[1] is not None:
opentime = datetime.combine(date(1,1,1), open_time[1])
before_trading_time = (opentime - timedelta(minutes=45)).time()
break

before_trading_start_minutes = days_at_time(
self.sim_params.sessions,
time(8, 45),
"US/Eastern",
before_trading_time,
str(self.trading_calendar.tz),
day_offset=0,
)

Expand Down