I have the following code I am trying to run:
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import Returns
from quantopian.pipeline.factors import SimpleMovingAverage
from quantopian.pipeline.filters.morningstar import Q1500US
import pandas as pd
import numpy as np
def initialize(context):
schedule_function(buy_open, date_rules.every_day(),time_rules.market_open(minutes=10))
schedule_function(sell_close, date_rules.every_day(),time_rules.market_close(minutes=10))
my_pipe = make_pipeline()
attach_pipeline(my_pipe, name = 'my_pipeline')
def make_pipeline():
base_universe = Q1500US()
std90 = np.std(Returns(window_length=90))
yday_low = USEquityPricing.low.latest
current_open = USEquityPricing.open.latest
lowret = (current_open-yday_low)/yday_low
gapdown_filter = lowret<std90
mean_close_20 = SimpleMovingAverage(inputs=[USEquityPricing.close],window_length = 20)
narrowing_filter = current_price>mean_close_20
comp_filter = gapdown_filter and narrowing_filter
smallest = lowret.bottom(10)
total_filter = smallest and comp_filter
return Pipeline(screen = base_universe and total_filter)
def buy_open(context,data):
for s in context.security_list:
order_target_percent(s,0.1)
def sell_close(context,data):
for s in context.portofolio.positions:
order_target_percent(s,0)
def before_trading_start(context, data):
context.output = pipeline_output('my_pipeline')
context.security_list = context.output.index
And I get a runtime error "ValueError: setting an array element with a sequence." on the line "my_pipe = make_pipeline()". I tried searching through the documentation and everything to see what I'm doing wrong but this seems like the way to use a Pipeline so I am completely lost as to what is not working. Any help would be appreciated.