Skip to content

Commit

Permalink
Merge pull request freqtrade#1089 from freqtrade/feat/backtest_multi_…
Browse files Browse the repository at this point in the history
…strat

Allow multi strategy backtest without data reload
  • Loading branch information
vertti authored Aug 2, 2018
2 parents 17d78b7 + 40ee86b commit 3a5b435
Show file tree
Hide file tree
Showing 8 changed files with 349 additions and 74 deletions.
27 changes: 26 additions & 1 deletion docs/backtesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ cp freqtrade/tests/testdata/pairs.json user_data/data/binance
Then run:

```bash
python scripts/download_backtest_data --exchange binance
python scripts/download_backtest_data.py --exchange binance
```

This will download ticker data for all the currency pairs you defined in `pairs.json`.
Expand Down Expand Up @@ -238,6 +238,31 @@ On the other hand, if you set a too high `minimal_roi` like `"0": 0.55`
profit. Hence, keep in mind that your performance is a mix of your
strategies, your configuration, and the crypto-currency you have set up.

## Backtesting multiple strategies

To backtest multiple strategies, a list of Strategies can be provided.

This is limited to 1 ticker-interval per run, however, data is only loaded once from disk so if you have multiple
strategies you'd like to compare, this should give a nice runtime boost.

All listed Strategies need to be in the same folder.

``` bash
freqtrade backtesting --timerange 20180401-20180410 --ticker-interval 5m --strategy-list Strategy001 Strategy002 --export trades
```

This will save the results to `user_data/backtest_data/backtest-result-<strategy>.json`, injecting the strategy-name into the target filename.
There will be an additional table comparing win/losses of the different strategies (identical to the "Total" row in the first table).
Detailed output for all strategies one after the other will be available, so make sure to scroll up.

```
=================================================== Strategy Summary ====================================================
| Strategy | buy count | avg profit % | cum profit % | total profit ETH | avg duration | profit | loss |
|:-----------|------------:|---------------:|---------------:|-------------------:|:----------------|---------:|-------:|
| Strategy1 | 19 | -0.76 | -14.39 | -0.01440287 | 15:48:00 | 15 | 4 |
| Strategy2 | 6 | -2.73 | -16.40 | -0.01641299 | 1 day, 14:12:00 | 3 | 3 |
```

## Next step

Great, your strategy is profitable. What if the bot can give your the
Expand Down
33 changes: 26 additions & 7 deletions docs/bot-usage.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Bot usage
This page explains the difference parameters of the bot and how to run
it.

This page explains the difference parameters of the bot and how to run it.

## Table of Contents

- [Bot commands](#bot-commands)
- [Backtesting commands](#backtesting-commands)
- [Hyperopt commands](#hyperopt-commands)

## Bot commands

```
usage: freqtrade [-h] [-v] [--version] [-c PATH] [-d PATH] [-s NAME]
[--strategy-path PATH] [--dynamic-whitelist [INT]]
Expand Down Expand Up @@ -41,6 +43,7 @@ optional arguments:
```

### How to use a different config file?

The bot allows you to select which config file you want to use. Per
default, the bot will load the file `./config.json`

Expand All @@ -49,6 +52,7 @@ python3 ./freqtrade/main.py -c path/far/far/away/config.json
```

### How to use --strategy?

This parameter will allow you to load your custom strategy class.
Per default without `--strategy` or `-s` the bot will load the
`DefaultStrategy` included with the bot (`freqtrade/strategy/default_strategy.py`).
Expand All @@ -60,6 +64,7 @@ To load a strategy, simply pass the class name (e.g.: `CustomStrategy`) in this
**Example:**
In `user_data/strategies` you have a file `my_awesome_strategy.py` which has
a strategy class called `AwesomeStrategy` to load it:

```bash
python3 ./freqtrade/main.py --strategy AwesomeStrategy
```
Expand All @@ -70,28 +75,33 @@ message the reason (File not found, or errors in your code).
Learn more about strategy file in [optimize your bot](https://github.com/freqtrade/freqtrade/blob/develop/docs/bot-optimization.md).

### How to use --strategy-path?

This parameter allows you to add an additional strategy lookup path, which gets
checked before the default locations (The passed path must be a folder!):
```bash
python3 ./freqtrade/main.py --strategy AwesomeStrategy --strategy-path /some/folder
```

#### How to install a strategy?

This is very simple. Copy paste your strategy file into the folder
`user_data/strategies` or use `--strategy-path`. And voila, the bot is ready to use it.

### How to use --dynamic-whitelist?

Per default `--dynamic-whitelist` will retrieve the 20 currencies based
on BaseVolume. This value can be changed when you run the script.

**By Default**
Get the 20 currencies based on BaseVolume.

```bash
python3 ./freqtrade/main.py --dynamic-whitelist
```

**Customize the number of currencies to retrieve**
Get the 30 currencies based on BaseVolume.

```bash
python3 ./freqtrade/main.py --dynamic-whitelist 30
```
Expand All @@ -102,6 +112,7 @@ negative value (e.g -2), `--dynamic-whitelist` will use the default
value (20).

### How to use --db-url?

When you run the bot in Dry-run mode, per default no transactions are
stored in a database. If you want to store your bot actions in a DB
using `--db-url`. This can also be used to specify a custom database
Expand All @@ -111,14 +122,14 @@ in production mode. Example command:
python3 ./freqtrade/main.py -c config.json --db-url sqlite:///tradesv3.dry_run.sqlite
```


## Backtesting commands

Backtesting also uses the config specified via `-c/--config`.

```
usage: main.py backtesting [-h] [-i TICKER_INTERVAL] [--eps] [--dmmp]
usage: freqtrade backtesting [-h] [-i TICKER_INTERVAL] [--eps] [--dmmp]
[--timerange TIMERANGE] [-l] [-r]
[--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]]
[--export EXPORT] [--export-filename PATH]
optional arguments:
Expand All @@ -139,6 +150,13 @@ optional arguments:
refresh the pairs files in tests/testdata with the
latest data from the exchange. Use it if you want to
run your backtesting with up-to-date data.
--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]
Provide a commaseparated list of strategies to
backtest Please note that ticker-interval needs to be
set either in config or via command line. When using
this together with --export trades, the strategy-name
is injected into the filename (so backtest-data.json
becomes backtest-data-DefaultStrategy.json
--export EXPORT export backtest results, argument are: trades Example
--export=trades
--export-filename PATH
Expand All @@ -151,6 +169,7 @@ optional arguments:
```

### How to use --refresh-pairs-cached parameter?

The first time your run Backtesting, it will take the pairs you have
set in your config file and download data from Bittrex.

Expand All @@ -162,7 +181,6 @@ to come back to the previous version.**
To test your strategy with latest data, we recommend continuing using
the parameter `-l` or `--live`.


## Hyperopt commands

To optimize your strategy, you can use hyperopt parameter hyperoptimization
Expand Down Expand Up @@ -194,10 +212,11 @@ optional arguments:
```

## A parameter missing in the configuration?

All parameters for `main.py`, `backtesting`, `hyperopt` are referenced
in [misc.py](https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/misc.py#L84)

## Next step
The optimal strategy of the bot will change with time depending of the
market trends. The next step is to

The optimal strategy of the bot will change with time depending of the market trends. The next step is to
[optimize your bot](https://github.com/freqtrade/freqtrade/blob/develop/docs/bot-optimization.md).
10 changes: 10 additions & 0 deletions freqtrade/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ def backtesting_options(parser: argparse.ArgumentParser) -> None:
action='store_true',
dest='refresh_pairs',
)
parser.add_argument(
'--strategy-list',
help='Provide a commaseparated list of strategies to backtest '
'Please note that ticker-interval needs to be set either in config '
'or via command line. When using this together with --export trades, '
'the strategy-name is injected into the filename '
'(so backtest-data.json becomes backtest-data-DefaultStrategy.json',
nargs='+',
dest='strategy_list',
)
parser.add_argument(
'--export',
help='export backtest results, argument are: trades\
Expand Down
8 changes: 8 additions & 0 deletions freqtrade/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ def _load_backtesting_config(self, config: Dict[str, Any]) -> Dict[str, Any]:
config.update({'refresh_pairs': True})
logger.info('Parameter -r/--refresh-pairs-cached detected ...')

if 'strategy_list' in self.args and self.args.strategy_list:
config.update({'strategy_list': self.args.strategy_list})
logger.info('Using strategy list of %s Strategies', len(self.args.strategy_list))

if 'ticker_interval' in self.args and self.args.ticker_interval:
config.update({'ticker_interval': self.args.ticker_interval})
logger.info('Overriding ticker interval with Command line argument')

# If --export is used we add it to the configuration
if 'export' in self.args and self.args.export:
config.update({'export': self.args.export})
Expand Down
Loading

0 comments on commit 3a5b435

Please sign in to comment.