Back

"BTCUSD" - What are Virtual Positions?

Hello, I wanted to test the live functionality of QC using GDAX. However the Liquidate function doesn't seem to work in live mode wih GDAX. The first time the Indicator conditions are met a setholdings() buy order is plaeced and I can see the transaction on my GDAX account. However, when the EMAFast < EMASlow the Liquidate function should be called. I see in the debug logs that even though those conditions are met there is no Liquidate() transaction. Has anyone also observed this? Should I use a different order function (e.g. marketOrder() ? I figured setHoldings() and Liquidate() can't be any simpler... ANy modifications/ suggestions/edits to trade live on GDAX would be greatly appreciated

 

private void MarketOrder(Coin coin, double allocation)
{
Debug("EMA Fast:" + coin.EMAFast + " " + "EMA Slow: " + coin.EMASlow);
Debug("Holdings:" + Portfolio.CashBook["BTC"].Amount);

var openOrders = Transactions.GetOpenOrders(coin.CoinSymbol);
if (openOrders == null || openOrders.Count == 0)
{
if (Portfolio.CashBook["BTC"].Amount == 0 && coin.EMAFast > coin.EMASlow)
{
SetHoldings(coin.CoinSymbol,allocation);
Debug("Bought:" + coin.Price);
}
if (Portfolio.CashBook["BTC"].Amount != 0 && coin.EMAFast < coin.EMASlow)
{
Liquidate(coin.CoinSymbol);
Debug("Sold:" + coin.Price);
}
}
}

Update Backtest








GDAX does not have virtual positions.

Say you have 3 coins: 1-EUR; $1-USD and 1 BTC. When LEAN goes to make the portfolio; do you have: EURUSD, or do you have BTCUSD or do you have BTCEUR? 

These joined currencies "BTCUSD" are called virtual positions. They do not exist; they are a fictional representation of real coins in your FX account based on past trades. The only way to know if BTCUSD exists as a virtual position is if the brokerage tells us. GDAX does not hold this information.

LEAN saves the coins into the CashBook; separated by each currency. So each time you restart your algorithm your virtual positions start from flat; even if you made a trade in a previous life. Liquidate only works on virtual positions. When you make a trade inside of a running algorithm we maintain the virtual position state for you -- but it won't survive between deployments.

You need to use your CashBook holdings to decide if you want to trade. The BTCUSD is great for indicators; but not useful for Portfolio management.

1

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.


Jared Broad you say to use the CashBook holdings to decide when to trade, but it looks like Iman was doign that. So I'm confused. I understand that QC doesn't know how many BTCUSD pairs I have. So is there anyway for QC to know how many BTC I have in GDAX?

Which of these gives a more accurate account of my holdings?

self.Portfolio["BTCUSD"].Quantity
self.Portfolio.CashBook["BTCUSD"].Amount

And if I have outstanding limit orders, obviously those orders won't be reflected here right?

0

Yes in the cash book - there is no BTCUSD.

self.Portfolio.CashBook["BTC"].Amount
self.Portfolio.CashBook["USD"].Amount
self.Portfolio.CashBook["LTC"].Amount

The coins exist in the cash book.

https://github.com/QuantConnect/Lean/blob/master/Common/Securities/Cash.cs
1

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.


This appears to be working well for C#:

var actualAmountHolding = Portfolio.CashBook["BTC"].Amount;

.....

Sell(Symbol, actualAmountHolding);

//Liquidate(Symbol);           //Don't use Liquidate()

I probably didn't need to make actualAmountHolding a variable, but it's been going short consecutively all night, so I'll let it run for the day.  

1

So am I understanding correctly from this that self.SetHoldings("BTC", 1) and self.Liquidate("BTC") will work? 

And for the EMAs, should it be self.EMA("BTCUSD", 10, Resolution.Hour) or self.EMA("BTC", 10, Resolution.Hour)?

0

Caleb Stought In your code examples, "BTCUSD" is a security symbol and should be used in SetHoldings, Liquidate and EMA method calls. "BTC" is a currency symbol and should be used when accessing the CashBook (e.g. Portfolio.CashBook["BTC"].Amount)

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