Back

Struggling with simple issue of getting purchase date

The algorithm I'm toying with presently involves unloading a stock that was purchased after n days if a specific criteria hasn't been met.  I'm having a tough time deciphering through the object model how to determine when an equity was actually purchased.

I'm guessing it's something in the TransActions.GetOrders(x => x.Symbol = theSymbol) or something, but I'm not seeing how to actually get the date the original buy order was completed.

Suggestions?  Thanks in advance.

Update Backtest








We need to specify the nature of the orders we are trying to get from the transaction records. If we want the time a stock was purchased, we also need to select orders by their symbol and status:

var filledSpyOrders = Transactions
.GetOrders(x=>
x.Symbol == "SPY" &&
x.Status == OrderStatus.Filled);

Then we need to check whether any order felt in this criteria and after that get the time the stock was purchased:

if (filledSpyOrders.Count() > 0)
{
// Only the last one under my criteria
var orderTime = filledSpyOrders.Last().Time;
Log(Time + ": " + orderTime);
}

 

0

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed