I am trying to write a program in the backtester that picks all stocks which have experienced positive dividend growth for the last three years. Specifically, in the research environment the logic I would use to pick the stocks would be:
fundamentals = init_fundamentals()
dummydate = '2016-02-01'
# Verifies that dividends have been growing for 3 years
div_data = get_fundamentals(query(fundamentals.earnings_report.dividend_per_share,
fundamentals.valuation_ratios.dividend_yield), dummydate, range_specifier='3y')
div = div_data['dividend_per_share'].dropna(axis = 1)
div_growth_stocks = div.T[div.iloc[1] - div.iloc[0] > 0].index.intersection(div.T[div.iloc[2] - div.iloc[1] > 0].index)
In the backtester, as part of the rebalance function I have put in:
def my_rebalance(context,data):
today = get_datetime()
if today.month == 2 or today.month == 5 or today.month == 8 or today.month == 11:
# Verifies that dividends have been growing for 3 years
div_data = get_fundamentals(query(fundamentals.earnings_report.dividend_per_share,fundamentals.valuation_ratios.dividend_yield), today, '3y')
div = div_data['dividend_per_share'].dropna(axis = 1)
div_growth_stocks = div.T[div.iloc[1] - div.iloc[0] > 0].index.intersection(div.T[div.iloc[2] - div.iloc[1] > 0].index)
but when I actually run the code I get
TypeError: get_fundamentals() takes at most 3 arguments (4 given)
It seems that the get_fundamentals syntax in the backtester is different than in the research environment. Is there any way I can translate the above code from the research environment into the backtester?