Apparently my approach to this is all wrong. My goal is automatically adjust the percentage of my portfolio which is long and the percentage which is short. It appears to be working on the long side, but not for shorts.
For example, lets say I would like to allocate 70% of my portfolio for a long position in the SPY, and the remaining 30% for a short position. This is my attempt..
target_value_amnt_long = .70
target_value_amnt_short = .30
if target_value_amnt_short > target_value_amnt_long:
order_target_percent(context.stock, -target_value_amnt_short)
if target_value_amnt_long > target_value_amnt_short:
order_target_percent(context.stock, target_value_amnt_long)
This is after a 50-50 allocation starting out
order_target_percent(context.stock, .5)
order_target_percent(context.stock, -.5)