I'm getting an error that the data frame is ambiguous when trying to load an if statement that is based on my pct_change variable.
Any help?
from pytz import timezone
from datetime import datetime, timedelta
from zipline.utils.tradingcalendar import get_early_closes
from quantopian.pipeline.data.builtin import USEquityPricing
import pandas as pd
import datetime
def initialize(context):
set_commission(commission.PerTrade(cost=0))
set_slippage(slippage.FixedSlippage(spread=0.00))
context.minutes_after = 5
context.stock = sid(40634)
def handle_data(context, data):
yesterdays_close = history(1, "1d", "high")
log.info(yesterdays_close)
todays_high = data[context.stock].open_price
log.info("current price: %f" % todays_high)
pct_change = (todays_high - yesterdays_close) / todays_high * 100
log.info(pct_change)
cash = context.portfolio.cash
for stock in data:
stock_price = data[stock].price
plausible_investment = cash
stop_price = stock_price - (stock_price * 0.005)
share_amount = int(plausible_investment / stock_price)
if pct_change >= 2.0:
order(stock, -share_amount)
if stock_price <= 1.90:
order(stock, - share_amount)
def market_open(context, data):
# Checks if it's market open at 9AM EST
loc_dt = get_datetime().astimezone(timezone('US/Eastern'))
# Backtesting starts the time at 9:31AM
if loc_dt.hour == 9 and loc_dt.minute == 31:
log.debug(get_datetime())
for stock in data:
context.daily_stocks[stock] = data[stock].price
else:
pass
def market_after_open(context, data):
# Checks if it's market open at 9AM EST + however minutes you want to set
loc_dt = get_datetime().astimezone(timezone('US/Eastern'))
if loc_dt.hour == 9 and loc_dt.minute == 30 + context.minutes_after:
log.debug(get_datetime())