Back

Calculating cost basis

How do I get the "cost basis" for a given position?  I'm trying to replicate behaviour from Quantopian, so I'm looking for the VWAP per share of a given position.  Is this something I need to calculate myself?

Update Backtest








Shaun

If I've understood your question properly, this is what I've used personally:

C#

BuyPrice = Portfolio["XIV"].AveragePrice;

Python

self.BuyPrice = self.Portfolio["XIV"].AveragePrice

I just very lazily update this every tick.

0

Portfolio["AAPL"].AveragePrice



Checkout the SecurityHolding object for all the available helper properties.
2

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.


Thanks.  That appears to be what I am looking for.  I have tried to follow the docs before, but I tend to get lost when trying to convert between the docs (which appear to be targetted for C#) and python (which I'm trying to write my algo in)

As suggested, I just checked the docs for the SecurityHolding object, but there doesnt appear to be an "AveragePrice" property.  I see VolumeWeightedAveragePrice, which appears to be what I'm looking for though.

0

Shaun Senecal its tricky to find in the generated docs, its clearer in the source -- here is the direct link:

https://github.com/QuantConnect/Lean/blob/24fcd239a702c391c26854601a99c514136eba7c/Common/Securities/SecurityHolding.cs#L79
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