mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-27 20:20:55 +08:00
ENH: Change DollarVolume to AverageDollarVolume.
This commit is contained in:
@@ -66,7 +66,8 @@ Pipeline API
|
||||
.. autoclass:: zipline.pipeline.factors.ExponentialWeightedMovingStdDev
|
||||
:members:
|
||||
|
||||
.. autofunction:: zipline.pipeline.factors.DollarVolume
|
||||
.. autoclass:: zipline.pipeline.factors.AverageDollarVolume
|
||||
:members:
|
||||
|
||||
.. autoclass:: zipline.pipeline.filters.Filter
|
||||
:members: __and__, __or__
|
||||
|
||||
@@ -53,7 +53,7 @@ Enhancements
|
||||
window_length. (:issue:`884`).
|
||||
|
||||
* Added a new built-in factor:
|
||||
:class:`~zipline.pipeline.factors.DollarVolume`. (:issue:`910`).
|
||||
:class:`~zipline.pipeline.factors.AverageDollarVolume`. (:issue:`927`).
|
||||
|
||||
* Added :class:`~zipline.pipeline.factors.ExponentialWeightedMovingAverage` and
|
||||
:class:`~zipline.pipeline.factors.ExponentialWeightedMovingStdDev`
|
||||
|
||||
@@ -54,7 +54,7 @@ from zipline.pipeline.loaders.equity_pricing_loader import (
|
||||
from zipline.pipeline.engine import SimplePipelineEngine
|
||||
from zipline.pipeline import CustomFactor
|
||||
from zipline.pipeline.factors import (
|
||||
DollarVolume,
|
||||
AverageDollarVolume,
|
||||
EWMA,
|
||||
EWMSTD,
|
||||
ExponentialWeightedMovingAverage,
|
||||
@@ -951,9 +951,18 @@ class ParameterizedFactorTestCase(TestCase):
|
||||
|
||||
def test_dollar_volume(self):
|
||||
results = self.engine.run_pipeline(
|
||||
Pipeline(columns={'dv': DollarVolume()}),
|
||||
self.dates[0],
|
||||
Pipeline(
|
||||
columns={
|
||||
'dv1': AverageDollarVolume(window_length=1),
|
||||
'dv5': AverageDollarVolume(window_length=5),
|
||||
}
|
||||
),
|
||||
self.dates[5],
|
||||
self.dates[-1],
|
||||
)['dv'].unstack()
|
||||
expected = (self.raw_data ** 2) * 2
|
||||
assert_frame_equal(results, expected)
|
||||
)
|
||||
|
||||
expected_1 = (self.raw_data[5:] ** 2) * 2
|
||||
assert_frame_equal(results['dv1'].unstack(), expected_1)
|
||||
|
||||
expected_5 = rolling_mean((self.raw_data ** 2) * 2, window=5)[5:]
|
||||
assert_frame_equal(results['dv5'].unstack(), expected_5)
|
||||
|
||||
@@ -8,7 +8,7 @@ from .events import (
|
||||
BusinessDaysUntilNextEarnings,
|
||||
)
|
||||
from .technical import (
|
||||
DollarVolume,
|
||||
AverageDollarVolume,
|
||||
EWMA,
|
||||
EWMSTD,
|
||||
ExponentialWeightedMovingAverage,
|
||||
@@ -25,7 +25,7 @@ __all__ = [
|
||||
'BusinessDaysSincePreviousEarnings',
|
||||
'BusinessDaysUntilNextEarnings',
|
||||
'CustomFactor',
|
||||
'DollarVolume',
|
||||
'AverageDollarVolume',
|
||||
'EWMA',
|
||||
'EWMSTD',
|
||||
'ExponentialWeightedMovingAverage',
|
||||
|
||||
@@ -130,12 +130,18 @@ class MaxDrawdown(CustomFactor, SingleInputMixin):
|
||||
out[i] = (peak - data[end, i]) / data[end, i]
|
||||
|
||||
|
||||
def DollarVolume():
|
||||
class AverageDollarVolume(CustomFactor):
|
||||
"""
|
||||
Returns a Factor computing the product of most recent close price and
|
||||
volume.
|
||||
Average Daily Dollar Volume
|
||||
|
||||
**Default Inputs:** [USEquityPricing.close, USEquityPricing.volume]
|
||||
|
||||
**Default Window Length:** None
|
||||
"""
|
||||
return USEquityPricing.close.latest * USEquityPricing.volume.latest
|
||||
inputs = [USEquityPricing.close, USEquityPricing.volume]
|
||||
|
||||
def compute(self, today, assets, out, close, volume):
|
||||
out[:] = nanmean(close * volume, axis=0)
|
||||
|
||||
|
||||
class _ExponentialWeightedFactor(SingleInputMixin, CustomFactor):
|
||||
|
||||
Reference in New Issue
Block a user