Hi, can anybody tell me why this code:
price = data[context.spy].price
sd = data[context.spy].stddev(20)/price
give me this runtime error:
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'
Hi, can anybody tell me why this code:
price = data[context.spy].price
sd = data[context.spy].stddev(20)/price
give me this runtime error:
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'
Hello Victor,
This eliminates the error:
def initialize(context):
context.spy = sid(8554)
def handle_data(context, data):
price = data[context.spy].price
std = data[context.spy].stddev(20)
if std != None:
sd = data[context.spy].stddev(20)/price
You can dig deeper, but I believe what's going on is that the stddev transform needs more than one data point, so it returns None until the backtest has progressed. Note that if you run on minute data and use the history API (see the help page), the algorithm will be "warmed up" so that you can compute the statistics based on a trailing window of data that is available at the backtest start.
Grant