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

I was just wondering if in Quantopian backtest you takes into consideration that it takes 2 days for cash to be settled (become available again) after stocks are sold on IB?

4 responses

It takes two days before it becomes available for withdrawal.... however you can buy stocks with that money before settlement

Chris,

Here's a blurb from IB, https://ibkb.interactivebrokers.com/tag/stocksetfs?page=3:

Availability of proceeds in a 'Cash' type account

"Accounts which have been set up as a 'Cash' type do not have access to the proceeds from the sale of securities until such time the transaction has settled at the clearinghouse and proceeds have been issued to IB. Securities settlement generally takes place on the third business day following the sale transaction. Providing access to the funds prior to settlement would constitute a loan, a transaction which is precluded from taking place within this account type.

Account holders who wish to have access to settled funds prior to the settlement day may do so by electing an account type of 'Margin'. Under this account type unsettled funds may be used for trading purposes but may not be withdrawn until settlement. Account holders maintaining a 'Cash' account may request an upgrade to a 'Margin' type account by logging into Account Management and selecting the Trading Access and then Trading Configuration menu options. Upgrade requests are subject to a compliance review to ensure that the account holder maintains the appropriate qualifications."

So you need to have a margin account to be able to trade within the settling period. Quantopian backtesting does not incorporate these rules automatically; you need to build in a delay to simulate a cash account.

Grant

My experience has been the same as Chris's: 2 days before it's available for more trading. Fortunately the algo. I'm working with re-balances once a week. However testing and debugging happens on a quicker time scale. This is especially true if all positions must be closed in order to bring a revised algo. online. It's very counter productive to have to wait two days before opening positions again utilizing the full value of the account. I suppose I could restrict the max. initial cash to less than my account value but the max. initial cash available often has an affect on the algo.'s performance.

Sure, I could switch to a margin account but that complicates overall book keeping. Likewise, it could quickly get out of hand if the algo. goes bonkers. Recall that we have to program our own 'circuit breakers' to trap a run-away algo.. As is the platform will let the algo. borrow as much as it wants.

Best,
Tom

The short answer is that Quantopian doesn't have a built-in model of how IB does cash management. That's at least partly because there are so many variations on it - different accounts have different settlement rules. We probably will build it someday, though.

Making sure you saw this new feature in the API: https://www.quantopian.com/posts/new-feature-ib-account-information-available-in-algorithm. That at least gives your algorithm the knowledge of what cash is or isn't available at any point in time according to IB. That's important, of course, because IB is the source of truth for that number.

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.