mirror of
https://github.com/wassname/catalyst.git
synced 2026-09-13 12:20:20 +08:00
ENH: Adds LinearWeightedMovingAverage factor
This commit is contained in:
@@ -16,6 +16,7 @@ from zipline.pipeline.factors import (
|
||||
Aroon,
|
||||
FastStochasticOscillator,
|
||||
IchimokuKinkoHyo,
|
||||
LinearWeightedMovingAverage,
|
||||
RateOfChangePercentage,
|
||||
)
|
||||
from zipline.testing import ExplodingObject, parameter_space
|
||||
@@ -380,3 +381,35 @@ class TestRateOfChangePercentage(ZiplineTestCase):
|
||||
out = np.zeros(len(assets))
|
||||
rocp.compute(today, assets, out, data)
|
||||
assert_equal(out, np.full((len(assets),), expected))
|
||||
|
||||
|
||||
class TestLinearWeightedMovingAverage(ZiplineTestCase):
|
||||
def test_wma1(self):
|
||||
wma1 = LinearWeightedMovingAverage(
|
||||
inputs=(USEquityPricing.close,),
|
||||
window_length=10
|
||||
)
|
||||
|
||||
today = pd.Timestamp('2015')
|
||||
assets = np.arange(5, dtype=np.int64)
|
||||
|
||||
data = np.ones((10, 5))
|
||||
out = np.zeros(data.shape[1])
|
||||
|
||||
wma1.compute(today, assets, out, data)
|
||||
assert_equal(out, np.ones(5))
|
||||
|
||||
def test_wma2(self):
|
||||
wma2 = LinearWeightedMovingAverage(
|
||||
inputs=(USEquityPricing.close,),
|
||||
window_length=10
|
||||
)
|
||||
|
||||
today = pd.Timestamp('2015')
|
||||
assets = np.arange(5, dtype=np.int64)
|
||||
|
||||
data = np.arange(50, dtype=float).reshape((10, 5))
|
||||
out = np.zeros(data.shape[1])
|
||||
|
||||
wma2.compute(today, assets, out, data)
|
||||
assert_equal(out, np.array([30., 31., 32., 33., 34.]))
|
||||
|
||||
Reference in New Issue
Block a user