Hi,
I have been trying to do fractional-share trading with custom data but haven't been able to do so using all methods mentioned in previous threads (listed below). I have tried using SetHoldings(), MarketOrder(), MarketOrder(quantity=float(X)), setting custom data secruity type to SecurityType.Crypto to no avail. I was able to achieve fractional trading in crypto assets on live trading (Coinbase Pro) but not when backtesting with custom data.
Note: All experiments done in LEAN locally.
Any help or clarification would be greatly appreciated.
Reader() implementation of Custom data
def Reader(self, config, line, date, isLiveMode):
coin = BinanceTradeBarData()
coin.Symbol = config.Symbol
data = line.split(",")
coin.Time = pd.to_datetime(data[0],unit='ms')
coin.EndTime = coin.Time + timedelta(minutes=1)
coin.Value = data[4]
coin.Open = float(data[1])
coin.High = float(data[2])
coin.Low = float(data[3])
coin.Close = float(data[4])
coin.Volume = float(data[5])
coin.SecurityType = SecurityType.Crypto
Previous Threads about Fractional Trading
Louis Szeto
Hi Nottakumasato
You'll have to set the SymbolProperties for the Security object when calling AddData.
Please refer to the GH source file for details.
BestLouis
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.
Nottakumasato
Louis Szeto I tried replicating the above code snippet but got an error:
error log:
Nottakumasato
From the source code (in Python) it seems that only MinimumPriceVariation and ContractMultiplier has setter methods:
Louis Szeto
Hi Nottakumasato
Please set it by this AddData overload:
Best
Louis
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.
Nottakumasato
@louis-szeto_1 thank you for the reply again.
Above code snippet managed to fix the above problem however I am still having problems:
When I use the SymbolProperties and SecurityExchangeHours when adding data with AddData, the order sizes are still integers with both SetHoldings and MarketOrder
would lead to orders like:
My first thought was changing `quoteCurrency to “USDT”` and it resulted in these errors:
Louis Szeto
Hi Nottakumasato
You'll also need to change this
Best
Louis
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.
Nottakumasato
Louis Szeto thanks that worked! I am still a bit confused about the relation between lotSize and minimumOrderSize. The python docs just state:
Is it a “best practice” to set them the same?
Nottakumasato
or I guess a better question is, when would I not set them to the same value?
Louis Szeto
Hi Nottakumasato
Usually, they'd be the same but on some occasions, e.g. when you want a minimum order size but allow partially filled for those orders, the minimumOrderSize > lotSize.
Best
Louis
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.
Nottakumasato
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!