Hi,
I have some questions about how to get the detail of each crypto symbol in portfolio (python) object:
1. Assume I bought BTCUSD and ETHUSD. In portfolio, the key will be BTCUSD or just BTC? How can I easily list all coins I have so far and the quantity (value) of each coins in portfolio? USD will be a coin or cash in this case?
2. Assume I bought 2 times BTCUSD. One time is $10000 for one BTC, 2nd time is $20000 for one BTC. In portfolio object,, the BTC (or BTCUSD) will keep one price which is $15000, or it will keep 2 prices (one is $10000, and one is $20000)
3.. Assume I bought 2 times BTCUSD. 1st time is 2021-01-01, 2nd time is 2021-02-01. Will Portfolio help me to check the record when I begin to hold the coins (it will record 2 times date or none date infomration?). So when I backtest, my algorithm can do different decision base on different purchase date?
Thanks,
henry
Derek Melchin
Hi Henry111,
#1
> Assume I bought BTCUSD and ETHUSD. In portfolio, the key will be BTCUSD or just BTC?
In the Portfolio/Securities objects, it would be keyed as 'BTCUSD'. However, we recommend looking for holdings in the CashBook since cryptocurrencies have virtual positions. In the CashBook, Bitcoin is keyed by BTC instead of BTCUSD.
> How can I easily list all coins I have so far and the quantity (value) of each coins in portfolio?
for cash in self.Portfolio.CashBook.Values: self.Log(f"Holding {cash.Amount} of {cash.Symbol} (${cash.ValueInAccountCurrency} USD value)")
> USD will be a coin or cash in this case?
Yes, if we use the loop above, USD will also be printed.
#2: We can get the average purchase price of our Bitcoin with
self.Portfolio['BTCUSD'].AveragePrice
If we want to track the save the fill prices of all our trades, we can save the order tickets that are generated when we place our trades.
for symbol in self.symbols: ticket = self.MarketOrder(symbol, 0.0001) self.tickets.append(ticket)
After saving the tickets, we can then access the purchase price of our trades with
for ticket in self.tickets: self.Log(f"Ordered {ticket.Quantity} of {ticket.Symbol} at {ticket.Time} for {ticket.AverageFillPrice}")
#3: The date of our crypto trades can be saved using the process in #2 above.
See the attached backtest for reference.
Best,
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.
Henry111
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!