mirror of
https://github.com/wassname/pandas-ta.git
synced 2026-08-15 12:45:08 +08:00
ENH CAGR added to util metrics
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user