mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Update freqAI documentation with missing typehints
This commit is contained in:
parent
c20b074880
commit
c5dc21e80c
|
@ -52,7 +52,7 @@ The FreqAI strategy requires including the following lines of code in the standa
|
||||||
|
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def feature_engineering_expand_all(self, dataframe, period, **kwargs):
|
def feature_engineering_expand_all(self, dataframe: DataFrame, period, **kwargs) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
This function will automatically expand the defined features on the config defined
|
This function will automatically expand the defined features on the config defined
|
||||||
|
@ -77,7 +77,7 @@ The FreqAI strategy requires including the following lines of code in the standa
|
||||||
|
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def feature_engineering_expand_basic(self, dataframe, **kwargs):
|
def feature_engineering_expand_basic(self, dataframe: DataFrame, **kwargs) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
This function will automatically expand the defined features on the config defined
|
This function will automatically expand the defined features on the config defined
|
||||||
|
@ -101,7 +101,7 @@ The FreqAI strategy requires including the following lines of code in the standa
|
||||||
dataframe["%-raw_price"] = dataframe["close"]
|
dataframe["%-raw_price"] = dataframe["close"]
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def feature_engineering_standard(self, dataframe, **kwargs):
|
def feature_engineering_standard(self, dataframe: DataFrame, **kwargs) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
This optional function will be called once with the dataframe of the base timeframe.
|
This optional function will be called once with the dataframe of the base timeframe.
|
||||||
|
@ -122,7 +122,7 @@ The FreqAI strategy requires including the following lines of code in the standa
|
||||||
dataframe["%-hour_of_day"] = (dataframe["date"].dt.hour + 1) / 25
|
dataframe["%-hour_of_day"] = (dataframe["date"].dt.hour + 1) / 25
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def set_freqai_targets(self, dataframe, **kwargs):
|
def set_freqai_targets(self, dataframe: DataFrame, **kwargs) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
Required function to set the targets for the model.
|
Required function to set the targets for the model.
|
||||||
|
@ -139,6 +139,7 @@ The FreqAI strategy requires including the following lines of code in the standa
|
||||||
/ dataframe["close"]
|
/ dataframe["close"]
|
||||||
- 1
|
- 1
|
||||||
)
|
)
|
||||||
|
return dataframe
|
||||||
```
|
```
|
||||||
|
|
||||||
Notice how the `feature_engineering_*()` is where [features](freqai-feature-engineering.md#feature-engineering) are added. Meanwhile `set_freqai_targets()` adds the labels/targets. A full example strategy is available in `templates/FreqaiExampleStrategy.py`.
|
Notice how the `feature_engineering_*()` is where [features](freqai-feature-engineering.md#feature-engineering) are added. Meanwhile `set_freqai_targets()` adds the labels/targets. A full example strategy is available in `templates/FreqaiExampleStrategy.py`.
|
||||||
|
|
|
@ -37,7 +37,7 @@ freqtrade trade --freqaimodel ReinforcementLearner --strategy MyRLStrategy --con
|
||||||
where `ReinforcementLearner` will use the templated `ReinforcementLearner` from `freqai/prediction_models/ReinforcementLearner` (or a custom user defined one located in `user_data/freqaimodels`). The strategy, on the other hand, follows the same base [feature engineering](freqai-feature-engineering.md) with `feature_engineering_*` as a typical Regressor. The difference lies in the creation of the targets, Reinforcement Learning doesn't require them. However, FreqAI requires a default (neutral) value to be set in the action column:
|
where `ReinforcementLearner` will use the templated `ReinforcementLearner` from `freqai/prediction_models/ReinforcementLearner` (or a custom user defined one located in `user_data/freqaimodels`). The strategy, on the other hand, follows the same base [feature engineering](freqai-feature-engineering.md) with `feature_engineering_*` as a typical Regressor. The difference lies in the creation of the targets, Reinforcement Learning doesn't require them. However, FreqAI requires a default (neutral) value to be set in the action column:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def set_freqai_targets(self, dataframe, **kwargs):
|
def set_freqai_targets(self, dataframe, **kwargs) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
Required function to set the targets for the model.
|
Required function to set the targets for the model.
|
||||||
|
@ -53,17 +53,19 @@ where `ReinforcementLearner` will use the templated `ReinforcementLearner` from
|
||||||
# For RL, there are no direct targets to set. This is filler (neutral)
|
# For RL, there are no direct targets to set. This is filler (neutral)
|
||||||
# until the agent sends an action.
|
# until the agent sends an action.
|
||||||
dataframe["&-action"] = 0
|
dataframe["&-action"] = 0
|
||||||
|
return dataframe
|
||||||
```
|
```
|
||||||
|
|
||||||
Most of the function remains the same as for typical Regressors, however, the function below shows how the strategy must pass the raw price data to the agent so that it has access to raw OHLCV in the training environment:
|
Most of the function remains the same as for typical Regressors, however, the function below shows how the strategy must pass the raw price data to the agent so that it has access to raw OHLCV in the training environment:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def feature_engineering_standard(self, dataframe, **kwargs):
|
def feature_engineering_standard(self, dataframe: DataFrame, **kwargs) -> DataFrame:
|
||||||
# The following features are necessary for RL models
|
# The following features are necessary for RL models
|
||||||
dataframe[f"%-raw_close"] = dataframe["close"]
|
dataframe[f"%-raw_close"] = dataframe["close"]
|
||||||
dataframe[f"%-raw_open"] = dataframe["open"]
|
dataframe[f"%-raw_open"] = dataframe["open"]
|
||||||
dataframe[f"%-raw_high"] = dataframe["high"]
|
dataframe[f"%-raw_high"] = dataframe["high"]
|
||||||
dataframe[f"%-raw_low"] = dataframe["low"]
|
dataframe[f"%-raw_low"] = dataframe["low"]
|
||||||
|
return dataframe
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally, there is no explicit "label" to make - instead it is necessary to assign the `&-action` column which will contain the agent's actions when accessed in `populate_entry/exit_trends()`. In the present example, the neutral action to 0. This value should align with the environment used. FreqAI provides two environments, both use 0 as the neutral action.
|
Finally, there is no explicit "label" to make - instead it is necessary to assign the `&-action` column which will contain the agent's actions when accessed in `populate_entry/exit_trends()`. In the present example, the neutral action to 0. This value should align with the environment used. FreqAI provides two environments, both use 0 as the neutral action.
|
||||||
|
|
|
@ -578,7 +578,7 @@ def populate_any_indicators(
|
||||||
Features will now expand automatically. As such, the expansion loops, as well as the `{pair}` / `{timeframe}` parts will need to be removed.
|
Features will now expand automatically. As such, the expansion loops, as well as the `{pair}` / `{timeframe}` parts will need to be removed.
|
||||||
|
|
||||||
``` python linenums="1"
|
``` python linenums="1"
|
||||||
def feature_engineering_expand_all(self, dataframe, period, **kwargs):
|
def feature_engineering_expand_all(self, dataframe, period, **kwargs) -> DataFrame::
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
This function will automatically expand the defined features on the config defined
|
This function will automatically expand the defined features on the config defined
|
||||||
|
@ -638,7 +638,7 @@ Features will now expand automatically. As such, the expansion loops, as well as
|
||||||
Basic features. Make sure to remove the `{pair}` part from your features.
|
Basic features. Make sure to remove the `{pair}` part from your features.
|
||||||
|
|
||||||
``` python linenums="1"
|
``` python linenums="1"
|
||||||
def feature_engineering_expand_basic(self, dataframe, **kwargs):
|
def feature_engineering_expand_basic(self, dataframe: DataFrame, **kwargs) -> DataFrame::
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
This function will automatically expand the defined features on the config defined
|
This function will automatically expand the defined features on the config defined
|
||||||
|
@ -673,7 +673,7 @@ Basic features. Make sure to remove the `{pair}` part from your features.
|
||||||
### FreqAI - feature engineering standard
|
### FreqAI - feature engineering standard
|
||||||
|
|
||||||
``` python linenums="1"
|
``` python linenums="1"
|
||||||
def feature_engineering_standard(self, dataframe, **kwargs):
|
def feature_engineering_standard(self, dataframe: DataFrame, **kwargs) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
This optional function will be called once with the dataframe of the base timeframe.
|
This optional function will be called once with the dataframe of the base timeframe.
|
||||||
|
@ -704,7 +704,7 @@ Basic features. Make sure to remove the `{pair}` part from your features.
|
||||||
Targets now get their own, dedicated method.
|
Targets now get their own, dedicated method.
|
||||||
|
|
||||||
``` python linenums="1"
|
``` python linenums="1"
|
||||||
def set_freqai_targets(self, dataframe, **kwargs):
|
def set_freqai_targets(self, dataframe: DataFrame, **kwargs) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
Required function to set the targets for the model.
|
Required function to set the targets for the model.
|
||||||
|
|
|
@ -618,7 +618,7 @@ class IStrategy(ABC, HyperStrategyMixin):
|
||||||
return df
|
return df
|
||||||
|
|
||||||
def feature_engineering_expand_all(self, dataframe: DataFrame, period: int,
|
def feature_engineering_expand_all(self, dataframe: DataFrame, period: int,
|
||||||
metadata: Dict, **kwargs):
|
metadata: Dict, **kwargs) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
This function will automatically expand the defined features on the config defined
|
This function will automatically expand the defined features on the config defined
|
||||||
|
@ -644,7 +644,8 @@ class IStrategy(ABC, HyperStrategyMixin):
|
||||||
"""
|
"""
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
def feature_engineering_expand_basic(
|
||||||
|
self, dataframe: DataFrame, metadata: Dict, **kwargs) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
This function will automatically expand the defined features on the config defined
|
This function will automatically expand the defined features on the config defined
|
||||||
|
@ -697,7 +698,7 @@ class IStrategy(ABC, HyperStrategyMixin):
|
||||||
"""
|
"""
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs):
|
def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
Required function to set the targets for the model.
|
Required function to set the targets for the model.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user