LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
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.
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.
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.
Alexandre Catarino
100.5k
,
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:
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
Nicolas Ferrari
2.5k
,
Hello Alexander, can you give an example of the FuncFilter with python? is a list comprehension? I cannot filter the GetOrders in the right way.
Â
Thanks!
Nicolás
0
Jack Simonson
49.4k
,
Hi Nicolas,
You can use this code to get the same results in Python:
filledSpyOrders = [x for x in self.Transactions.GetOrders(None) if (x.Symbol.Value == 'SPY') and (x.Status == OrderStatus.Filled)]
if len(filledSpyOrders) > 0:
self.Log(f'{self.Time}: {filledSpyOrders[0].Time}')
This will retrieve all orders using self.Transactions.GetOrders(None) and then applies the boolean filtering using a list comprehension.
TypeError : No method matches given arguments for GetOrders (Open Stacktrace)
Are there any performance benfits if calling GetOrders with or without a filter function?Â
0
Derek Melchin
STAFF
,
Hi Sachinahj,
Passing a function to the GetOrders method could have some performance benefits, but this currently only works when using C#. With Python, we can use the filtering method Jack published above.
A GitHub Issue has been created to implement this functionality in the python API. Its progression can be tracked here.
Best, Derek Melchin
0
Edited by Derek Melchin
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.
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...
To unlock posting to the community forums please complete at least 30% of Boot Camp. You can
continue your Boot Camp training progress from the terminal. We
hope to see you in the community soon!