mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-09 13:23:25 +08:00
Applies PEP-8 recommendations to vwap module.
This commit is contained in:
@@ -3,6 +3,7 @@ from collections import defaultdict
|
||||
|
||||
from zipline.gens.transform import EventWindow, TransformMeta
|
||||
|
||||
|
||||
class VWAP(object):
|
||||
"""
|
||||
Class that maintains a dictionary from sids to VWAPEventWindows.
|
||||
@@ -14,7 +15,7 @@ class VWAP(object):
|
||||
self.market_aware = market_aware
|
||||
self.delta = delta
|
||||
self.days = days
|
||||
|
||||
|
||||
# Market-aware mode only works with full-day windows.
|
||||
if self.market_aware:
|
||||
assert self.days and not self.delta,\
|
||||
@@ -28,13 +29,13 @@ class VWAP(object):
|
||||
# No way to pass arguments to the defaultdict factory, so we
|
||||
# need to define a method to generate the correct EventWindows.
|
||||
self.sid_windows = defaultdict(self.create_window)
|
||||
|
||||
|
||||
def create_window(self):
|
||||
"""Factory method for self.sid_windows."""
|
||||
return VWAPEventWindow(
|
||||
self.market_aware,
|
||||
days = self.days,
|
||||
delta = self.delta
|
||||
self.market_aware,
|
||||
days=self.days,
|
||||
delta=self.delta
|
||||
)
|
||||
|
||||
def update(self, event):
|
||||
@@ -48,6 +49,7 @@ class VWAP(object):
|
||||
window.update(event)
|
||||
return window.get_vwap()
|
||||
|
||||
|
||||
class VWAPEventWindow(EventWindow):
|
||||
"""
|
||||
Iteratively maintains a vwap for a single sid over a given
|
||||
@@ -69,7 +71,7 @@ class VWAPEventWindow(EventWindow):
|
||||
def handle_remove(self, event):
|
||||
self.flux -= event.volume * event.price
|
||||
self.totalvolume -= event.volume
|
||||
|
||||
|
||||
def get_vwap(self):
|
||||
"""
|
||||
Return the calculated vwap for this sid.
|
||||
|
||||
Reference in New Issue
Block a user