chore: update to modern typing syntax
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import Dict
|
|
||||||
|
|
||||||
import numpy as np # noqa
|
import numpy as np # noqa
|
||||||
import pandas as pd # noqa
|
import pandas as pd # noqa
|
||||||
@@ -98,7 +97,7 @@ class FreqaiExampleHybridStrategy(IStrategy):
|
|||||||
exit_short_rsi = IntParameter(low=1, high=50, default=30, space="buy", optimize=True, load=True)
|
exit_short_rsi = IntParameter(low=1, high=50, default=30, space="buy", optimize=True, load=True)
|
||||||
|
|
||||||
def feature_engineering_expand_all(
|
def feature_engineering_expand_all(
|
||||||
self, dataframe: DataFrame, period: int, metadata: Dict, **kwargs
|
self, dataframe: DataFrame, period: int, metadata: dict, **kwargs
|
||||||
) -> DataFrame:
|
) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
@@ -151,7 +150,7 @@ class FreqaiExampleHybridStrategy(IStrategy):
|
|||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def feature_engineering_expand_basic(
|
def feature_engineering_expand_basic(
|
||||||
self, dataframe: DataFrame, metadata: Dict, **kwargs
|
self, dataframe: DataFrame, metadata: dict, **kwargs
|
||||||
) -> DataFrame:
|
) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
@@ -185,7 +184,7 @@ class FreqaiExampleHybridStrategy(IStrategy):
|
|||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def feature_engineering_standard(
|
def feature_engineering_standard(
|
||||||
self, dataframe: DataFrame, metadata: Dict, **kwargs
|
self, dataframe: DataFrame, metadata: dict, **kwargs
|
||||||
) -> DataFrame:
|
) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
@@ -212,7 +211,7 @@ class FreqaiExampleHybridStrategy(IStrategy):
|
|||||||
dataframe["%-hour_of_day"] = dataframe["date"].dt.hour
|
dataframe["%-hour_of_day"] = dataframe["date"].dt.hour
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs) -> DataFrame:
|
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.
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from typing import Dict
|
|
||||||
|
|
||||||
import talib.abstract as ta
|
import talib.abstract as ta
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
@@ -46,7 +45,7 @@ class FreqaiExampleStrategy(IStrategy):
|
|||||||
can_short = True
|
can_short = True
|
||||||
|
|
||||||
def feature_engineering_expand_all(
|
def feature_engineering_expand_all(
|
||||||
self, dataframe: DataFrame, period: int, metadata: Dict, **kwargs
|
self, dataframe: DataFrame, period: int, metadata: dict, **kwargs
|
||||||
) -> DataFrame:
|
) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
@@ -103,7 +102,7 @@ class FreqaiExampleStrategy(IStrategy):
|
|||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def feature_engineering_expand_basic(
|
def feature_engineering_expand_basic(
|
||||||
self, dataframe: DataFrame, metadata: Dict, **kwargs
|
self, dataframe: DataFrame, metadata: dict, **kwargs
|
||||||
) -> DataFrame:
|
) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
@@ -141,7 +140,7 @@ class FreqaiExampleStrategy(IStrategy):
|
|||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def feature_engineering_standard(
|
def feature_engineering_standard(
|
||||||
self, dataframe: DataFrame, metadata: Dict, **kwargs
|
self, dataframe: DataFrame, metadata: dict, **kwargs
|
||||||
) -> DataFrame:
|
) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
*Only functional with FreqAI enabled strategies*
|
*Only functional with FreqAI enabled strategies*
|
||||||
@@ -172,7 +171,7 @@ class FreqaiExampleStrategy(IStrategy):
|
|||||||
dataframe["%-hour_of_day"] = dataframe["date"].dt.hour
|
dataframe["%-hour_of_day"] = dataframe["date"].dt.hour
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs) -> DataFrame:
|
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.
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from math import exp
|
from math import exp
|
||||||
from typing import Dict
|
|
||||||
|
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
|
|
||||||
@@ -41,7 +40,7 @@ class SampleHyperOptLoss(IHyperOptLoss):
|
|||||||
min_date: datetime,
|
min_date: datetime,
|
||||||
max_date: datetime,
|
max_date: datetime,
|
||||||
config: Config,
|
config: Config,
|
||||||
processed: Dict[str, DataFrame],
|
processed: dict[str, DataFrame],
|
||||||
*args,
|
*args,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> float:
|
) -> float:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import Callable, List, Optional, Union
|
from typing import Callable, Optional, Union
|
||||||
|
|
||||||
from rich.console import ConsoleRenderable, Group, RichCast
|
from rich.console import ConsoleRenderable, Group, RichCast
|
||||||
from rich.progress import Progress
|
from rich.progress import Progress
|
||||||
@@ -8,8 +8,8 @@ class CustomProgress(Progress):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*args,
|
*args,
|
||||||
cust_objs: Optional[List[ConsoleRenderable]] = None,
|
cust_objs: Optional[list[ConsoleRenderable]] = None,
|
||||||
cust_callables: Optional[List[Callable[[], ConsoleRenderable]]] = None,
|
cust_callables: Optional[list[Callable[[], ConsoleRenderable]]] = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> None:
|
) -> None:
|
||||||
self._cust_objs = cust_objs or []
|
self._cust_objs = cust_objs or []
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
from typing import Any, Dict, List, Optional, Sequence, Union
|
from collections.abc import Sequence
|
||||||
|
from typing import Any, Optional, Union
|
||||||
|
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
@@ -11,12 +12,12 @@ TextOrString = Union[str, Text]
|
|||||||
|
|
||||||
|
|
||||||
def print_rich_table(
|
def print_rich_table(
|
||||||
tabular_data: Sequence[Union[Dict[str, Any], Sequence[TextOrString]]],
|
tabular_data: Sequence[Union[dict[str, Any], Sequence[TextOrString]]],
|
||||||
headers: Sequence[str],
|
headers: Sequence[str],
|
||||||
summary: Optional[str] = None,
|
summary: Optional[str] = None,
|
||||||
*,
|
*,
|
||||||
justify="right",
|
justify="right",
|
||||||
table_kwargs: Optional[Dict[str, Any]] = None,
|
table_kwargs: Optional[dict[str, Any]] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
table = Table(
|
table = Table(
|
||||||
*[c if isinstance(c, Column) else Column(c, justify=justify) for c in headers],
|
*[c if isinstance(c, Column) else Column(c, justify=justify) for c in headers],
|
||||||
@@ -34,7 +35,7 @@ def print_rich_table(
|
|||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
row_to_add: List[Union[str, Text]] = [r if isinstance(r, Text) else str(r) for r in row]
|
row_to_add: list[Union[str, Text]] = [r if isinstance(r, Text) else str(r) for r in row]
|
||||||
table.add_row(*row_to_add)
|
table.add_row(*row_to_add)
|
||||||
|
|
||||||
width = None
|
width = None
|
||||||
@@ -58,7 +59,7 @@ def print_df_rich_table(
|
|||||||
*,
|
*,
|
||||||
show_index=False,
|
show_index=False,
|
||||||
index_name: Optional[str] = None,
|
index_name: Optional[str] = None,
|
||||||
table_kwargs: Optional[Dict[str, Any]] = None,
|
table_kwargs: Optional[dict[str, Any]] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
table = Table(title=summary, **(table_kwargs or {}))
|
table = Table(title=summary, **(table_kwargs or {}))
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
Jinja2 rendering utils, used to generate new strategy and configurations.
|
Jinja2 rendering utils, used to generate new strategy and configurations.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Dict, Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
def render_template(templatefile: str, arguments: Dict) -> str:
|
def render_template(templatefile: str, arguments: dict) -> str:
|
||||||
from jinja2 import Environment, PackageLoader, select_autoescape
|
from jinja2 import Environment, PackageLoader, select_autoescape
|
||||||
|
|
||||||
env = Environment(
|
env = Environment(
|
||||||
@@ -17,7 +17,7 @@ def render_template(templatefile: str, arguments: Dict) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def render_template_with_fallback(
|
def render_template_with_fallback(
|
||||||
templatefile: str, templatefallbackfile: str, arguments: Optional[Dict] = None
|
templatefile: str, templatefallbackfile: str, arguments: Optional[dict] = None
|
||||||
) -> str:
|
) -> str:
|
||||||
"""
|
"""
|
||||||
Use templatefile if possible, otherwise fall back to templatefallbackfile
|
Use templatefile if possible, otherwise fall back to templatefallbackfile
|
||||||
|
|||||||
Reference in New Issue
Block a user