Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio -0.375 Tracking Error 0.297 Treynor Ratio 0 Total Fees $0.00 |
/* * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using QuantConnect.Interfaces; using QuantConnect.Indicators; using System.Collections.Generic; using QuantConnect.Data.Consolidators; using QuantConnect.Data.Market; using QuantConnect.Securities.Future; namespace QuantConnect.Algorithm.CSharp { /// <summary> /// Demonstration of how to rollover futures /// </summary> /// <meta name="tag" content="renko" /> /// <meta name="tag" content="indicators" /> /// <meta name="tag" content="using data" /> /// <meta name="tag" content="consolidating data" /> public class RolloverAlgorithm : QCAlgorithm { private FuturesContract frontmonthContract; private Future myFuture; private RollingWindow<string> mySymbolValue; /// <summary> /// Initializes the algorithm state. /// </summary> public override void Initialize() { SetStartDate(2019, 7, 7); SetEndDate(2020, 7, 8); //SetEndDate(DateTime.Now.Date.AddDays(-1)); // Or use a relative date. SetCash(1000000); // Subscribe to futures chain myFuture = AddFuture(Futures.Indices.SP500EMini, Resolution.Minute, Market.CME, false, 0m); // Filter for front month contracts, ignore non-front month contracts myFuture.SetFilter(universe => universe.FrontMonth()); mySymbolValue = new RollingWindow<string>(2); mySymbolValue.Add("foobar"); mySymbolValue.Add("foobar"); } /// <summary> /// We're doing our analysis in the OnRenkoBar method, but the framework verifies that this method exists, so we define it. /// </summary> public void OnData(TradeBars data) { } public void OnData(Slice data) { foreach(var chain in data.FutureChains) { // Get trade bars for contracts in chain var tradebars = chain.Value.TradeBars; // Get front month contract var contract = chain.Value.FirstOrDefault(); // Check if front month contract has been delisted/updated if (frontmonthContract == null || (contract.Symbol != frontmonthContract.Symbol)) { // Otherwise we have the front month contract frontmonthContract = contract; } // Get symbol for front month contract var symbol = frontmonthContract.Symbol; Debug(frontmonthContract.Expiry.ToString()); // Check if tradebar contains our symbol if (tradebars.Keys.Contains(symbol)) { var myTradeBar = tradebars[symbol]; mySymbolValue.Add(symbol.Value); if (!mySymbolValue.IsReady) return; if (mySymbolValue[0] != mySymbolValue[1]) { Debug($"{myTradeBar.Time.ToIso8601Invariant()} {symbol} {symbol.Value}"); } } } } } }