ENH CAGR added to util metrics

This commit is contained in:
Kevin Johnson
2020-09-30 15:35:33 -07:00
parent cfe54c68bb
commit 52e8e1da88
4 changed files with 43 additions and 1 deletions
+4
View File
@@ -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
+9
View File
@@ -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
+1 -1
View File
@@ -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",
+29
View File
@@ -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)