|
| 1 | +/* |
| 2 | + * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. |
| 3 | + * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | +*/ |
| 15 | + |
| 16 | +using System; |
| 17 | +using QuantConnect.Interfaces; |
| 18 | +using System.Collections.Generic; |
| 19 | + |
| 20 | +namespace QuantConnect.Algorithm.CSharp |
| 21 | +{ |
| 22 | + /// <summary> |
| 23 | + /// Regression algorithm asserting the behavior of the time and date rules |
| 24 | + /// </summary> |
| 25 | + public class TimeAndDateRulesRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition |
| 26 | + { |
| 27 | + private readonly List<DateTime> _scheduleEquityEvents = new(); |
| 28 | + private readonly List<DateTime> _scheduleCryptoEvents = new(); |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. |
| 32 | + /// </summary> |
| 33 | + public override void Initialize() |
| 34 | + { |
| 35 | + SetStartDate(2013, 10, 07); |
| 36 | + SetEndDate(2013, 10, 14); |
| 37 | + |
| 38 | + Schedule.On(Schedule.DateRules.EveryDay("SPY"), Schedule.TimeRules.AfterMarketOpen("SPY", 10), () => |
| 39 | + { |
| 40 | + _scheduleEquityEvents.Add(Time); |
| 41 | + }); |
| 42 | + Schedule.On(Schedule.DateRules.EveryDay("BTCUSD"), Schedule.TimeRules.Noon, () => |
| 43 | + { |
| 44 | + _scheduleCryptoEvents.Add(Time); |
| 45 | + }); |
| 46 | + } |
| 47 | + |
| 48 | + public override void OnEndOfAlgorithm() |
| 49 | + { |
| 50 | + if (_scheduleEquityEvents.Count != 6) |
| 51 | + { |
| 52 | + throw new RegressionTestException("No events were scheduled for equity!"); |
| 53 | + } |
| 54 | + if (_scheduleCryptoEvents.Count != 8) |
| 55 | + { |
| 56 | + throw new RegressionTestException("No events were scheduled for crypto!"); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm. |
| 62 | + /// </summary> |
| 63 | + public bool CanRunLocally { get; } = true; |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// This is used by the regression test system to indicate which languages this algorithm is written in. |
| 67 | + /// </summary> |
| 68 | + public List<Language> Languages { get; } = new() { Language.CSharp }; |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Data Points count of all timeslices of algorithm |
| 72 | + /// </summary> |
| 73 | + public long DataPoints => 49; |
| 74 | + |
| 75 | + /// <summary> |
| 76 | + /// Data Points count of the algorithm history |
| 77 | + /// </summary> |
| 78 | + public int AlgorithmHistoryDataPoints => 0; |
| 79 | + |
| 80 | + /// <summary> |
| 81 | + /// Final status of the algorithm |
| 82 | + /// </summary> |
| 83 | + public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed; |
| 84 | + |
| 85 | + /// <summary> |
| 86 | + /// This is used by the regression test system to indicate what the expected statistics are from running the algorithm |
| 87 | + /// </summary> |
| 88 | + public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string> |
| 89 | + { |
| 90 | + {"Total Orders", "0"}, |
| 91 | + {"Average Win", "0%"}, |
| 92 | + {"Average Loss", "0%"}, |
| 93 | + {"Compounding Annual Return", "0%"}, |
| 94 | + {"Drawdown", "0%"}, |
| 95 | + {"Expectancy", "0"}, |
| 96 | + {"Start Equity", "100000"}, |
| 97 | + {"End Equity", "100000"}, |
| 98 | + {"Net Profit", "0%"}, |
| 99 | + {"Sharpe Ratio", "0"}, |
| 100 | + {"Sortino Ratio", "0"}, |
| 101 | + {"Probabilistic Sharpe Ratio", "0%"}, |
| 102 | + {"Loss Rate", "0%"}, |
| 103 | + {"Win Rate", "0%"}, |
| 104 | + {"Profit-Loss Ratio", "0"}, |
| 105 | + {"Alpha", "0"}, |
| 106 | + {"Beta", "0"}, |
| 107 | + {"Annual Standard Deviation", "0"}, |
| 108 | + {"Annual Variance", "0"}, |
| 109 | + {"Information Ratio", "-7.357"}, |
| 110 | + {"Tracking Error", "0.161"}, |
| 111 | + {"Treynor Ratio", "0"}, |
| 112 | + {"Total Fees", "$0.00"}, |
| 113 | + {"Estimated Strategy Capacity", "$0"}, |
| 114 | + {"Lowest Capacity Asset", ""}, |
| 115 | + {"Portfolio Turnover", "0%"}, |
| 116 | + {"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"} |
| 117 | + }; |
| 118 | + } |
| 119 | +} |
0 commit comments