mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-08 11:16:58 +08:00
Misc changes.
This commit is contained in:
@@ -3,6 +3,7 @@ import yaml
|
||||
import argparse
|
||||
import fileinput
|
||||
from cStringIO import StringIO
|
||||
from zipline.utils.date_utils import EPOCH, date_to_datetime
|
||||
|
||||
def interpret(args):
|
||||
print 'Reading {ifile}'.format(ifile=args.file)
|
||||
@@ -13,7 +14,7 @@ def interpret(args):
|
||||
metadata = StringIO()
|
||||
algorithm = StringIO()
|
||||
|
||||
for line in fileinput.input(sys.argv[1]):
|
||||
for line in fileinput.input(args.file):
|
||||
if line.startswith('---'):
|
||||
if metastart:
|
||||
metastart = False
|
||||
@@ -45,18 +46,28 @@ def interpret(args):
|
||||
except StopIteration:
|
||||
raise RuntimeError("No metadata in file.")
|
||||
|
||||
start = meta['start']
|
||||
end = meta['end']
|
||||
algocode = algorithm.getvalue()
|
||||
|
||||
start = meta['start_date']
|
||||
end = meta['end_date']
|
||||
|
||||
meta['start_date'] = EPOCH(date_to_datetime(start))
|
||||
meta['end_date'] = EPOCH(date_to_datetime(end))
|
||||
meta['algocode'] = algocode
|
||||
|
||||
print end - start
|
||||
|
||||
ns = {}
|
||||
exec(algorithm.getvalue()) in ns
|
||||
|
||||
# -- Sanity check --
|
||||
exec(algocode) in ns
|
||||
|
||||
assert ns['initialize']
|
||||
assert ns['get_sid_filter']
|
||||
assert ns['handle_data']
|
||||
|
||||
return algocode, meta
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('file', metavar='file', help='Algorithm file.')
|
||||
|
||||
@@ -128,3 +128,8 @@ if __name__ == '__main__':
|
||||
for day in trading_days(now, now30):
|
||||
print day
|
||||
print time.time() - tic
|
||||
|
||||
def date_to_datetime(t):
|
||||
dt = datetime.fromordinal(t.toordinal())
|
||||
dt = dt.replace(tzinfo = pytz.utc)
|
||||
return dt
|
||||
|
||||
@@ -141,7 +141,7 @@ class ndict(MutableMapping):
|
||||
self.__internal.update(other_nd.__internal)
|
||||
|
||||
def __repr__(self):
|
||||
return "namedict: " + str(self.__internal)
|
||||
return "ndict(%s)" % str(self.__internal)
|
||||
|
||||
# Faster dictionary comparison?
|
||||
#def __eq__(self, other):
|
||||
|
||||
Reference in New Issue
Block a user