I'm trying to get a feel for algorithms so I'm trying to build a simple "buy bear, sell bull" algorithm.
but when i try to add sell short functions, my algo goes crazy. it ends up with my cash somewhere around 1 trillion though my pnl is -1.5 trillion
could someone post an example showing how to properly code a (sane) short sell algo?
my code is basically like this:
def sell_short(context, sec, data, day, state):
spend = context.portfolio.cash / 10
amount = spend / data[sec].price
state.orderAmount-=amount
i guess i shouldn't use cash on hand for short selling....