Files
quantconnect--lean/ToolBox/Program.cs
T
Adalyat Nazirov 0c26d42561
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Feature 2839 black scholes data generator (#6135)
* replace to local functions as they are more performant

* fix random generator upper bound

Next() includes minValue, but not maxValue, so we increment it +1

* introduce abstract layers

* refactoring

* fix tets

* adapt tests

* fixup

* implement blackschole price model for options

* use risk free rate

* use ql price model

* wip

* change interface

* fix

* tidy up the code

* wip

* iterate groupped symbols

* wip

* wip

* fix

* allow symbol of different types

* improve settings

* wip

* iterate full range

* fix issue with negative option

* fix

* fixup

* use StandardDeviationOfReturnsVolatilityModel

* re-use existing tick types per security type

* parametrize underlying security type

* use default option style

* dynamic option price model

* fix enumeration

* test

* fix unit tests

* refactor code

* remove unused file

* minor tweaks and refactoring

* rename symbol generator class

* fix interface

* add comments

* more comments and unit tests

* more tests

* add disclaimer

* more tests

* more comments and tests

* split tests into different files

* tidy up the code

* tidy up the code; more tests

* refactor TickGenerator => use security price directly on each iteration

* remove dupe; reuse main constructor

* use SecurityManager, refactor code

* bugfix: save ticks in history array

* check volatility warm up & tests

* more unit tests

* describe volatility period span in settings

* rename command line option

* Minor adjusments. Address review

- Use Lean log handler instead of writting directly to console
- Rename BlackShcolesPriceGenerator to generically OptionPriceModelPriceGenerator
- Minor format clean up & standarization
- Add support for specifying the option chain size

* Rename TickGenerator private fields

* Fix unit tests

* fix tests class name

* Support tickers being specified

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-01-10 17:21:03 -03:00

266 lines
14 KiB
C#

/*
* 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.Configuration;
using QuantConnect.Logging;
using QuantConnect.ToolBox.AlgoSeekFuturesConverter;
using QuantConnect.ToolBox.AlgoSeekOptionsConverter;
using QuantConnect.ToolBox.AlphaVantageDownloader;
using QuantConnect.ToolBox.BinanceDownloader;
using QuantConnect.ToolBox.BitfinexDownloader;
using QuantConnect.ToolBox.CoarseUniverseGenerator;
using QuantConnect.ToolBox.CoinApiDataConverter;
using QuantConnect.ToolBox.CryptoiqDownloader;
using QuantConnect.ToolBox.DukascopyDownloader;
using QuantConnect.ToolBox.GDAXDownloader;
using QuantConnect.ToolBox.IBDownloader;
using QuantConnect.ToolBox.IEX;
using QuantConnect.ToolBox.IQFeedDownloader;
using QuantConnect.ToolBox.IVolatilityEquityConverter;
using QuantConnect.ToolBox.KaikoDataConverter;
using QuantConnect.ToolBox.KrakenDownloader;
using QuantConnect.ToolBox.NseMarketDataConverter;
using QuantConnect.ToolBox.OandaDownloader;
using QuantConnect.ToolBox.Polygon;
using QuantConnect.ToolBox.QuandlBitfinexDownloader;
using QuantConnect.ToolBox.QuantQuoteConverter;
using QuantConnect.ToolBox.RandomDataGenerator;
using QuantConnect.ToolBox.YahooDownloader;
using QuantConnect.ToolBox.ZerodhaDownloader;
using QuantConnect.Util;
using System;
using System.IO;
using QuantConnect.Interfaces;
using static QuantConnect.Configuration.ApplicationParser;
namespace QuantConnect.ToolBox
{
public class Program
{
public static void Main(string[] args)
{
Log.DebuggingEnabled = Config.GetBool("debug-mode");
var destinationDir = Config.Get("results-destination-folder");
if (!string.IsNullOrEmpty(destinationDir))
{
Directory.CreateDirectory(destinationDir);
Log.FilePath = Path.Combine(destinationDir, "log.txt");
}
Log.LogHandler = Composer.Instance.GetExportedValueByTypeName<ILogHandler>(Config.Get("log-handler", "CompositeLogHandler"));
var optionsObject = ToolboxArgumentParser.ParseArguments(args);
if (optionsObject.Count == 0)
{
PrintMessageAndExit();
}
var dataProvider
= Composer.Instance.GetExportedValueByTypeName<IDataProvider>(Config.Get("data-provider", "DefaultDataProvider"));
var mapFileProvider
= Composer.Instance.GetExportedValueByTypeName<IMapFileProvider>(Config.Get("map-file-provider", "LocalDiskMapFileProvider"));
var factorFileProvider
= Composer.Instance.GetExportedValueByTypeName<IFactorFileProvider>(Config.Get("factor-file-provider", "LocalDiskFactorFileProvider"));
mapFileProvider.Initialize(dataProvider);
factorFileProvider.Initialize(mapFileProvider, dataProvider);
var targetApp = GetParameterOrExit(optionsObject, "app").ToLowerInvariant();
if (targetApp.Contains("download") || targetApp.EndsWith("dl"))
{
var fromDate = Parse.DateTimeExact(GetParameterOrExit(optionsObject, "from-date"), "yyyyMMdd-HH:mm:ss");
var resolution = optionsObject.ContainsKey("resolution") ? optionsObject["resolution"].ToString() : "";
var market = optionsObject.ContainsKey("market") ? optionsObject["market"].ToString() : "";
var securityType = optionsObject.ContainsKey("security-type") ? optionsObject["security-type"].ToString() : "";
var tickers = ToolboxArgumentParser.GetTickers(optionsObject);
var toDate = optionsObject.ContainsKey("to-date")
? Parse.DateTimeExact(optionsObject["to-date"].ToString(), "yyyyMMdd-HH:mm:ss")
: DateTime.UtcNow;
switch (targetApp)
{
case "zdl":
case "zerodhadownloader":
ZerodhaDataDownloaderProgram.ZerodhaDataDownloader(tickers, market, resolution, securityType, fromDate, toDate);
break;
case "gdaxdl":
case "gdaxdownloader":
GDAXDownloaderProgram.GDAXDownloader(tickers, resolution, fromDate, toDate);
break;
case "cdl":
case "cryptoiqdownloader":
CryptoiqDownloaderProgram.CryptoiqDownloader(tickers, GetParameterOrExit(optionsObject, "exchange"), fromDate, toDate);
break;
case "ddl":
case "dukascopydownloader":
DukascopyDownloaderProgram.DukascopyDownloader(tickers, resolution, fromDate, toDate);
break;
case "ibdl":
case "ibdownloader":
IBDownloaderProgram.IBDownloader(tickers, resolution, fromDate, toDate);
break;
case "iexdl":
case "iexdownloader":
IEXDownloaderProgram.IEXDownloader(tickers, resolution, fromDate, toDate);
break;
case "iqfdl":
case "iqfeeddownloader":
IQFeedDownloaderProgram.IQFeedDownloader(tickers, resolution, fromDate, toDate);
break;
case "kdl":
case "krakendownloader":
KrakenDownloaderProgram.KrakenDownloader(tickers, resolution, fromDate, toDate);
break;
case "odl":
case "oandadownloader":
OandaDownloaderProgram.OandaDownloader(tickers, resolution, fromDate, toDate);
break;
case "qbdl":
case "quandlbitfinexdownloader":
QuandlBitfinexDownloaderProgram.QuandlBitfinexDownloader(fromDate, GetParameterOrExit(optionsObject, "api-key"));
break;
case "ydl":
case "yahoodownloader":
YahooDownloaderProgram.YahooDownloader(tickers, resolution, fromDate, toDate);
break;
case "bfxdl":
case "bitfinexdownloader":
BitfinexDownloaderProgram.BitfinexDownloader(tickers, resolution, fromDate, toDate);
break;
case "mbxdl":
case "binancedownloader":
BinanceDownloaderProgram.DataDownloader(tickers, resolution, fromDate, toDate);
break;
case "pdl":
case "polygondownloader":
PolygonDownloaderProgram.PolygonDownloader(
tickers,
GetParameterOrExit(optionsObject, "security-type"),
GetParameterOrExit(optionsObject, "market"),
resolution,
fromDate,
toDate);
break;
case "avdl":
case "alphavantagedownloader":
AlphaVantageDownloaderProgram.AlphaVantageDownloader(
tickers,
resolution,
fromDate,
toDate,
GetParameterOrExit(optionsObject, "api-key")
);
break;
default:
PrintMessageAndExit(1, "ERROR: Unrecognized --app value");
break;
}
}
else if (targetApp.Contains("updater") || targetApp.EndsWith("spu"))
{
switch (targetApp)
{
case "mbxspu":
case "binancesymbolpropertiesupdater":
BinanceDownloaderProgram.ExchangeInfoDownloader();
break;
default:
PrintMessageAndExit(1, "ERROR: Unrecognized --app value");
break;
}
}
else
{
switch (targetApp)
{
case "asfc":
case "algoseekfuturesconverter":
AlgoSeekFuturesProgram.AlgoSeekFuturesConverter(GetParameterOrExit(optionsObject, "date"));
break;
case "asoc":
case "algoseekoptionsconverter":
AlgoSeekOptionsConverterProgram.AlgoSeekOptionsConverter(GetParameterOrExit(optionsObject, "date"));
break;
case "ivec":
case "ivolatilityequityconverter":
IVolatilityEquityConverterProgram.IVolatilityEquityConverter(GetParameterOrExit(optionsObject, "source-dir"),
GetParameterOrExit(optionsObject, "source-meta-dir"),
GetParameterOrExit(optionsObject, "destination-dir"),
GetParameterOrExit(optionsObject, "resolution"));
break;
case "kdc":
case "kaikodataconverter":
KaikoDataConverterProgram.KaikoDataConverter(GetParameterOrExit(optionsObject, "source-dir"),
GetParameterOrExit(optionsObject, "date"),
GetParameterOrDefault(optionsObject, "exchange", string.Empty));
break;
case "cadc":
case "coinapidataconverter":
CoinApiDataConverterProgram.CoinApiDataProgram(
GetParameterOrExit(optionsObject, "date"),
GetParameterOrExit(optionsObject, "source-dir"),
GetParameterOrExit(optionsObject, "destination-dir"),
GetParameterOrDefault(optionsObject, "market", null));
break;
case "nmdc":
case "nsemarketdataconverter":
NseMarketDataConverterProgram.NseMarketDataConverter(GetParameterOrExit(optionsObject, "source-dir"),
GetParameterOrExit(optionsObject, "destination-dir"));
break;
case "qqc":
case "quantquoteconverter":
QuantQuoteConverterProgram.QuantQuoteConverter(GetParameterOrExit(optionsObject, "destination-dir"),
GetParameterOrExit(optionsObject, "source-dir"),
GetParameterOrExit(optionsObject, "resolution"));
break;
case "cug":
case "coarseuniversegenerator":
CoarseUniverseGeneratorProgram.CoarseUniverseGenerator();
break;
case "rdg":
case "randomdatagenerator":
var tickers = ToolboxArgumentParser.GetTickers(optionsObject);
RandomDataGeneratorProgram.RandomDataGenerator(
GetParameterOrExit(optionsObject, "start"),
GetParameterOrExit(optionsObject, "end"),
GetParameterOrExit(optionsObject, "symbol-count"),
GetParameterOrDefault(optionsObject, "market", null),
GetParameterOrDefault(optionsObject, "security-type", "Equity"),
GetParameterOrDefault(optionsObject, "resolution", "Minute"),
GetParameterOrDefault(optionsObject, "data-density", "Dense"),
GetParameterOrDefault(optionsObject, "include-coarse", "true"),
GetParameterOrDefault(optionsObject, "quote-trade-ratio", "1"),
GetParameterOrDefault(optionsObject, "random-seed", null),
GetParameterOrDefault(optionsObject, "ipo-percentage", "5.0"),
GetParameterOrDefault(optionsObject, "rename-percentage", "30.0"),
GetParameterOrDefault(optionsObject, "splits-percentage", "15.0"),
GetParameterOrDefault(optionsObject, "dividends-percentage", "60.0"),
GetParameterOrDefault(optionsObject, "dividend-every-quarter-percentage", "30.0"),
GetParameterOrDefault(optionsObject, "option-price-engine", "BaroneAdesiWhaleyApproximationEngine"),
GetParameterOrDefault(optionsObject, "volatility-model-resolution", "Daily"),
GetParameterOrDefault(optionsObject, "chain-symbol-count", "1"),
tickers
);
break;
default:
PrintMessageAndExit(1, "ERROR: Unrecognized --app value");
break;
}
}
}
}
}