Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Negative Cash

Hi all,
Ive been playing with the sample algorithms and I am trying to add both a long and a short position to the algos. This however keeps either buying or selling me into negative cash. I have read other forums and added numerous trading guards to no avail. If I lose 100% I don't want to lose more, I do not want to use cash that I don't have. Am I missing something basic here?

4 responses

Here is another example

If you don't want to order when you have a negative cash balance, add a check that " if cash < 0: return" in your ordering logic. Also, is there a reason why you chose to user the simple order() method rather than using an order_target method? These methods are generally more robust and will help to seek to your target positions. Check them out!

In this case, adding a trading guard won't help you because they check for maximum positions and long only positions - rather than the cash balance.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Hey Alisa,
Thanks for the reply. Where exactly should I put the if statement? I put it where I thought it would make sense, but it does not seem to have worked. Also what is the difference between using order and telling the order how many shares to buy and the order_target which also I explain how many shares to buy

Hi Minyong,

I cloned your latest algo and recorded the cash value. Looking at the custom data graph below, the algo is doing what you specified - avoiding going into negative cash. So the code was successful! There isn't a difference between calculating the number of shares to buy and using an order_target call, these steps are equivalent. I suggested this fix to remove the manual calculation since we have a built-in function that can take care of it for you :)

Alisa