Package: bktest
A small backtesting utility.InstallUsageOptionsExportersConsoleDumpInfluxQuantStatsPDFSpecific ReturnData SourcesYahooCoinMarketCapFactSetFile.parquetInstallpip install --upgrade bktestUsagebktest[OPTIONS]OptionsOptionValueDefaultFormatDescription--start<start date>orders' first datedate(ISO-8601)The starting date of the backtesting. If the value is before the first ordering day, the value will be discarded.--end<end date>orders' last datedate(ISO-8601)The ending date of the backtesting. If the value is after today, the value will be discarded.--offset-before-trading<days>1intNumber of day to offset to push the signal before trading it.--offset-before-ending<days>0intNumber of day to continue the backtest after every orders.--order-file<file>pathThe single order file to use. The file must contain symbol, quantity and date information.--single-file-provider-column-date<column>datestringChange the date column name to use.--single-file-provider-column-symbol<column>symbolstringChange the symbol column name to use.--single-file-provider-column-quantity<column>quantitystringChange the quantity column name to use.--order-files<directory>pathThe directory of order file to use. The filename must be a date. The file must contain symbol and quantity information.--order-files-extension<extension>csv[csv, parquet, json]Change the file extension to use when listing for order files.--initial-cash<amount>100_000numberChange the initial cash to use for the backtesting.--quantity-mode<mode>percent[percent, share]If the mode isshare, all quantities will be interpreted as integers. If the mode ispercent, all values will be multiplied by the current cash value.--auto-close-othersfalseShould other position be closed after an ordering?--weekendsfalseEnable ordering on weekends.--holidaysfalseEnable ordering on holidays.--symbol-mapping<mapping>path(.json)Specify a custom symbol mapping file enabling vendor-id translation.--no-cachingfalseDisable prices caching.--fee-model<model>expressionorconstantSpecify a fee model to use. The value can be aconstant. Or an expression that allow the usage of thepriceandquantityvariable.Example:abs(price * quantity) * 0.1--rfr-file<directory>pathThe directory of rfr file to use. The file must contain a column with date information and a column with the rfr information in %.--rfr-file-column-date<column>datestringChange the date column name to use.ExportersMultiple exporters can be enabled at one time.ConsoleThe console exporter allows a quick look at the backtest.OptionValueDefaultFormatDescription--consolefalseEnable the console exporter.--console-format<format>text[text, json]Change the output format.--console-file<file>out[out, err]Change the output file.--console-hide-skipsfalseDo not the skipped days.--console-text-no-colorfalseDisable colors in the output. (only if the format istext)DumpThe dump exporter generate a dump of the portfolio at each day.OptionValueDefaultFormatDescription--dumpfalseEnable the dump exporter.--dump-output-file<file>dump.csvpathSpecify the output file.--dump-auto-deletefalseAutomatically delete the previous dump file if it is present.InfluxExport the generated data to an Influx database.Making it easier to plot the values using software like Grafana.OptionValueDefaultFormatDescription--influxfalseEnable the influx exporter.--influx-host<host>localhoststringSpecify the remote influx address.--influx-port<port>8086numberSpecify the remote influx port.--influx-database<database>backteststringSpecify the influx database to use.--influx-measurement<measurement>snapshotsstringSpecify the table name to use.--influx-key<key>teststringSpecify the unique key to use.Previous data with the same key will be deleted!QuantStatsGenerate a tearsheet from the backtest data.OptionValueDefaultFormatDescription--quantstatsfalseEnable the quantstats exporter.--quantstats-output-file-html<file>report.htmlpathSpecify the output file containing the tearsheet.--quantstats-output-file-csv<file>report.csvpathSpecify the output file containing raw returns.--quantstats-benchmark-ticker<ticker>SPYsymbolSpecify the ticker to use as a benchmark in the tearsheet.--quantstats-auto-deletefalseAutomatically delete the previous report files if they are present.PDFGenerate a tearsheet from a custom template.OptionValueDefaultFormatDescription--pdffalseEnable the pdf exporter.--pdf-template<file>tearsheet.sketchpathSpecify the template file.--pdf-output-file<file>report.pdfpathSpecify the output file.--pdf-auto-deletefalseAutomatically delete the previous report file if present.--pdf-debugfalseEnable the pdf renderer's debugging tools.--pdf-variable[<key> <value>][]stringstringAdd a custom variable.--pdf-user-script[<file>][]pathAdd a user script.Specific ReturnGenerate a tearsheet from the specific return backtest data.OptionValueDefaultFormatDescription--specific-return<file>pathEnable the specific return exporter by proving a file.--specific-return-column-date<column>datestringSpecify the name of column containing the dates informations.--specific-return-column-symbol<column>symbolstringSpecify the name of column containing the symbols informations.--specific-return-column-value<column>specific_returnstringSpecify the name of column containing the value informations.--specific-return-output-file-html<file>sr-report.htmlpathSpecify the output file containing the tearsheet.--specific-return-output-file-csv<file>sr-report.csvpathSpecify the output file containing raw returns.--specific-return-auto-deletefalseAutomatically delete the previous report files if they are present.Data SourcesOnly one data source can be used at once.YahooOptionValueDefaultFormatDescription--yahoofalseEnable yahoo as the data source.CoinMarketCapOptionValueDefaultFormatDescription--coinmarketcapfalseEnable coinmarketcap as the data source.--coinmarketcap-force-mapping-refreshfalseForce a mapping refresh. This is usually only done automatically the first time of using this data source.--coinmarketcap-page-size<size>10_000numberSpecify the page size while building the mapping.FactSetOptionValueDefaultFormatDescription--factsetfalseEnable factset as the data source.--factset-username-serial$FACTSET_USERNAME_SERIALSpecify the factset's username serial to use.--factset-api-key$FACTSET_API_KEYSpecify the factset's api key to use.FileUse a static file as a price data source.If another data source is specified, files sources will be used first in a delegated data source. Meaning that if the data are not available in the file, the next data source will be used..parquetOptionValueDefaultFormatDescription--file-parquet<file>pathUse a static.parquetfile as a the data source.--file-parquet-column-date<column>datestringSpecify the name of column containing the dates informations.--file-parquet-column-symbol<column>symbolstringSpecify the name of column containing the symbols informations.--file-parquet-column-price<column>pricestringSpecify the name of column containing the prices informations.