Lean  $LEAN_TAG$
RandomDataGeneratorProgram.cs
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 
23 using QuantConnect.Util;
24 using System;
25 using System.Collections.Generic;
26 using QuantConnect.Logging;
27 using QuantConnect.Data;
28 
30 {
31  /// <summary>
32  /// Creates and starts <see cref="RandomDataGenerator"/> instance
33  /// </summary>
34  public static class RandomDataGeneratorProgram
35  {
36  private static readonly IRiskFreeInterestRateModel _interestRateProvider = new InterestRateProvider();
37 
38  public static void RandomDataGenerator(
39  string startDateString,
40  string endDateString,
41  string symbolCountString,
42  string market,
43  string securityTypeString,
44  string resolutionString,
45  string dataDensityString,
46  string includeCoarseString,
47  string quoteTradeRatioString,
48  string randomSeed,
49  string hasIpoPercentageString,
50  string hasRenamePercentageString,
51  string hasSplitsPercentageString,
52  string hasDividendsPercentageString,
53  string dividendEveryQuarterPercentageString,
54  string optionPriceEngineName,
55  string volatilityModelResolutionString,
56  string chainSymbolCountString,
57  List<string> tickers
58  )
59  {
60  var settings = RandomDataGeneratorSettings.FromCommandLineArguments(
61  startDateString,
62  endDateString,
63  symbolCountString,
64  market,
65  securityTypeString,
66  resolutionString,
67  dataDensityString,
68  includeCoarseString,
69  quoteTradeRatioString,
70  randomSeed,
71  hasIpoPercentageString,
72  hasRenamePercentageString,
73  hasSplitsPercentageString,
74  hasDividendsPercentageString,
75  dividendEveryQuarterPercentageString,
76  optionPriceEngineName,
77  volatilityModelResolutionString,
78  chainSymbolCountString,
79  tickers
80  );
81 
82  if (settings.Start.Year < 1998)
83  {
84  Log.Error($"RandomDataGeneratorProgram(): Required parameter --start must be at least 19980101");
85  Environment.Exit(1);
86  }
87 
88  var securityManager = new SecurityManager(new TimeKeeper(settings.Start, new[] { TimeZones.Utc }));
89  var securityService = new SecurityService(
90  new CashBook(),
94  {
95  // init price
96  security.SetMarketPrice(new Tick(settings.Start, security.Symbol, 100, 100));
97  security.SetMarketPrice(new OpenInterest(settings.Start, security.Symbol, 10000));
98 
99  // from settings
100  security.VolatilityModel = new StandardDeviationOfReturnsVolatilityModel(settings.VolatilityModelResolution);
101 
102  // from settings
103  if (security is Option option)
104  {
105  option.PriceModel = OptionPriceModels.Create(settings.OptionPriceEngineName,
106  _interestRateProvider.GetRiskFreeRate(settings.Start, settings.End));
107  }
108  })),
111  new SecurityPortfolioManager(securityManager, new SecurityTransactionManager(null, securityManager), new AlgorithmSettings())),
112  new MapFilePrimaryExchangeProvider(Composer.Instance.GetExportedValueByTypeName<IMapFileProvider>(Config.Get("map-file-provider", "LocalDiskMapFileProvider")))
113  );
114  securityManager.SetSecurityService(securityService);
115 
116  var generator = new RandomDataGenerator();
117  generator.Init(settings, securityManager);
118  generator.Run();
119 
120  if (settings.IncludeCoarse && settings.SecurityType == SecurityType.Equity)
121  {
122  Log.Trace("RandomDataGeneratorProgram(): Launching coarse data generator...");
123 
125  }
126 
127  if (!Console.IsInputRedirected)
128  {
129  Log.Trace("RandomDataGeneratorProgram(): Press any key to exit...");
130  Console.ReadKey();
131  }
132  }
133  }
134 }