18 using System.Collections.Generic;
19 using System.Globalization;
21 using System.Threading;
29 private static int MarketCode = 100;
32 public DateTime Start {
get; init; }
33 public DateTime End {
get; init; }
37 public string Market {
get; init; }
38 public bool IncludeCoarse {
get; init; } =
true;
39 public int SymbolCount {
get;
set; }
40 public double QuoteTradeRatio {
get; init; } = 1;
41 public int RandomSeed {
get; init; }
42 public bool RandomSeedSet {
get; init; }
43 public double HasIpoPercentage {
get; init; }
44 public double HasRenamePercentage {
get; init; }
45 public double HasSplitsPercentage {
get; init; }
46 public double MonthSplitPercentage {
get; init; }
47 public double HasDividendsPercentage {
get; init; }
48 public double DividendEveryQuarterPercentage {
get; init; }
49 public string OptionPriceEngineName {
get; init; }
50 public int ChainSymbolCount {
get; init; } = 1;
52 public List<string> Tickers {
get; init; }
54 string startDateString,
56 string symbolCountString,
58 string securityTypeString,
59 string resolutionString,
60 string dataDensityString,
61 string includeCoarseString,
62 string quoteTradeRatioString,
63 string randomSeedString,
64 string hasIpoPercentageString,
65 string hasRenamePercentageString,
66 string hasSplitsPercentageString,
67 string hasDividendsPercentageString,
68 string dividendEveryQuarterPercentageString,
69 string optionPriceEngineName,
70 string volatilityModelResolutionString,
71 string chainSymbolCountString,
73 double monthSplitPercentage = 5.0
76 var randomSeedSet =
true;
83 double quoteTradeRatio;
86 DateTime startDate, endDate;
87 double hasIpoPercentage;
88 double hasRenamePercentage;
89 double hasSplitsPercentage;
90 double hasDividendsPercentage;
91 double dividendEveryQuarterPercentage;
96 if (!DateTime.TryParseExact(startDateString, DateFormats,
null, DateTimeStyles.None, out startDate))
99 Log.
Error($
"RandomDataGeneratorSettings(): Required parameter --from-date was incorrectly formatted. Please specify in yyyyMMdd format. Value provided: '{startDateString}'");
103 if (!DateTime.TryParseExact(endDateString, DateFormats,
null, DateTimeStyles.None, out endDate))
106 Log.
Error($
"RandomDataGeneratorSettings(): Required parameter --to-date was incorrectly formatted. Please specify in yyyyMMdd format. Value provided: '{endDateString}'");
110 if (!tickers.IsNullOrEmpty())
112 symbolCount = tickers.Count;
113 Log.
Trace(
"RandomDataGeneratorSettings(): Ignoring symbol count will use provided tickers");
116 else if (!
int.TryParse(symbolCountString, out symbolCount) || symbolCount <= 0)
119 Log.
Error($
"RandomDataGeneratorSettings(): Required parameter --symbol-count was incorrectly formatted. Please specify a valid integer greater than zero. Value provided: '{symbolCountString}'");
123 if (!
int.TryParse(chainSymbolCountString, out chainSymbolCount) || chainSymbolCount <= 0)
125 chainSymbolCount = 10;
126 Log.
Trace($
"RandomDataGeneratorSettings(): Using default value of '{chainSymbolCount}' for --chain-symbol-count");
130 if (
string.IsNullOrEmpty(resolutionString))
133 Log.
Trace($
"RandomDataGeneratorSettings(): Using default value of '{resolution}' for --resolution");
135 else if (!Enum.TryParse(resolutionString,
true, out resolution))
137 var validValues =
string.Join(
", ", Enum.GetValues(typeof(
Resolution)).Cast<Resolution>());
139 Log.
Error($
"RandomDataGeneratorSettings(): Optional parameter --resolution was incorrectly formatted. Default is Minute. Please specify a valid Resolution. Value provided: '{resolutionString}' Valid values: {validValues}");
143 if (
string.IsNullOrEmpty(volatilityModelResolutionString))
146 Log.
Trace($
"RandomDataGeneratorSettings():Using default value of '{resolution}' for --resolution");
148 else if (!Enum.TryParse(volatilityModelResolutionString,
true, out volatilityModelResolution))
150 var validValues =
string.Join(
", ", Enum.GetValues(typeof(
Resolution)).Cast<Resolution>());
152 Log.
Error($
"RandomDataGeneratorSettings(): Optional parameter --volatility-model-resolution was incorrectly formatted. Default is Daily. Please specify a valid Resolution. Value provided: '{volatilityModelResolutionString}' Valid values: {validValues}");
156 if (
string.IsNullOrEmpty(securityTypeString))
159 Log.
Trace($
"RandomDataGeneratorSettings(): Using default value of '{securityType}' for --security-type");
161 else if (!Enum.TryParse(securityTypeString,
true, out securityType))
163 var validValues =
string.Join(
", ", Enum.GetValues(typeof(
SecurityType)).Cast<SecurityType>());
165 Log.
Error($
"RandomDataGeneratorSettings(): Optional parameter --security-type is invalid. Default is Equity. Please specify a valid SecurityType. Value provided: '{securityTypeString}' Valid values: {validValues}");
171 Log.
Error($
"RandomDataGeneratorSettings(): When using --security-type=Option you must specify --resolution=Minute");
175 if (
string.IsNullOrEmpty(market))
178 Log.
Trace($
"RandomDataGeneratorSettings(): Using default value of '{market}' for --market and --security-type={securityType}");
184 Log.
Trace($
"RandomDataGeneratorSettings(): Please verify that the specified market value is correct: '{market}' This value is not known has been added to the market value map. If this is an error, stop the application immediately using Ctrl+C");
188 if (
string.IsNullOrEmpty(includeCoarseString))
193 Log.
Trace($
"RandomDataGeneratorSettings(): Using default value of '{includeCoarse}' for --security-type={securityType}");
196 else if (!
bool.TryParse(includeCoarseString, out includeCoarse))
199 Log.
Error($
"RandomDataGeneratorSettings(): Optional parameter --include-coarse was incorrectly formatted. Please specify a valid boolean. Value provided: '{includeCoarseString}'. Valid values: 'true' or 'false'");
201 else if (includeCoarse && securityType !=
SecurityType.Equity)
203 Log.
Trace(
"RandomDataGeneratorSettings(): Optional parameter --include-coarse will be ignored because it only applies to --security-type=Equity");
207 if (
string.IsNullOrEmpty(dataDensityString))
210 Log.
Trace($
"RandomDataGeneratorSettings(): Using default value of '{dataDensity}' for --data-density");
212 else if (!Enum.TryParse(dataDensityString,
true, out dataDensity))
216 Log.
Error($
"RandomDataGeneratorSettings(): Optional parameter --data-density was incorrectly formatted. Please specify a valid DataDensity. Value provided: '{dataDensityString}'. Valid values: {validValues}");
220 if (
string.IsNullOrEmpty(quoteTradeRatioString))
224 else if (!
double.TryParse(quoteTradeRatioString, out quoteTradeRatio))
227 Log.
Error($
"RandomDataGeneratorSettings(): Optional parameter --quote-trade-ratio was incorrectly formatted. Please specify a valid double greater than or equal to zero. Value provided: '{quoteTradeRatioString}'");
231 if (
string.IsNullOrEmpty(randomSeedString))
234 randomSeedSet =
false;
236 else if (!
int.TryParse(randomSeedString, out randomSeed))
239 Log.
Error($
"RandomDataGeneratorSettings(): Optional parameter --random-seed was incorrectly formatted. Please specify a valid integer");
243 if (
string.IsNullOrEmpty(hasIpoPercentageString))
245 hasIpoPercentage = 5.0;
247 else if (!
double.TryParse(hasIpoPercentageString, out hasIpoPercentage))
250 Log.
Error($
"RandomDataGeneratorSettings(): Optional parameter --ipo-percentage was incorrectly formatted. Please specify a valid double greater than or equal to zero. Value provided: '{hasIpoPercentageString}'");
254 if (
string.IsNullOrEmpty(hasRenamePercentageString))
256 hasRenamePercentage = 30.0;
258 else if (!
double.TryParse(hasRenamePercentageString, out hasRenamePercentage))
261 Log.
Error($
"RandomDataGeneratorSettings(): Optional parameter --rename-percentage was incorrectly formatted. Please specify a valid double greater than or equal to zero. Value provided: '{hasRenamePercentageString}'");
265 if (
string.IsNullOrEmpty(hasSplitsPercentageString))
267 hasSplitsPercentage = 15.0;
269 else if (!
double.TryParse(hasSplitsPercentageString, out hasSplitsPercentage))
272 Log.
Error($
"RandomDataGeneratorSettings(): Optional parameter --splits-percentage was incorrectly formatted. Please specify a valid double greater than or equal to zero. Value provided: '{hasSplitsPercentageString}'");
276 if (
string.IsNullOrEmpty(hasDividendsPercentageString))
278 hasDividendsPercentage = 60.0;
280 else if (!
double.TryParse(hasDividendsPercentageString, out hasDividendsPercentage))
283 Log.
Error($
"RandomDataGeneratorSettings(): Optional parameter --dividends-percentage was incorrectly formatted. Please specify a valid double greater than or equal to zero. Value provided: '{hasDividendsPercentageString}'");
287 if (
string.IsNullOrEmpty(dividendEveryQuarterPercentageString))
289 dividendEveryQuarterPercentage = 30.0;
291 else if (!
double.TryParse(dividendEveryQuarterPercentageString, out dividendEveryQuarterPercentage))
294 Log.
Error($
"RandomDataGeneratorSettings(): Optional parameter --dividend-ever-quarter-percentage was incorrectly formatted. Please specify a valid double greater than or equal to zero. Value provided: '{dividendEveryQuarterPercentageString}'");
299 Log.
Error(
"RandomDataGeneratorSettings(): Please address the errors and run the application again.");
300 Environment.Exit(-1);
309 SymbolCount = symbolCount,
311 QuoteTradeRatio = quoteTradeRatio,
312 ChainSymbolCount = chainSymbolCount,
317 IncludeCoarse = includeCoarse,
318 RandomSeed = randomSeed,
319 RandomSeedSet = randomSeedSet,
321 HasIpoPercentage = hasIpoPercentage,
322 HasRenamePercentage = hasRenamePercentage,
323 HasSplitsPercentage = hasSplitsPercentage,
324 MonthSplitPercentage = monthSplitPercentage,
325 HasDividendsPercentage = hasDividendsPercentage,
326 DividendEveryQuarterPercentage = dividendEveryQuarterPercentage,
327 OptionPriceEngineName = optionPriceEngineName,
328 VolatilityModelResolution = volatilityModelResolution,