Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Algo adding target to current_price instead of subtracting...

Not sure if I have this formatted correctly, but here goes.

When we take a short position, I want to set the context.target to the current_price - context.tgtval.

But the code appears to be adding the context.tgtval instead of subtracting it.

It even adds the value when I remove the variable and type the amount directly.

I put a comment with the word BUG right above where this happens.

What am I doing incorrect?

1 response

Chuck, that branch of code is never executed because cash is never $10k more than capital_used in your time period.

Also you should know that both cash and capital_used are calculated as the net of long and short positions (short dollars subtracted from long dollars). You may be expecting them to be calculated as the absolute sum (I posted a recent thread on the subject).

Your use of the variables may be consistent with the net calculation but I wanted to bring it to your attention nonetheless.