diff --git a/Makefile b/Makefile index 883041d..bfd9a8e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ .PHONY: all all: make test_utils + make test_metrics make test_ta make test_ext make test_strats @@ -17,6 +18,9 @@ init: test_ext: python -m unittest -v tests/test_ext_indicator_*.py +test_metrics: + python -m unittest -v tests/test_utils_metrics.py + test_strats: python -m unittest -v tests/test_strategy.py diff --git a/pandas_ta/utils/_metrics.py b/pandas_ta/utils/_metrics.py index d8be264..6791ece 100644 --- a/pandas_ta/utils/_metrics.py +++ b/pandas_ta/utils/_metrics.py @@ -1,2 +1,11 @@ # -*- coding: utf-8 -*- from pandas import DataFrame, Series + +from ._core import verify_series +from ._time import total_time + +def cagr(close: Series) -> float: + """Compounded Annual Growth Rate""" + close = verify_series(close) + start, end = close.iloc[0], close.iloc[-1] + return ((end / start) ** (1 / total_time(close))) - 1 \ No newline at end of file diff --git a/setup.py b/setup.py index 35396a0..7a5ea08 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ long_description = "An easy to use Python 3 Pandas Extension with 115+ Technical setup( name ="pandas_ta", packages =["pandas_ta", "pandas_ta.candles", "pandas_ta.momentum", "pandas_ta.overlap", "pandas_ta.performance", "pandas_ta.statistics", "pandas_ta.trend", "pandas_ta.utils", "pandas_ta.volatility", "pandas_ta.volume"], - version =".".join(("0", "2", "17b")), + version =".".join(("0", "2", "18b")), description =long_description, long_description =long_description, author ="Kevin Johnson", diff --git a/tests/test_utils_metrics.py b/tests/test_utils_metrics.py new file mode 100644 index 0000000..1f1aafe --- /dev/null +++ b/tests/test_utils_metrics.py @@ -0,0 +1,29 @@ +from .config import sample_data +from .context import pandas_ta + +from unittest import skip, TestCase +from unittest.mock import patch + +# import numpy as np +# import numpy.testing as npt +# from pandas import DataFrame, Series + +class TestUtilityMetrics(TestCase): + @classmethod + def setUpClass(cls): + cls.data = sample_data + + @classmethod + def tearDownClass(cls): + del cls.data + + def setUp(self): + self.utils = pandas_ta.utils + + def tearDown(self): + del self.utils + + def test_cagr(self): + result = pandas_ta.utils.cagr(self.data.close) + self.assertIsInstance(result, float) + self.assertGreater(result, 0) \ No newline at end of file