Skip to content

Commit

Permalink
Move PerformanceWarning to advanced section
Browse files Browse the repository at this point in the history
rewrite to use strategy parameters instead of plain range
  • Loading branch information
xmatthias committed Sep 23, 2021
1 parent c17595b commit d7903f0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
30 changes: 30 additions & 0 deletions docs/strategy-advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -695,3 +695,33 @@ The variable 'content', will contain the strategy file in a BASE64 encoded form.
```

Please ensure that 'NameOfStrategy' is identical to the strategy name!

## Performance warning

When executing a strategy, one can sometimes be greeted by the following in the logs

> PerformanceWarning: DataFrame is highly fragmented.
This is a warning from [`pandas`](https://github.com/pandas-dev/pandas) and as the warning continues to say:
use `pd.concat(axis=1)`.
This can have slight performance implications, which are usually only visible during hyperopt (when optimizing an indicator).

For example:

```python
for val in self.buy_ema_short.range:
dataframe[f'ema_short_{val}'] = ta.EMA(dataframe, timeperiod=val)
```

should be rewritten to

```python
frames = [dataframe]
for val in self.buy_ema_short.range:
frames.append({
f'ema_short_{val}': ta.EMA(dataframe, timeperiod=val)
})

# Append columns to existing dataframe
merged_frame = pd.concat(frames, axis=1)
```
27 changes: 0 additions & 27 deletions docs/strategy-customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -793,33 +793,6 @@ The following lists some common patterns which should be avoided to prevent frus
- don't use `dataframe['volume'].mean()`. This uses the full DataFrame for backtesting, including data from the future. Use `dataframe['volume'].rolling(<window>).mean()` instead
- don't use `.resample('1h')`. This uses the left border of the interval, so moves data from an hour to the start of the hour. Use `.resample('1h', label='right')` instead.

### Performance warning

When executing a strategy, one can sometimes be greeted by the following in the logs

> PerformanceWarning: DataFrame is highly fragmented.
This is a warning from [`pandas`](https://github.com/pandas-dev/pandas) and as the warning continues to say:
use `pd.concat(axis=1)`. For example

```python
for i in range(100):
dataframe[i] = ta.indicator(dataframe, param=i)
```

should be rewritten to

```python
frames = [dataframe]
for i in range(100):
frames.append({
str(i): ta.indicator(dataframe, param=i)
})

# Append columns to existing dataframe
merged_frame = pd.concat(frames, axis=1)
```

## Further strategy ideas

To get additional Ideas for strategies, head over to our [strategy repository](https://github.com/freqtrade/freqtrade-strategies). Feel free to use them as they are - but results will depend on the current market situation, pairs used etc. - therefore please backtest the strategy for your exchange/desired pairs first, evaluate carefully, use at your own risk.
Expand Down

0 comments on commit d7903f0

Please sign in to comment.