mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-07 13:19:50 +08:00
fixed bugs in transform calculations.
This commit is contained in:
@@ -7,16 +7,16 @@ class MovingAverageTransform(BaseTransform):
|
||||
|
||||
def init(self, daycount=3):
|
||||
self.daycount = daycount
|
||||
self.by_sid = defaultdict(MovingAverage)
|
||||
self.by_sid = defaultdict(self._create)
|
||||
|
||||
def transform(self, event):
|
||||
cur = self.by_sid(event.sid)
|
||||
cur = self.by_sid[event.sid]
|
||||
cur.update(event)
|
||||
self.state['value'] = cur.average
|
||||
return self.state
|
||||
|
||||
def create_vwap(self):
|
||||
return DailyVWAP(self.daycount)
|
||||
def _create(self):
|
||||
return MovingAverage(self.daycount)
|
||||
|
||||
class MovingAverage(object):
|
||||
|
||||
|
||||
@@ -4,17 +4,19 @@ from collections import defaultdict
|
||||
|
||||
from zipline.messaging import BaseTransform
|
||||
|
||||
class WindowTransform(BaseTransform):
|
||||
class ReturnsTransform(BaseTransform):
|
||||
|
||||
def init(self, daycount=3):
|
||||
self.daycount = daycount
|
||||
self.by_sid = defaultdict(DailyReturns)
|
||||
def init(self):
|
||||
self.by_sid = defaultdict(self._create)
|
||||
|
||||
def transform(self, event):
|
||||
cur = self.by_sid(event.sid)
|
||||
cur = self.by_sid[event.sid]
|
||||
cur.update(event)
|
||||
self.state['value'] = cur.vwap
|
||||
self.state['value'] = cur.returns
|
||||
return self.state
|
||||
|
||||
def _create(self):
|
||||
return ReturnsFromPriorClose()
|
||||
|
||||
class ReturnsFromPriorClose(object):
|
||||
"""
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import datetime
|
||||
import pytz
|
||||
import math
|
||||
import pandas
|
||||
import time
|
||||
|
||||
from collections import Counter
|
||||
@@ -14,7 +13,7 @@ import zipline.util as qutil
|
||||
import zipline.protocol as zp
|
||||
import zipline.finance.performance as perf
|
||||
|
||||
from zipline.protocol_utils import Enum, namedict
|
||||
from zipline.protocol_utils import Enum, ndict
|
||||
|
||||
# the simulation style enumerates the available transaction simulation
|
||||
# strategies.
|
||||
@@ -43,10 +42,7 @@ class TradeSimulationClient(qmsg.Component):
|
||||
self.txn_sim = TransactionSimulator(sim_style)
|
||||
|
||||
assert self.trading_environment.frame_index != None
|
||||
self.event_frame = pandas.DataFrame(
|
||||
index=self.trading_environment.frame_index
|
||||
)
|
||||
|
||||
self.event_frame = ndict()
|
||||
self.perf = perf.PerformanceTracker(self.trading_environment)
|
||||
|
||||
@property
|
||||
@@ -178,8 +174,7 @@ class TradeSimulationClient(qmsg.Component):
|
||||
def queue_event(self, event):
|
||||
if self.event_queue == None:
|
||||
self.event_queue = []
|
||||
series = event.as_series()
|
||||
self.event_queue.append(series)
|
||||
self.event_queue.append(event)
|
||||
|
||||
def get_frame(self):
|
||||
for event in self.event_queue:
|
||||
|
||||
@@ -12,7 +12,7 @@ class VWAPTransform(BaseTransform):
|
||||
self.by_sid = defaultdict(self.create_vwap)
|
||||
|
||||
def transform(self, event):
|
||||
cur = self.by_sid(event.sid)
|
||||
cur = self.by_sid[event.sid]
|
||||
cur.update(event)
|
||||
self.state['value'] = cur.vwap
|
||||
return self.state
|
||||
|
||||
Reference in New Issue
Block a user