mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-30 05:39:30 +08:00
STY: PEP8 fixes.
This commit is contained in:
@@ -51,7 +51,7 @@ CACHE_PATH = os.path.join(
|
||||
'cache'
|
||||
)
|
||||
|
||||
#Mapping from index symbol to appropriate bond data
|
||||
# Mapping from index symbol to appropriate bond data
|
||||
INDEX_MAPPING = {
|
||||
'^GSPC':
|
||||
('treasuries', 'treasury_curves.csv', 'data.treasury.gov'),
|
||||
@@ -197,8 +197,8 @@ Fetching data from Yahoo Finance.
|
||||
):
|
||||
benchmark_returns = benchmark_returns.tz_localize('UTC')
|
||||
|
||||
#Get treasury curve module, filename & source from mapping.
|
||||
#Default to USA.
|
||||
# Get treasury curve module, filename & source from mapping.
|
||||
# Default to USA.
|
||||
module, filename, source = INDEX_MAPPING.get(
|
||||
bm_symbol, INDEX_MAPPING['^GSPC'])
|
||||
|
||||
@@ -264,7 +264,7 @@ must specify stocks or indexes"""
|
||||
if start is None:
|
||||
start = pd.datetime(1990, 1, 1, 0, 0, 0, 0, pytz.utc)
|
||||
|
||||
if not start is None and not end is None:
|
||||
if start is not None and end is not None:
|
||||
assert start < end, "start date is later than end date."
|
||||
|
||||
data = OrderedDict()
|
||||
|
||||
@@ -36,7 +36,7 @@ _CURVE_MAPPINGS = {
|
||||
'5year': (get_treasury_rate, "V39053"),
|
||||
'7year': (get_treasury_rate, "V39054"),
|
||||
'10year': (get_treasury_rate, "V39055"),
|
||||
#Bank of Canada refers to this as 'Long' Rate, approximately 30 years.
|
||||
# Bank of Canada refers to this as 'Long' Rate, approximately 30 years.
|
||||
'30year': (get_treasury_rate, "V39056"),
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ BONDS = ['V39051', 'V39052', 'V39053', 'V39054', 'V39055', 'V39056']
|
||||
def get_treasury_source(start_date=None, end_date=None):
|
||||
|
||||
today = datetime.date.today()
|
||||
#Bank of Canada only has 10 years of data and has this in the URL.
|
||||
# Bank of Canada only has 10 years of data and has this in the URL.
|
||||
restriction = datetime.date(today.year-10, today.month, today.day)
|
||||
|
||||
if not end_date:
|
||||
@@ -100,7 +100,7 @@ def get_treasury_source(start_date=None, end_date=None):
|
||||
"%Y-%m-%d").date()
|
||||
bond_header = bond_row.split(",")
|
||||
|
||||
#Line up the two dates
|
||||
# Line up the two dates
|
||||
if bill_end_date > bond_end_date:
|
||||
bill_iter.next()
|
||||
elif bond_end_date > bill_end_date:
|
||||
|
||||
@@ -265,7 +265,7 @@ class PerformancePeriod(object):
|
||||
return
|
||||
|
||||
if not pd.isnull(event.price):
|
||||
# isnan check will keep the last price if its not present
|
||||
# isnan check will keep the last price if its not present
|
||||
self.update_position(event.sid, last_sale_price=event.price,
|
||||
last_sale_date=event.dt)
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ class AlgorithmSimulator(object):
|
||||
# Processor function for injecting the algo_dt into
|
||||
# user prints/logs.
|
||||
def inject_algo_dt(record):
|
||||
if not 'algo_dt' in record.extra:
|
||||
if 'algo_dt' not in record.extra:
|
||||
record.extra['algo_dt'] = self.simulation_dt
|
||||
self.processor = Processor(inject_algo_dt)
|
||||
|
||||
|
||||
@@ -342,7 +342,7 @@ class BatchTransform(object):
|
||||
if self.refresh_period == 0:
|
||||
period_signals_update = True
|
||||
else:
|
||||
# 1. Is the refresh period over?
|
||||
# 1. Is the refresh period over?
|
||||
period_signals_update = (
|
||||
self.trading_days_total % self.refresh_period == 0)
|
||||
# 2. Have the args or kwargs been changed since last time?
|
||||
|
||||
@@ -106,7 +106,7 @@ def merge_all_files_into_pytables(file_dir, file_out):
|
||||
createparents=True)
|
||||
table.append(rows)
|
||||
table.flush()
|
||||
if not table is None:
|
||||
if table is not None:
|
||||
table.flush()
|
||||
end = datetime.datetime.now()
|
||||
diff = (end - start).seconds
|
||||
|
||||
@@ -51,9 +51,9 @@ def create_test_zipline(**config):
|
||||
# trade than order
|
||||
trade_count = 101
|
||||
|
||||
#-------------------
|
||||
# -------------------
|
||||
# Create the Algo
|
||||
#-------------------
|
||||
# -------------------
|
||||
if 'algorithm' in config:
|
||||
test_algo = config['algorithm']
|
||||
else:
|
||||
@@ -65,9 +65,9 @@ def create_test_zipline(**config):
|
||||
factory.create_simulation_parameters())
|
||||
)
|
||||
|
||||
#-------------------
|
||||
# -------------------
|
||||
# Trade Source
|
||||
#-------------------
|
||||
# -------------------
|
||||
if 'trade_source' in config:
|
||||
trade_source = config['trade_source']
|
||||
else:
|
||||
@@ -80,21 +80,21 @@ def create_test_zipline(**config):
|
||||
if trade_source:
|
||||
test_algo.set_sources([trade_source])
|
||||
|
||||
#-------------------
|
||||
# -------------------
|
||||
# Benchmark source
|
||||
#-------------------
|
||||
# -------------------
|
||||
|
||||
test_algo.benchmark_return_source = config.get('benchmark_source', None)
|
||||
|
||||
#-------------------
|
||||
# -------------------
|
||||
# Transforms
|
||||
#-------------------
|
||||
# -------------------
|
||||
|
||||
transforms = config.get('transforms', None)
|
||||
if transforms is not None:
|
||||
test_algo.set_transforms(transforms)
|
||||
|
||||
#-------------------
|
||||
# -------------------
|
||||
# Slippage
|
||||
# ------------------
|
||||
slippage = config.get('slippage', None)
|
||||
|
||||
@@ -88,7 +88,7 @@ def get_non_trading_days(start, end):
|
||||
)
|
||||
non_trading_rules.append(good_friday)
|
||||
|
||||
#Monday prior to May 25th.
|
||||
# Monday prior to May 25th.
|
||||
victoria_day = rrule.rrule(
|
||||
rrule.MONTHLY,
|
||||
bymonth=5,
|
||||
@@ -207,7 +207,7 @@ def get_non_trading_days(start, end):
|
||||
)
|
||||
non_trading_rules.append(boxing_day)
|
||||
|
||||
#if boxing day is a sunday, the Christmas was saturday.
|
||||
# if boxing day is a sunday, the Christmas was saturday.
|
||||
# Christmas is observed on the 27th, a month and boxing day is observed
|
||||
# on the 28th, a tuesday.
|
||||
boxing_day_sunday = rrule.rrule(
|
||||
@@ -271,34 +271,34 @@ def get_trading_days(start, end, trading_day=trading_day):
|
||||
|
||||
trading_days = get_trading_days(start, end)
|
||||
|
||||
#Days in Environment but not in Calendar (using ^GSPTSE as bm_symbol):
|
||||
#--------------------------------------------------------------------
|
||||
#Used http://web.tmxmoney.com/pricehistory.php?qm_page=61468&qm_symbol=^TSX
|
||||
#to check whether exchange was open on these days.
|
||||
#1994-07-01 - July 1st, Yahoo Finance has Volume = 0
|
||||
#1996-07-01 - July 1st, Yahoo Finance has Volume = 0
|
||||
#1996-08-05 - Civic Holiday, Yahoo Finance has Volume = 0
|
||||
#1997-07-01 - July 1st, Yahoo Finance has Volume = 0
|
||||
#1997-08-04 - Civic Holiday, Yahoo Finance has Volume = 0
|
||||
#2001-05-21 - Victoria day, Yahoo Finance has Volume = 0
|
||||
#2004-10-11 - Closed, Thanksgiving - Confirmed closed
|
||||
#2004-12-28 - Closed, Boxing Day - Confirmed closed
|
||||
#2012-10-08 - Closed, Thanksgiving - Confirmed closed
|
||||
# Days in Environment but not in Calendar (using ^GSPTSE as bm_symbol):
|
||||
# --------------------------------------------------------------------
|
||||
# Used http://web.tmxmoney.com/pricehistory.php?qm_page=61468&qm_symbol=^TSX
|
||||
# to check whether exchange was open on these days.
|
||||
# 1994-07-01 - July 1st, Yahoo Finance has Volume = 0
|
||||
# 1996-07-01 - July 1st, Yahoo Finance has Volume = 0
|
||||
# 1996-08-05 - Civic Holiday, Yahoo Finance has Volume = 0
|
||||
# 1997-07-01 - July 1st, Yahoo Finance has Volume = 0
|
||||
# 1997-08-04 - Civic Holiday, Yahoo Finance has Volume = 0
|
||||
# 2001-05-21 - Victoria day, Yahoo Finance has Volume = 0
|
||||
# 2004-10-11 - Closed, Thanksgiving - Confirmed closed
|
||||
# 2004-12-28 - Closed, Boxing Day - Confirmed closed
|
||||
# 2012-10-08 - Closed, Thanksgiving - Confirmed closed
|
||||
|
||||
#Days in Calendar but not in Environment using ^GSPTSE as bm_symbol:
|
||||
#--------------------------------------------------------------------
|
||||
#Used http://web.tmxmoney.com/pricehistory.php?qm_page=61468&qm_symbol=^TSX
|
||||
#to check whether exchange was open on these days.
|
||||
#2000-06-28 - No data this far back, can't confirm
|
||||
#2000-08-28 - No data this far back, can't confirm
|
||||
#2000-08-29 - No data this far back, can't confirm
|
||||
#2001-09-11 - TSE Open for 71 min.
|
||||
#2002-02-01 - Confirm TSE Open
|
||||
#2002-06-14 - Confirm TSE Open
|
||||
#2002-07-02 - Confirm TSE Open
|
||||
#2002-11-11 - TSX website has no data for 2 weeks in 2002
|
||||
#2003-07-07 - Confirm TSE Open
|
||||
#2003-12-16 - Confirm TSE Open
|
||||
# Days in Calendar but not in Environment using ^GSPTSE as bm_symbol:
|
||||
# --------------------------------------------------------------------
|
||||
# Used http://web.tmxmoney.com/pricehistory.php?qm_page=61468&qm_symbol=^TSX
|
||||
# to check whether exchange was open on these days.
|
||||
# 2000-06-28 - No data this far back, can't confirm
|
||||
# 2000-08-28 - No data this far back, can't confirm
|
||||
# 2000-08-29 - No data this far back, can't confirm
|
||||
# 2001-09-11 - TSE Open for 71 min.
|
||||
# 2002-02-01 - Confirm TSE Open
|
||||
# 2002-06-14 - Confirm TSE Open
|
||||
# 2002-07-02 - Confirm TSE Open
|
||||
# 2002-11-11 - TSX website has no data for 2 weeks in 2002
|
||||
# 2003-07-07 - Confirm TSE Open
|
||||
# 2003-12-16 - Confirm TSE Open
|
||||
|
||||
|
||||
def get_early_closes(start, end):
|
||||
|
||||
Reference in New Issue
Block a user