Lean  $LEAN_TAG$
ToolboxArgumentParser.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  *
8  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15 */
16 
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20 using McMaster.Extensions.CommandLineUtils;
21 
23 {
24  /// <summary>
25  /// Command Line arguments parser for Toolbox configuration
26  /// </summary>
27  public static class ToolboxArgumentParser
28  {
29  private const string ApplicationName = "QuantConnect.ToolBox.exe";
30  private const string ApplicationDescription = "Lean Engine ToolBox";
31  private const string ApplicationHelpText = "\nThe ToolBox is a wrapper of >15 tools. "
32  + "Each require a different set of parameters. Example: --app=RandomDataGenerator --tickers="
33  + "SPY,AAPL --resolution=Daily --from-date=yyyyMMdd-HH:mm:ss --to-date=yyyyMMdd-HH:mm:ss";
34  private static readonly List<CommandLineOption> Options = new List<CommandLineOption>
35  {
36  new CommandLineOption("app", CommandOptionType.SingleValue,
37  "[REQUIRED] Target tool, CASE INSENSITIVE: GDAXDownloader or GDAXDL"
38  + "/GoogleDownloader or GDL/IBDownloader or IBDL"
39  + "/AlgoSeekFuturesConverter or ASFC"
40  + "/KaikoDataConverter or KDC"
41  + "/CoarseUniverseGenerator or CUG/\n"
42  + "RandomDataGenerator or RDG\n"
43  + "Example 1: --app=RDG"),
44  new CommandLineOption("tickers", CommandOptionType.MultipleValue, "[REQUIRED ALL downloaders] "
45  + "--tickers=SPY,AAPL,etc"),
46  new CommandLineOption("resolution", CommandOptionType.SingleValue, "[REQUIRED ALL downloaders]"
47  + " *Not all downloaders support all resolutions. Send empty for more information.*"
48  + " CASE SENSITIVE: --resolution=Tick/Second/Minute/Hour/Daily/All" +Environment.NewLine+
49  "[OPTIONAL for RandomDataGenerator - same format as downloaders, Options only support Minute"),
50  new CommandLineOption("from-date", CommandOptionType.SingleValue, "[REQUIRED ALL downloaders] --from-date=yyyyMMdd-HH:mm:ss"),
51  new CommandLineOption("to-date", CommandOptionType.SingleValue, "[OPTIONAL for downloaders] If not provided 'DateTime.UtcNow' will "
52  + "be used. --to-date=yyyyMMdd-HH:mm:ss"),
53  new CommandLineOption("exchange", CommandOptionType.SingleValue, "[Optional for KaikoDataConverter] The exchange to process, if not defined, all exchanges will be processed."),
54  new CommandLineOption("date", CommandOptionType.SingleValue, "[REQUIRED for AlgoSeekFuturesConverter, AlgoSeekOptionsConverter, KaikoDataConverter]"
55  + "Date for the option bz files: --date=yyyyMMdd"),
56  new CommandLineOption("source-dir", CommandOptionType.SingleValue, "[REQUIRED for KaikoDataConverter,"),
57  new CommandLineOption("destination-dir", CommandOptionType.SingleValue, "[REQUIRED for RandomDataGenerator]"),
58  new CommandLineOption("start", CommandOptionType.SingleValue, "[REQUIRED for RandomDataGenerator. Format yyyyMMdd Example: --start=20010101]"),
59  new CommandLineOption("end", CommandOptionType.SingleValue, "[REQUIRED for RandomDataGenerator. Format yyyyMMdd Example: --end=20020101]"),
60  new CommandLineOption("market", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Market of generated symbols. Defaults to default market for security type: Example: --market=usa]"),
61  new CommandLineOption("symbol-count", CommandOptionType.SingleValue, "[REQUIRED for RandomDataGenerator. Number of symbols to generate data for: Example: --symbol-count=10]"),
62  new CommandLineOption("security-type", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Security type of generated symbols, defaults to Equity: Example: --security-type=Equity/Option/Forex/Future/Cfd/Crypto]"),
63  new CommandLineOption("data-density", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Defaults to Dense. Valid values: --data-density=Dense/Sparse/VerySparse ]"),
64  new CommandLineOption("include-coarse", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Only used for Equity, defaults to true: Example: --include-coarse=true]"),
65  new CommandLineOption("quote-trade-ratio", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the ratio of generated quotes to generated trades. Values larger than 1 mean more quotes than trades. Only used for Option, Future and Crypto, defaults to 1: Example: --quote-trade-ratio=1.75 ]"),
66  new CommandLineOption("random-seed", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the random number generator seed. Defaults to null (random seed). Example: --random-seed=11399 ]"),
67  new CommandLineOption("ipo-percentage", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the probability each equity generated will have an IPO event. Note that this is not the total probability for all symbols generated. Only used for Equity. Defaults to 5.0: Example: --ipo-percentage=43.25 ]"),
68  new CommandLineOption("rename-percentage", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the probability each equity generated will have a rename event. Note that this is not the total probability for all symbols generated. Only used for Equity. Defaults to 30.0: Example: --rename-percentage=20.0 ]"),
69  new CommandLineOption("splits-percentage", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the probability each equity generated will have a stock split event. Note that this is not the total probability for all symbols generated. Only used for Equity. Defaults to 15.0: Example: --splits-percentage=10.0 ]"),
70  new CommandLineOption("dividends-percentage", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the probability each equity generated will have dividends. Note that this is not the probability for all symbols genearted. Only used for Equity. Defaults to 60.0: Example: --dividends-percentage=25.5 ]"),
71  new CommandLineOption("dividend-every-quarter-percentage", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the probability each equity generated will have a dividend event every quarter. Note that this is not the total probability for all symbols generated. Only used for Equity. Defaults to 30.0: Example: --dividend-every-quarter-percentage=15.0 ]"),
72  new CommandLineOption("option-price-engine", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the stochastic process, and returns new pricing engine to run calculations for that option. Defaults to BaroneAdesiWhaleyApproximationEngine: Example: --option-price-engine=BaroneAdesiWhaleyApproximationEngine ]"),
73  new CommandLineOption("volatility-model-resolution", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the volatility model period span. Defaults to Daily: Example: --volatility-model-resolution=Daily ]"),
74  new CommandLineOption("chain-symbol-count", CommandOptionType.SingleValue, "[OPTIONAL for RandomDataGenerator. Sets the size of the option chain. Defaults to 1 put and 1 call: Example: --chain-symbol-count=2 ]")
75  };
76 
77  /// <summary>
78  /// Argument parser contructor
79  /// </summary>
80  public static Dictionary<string, object> ParseArguments(string[] args)
81  {
82  return ApplicationParser.Parse(ApplicationName, ApplicationDescription, ApplicationHelpText, args, Options);
83  }
84 
85  /// <summary>
86  /// Helper method to get the tickers from the provided options
87  /// </summary>
88  public static List<string> GetTickers(Dictionary<string, object> optionsObject)
89  {
90  return optionsObject.ContainsKey("tickers")
91  ? (optionsObject["tickers"] as Dictionary<string, string>)?.Keys.ToList()
92  : new List<string>();
93  }
94  }
95 }