mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-14 04:03:55 +00:00
improve performance and documentation of spice-rack.
This commit is contained in:
parent
d362332527
commit
06f4f2db0a
68
docs/freqai-spice-rack.md
Normal file
68
docs/freqai-spice-rack.md
Normal file
|
@ -0,0 +1,68 @@
|
|||
# Using the `spice_rack`
|
||||
|
||||
The `spice_rack` is aimed at users who do not wish to deal with setting up `FreqAI` confgs, but instead prefer to interact with `FreqAI` similar to a `talib` indicator. In this case, the user can instead simply add two keys to their config:
|
||||
|
||||
```json
|
||||
"freqai_spice_rack": true,
|
||||
"freqai_identifier": "spicey-id",
|
||||
```
|
||||
|
||||
Which tells `FreqAI` to set up a pre-set `FreqAI` instance automatically under the hood with preset parameters. Now the user can access a suite of custom `FreqAI` supercharged indicators inside their strategy:
|
||||
|
||||
```python
|
||||
dataframe['dissimilarity_index'] = self.freqai.spice_rack(
|
||||
'DI_values', dataframe, metadata, self)
|
||||
dataframe['extrema'] = self.freqai.spice_rack(
|
||||
'&s-extrema', dataframe, metadata, self)
|
||||
self.freqai.close_spice_rack() # user must close the spicerack
|
||||
```
|
||||
|
||||
Users can then use these columns, concert with all their own additional indicators added to `populate_indicators` in their entry/exit criteria and strategy callback methods the same way as any typical indicator (note: `spice_rack` indicators should not be used exclusively for entries and exits, the following example is just a demonstration of syntax. `spice_rack` indicators should **always** be used to support existing strategies). For example:
|
||||
|
||||
```python
|
||||
def populate_entry_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
|
||||
|
||||
df.loc[
|
||||
(
|
||||
(df['dissimilarity_index'] < 1) &
|
||||
(df['extrema'] > 0.1)
|
||||
),
|
||||
'enter_long'] = 1
|
||||
|
||||
df.loc[
|
||||
(
|
||||
(df['dissimilarity_index'] < 1) &
|
||||
(df['extrema'] <> -0.1)
|
||||
),
|
||||
'enter_short'] = 1
|
||||
|
||||
return df
|
||||
|
||||
def populate_exit_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
|
||||
|
||||
df.loc[
|
||||
(
|
||||
(df['dissimilarity_index'] < 1) &
|
||||
(df['extrema'] > 0.1)
|
||||
),
|
||||
|
||||
'exit_long'] = 1
|
||||
|
||||
df.loc[
|
||||
(
|
||||
|
||||
(df['dissimilarity_index'] < 1) &
|
||||
(df['extrema'] < -0.1)
|
||||
),
|
||||
'exit_short'] = 1
|
||||
|
||||
return df
|
||||
```
|
||||
|
||||
|
||||
## Available indicators
|
||||
|
||||
| Parameter | Description |
|
||||
|------------|-------------|
|
||||
| `DI_values` | **Required.** <br> The dissimilarity index of the current candle to the recent candles. More information available [here](freqai-feature-engineering.md#identifying-outliers-with-the-dissimilarity-index-di) <br> **Datatype:** Floats.
|
||||
| `extrema` | **Required.** <br> A continuous prediction from FreqAI which aims to help predict if the current candle is a maxima or a minma. FreqAI aims for 1 to be a maxima and -1 to be a minima - but the values should typically hover between -0.2 and 0.2. <br> **Datatype:** Floats.
|
|
@ -1262,7 +1262,7 @@ class FreqaiDataKitchen:
|
|||
return file_exists
|
||||
|
||||
def spice_extractor(self, indicator: str, dataframe: DataFrame) -> npt.NDArray:
|
||||
if indicator in dataframe:
|
||||
if indicator in dataframe.columns:
|
||||
return np.array(dataframe[indicator])
|
||||
else:
|
||||
logger.warning(f'User asked spice_rack for {indicator}, '
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"enabled": true,
|
||||
"purge_old_models": true,
|
||||
"train_period_days": 4,
|
||||
"backtest_period_days": 2,
|
||||
"backtest_period_days": 1,
|
||||
"identifier": "spicy-id",
|
||||
"feature_parameters": {
|
||||
"include_timeframes": [
|
||||
|
|
|
@ -160,14 +160,13 @@ def auto_populate_any_indicators(
|
|||
if set_generalized_indicators:
|
||||
df["%-day_of_week"] = (df["date"].dt.dayofweek + 1) / 7
|
||||
df["%-hour_of_day"] = (df["date"].dt.hour + 1) / 25
|
||||
df["&s-minima"] = 0
|
||||
df["&s-maxima"] = 0
|
||||
df["&s-extrema"] = 0
|
||||
min_peaks = argrelextrema(df["close"].values, np.less, order=80)
|
||||
max_peaks = argrelextrema(df["close"].values, np.greater, order=80)
|
||||
for mp in min_peaks[0]:
|
||||
df.at[mp, "&s-minima"] = 1
|
||||
df.at[mp, "&s-extrema"] = -1
|
||||
for mp in max_peaks[0]:
|
||||
df.at[mp, "&s-maxima"] = 1
|
||||
df.at[mp, "&s-extrema"] = 1
|
||||
|
||||
return df
|
||||
|
||||
|
@ -222,7 +221,7 @@ def setup_freqai_spice_rack(config: dict, exchange: Optional[Exchange]) -> Dict[
|
|||
|
||||
config['freqai']['feature_parameters'].update({'include_timeframes': new_tfs})
|
||||
config['freqai']['feature_parameters'].update({'include_corr_pairlist': new_corr_pairs})
|
||||
config.update({"freqaimodel": 'LightGBMRegressorMultiTarget'})
|
||||
config.update({"freqaimodel": 'LightGBMRegressor'})
|
||||
return config
|
||||
|
||||
# Keep below for when we wish to download heterogeneously lengthed data for FreqAI.
|
||||
|
|
|
@ -29,6 +29,7 @@ nav:
|
|||
- Parameter table: freqai-parameter-table.md
|
||||
- Feature engineering: freqai-feature-engineering.md
|
||||
- Running FreqAI: freqai-running.md
|
||||
- Spice Rack: freqai-spice-rack.md
|
||||
- Developer guide: freqai-developers.md
|
||||
- Short / Leverage: leverage.md
|
||||
- Utility Sub-commands: utils.md
|
||||
|
|
Loading…
Reference in New Issue
Block a user