Hey guys. Just getting started here. Trying to build a simple RSI2 strategy using the Pipeline. I've previously used basically the same code (have since edited a few things to try to fix this error) to implement the strategy on a list of sids. Once I brought in the Pipeline, I've failed to get the algo to run.
Here's the error I get:
AssertionError: real has wrong dimensions
There was a runtime error on line 44.
The error arises when I try to pull in the RSI from talib. I've used the same way of pulling in RSI on several simpler algos. This is how I've done it up to now:
hist = data.history(context.security, 'close', 100, '1d')
rsi = ta.RSI(hist, 2)
It's clear that the Pipeline doesn't like this way of doing it, but I'm pretty stumped after searching through a bunch of Quantopian forums looking for an answer.
Here's the code:
import quantopian.algorithm as algo
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.filters import Q500US, Q1500US ,Q3000US
import talib as ta
from quantopian.pipeline.factors import RSI
def initialize(context):
schedule_function(trade , date_rules.every_day() , time_rules.market_close(minutes=30))
algo.attach_pipeline(make_pipeline(), 'pipeline')
#context.rsi_lookback = 2
context.rsi_buy_level = 20
context.rsi_sell_level = 65
#context.rsi = RSI(inputs = [USEquityPricing.close], window_length = 2)
def make_pipeline():
# Base universe set to the Q500US
universe = Q3000US()
# Factor of yesterday's close price.
close_price = USEquityPricing.close.latest
pipe = Pipeline(
columns={
'close': close_price,
},
screen=universe
)
return pipe
def before_trading_start(context, data):
context.output = algo.pipeline_output('pipeline')
context.security_list = context.output.index
def trade(context,data):
for x in context.security_list:
current_price = data.current(context.security_list , 'price')
hist = data.history(context.security_list , 'close' , 100 , '1d')
sma_100_day = hist.mean()
rsi = ta.RSI(hist, 2)
if rsi < context.rsi_buy_level and current_price > sma_100_day and context.portfolio.positions[x].amount == 0:
order_target_percent(x , 1.00)
print('we bought {}', x)
if context.portfolio.positions[x].amount > 0 and rsi > context.rsi_sell_level:
order_target_percent(x , 0.0)
Would love some guidance guys. Really loving the Quantopian platform so far, very comfortable way to learn algo trading basics.