Hi all,
New to coding and new to Quantopian and I'm trying to build my first algorithm, but I can't understand this Runtime Error:
"AttributeError: 'module' object has no attribute 'dependencies'"
It is occurring on a line within my before trading starts function:
context.pipe_output = pipeline_output('fundamentals_pipeline')
I'm basically following the Fundamental Data Algorithm exactly from the help (https://www.quantopian.com/help#module-quantopian_pipeline_factors), and I've copy/pasted my entire code below. Very confused because I ran the sample fundamental data algo and it backtested fine, even though it contains the exact same line of code that is triggering an error in mine (I even changed the name of my pipeline and copy/pasted the sample code over, still hitting that error).
Thanks for any help you can offer, I really appreciate it.
Code:
"""
Investment thesis:
Companies with the highest diluted EPS growth will outperform market, and companies with lowest diluted EPS growth will underperform market. Will go long "growers" and short "shrinkers," juicing market returns (anticipate a high beta, >1.5).
Steps:
1. Look at stocks in QTradableStocksUS
2. Go long in the top 50 stocks by diluted EPS growth
3. Go short in the bottom 50 stocks by diluted EPS growth.
4. Rebalance once a month (EPS growth is only updated every quarter, but companies report earnings at different times).
"""
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data import Fundamentals
from quantopian.pipeline.filters import QTradableStocksUS
def initialize(context):
"""
Called once at the start of the algorithm.
"""
# Rebalance every month, 1 hour after market open.
schedule_function(
rebalance,
date_rules.month_start(),
time_rules.market_open(hours=1),
)
# Record tracking variables at the end of each day.
schedule_function(
record_vars,
date_rules.every_day(),
time_rules.market_close(),
)
# Create our dynamic stock selector.
attach_pipeline(make_pipeline(), 'fundamentals_pipeline')
def make_pipeline():
"""
A filter for the top and bottom US companies by diluted EPS growth
"""
# Base universe set to the QTradableStocksUS
base_universe = QTradableStocksUS()
# Factor of diluted EPS growth
dil_eps = Fundamentals.diluted_eps_growth.latest
# Top 50 and bottom 50 by diluted EPS growth
top_growth_stocks = dil_eps.top(50, mask=universe)
bottom_growth_stocks = dil_eps.bottom(50, mask=universe)
# Screen for those securities
securities_to_trade = (top_growth_stocks | bottom_growth_stocks)
pipe = Pipeline(
columns={
'eps_growth': dil_eps,
'longs': top_growth_stocks,
'shorts': bottom_growth_stocks,
},
screen=securities_to_trade
)
return pipe
def before_trading_start(context, data):
"""
Called every day before market open.
"""
context.pipe_output = pipeline_output('fundamentals_pipeline')
# These are the securities that we are interested in trading each day.
context.longs = context.pipe_output[context.pipe_output['longs']].index
context.shorts = context.pipe_output[context.pipe_output['shorts']].index
def rebalance(context, data):
"""
Execute orders according to our schedule_function() timing.
"""
my_positions = context.portfolio.positions
#if we have any positions
if (len(context.longs) > 0) and (len(context.shorts) > 0):
# Equally weight all longs and shorts
long_weight = 0.5/len(context.longs)
short_weight = -0.5/len(context.shorts)
# Get our securities for the long and short baskets
target_long_symbols = [s.symbol for s in context.longs]
target_short_symbols = [s.symbol for s in context.shorts]
log.info("Opening long position each worth %.2f of our portfolio in: %s" \
% (long_weight, ','.join(target_long_symbols)))
log.info("Opening short position each worth %.2f of our portfolio in: %s" \
% (short_weight, ','.join(target_short_symbols)))
# Open long positions
for security in context.longs:
if data.can_trade(security):
if security not in my_positions:
order_target_percent(security, long_weight)
else:
log.info("Didn't open long position in "+security+" because untradable")
# Open short positions
for security in context.shorts:
if data.can_trade(security):
if security not in my_positions:
order_target_percent(security, short_weight)
else:
log.info("Didn't open short position in "+security+" because untradable")
closed_positions = []
#Close our previous positions that are no longer in our pipeline
for security in my_positions:
if security not in context.longs and security not in context.shorts \
and data.can_trade(security):
order_target_percent(security, 0)
closed_positions.append(security)
log.info("Closing our positions in %s." % (','.join([s.symbol for s in closed_positions])))
def record_vars(context, data):
"""
Plot variables at the end of each day.
"""
pass
def handle_data(context, data):
"""
Called every minute.
"""
pass