Hi everybody,
As you can see below, my algo stoped trading after a while. I wonder if anyone knows where the problem is ?
Thanks!
Hi everybody,
As you can see below, my algo stoped trading after a while. I wonder if anyone knows where the problem is ?
Thanks!
Hi Youness,
I took a look at your algo and it seems it's getting stuck with an open order in April 2013 that's preventing the ordering part of your code from being executed. The stock with the stuck order was WRC and it actually was delisted in February 2013. The algo opens a sell order on this stock in March but since it's delisted, that order can never be filled. WRC is actually appearing in your context.portfolio.positions because you held a position in it when it became delisted.
Here is a possible solution:
Create a variable such as context.delisted
to keep track of securities that are delisted. To find when a stock becomes delisted, every day of the simulation, you can look at the end_date
of each stock (data[stock].sid.end_date
) and compare it to get_datetime()
. If the end_date
is less than get_datetime()
, then the stock is delistesd and you can store it in contest.delisted
. Then, in your trade logic, you can exclude anything stored in context.delisted
. This might include factoring delisted stocks into certain calculations as it will still exist in context.portfolio.positions
.
I should add that while this is a situation that can arise in backtesting, delisted securities will not exist in context.portfolio.positions
for live IB algorithms.
Let me know if this helps or if you have any other questions!
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.