Been working in this for a little bit cant quite get it to run take a look at what I have so far.
def rename_col(df):
log.info(df.head())
return df
def initialize(context):
context.investment_size = (context.portfolio.cash / 10.0)
#Invest 10 percent of total cash
context.stop_loss_pct = 0.995
#Use Stop Loss
set_symbol_lookup_date('2013-10-01')
#Call Zonal Usage CSV
fetch_csv('https://td2ec2in4mv1euwest.teamdrive.net/primespace/59358/public/UH34BU000Z7FX005394VPP9272UGRRD6/Combined%20Weather%20Data.csv?P1RID=1',
date_column='Date',
pre_func = rename_col,
date_format = '%m/%d/%y')
context.stock = symbol('UNG')
def handle_data(context, data):
cash = context.portfolio.cash
try:
for s in data
if 'Casio Usage' in data[s]:
Casio = data[s]['Casio Usage']
current_postion = context.portfolio.positions[s].amount
current_price = data[s].price
#If Power Usage is high from temperature data then UNG will trade at a premium
if (Casio > 650) and (current_postion == 0):
if cash > context.investment_size:
order_value(s,context.investment_size, style=StopOrder(context.stop_loss*current_price))
#If Power Usage is low then UNG should trade at a discount and we should exit position
elif (Casio <= 650) and (current_position > 0):
order_target(s,0)
except Exception as e:
print(str(e))