Hi all, trying to run my first strategy (based on Futures) on Desktop LEAN through IB but it does not generate any signal. (You can read below the visual output)I must have missed something in the configuration of VS or IB automater/Gateway but I cannot find the culprit. Any support is appreciated.
Thank you
LOG from IB Gatewayhttps://drive.google.com/file/d/1AQZuS5dKOxfiyVzzI2G5S7zYtwa-dCW7/view?usp=sharing
Douglas Stridsberg
To narrow down whether it is indeed a problem with the connection to IB, do you mind trying to run it on a QuantConnect Paper account?
Rob Pec
QC paper trading does not support futures if I am not mistaken.
I have tried to run a different strategy on desktop lean by setting live paper environment but it returns an error.
Please find the log pasted below
20190716 14:52:03.022 Trace:: LiveTradingDataFeed.CreateUniverseSubscription(): Creating coarse universe: QC-UNIVERSE-COARSE-USA-7022B00C-13D4-4CF9-B4DE-DC75066BBAB5 2T
20190716 14:52:03.121 ERROR:: FitnessScore.Initialize(): fitness score will not be calculated because the algorithms starting portfolio value is 0.
20190716 14:52:03.202 ERROR:: LiveTradingResultHandler.Update(): Algorithm not yet initialized.
20190716 14:52:03.349 ERROR:: Engine.Run(): During the algorithm initialization, the following exception has occurred: System.NotImplementedException: QuantConnect.Queues.LiveDataQueue has not implemented live data.
at QuantConnect.Lean.Engine.DataFeeds.Queues.LiveDataQueue.Subscribe(LiveNodePacket job, IEnumerable`1 symbols) in D:\Downloads\Lean-master\Engine\DataFeeds\Queues\DataQueue.cs:line 43
at QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed.CreateUniverseSubscription(SubscriptionRequest request) in D:\Downloads\Lean-master\Engine\DataFeeds\LiveTradingDataFeed.cs:line 459
at QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed.CreateSubscription(SubscriptionRequest request) in D:\Downloads\Lean-master\Engine\DataFeeds\LiveTradingDataFeed.cs:line 119
at QuantConnect.Lean.Engine.DataFeeds.DataManager.AddSubscription(SubscriptionRequest request) in D:\Downloads\Lean-master\Engine\DataFeeds\DataManager.cs:line 173
at QuantConnect.Lean.Engine.DataFeeds.DataManager.<>c__DisplayClass12_0.<.ctor>b__0(Object sender, NotifyCollectionChangedEventArgs args) in D:\Downloads\Lean-master\Engine\DataFeeds\DataManager.cs:line 104
at QuantConnect.Securities.UniverseManager.OnCollectionChanged(NotifyCollectionChangedEventArgs e) in D:\Downloads\Lean-master\Common\Securities\UniverseManager.cs:line 263
at QuantConnect.Securities.UniverseManager.Add(Symbol key, Universe universe) in D:\Downloads\Lean-master\Common\Securities\UniverseManager.cs:line 171
at QuantConnect.Algorithm.QCAlgorithm.AddUniverse(Universe universe) in D:\Downloads\Lean-master\Algorithm\QCAlgorithm.Universe.cs:line 184
at QuantConnect.Algorithm.QCAlgorithm.FrameworkPostInitialize() in D:\Downloads\Lean-master\Algorithm\QCAlgorithm.Framework.cs:line 82
at QuantConnect.Algorithm.QCAlgorithm.PostInitialize() in D:\Downloads\Lean-master\Algorithm\QCAlgorithm.cs:line 542
at QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler.Setup(SetupHandlerParameters parameters) in D:\Downloads\Lean-master\Engine\Setup\BrokerageSetupHandler.cs:line 357QuantConnect.Queues.LiveDataQueue has not implemented live data.
20190716 14:52:03.360 Trace:: JOB HANDLERS:
20190716 14:52:03.363 Trace:: DataFeed: QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed
20190716 14:52:03.363 Trace:: Setup: QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler
20190716 14:52:03.364 Trace:: RealTime: QuantConnect.Lean.Engine.RealTime.LiveTradingRealTimeHandler
20190716 14:52:03.365 Trace:: Results: QuantConnect.Lean.Engine.Results.LiveTradingResultHandler
20190716 14:52:03.366 Trace:: Transactions: QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler
20190716 14:52:03.367 Trace:: Alpha: QuantConnect.Lean.Engine.Alphas.DefaultAlphaHandler
20190716 14:52:03.368 Trace:: History Provider: QuantConnect.Lean.Engine.HistoricalData.SubscriptionDataReaderHistoryProvider
20190716 14:52:03.369 Trace:: Brokerage: QuantConnect.Brokerages.Paper.PaperBrokerage
20190716 14:52:03.401 Trace:: Waiting for threads to exit...
20190716 14:52:03.407 ERROR:: During the algorithm initialization, the following exception has occurred: System.NotImplementedException: QuantConnect.Queues.LiveDataQueue has not implemented live data.
at QuantConnect.Lean.Engine.DataFeeds.Queues.LiveDataQueue.Subscribe(LiveNodePacket job, IEnumerable`1 symbols) in D:\Downloads\Lean-master\Engine\DataFeeds\Queues\DataQueue.cs:line 43
at QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed.CreateUniverseSubscription(SubscriptionRequest request) in D:\Downloads\Lean-master\Engine\DataFeeds\LiveTradingDataFeed.cs:line 459
at QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed.CreateSubscription(SubscriptionRequest request) in D:\Downloads\Lean-master\Engine\DataFeeds\LiveTradingDataFeed.cs:line 119
at QuantConnect.Lean.Engine.DataFeeds.DataManager.AddSubscription(SubscriptionRequest request) in D:\Downloads\Lean-master\Engine\DataFeeds\DataManager.cs:line 173
at QuantConnect.Lean.Engine.DataFeeds.DataManager.<>c__DisplayClass12_0.<.ctor>b__0(Object sender, NotifyCollectionChangedEventArgs args) in D:\Downloads\Lean-master\Engine\DataFeeds\DataManager.cs:line 104
at QuantConnect.Securities.UniverseManager.OnCollectionChanged(NotifyCollectionChangedEventArgs e) in D:\Downloads\Lean-master\Common\Securities\UniverseManager.cs:line 263
at QuantConnect.Securities.UniverseManager.Add(Symbol key, Universe universe) in D:\Downloads\Lean-master\Common\Securities\UniverseManager.cs:line 171
at QuantConnect.Algorithm.QCAlgorithm.AddUniverse(Universe universe) in D:\Downloads\Lean-master\Algorithm\QCAlgorithm.Universe.cs:line 184
at QuantConnect.Algorithm.QCAlgorithm.FrameworkPostInitialize() in D:\Downloads\Lean-master\Algorithm\QCAlgorithm.Framework.cs:line 82
at QuantConnect.Algorithm.QCAlgorithm.PostInitialize() in D:\Downloads\Lean-master\Algorithm\QCAlgorithm.cs:line 542
at QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler.Setup(SetupHandlerParameters parameters) in D:\Downloads\Lean-master\Engine\Setup\BrokerageSetupHandler.cs:line 357QuantConnect.Queues.LiveDataQueue has not implemented live data.
20190716 14:52:03.418 ERROR:: LiveTradingResultHandler.Update(): Algorithm not yet initialized.
20190716 14:52:03.520 Trace:: LiveTradingResultHandler.Run(): Ending Thread...
20190716 14:52:03.621 Trace:: Waiting for threads to exit...
20190716 14:52:36.441 Trace:: Engine.Run(): Disconnecting from brokerage...
20190716 14:52:36.441 Trace:: Engine.Run(): Disposing of setup handler...
20190716 14:52:36.445 Trace:: Engine.Main(): Analysis Completed and Results Posted.
20190716 14:52:36.446 Trace:: LiveTradingDataFeed.Exit(): Start. Setting cancellation token...
20190716 14:52:36.446 Trace:: BaseDataExchange(DataQueueExchange).ConsumeQueue(): Cancellation requested. Exiting...
20190716 14:52:36.446 Trace:: BaseDataExchange(DataQueueExchange) Stopping...
20190716 14:52:36.448 Trace:: BaseDataExchange(CustomDataExchange) Stopping...
20190716 14:52:36.448 Trace:: LiveTradingDataFeed.Exit(): Exit Finished.
Engine.Main(): Analysis Complete. Press any key to continue.
20190716 14:52:36.452 Trace:: BaseDataExchange(CustomDataExchange).ConsumeQueue(): Cancellation requested. Exiting...
Daniel Chen
Hi Rob,
Thank you for using live trading in QC! You're right on the information that QC paper trading does not support futures (more details can be found here ). However, it is possible to trade futures with IB account on Desktop LEAN. The setup that you have shown us in the original post with live-interactive is the way to accomplish it.
Regarding your original question, it is possibly caused by IB's futures data bundle is not acquired, which is also necessary to trade in QC.com too. Otherwise, no data will be received. You can perform a simple sanity check by adding SPY to the algorithm (AddEquity("SPY")) and write the current price in the OnData method. If the issue still exists, we recommend you go for Private Support by sharing your algorithm. You can find Private Support on the 5th tab here.
Thank you for using live trading in QC. Good luck with your futures algorithm!
Rob Pec
Hi Daniel,
thanks for your reply.
Unfortunately this strategy keeps not working properly on DesktopLean.
It runs smoothly on QC backtesting environment.
Other example alphas seem to be run smothly on my Desktop Lean environment hence I presume it is a coding issue..
Attached the code. below.
Any help is welcome.
/
using System; using System.Collections.Generic; using System.Linq; using QuantConnect.Brokerages; using QuantConnect.Data; using QuantConnect.Interfaces; using QuantConnect.Indicators; using QuantConnect.Data.Custom; using QuantConnect.Securities; using QuantConnect.Securities.Future; namespace QuantConnect.Algorithm.CSharp { public class VIXFuturesSwitch : QCAlgorithm, IRegressionAlgorithmDefinition { private Future _es; private Identity _esIdentity; private IndicatorDataPoint _latestEs; private IndicatorDataPoint _latestVx; private Identity _vix; private Future _vx; private Identity _vxIdentity; private bool _entryLong; private DateTime _entryDate; /// <summary> /// Initialize your algorithm and add desired assets. /// </summary> public override void Initialize() { SetStartDate( 2019,7,15); SetCash(startingCash: 100000); SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin); //add desired Futures. _es = AddFuture(Futures.Indices.SP500EMini); _vx = AddFuture(Futures.Indices.VIX); // set our expiry filter for this futures chain _es.SetFilter(f => f.FrontMonth()); _vx.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(value: 182)); AddData<QuandlVIX>("CBOE/VIX", Resolution.Daily); _vix = new Identity("VIX"); _vxIdentity = new Identity("VX"); _esIdentity = new Identity("ES"); PlotIndicator("VIX", _vix); PlotIndicator("VIX", _vxIdentity); PlotIndicator("ES", _esIdentity); } public override void OnData(Slice slice) { if (slice.FutureChains.ContainsKey(_vx.Symbol)) { var vixContract = slice.FutureChains[_vx.Symbol].OrderBy(x => x.Expiry).FirstOrDefault(); if (vixContract != null) { _latestVx = new IndicatorDataPoint(Time, vixContract.LastPrice); } } if (slice.FutureChains.ContainsKey(_es.Symbol)) { var esContract = slice.FutureChains[_es.Symbol].OrderBy(x => x.Expiry).LastOrDefault(); if (esContract != null) { _latestEs = new IndicatorDataPoint(Time, esContract.LastPrice); if (!Portfolio.Invested && _entryLong) { MarketOrder(esContract.Symbol, 1); _entryDate = Time; } if (Portfolio.Invested && Time > _entryDate.AddDays(15)) { Liquidate(); } } } } public void OnData(Quandl data) { // Updates the identity indicators. if (data.Symbol.Value.EndsWith("VIX")) _vix.Update(Time, data.Value); } public override void OnEndOfDay() { _vxIdentity.Update(_latestVx); _esIdentity.Update(_latestEs); _entryLong = _vix < _vxIdentity; } /// <summary> /// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm. /// </summary> public bool CanRunLocally { get; } = true; /// <summary> /// This is used by the regression test system to indicate which languages this algorithm is written in. /// </summary> public Language[] Languages { get; } = { Language.CSharp, Language.Python }; /// <summary> /// This is used by the regression test system to indicate what the expected statistics are from running the algorithm /// </summary> public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string> { {"Total Trades", "8220"}, {"Average Win", "0.00%"}, {"Average Loss", "0.00%"}, {"Compounding Annual Return", "-100.000%"}, {"Drawdown", "13.500%"}, {"Expectancy", "-0.818"}, {"Net Profit", "-13.517%"}, {"Sharpe Ratio", "-29.354"}, {"Loss Rate", "89%"}, {"Win Rate", "11%"}, {"Profit-Loss Ratio", "0.69"}, {"Alpha", "-7.746"}, {"Beta", "-0.859"}, {"Annual Standard Deviation", "0.305"}, {"Annual Variance", "0.093"}, {"Information Ratio", "-24.985"}, {"Tracking Error", "0.414"}, {"Treynor Ratio", "10.413"}, {"Total Fees", "$15207.00"}, {"Fitness Score", "0.033"} }; } public class QuandlVIX : Quandl { public QuandlVIX() : base(valueColumnName:"VIX Close") { } } }
Daniel Chen
Hi Rob,
Thank you for the follow-up. We are glad to say that your code doesn't have any problem since it runs smoothly on the QC cloud. However, because of data provider restrictions, we don't provide most of the data in the local environment. We only provide a sample data of a week in 2013, so if the backtest period is from 2019-07-15 to now, there will be errors due to missing data.
Therefore, we recommend you develop your algorithm locally and backtest it on the QC cloud to enjoy all the data we provide. If there is any confusion, please feel free to let me know!
Rob Pec
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!