mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-18 12:20:12 +08:00
fixed allocation issue
This commit is contained in:
@@ -15,6 +15,9 @@ class MovingAverageTransform(BaseTransform):
|
||||
cur.update(event)
|
||||
self.state['value'] = cur.average
|
||||
return self.state
|
||||
|
||||
def create_vwap(self):
|
||||
return DailyVWAP(self.daycount)
|
||||
|
||||
class MovingAverage(object):
|
||||
|
||||
|
||||
@@ -9,18 +9,21 @@ class VWAPTransform(BaseTransform):
|
||||
|
||||
def init(self, daycount=3):
|
||||
self.daycount = daycount
|
||||
self.by_sid = defaultdict(DailyVWAP)
|
||||
self.by_sid = defaultdict(self.create_vwap)
|
||||
|
||||
def transform(self, event):
|
||||
cur = self.by_sid(event.sid)
|
||||
cur.update(event)
|
||||
self.state['value'] = cur.vwap
|
||||
return self.state
|
||||
|
||||
def create_vwap(self):
|
||||
return DailyVWAP(self.daycount)
|
||||
|
||||
class DailyVWAP:
|
||||
"""A class that tracks the volume weighted average price
|
||||
based on tick updates."""
|
||||
def __init__(self, daycount=3):
|
||||
def __init__(self, daycount):
|
||||
self.window = EventWindow(daycount)
|
||||
self.flux = 0.0
|
||||
self.volume = 0
|
||||
|
||||
@@ -143,6 +143,8 @@ class SimulatedTrading(object):
|
||||
sockets[7],
|
||||
logging = qutil.LOGGER
|
||||
)
|
||||
|
||||
self.con.cancel_socket = self.allocator.lease(1)[0]
|
||||
|
||||
# TODO: Not freeform
|
||||
self.con.manage(
|
||||
|
||||
@@ -17,6 +17,8 @@ class ZiplineWithTransformsTestCase(TestCase):
|
||||
leased_sockets = defaultdict(list)
|
||||
|
||||
def setUp(self):
|
||||
# skip ahead 100 spots
|
||||
allocator.lease(100)
|
||||
qutil.configure_logging()
|
||||
self.trading_environment = factory.create_trading_environment()
|
||||
self.zipline_test_config = {
|
||||
|
||||
Reference in New Issue
Block a user