BacktestTool - batch backtest, import and strategy parameters optimalization
#1
I present Gekko's BacktestTool. Script written in Perl.

How it's work?
The tool allows you to perform multiple backtests on previously defined multiple pairs, strategies and candleSize. All you have to do is enter your variables into the configuration file and run the program. Then BacktestTool will perform all the tasks you have ordered. Results are printed as terminal output and saved in csv file. Example of csv file is here: https://github.com/xFFFFF/Gekko-Strategi...tabase.csv

Features
- Test multiple candleSize, strategies and mulitple pairs on one run
- Start multiple PaperTraders
- Multiple datasets import
- Backtests results are exported to CSV file
- Multithreading - in contrast to raw Gekko backtest this tool uses 100% of your processor
- Extended statistics

DEMO 
Start backtests
[Image: backtest.gif]

All results are exported to CSV file (You can open it in Excel or LibreOffice Calc)
[Image: csv.gif]

Installation
1. Clone git https://github.com/xFFFFF/GekkoBacktestTool.git
2. Copy files to Gekko's main directory
3. Install dependies by command: 

Code:
$ sudo cpan install Parallel::ForkManager Time::ParseDate Time::Elapsed Getopt::Long List::MoreUtils File::chdir Statistics::Basic DBI

4. Edit backtest-config.pl in text editor.

Run
for backtest: 

Code:
$ perl backtest.pl 

For import: 

Code:
$ perl backtest.pl -i 

For start multiple paperTraders: 

Code:
$ perl backtest.pl -p

Available commands:
Code:
usage: perl backtest.pl
To run backtests machine

usage: perl backtest.pl [parameter] [optional parameter]
Parameters:
 -i, --import     - Import new datasets
 -g, --paper     - Start multiple sessions of PaperTrader
 -v, --convert     - Convert TOML file to Gekko's CLI config format, ex: backtest.pl -v MACD.toml
 
Optional parameters:
 -c, --config         - BacktestTool config file. Default is backtest-config.pl
 -s, --strat STRATEGY_NAME - Define strategies for backtests. You can add multiple strategies seperated by commas example: backtest.pl --strat=MACD,CCI
 -p, --pair PAIR     - Define pairs to backtest in exchange:currency:asset format ex: backtest.pl --p bitfinex:USD:AVT. You can add multiple pairs seperated by commas.
 -p exchange:ALL     - Perform action on all available pairs. Other usage: exchange:USD:ALL to perform action for all USD pairs.
 -n, --candle CANDLE     - Define candleSize and warmup period for backtest in candleSize:warmup format, ex: backtest.pl -n 5:144,10:73. You can add multiple values seperated by commas.
 -f, --from
 -f last        - Start import from last candle available in DB. If pair not exist in DB then start from 24h ago.
 -t, --to         - Time range for backtest datasets or import. Example: backtest.pl --from="2018-01-01 09:10" --to="2018-01-05 12:23"
 -t now        - 'now' is current time in GMT.
 -o, --output FILENAME - CSV file name.

Example usage:
Backtests of all available pairs for Binance Exchange in Gekko's scan datarange mode:
Code:
$ perl backtest.pl -p binance:ALL`

Backtest on all pairs and strategies defined in backtest-config.pl with candles 5, 10, 20, 40 and 12 hours warmup period:
Code:
$ perl backtest.pl -n 5:144,10:73,20:36,40:15`

Import all new candles for all BNB pairs:
Code:
$ perl backtest.pl -i -p binance:BNB:ALL -f last -t now`

Import all candles for pairs defined in backtest-config.pl from 2017-01-02 to now:
Code:
$ perl backtest.pl -i -f 2017-01-02 -t now`

Sample backtest output
Link: https://github.com/xFFFFF/Gekko-Backtest...output.csv

Github

Check our Git for more info: https://github.com/xFFFFF/GekkoBacktestTool
Feel free to submit suggestions or features request.
  Reply
#2
how to change it to use one srtat with different params?
  Reply
#3
This same way like Gekko cli. In config file of backtesttool is some examples like this:
Code:
config.RSI_BULL_BEAR_ADX = {
  SMA_long: 1000,
  SMA_short: 50,
  BULL_RSI: 10,
  BULL_RSI_high: 80,
  BULL_RSI_low: 60,
  BEAR_RSI: 15,
  BEAR_RSI_high: 50,
  BEAR_RSI_low: 20,
  BULL_MOD_high: 5,
  BULL_MOD_low: -5,
  BEAR_MOD_high: 15,
  BEAR_MOD_low: -5,
  ADX: 3,
  ADX_high: 70,
  ADX_low: 50
};
Just edit backtest.pl file by text editor.
  Reply
#4
thx for that. worked well for me. 
its a good way to quickly search for a good match.
  Reply
#5
New version was released today.

New features:
Quote:- Gekko BacktestTool external config file support. Default config is backtest-config.pl, but You can create own and use backtest.pl
- using TOML files for strategies configuration as default. Can be changed in backtest-config.pl
- percentage wins, best win, worst loss, median win, median lost, average exposed duration added to csv file.
- parameter --covert TOML_FILE. Convert toml file and print strategy settings in Gekko's config file format
- parameter exchange:ALL and exchange:asset:ALL for backtest pairs. Do backtest for all available pairs. Based on non empty tables from sqlite database.
- parameter exchange:ALL and exchange:asset:ALL for import pairs. Import all available pairs from exchange. Based on exchange/exchange-markets.json file
- parameter --import --from=last --to=now. The 'last' value checks in the database the time of the last candle for each pair and assign this value to --from. 'now' assign current time in GMT time zone. In short: with this command you can import from the last candle from datasets to current time.
My projects [Strategies] [Datasets]
  Reply
#6
xFFFFF, will this tools suggest better parameters for the start or will it show results based on the config and i manually adjust them an retest? i'm looking for a simple setup tool to brute force test a strat.

Can i set this for data ranges and certain pairs only? example is that i know the pairs i want to trade and i do not want to backtest the December bull run as it will knock the figures out massively.
  Reply
#7
This tool only do mass backtests on multiple pairs or strategies with strat's parameters defined by You. You can use defined period of backtest on multiple pairs
Code:
./backtest.pl -p binance:USD:BTC,binance:BTC:BNB -f "2018-01-01" -t "2018-02-02"
or edit backtest-config.pl and just run
Code:
./backtest.pl

To brute force strat's parameters You can use:
https://github.com/Gab0/japonicus
https://github.com/gekkowarez/gekkoga
https://github.com/tommiehansen/gab

In my opinion japonicus finding best values in shorter period and allow to set two different pairs to bruteforce.
My projects [Strategies] [Datasets]
  Reply
#8
To make the program's idea easier to understand I have expanded README.

Available commands:
Code:
usage: perl backtest.pl
To run backtests machine

usage: perl backtest.pl [parameter] [optional parameter]
Parameters:
 -i, --import     - Import new datasets
 -g, --paper     - Start multiple sessions of PaperTrader
 -v, --convert     - Convert TOML file to Gekko's CLI config format, ex: backtest.pl -v MACD.toml
 
Optional parameters:
 -c, --config         - BacktestTool config file. Default is backtest-config.pl
 -s, --strat STRATEGY_NAME - Define strategies for backtests. You can add multiple strategies seperated by commas example: backtest.pl --strat=MACD,CCI
 -p, --pair PAIR     - Define pairs to backtest in exchange:currency:asset format ex: backtest.pl --p bitfinex:USD:AVT. You can add multiple pairs seperated by commas.
 -p exchange:ALL     - Perform action on all available pairs. Other usage: exchange:USD:ALL to perform action for all USD pairs.
 -n, --candle CANDLE     - Define candleSize and warmup period for backtest in candleSize:warmup format, ex: backtest.pl -n 5:144,10:73. You can add multiple values seperated by commas.
 -f, --from
 -f last        - Start import from last candle available in DB. If pair not exist in DB then start from 24h ago.
 -t, --to         - Time range for backtest datasets or import. Example: backtest.pl --from="2018-01-01 09:10" --to="2018-01-05 12:23"
 -t now        - 'now' is current time in GMT.
 -o, --output FILENAME - CSV file name.

Example usage:
Backtests of all available pairs for Binance Exchange in Gekko's scan datarange mode:
Code:
$ perl backtest.pl -p binance:ALL

Backtest on all pairs and strategies defined in backtest-config.pl with candles 5, 10, 20, 40 and 12 hours warmup period:
Code:
$ perl backtest.pl -n 5:144,10:73,20:36,40:15

Import all new candles for all BNB pairs:
Code:
$ perl backtest.pl -i -p binance:BNB:ALL -f last -t now

Import all candles for pairs defined in backtest-config.pl from 2017-01-02 to now:
Code:
$ perl backtest.pl -i -f 2017-01-02 -t now

New features:
Code:
- price *volality* (based on relative standard deviation) in CSV output
- sum of *volume* and *volume/day* for dataset period in CSV output
- sum of *overall exchange trades* and sum of *overall trades/day* for dataset period in CSV output
- if pair not exist in DB on parameter `-f last` then create table and import from last 24 hours.
- update parameter `--help`
- README update
- some code clean
- some fixes

Sample backtest output
https://github.com/xFFFFF/Gekko-Backtest...output.csv
My projects [Strategies] [Datasets]
  Reply
#9
BacktestTool is working on MS Windows from now!

Other changes:
Code:
- price: open, close, high, low, average for dataset period in CSV output
- coinmarketcap.com data in CSV output: current marketcap, current rank, last 24h global volume
- CSV's template - now You can choose which columns will be add to CSV file
- temporary GBT's files are in tmp directory now.
- MS Windows compatibility fix (tested on W7x64 and StrawberryPerl)
- backtest-config.pl file updated
My projects [Strategies] [Datasets]
  Reply
#10
New "layout"
[Image: 687474703a2f2f692e696d6775722e636f6d2f4f...622e706e67]

@Kris191 from new version BacktestTool support searching best parameters for strategies. Feature can be run on multiple pairs, so you can found optimal parameters on different market condition.

Enabling brute force mode
[Image: 687474703a2f2f692e696d6775722e636f6d2f4f...6d2e706e67]

Searching parametrs
[Image: 687474703a2f2f692e696d6775722e636f6d2f67...412e706e67]

At end strategy (and settings) are sorted in table like this:
[Image: 687474703a2f2f692e696d6775722e636f6d2f4a...542e706e67]

New feature can find best pairs too
[Image: 687474703a2f2f692e696d6775722e636f6d2f55...6e2e706e67]

Binaries of BacktestTool
Since version 0.5 you do not need to install any additional dependencies for BacktestTool on Linux, Windows and FreeBSD. Just download the binary version and run the program with the ./backtest or backtest.exe command. Binaries are available here: https://github.com/xFFFFF/Gekko-BacktestTool/releases

All changes
Code:
- after completion of the backtests, the analysis module displays three tables with data: ALL RESULTS, TOP STRATEGIES, TOP DATASET
- parameter --analyze mycsvfile.csv for analyze any results from BacktestTool's external file
- searching optimal strategy parameters by brute force method with syntax start..end:step or value1, value2, value3 in strat's toml file
- value ALL for exchanges and strategies for backtest machine - do backtests on all available exchanges, currencies, assets or strategies. Based on filenames in history and strategies directories.
- add binaries for Linux and FreeBSD to releases
- backtest-config.pl updated
- README.MD updated
My projects [Strategies] [Datasets]
  Reply


Forum Jump:


Users browsing this thread: