Notebook
from quantopian.pipeline import Pipeline
from quantopian.research import run_pipeline
from quantopian.pipeline.factors import SimpleMovingAverage, MovingAverageConvergenceDivergenceSignal, EWMA
from quantopian.pipeline.data.builtin import USEquityPricing
def make_pipeline():
ewma = EWMA.from_span(inputs=[USEquityPricing.close], window_length=20, span=15,)
macd = MovingAverageConvergenceDivergenceSignal(inputs=[USEquityPricing.close])
close = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=20)
pipe = Pipeline(
columns = {
'close': close,
'macd' : macd,
'ewma' : ewma
}
)
return pipe
run_pipeline(make_pipeline(), start_date = '2015-01-01', end_date = '2015-03-01').sort_values('close', ascending=False).head(5)
Algorithm
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from quantopian.pipeline.factors import SimpleMovingAverage, MovingAverageConvergenceDivergenceSignal, EWMA
from quantopian.pipeline.data.builtin import USEquityPricing
def initialize(context):
pipe = make_pipeline()
attach_pipeline(pipe, 'make_pipeline')
def make_pipeline():
ewma = EWMA.from_span(inputs=[USEquityPricing.close], window_length=20, span=15,)
macd = MovingAverageConvergenceDivergenceSignal(inputs=[USEquityPricing.close])
close = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=20)
pipe = Pipeline(
columns = {
'close': close,
'macd' : macd,
'ewma' : ewma
}
)
return pipe
def before_trading_start(context,data):
context.output = pipeline_output('make_pipeline')
print(context.output.sort_values('close', ascending=False).head(5))