Hi Everyone - I am very very new to coding and am having some trouble with talib EMA. I am not getting any EMA calculations for certain stocks I run through my code. If I run a high volume stock like APPL I have no problems, but anything with lower volume the logs just give NaN . I believe it has to do with how history deals with periods of no data (no trades in a given minute). Because I am dealing with the EMAs the bar count has to go back a long period or I would just shorten the window. Any suggestions, ideas, help?
import pandas as pd
import talib
def initialize(context):
context.my_stock = sid(13835)
cash = context.portfolio.cash
set_commission(commission.PerShare(cost=.005, min_trade_cost=1))
set_benchmark(context.my_stock)
# Will be called on every trade event for the securities you specify.
def handle_data(context, data):
exchange_time = pd.Timestamp(get_datetime()).tz_convert('US/Eastern')
priceHistory1 = history(bar_count=500, frequency='1m', field='close_price')
my_stock_series1 = priceHistory1[context.my_stock]
mAvg1 = talib.EMA(my_stock_series1, timeperiod=15)[-1]
mAvg2 = talib.EMA(my_stock_series1, timeperiod=42)[-1]