mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-18 11:50:11 +08:00
MIN: Replaced annualizer with a dictionary. Added set_granularity method.
This commit is contained in:
+9
-11
@@ -43,6 +43,10 @@ from zipline import MESSAGES
|
|||||||
|
|
||||||
DEFAULT_CAPITAL_BASE = float("1.0e5")
|
DEFAULT_CAPITAL_BASE = float("1.0e5")
|
||||||
|
|
||||||
|
ANNUALIZER = {'daily': 250,
|
||||||
|
'hourly': 250 * 6,
|
||||||
|
'minutely': 250 * 6 * 60}
|
||||||
|
|
||||||
|
|
||||||
class TradingAlgorithm(object):
|
class TradingAlgorithm(object):
|
||||||
"""Base class for trading algorithms. Inherit and overload
|
"""Base class for trading algorithms. Inherit and overload
|
||||||
@@ -110,17 +114,7 @@ class TradingAlgorithm(object):
|
|||||||
# this is happening after initialize because granularity
|
# this is happening after initialize because granularity
|
||||||
# could be set in there.
|
# could be set in there.
|
||||||
if self.annualizer is None:
|
if self.annualizer is None:
|
||||||
if self.granularity == 'daily':
|
self.annualizer = ANNUALIZER[self.granularity]
|
||||||
self.annualizer = 250
|
|
||||||
elif self.granularity == 'hourly':
|
|
||||||
# trading days * hours
|
|
||||||
self.annualizer = 250 * 6
|
|
||||||
elif self.granularity == 'minutely':
|
|
||||||
# trading days * hours * minutes
|
|
||||||
self.annualizer = 250 * 6 * 60
|
|
||||||
else:
|
|
||||||
raise NotImplementedError('{g} is not implemented.\
|
|
||||||
'.format(g=self.granularity))
|
|
||||||
|
|
||||||
def _create_generator(self, environment):
|
def _create_generator(self, environment):
|
||||||
"""
|
"""
|
||||||
@@ -323,3 +317,7 @@ class TradingAlgorithm(object):
|
|||||||
def set_transforms(self, transforms):
|
def set_transforms(self, transforms):
|
||||||
assert isinstance(transforms, list)
|
assert isinstance(transforms, list)
|
||||||
self.transforms = transforms
|
self.transforms = transforms
|
||||||
|
|
||||||
|
def set_granuliarity(self, granularity):
|
||||||
|
assert granularity in ('daily', 'minute')
|
||||||
|
self.granularity = granularity
|
||||||
|
|||||||
Reference in New Issue
Block a user