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

Is there a way to access the date/time a position was entered into outside of trying to keep track of it in the algo?

I've got a method to track it in the algo for an individual security, but would like to do it for multiple. It would be great if something like that could be stored in the context.portfolio.positions[] object. Maybe the oldest date the position was started for instances where you add to a position over time.

9 responses

Here is an algorithm that keeps track of when individual trades are entered as well as when any position in a given security is entered. Hopefully this will be useful.

Ryan

Here is the same approach extended to multiple securities.

Thanks Ryan, I'll give it a shot

In the context of live trading with Interactive Brokers, this is an interesting question. Does an order confirmation get returned to the algo from IB with a datetime stamp corresponding to the actual time when the order was asynchronously filled by IB? Or is the datetime stamp applied at the minutely tic of the Quantopian clock (i.e. synchronously)?

On the help page, it states, under the Order object section:

created
Datetime: The date and time the order was created, in UTC
timezone.

Presumably, "created" means submitted. Is there any way to track when the order was filled?

Grant

Hi Grant,

The time stamp of the filled order will be at the minutely bar. Handle_data() is called every minute so your order fill will be updated at that frequency.

When you're live trading on Quantopian, you can request a second login with IB to view your account via TWS, WebTrader etc. On these dashboards, you can view the exact time of the filled order. While there may be a small discrepancy, within seconds, of the time for the filled order, it won't impact your algo because handle_data will only be executed on minutely bars, not tick-by tick-bars. The fill details including number of shares, time of fill, and price, are updated on the live trading dashboard.

Alisa

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.

Thanks Alisa,

Why did you decide not to make the actual time stamp of the IB filled order available to the algorithm?

Grant

The main reason is that in the algorithm, it simply doesn't matter what time the position fill happened. The algorithm is concerned with the state at the time the algo runs (ie every minute). It is looking for the current position, current price, and the current signals. If the fill happened 2 seconds ago or at worst, 59 seconds ago, the state of the order is identical. And it will be processed identically by the algo.

With that said, in the future when we build additional functionality, I'd imagine this information will be brought into the algo for logging and informational purposes.

Thanks Alisa,

I realize that you are still building up the system, but it would seem best to feed back as much detail from IB to the algorithm as is available, right? For example, the delay in order filling might turn out to be a useful indicator. To use your example, 2 seconds might be o.k., but 59 seconds would indicate that maybe the algorithm should hold off more trading, since one more second of delay and there will be slippage.

Grant

Agreed, it would be great to pull in the time stamp of the filled order from IB and it's part of the many feature's we're building towards