Pretty simple, if you call this.Portfolio.GetBuyingPower(..) at all in your algo, it causes back-tests to run 3-4x slower than they do by just using this.Portfolio.Cash. That's a massive perf impact, and I think this call should be analyzed for performance issues.
Using 2017 Jan 2 -> 2017 Jan 12 (10 days), notice the log difference between calling the two every 1 minute during the trade day. Here's when GetBuyingPower is called:
Algorithm Id:(cdd8c084998ff3bd80250d5befa71bad) completed in 38.29 seconds at 16k data points per second. Processing total of 595,013 data points.
And when it isn't:
Algorithm Id:(d72eef41ff55b9f2a6e21cfd01e56795) completed in 10.86 seconds at 55k data points per second. Processing total of 595,013 data points.
That's a massive difference. I've attached the back-test that uses GetBuyingPower to this to illustrate the issue.
Automaton
And here's the same project but just calling this.Portfolio.Cash instead, which is much faster.
Alethea Lin
Hi Automaton,
Portfolio.Cash and Portfolio.GetBuyingPower have different purposes. The GetBuyingPower method gets the margin available for trading a specific symbol in a specific direction, so it would take longer when this method is called since calculations will be done to return the desired value. On the other hand, this.Portfolio.Cash returns the sum of all currencies in account in US dollars (only settled cash). This is a property of the Portfolio Class so it does not take long to retrieve this value.Â
You can read more about the methods and properties of SecurityPortfolioManager Class here.
Thanks for your support!
Automaton
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.
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!