diff --git a/infertrade/_version.py b/infertrade/_version.py index 02b00a71..f9583986 100644 --- a/infertrade/_version.py +++ b/infertrade/_version.py @@ -18,4 +18,4 @@ File for storing current version of package. """ -__version__ = "0.0.61" +__version__ = "0.0.62" diff --git a/infertrade/api.py b/infertrade/api.py index 539904ac..5b55235a 100644 --- a/infertrade/api.py +++ b/infertrade/api.py @@ -159,8 +159,11 @@ def _get_raw_callable(name_of_strategy_or_signal: str) -> callable: @staticmethod def calculate_allocations( - df: pd.DataFrame, name_of_strategy: str, name_of_price_series: str = PandasEnum.MID.value, - allocation_lower_limit: float = -1.0, allocation_upper_limit: float = 1.0 + df: pd.DataFrame, + name_of_strategy: str, + name_of_price_series: str = PandasEnum.MID.value, + allocation_lower_limit: float = -1.0, + allocation_upper_limit: float = 1.0, ) -> pd.DataFrame: """Calculates the allocations using the supplied strategy.""" if name_of_price_series is not PandasEnum.MID.value: diff --git a/infertrade/base.py b/infertrade/base.py index 4a445526..75767a44 100644 --- a/infertrade/base.py +++ b/infertrade/base.py @@ -27,6 +27,7 @@ # TODO - migrate last function to utilities. + def get_signal_calc(func: callable, adapter: callable = None) -> callable or pd.DataFrame: """An adapter to calculate a signal prior to usage within a trading rule.""" if adapter: diff --git a/infertrade/utilities/operations.py b/infertrade/utilities/operations.py index 87779db7..2f2f81ef 100644 --- a/infertrade/utilities/operations.py +++ b/infertrade/utilities/operations.py @@ -617,7 +617,7 @@ def calculate_regression_with_kelly_optimum( if volatility < recent_fractional_realised_vol: volatility = recent_fractional_realised_vol - + # Absolute floor for volatility at 0.01% == 1bp minimum_volatility = 0.0001 if volatility < minimum_volatility: diff --git a/tests/test_allocations.py b/tests/test_allocations.py index e922f565..0e73cfee 100644 --- a/tests/test_allocations.py +++ b/tests/test_allocations.py @@ -122,4 +122,3 @@ def test_all_allocations_list_required_series(): """Checks that all allocation rules list required series.""" for ii_rule in Api.available_algorithms(filter_by_category="allocation"): assert isinstance(Api.required_inputs_for_algorithm(ii_rule), list) - diff --git a/tests/test_api.py b/tests/test_api.py index 945c4683..889850b7 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -174,8 +174,8 @@ def test_return_representations(algorithm): ) for representation in dict_of_properties[algorithm]["available_representation_types"]: assert ( - returned_representations[representation] - == dict_of_properties[algorithm]["available_representation_types"][representation] + returned_representations[representation] + == dict_of_properties[algorithm]["available_representation_types"][representation] ) # Check if the if the function returns the correct representation when given a string @@ -187,8 +187,8 @@ def test_return_representations(algorithm): type(returned_representations), ) assert ( - returned_representations[representation] - == dict_of_properties[algorithm]["available_representation_types"][representation] + returned_representations[representation] + == dict_of_properties[algorithm]["available_representation_types"][representation] ) # Check if the function returns the correct representations when given a list @@ -200,8 +200,8 @@ def test_return_representations(algorithm): ) for representation in algorithm_representations: assert ( - returned_representations[representation] - == dict_of_properties[algorithm]["available_representation_types"][representation] + returned_representations[representation] + == dict_of_properties[algorithm]["available_representation_types"][representation] ) @@ -367,15 +367,21 @@ def test_allocation_limit(test_df): test_df_copy = copy.deepcopy(test_df) df_with_allocations = Api.calculate_allocations( - df=test_df_copy, name_of_strategy=available_allocation_algorithms[0], name_of_price_series="close", - allocation_lower_limit=0, allocation_upper_limit=0 + df=test_df_copy, + name_of_strategy=available_allocation_algorithms[0], + name_of_price_series="close", + allocation_lower_limit=0, + allocation_upper_limit=0, ) if not all(df_with_allocations["allocation"] == 0.0): raise ValueError("Allocation limits breached") df_with_allocations = Api.calculate_allocations( - df=test_df_copy, name_of_strategy=available_allocation_algorithms[0], name_of_price_series="close", - allocation_lower_limit=-0.1, allocation_upper_limit=0.1 + df=test_df_copy, + name_of_strategy=available_allocation_algorithms[0], + name_of_price_series="close", + allocation_lower_limit=-0.1, + allocation_upper_limit=0.1, ) if any(-0.1 > df_with_allocations["allocation"]) or any(df_with_allocations["allocation"] > 0.1): raise ValueError("Allocation limits breached")