mirror of
https://github.com/wassname/pandas-ta.git
synced 2026-06-27 16:10:07 +08:00
added overlap indicators and tests
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
init:
|
||||
pip install -r requirements.txt
|
||||
|
||||
test:
|
||||
python3 -m unittest discover -v
|
||||
@@ -68,6 +68,34 @@ help(pd.DataFrame().ta.log_return)
|
||||
|
||||
# Technical Analysis Indicators (by Category)
|
||||
|
||||
## _Overlap_ (19)
|
||||
|
||||
* _Double Exponential Moving Average_: **dema**
|
||||
* _Exponential Moving Average_: **ema**
|
||||
* _Fibonacci's Weighted Moving Average_: **fwma**
|
||||
* _High-Low Average_: **hl2**
|
||||
* _High-Low-Close Average_: **hlc3**
|
||||
* Commonly known as 'Typical Price' in Technical Analysis literature
|
||||
* _Hull Exponential Moving Average_: **hma**
|
||||
* _Ichimoku Kinkō Hyō_: **ichimoku**
|
||||
* Use: help(ta.ichimoku). Returns two DataFrames.
|
||||
* _Midpoint_: **midpoint**
|
||||
* _Midprice_: **midprice**
|
||||
* _Open-High-Low-Close Average_: **ohlc4**
|
||||
* _Pascal's Weighted Moving Average_: **pwma**
|
||||
* _William's Moving Average_: **rma**
|
||||
* _Simple Moving Average_: **sma**
|
||||
* _T3 Moving Average_: **t3**
|
||||
* _Triple Exponential Moving Average_: **tema**
|
||||
* _Triangular Moving Average_: **trima**
|
||||
* _Volume Weighted Average Price_: **vwap**
|
||||
* _Volume Weighted Moving Average_: **vwma**
|
||||
* _Weighted Moving Average_: **wma**
|
||||
|
||||
| _Simple Moving Averages_ (SMA) and _Bollinger Bands_ (BBANDS) |
|
||||
|:--------:|
|
||||
|  |
|
||||
|
||||
## _Performance_ (2)
|
||||
|
||||
Use parameter: cumulative=**True** for cumulative results.
|
||||
@@ -81,6 +109,7 @@ Use parameter: cumulative=**True** for cumulative results.
|
||||
|
||||
|
||||
# Inspiration
|
||||
Inspired by Bukosabino: https://github.com/bukosabino/ta
|
||||
* Original TA-LIB http://ta-lib.org/
|
||||
* Bukosabino: https://github.com/bukosabino/ta
|
||||
|
||||
Please leave any comments, feedback, or suggestions.
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
name = "pandas_ta"
|
||||
"""
|
||||
.. moduleauthor:: Kevin Johnson
|
||||
|
||||
+154
-3
@@ -3,8 +3,9 @@ import time
|
||||
import pandas as pd
|
||||
from pandas.core.base import PandasObject
|
||||
|
||||
from .utils import *
|
||||
from .overlap import *
|
||||
from .performance import *
|
||||
from .utils import *
|
||||
|
||||
|
||||
class BasePandasObject(PandasObject):
|
||||
@@ -229,9 +230,159 @@ class AnalysisIndicators(BasePandasObject):
|
||||
else:
|
||||
print(s)
|
||||
|
||||
|
||||
|
||||
|
||||
# Overlap Indicators
|
||||
def dema(self, close=None, length=None, offset=None, **kwargs):
|
||||
close = self._get_column(close, 'close')
|
||||
result = dema(close=close, length=length, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def ema(self, close=None, length=None, offset=None, adjust=None, **kwargs):
|
||||
close = self._get_column(close, 'close')
|
||||
result = ema(close=close, length=length, offset=offset, adjust=adjust, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def fwma(self, close=None, length=None, offset=None, **kwargs):
|
||||
close = self._get_column(close, 'close')
|
||||
result = fwma(close=close, length=length, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def hl2(self, high=None, low=None, offset=None, **kwargs):
|
||||
high = self._get_column(high, 'high')
|
||||
low = self._get_column(low, 'low')
|
||||
result = hl2(high=high, low=low, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def hlc3(self, high=None, low=None, close=None, offset=None, **kwargs):
|
||||
high = self._get_column(high, 'high')
|
||||
low = self._get_column(low, 'low')
|
||||
close = self._get_column(close, 'close')
|
||||
result = hlc3(high=high, low=low, close=close, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def hma(self, close=None, length=None, offset=None, **kwargs):
|
||||
close = self._get_column(close, 'close')
|
||||
result = hma(close=close, length=length, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def ichimoku(self, high=None, low=None, close=None, tenkan=None, kijun=None, senkou=None, offset=None, **kwargs):
|
||||
high = self._get_column(high, 'high')
|
||||
low = self._get_column(low, 'low')
|
||||
close = self._get_column(close, 'close')
|
||||
# result, span = ichimoku(high=high, low=low, close=close, tenkan=tenkan, kijun=kijun, senkou=senkou, offset=offset, **kwargs)
|
||||
result = ichimoku(high=high, low=low, close=close, tenkan=tenkan, kijun=kijun, senkou=senkou, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
# return result, span
|
||||
return result
|
||||
|
||||
|
||||
def midpoint(self, close=None, length=None, offset=None, **kwargs):
|
||||
close = self._get_column(close, 'close')
|
||||
result = midpoint(close=close, length=length, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def midprice(self, high=None, low=None, length=None, offset=None, **kwargs):
|
||||
high = self._get_column(high, 'high')
|
||||
low = self._get_column(low, 'low')
|
||||
result = midprice(high=high, low=low, length=length, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def ohlc4(self, open_=None, high=None, low=None, close=None, offset=None, **kwargs):
|
||||
open_ = self._get_column(open_, 'open')
|
||||
high = self._get_column(high, 'high')
|
||||
low = self._get_column(low, 'low')
|
||||
close = self._get_column(close, 'close')
|
||||
result = ohlc4(open_=open_, high=high, low=low, close=close, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def pwma(self, close=None, length=None, offset=None, **kwargs):
|
||||
close = self._get_column(close, 'close')
|
||||
result = pwma(close=close, length=length, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def rma(self, close=None, length=None, offset=None, **kwargs):
|
||||
close = self._get_column(close, 'close')
|
||||
result = rma(close=close, length=length, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def sma(self, close=None, length=None, offset=None, **kwargs):
|
||||
close = self._get_column(close, 'close')
|
||||
result = sma(close=close, length=length, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def t3(self, close=None, length=None, a=None, offset=None, **kwargs):
|
||||
close = self._get_column(close, 'close')
|
||||
result = t3(close=close, length=length, a=a, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def tema(self, close=None, length=None, offset=None, **kwargs):
|
||||
close = self._get_column(close, 'close')
|
||||
result = tema(close=close, length=length, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def trima(self, close=None, length=None, offset=None, **kwargs):
|
||||
close = self._get_column(close, 'close')
|
||||
result = trima(close=close, length=length, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def vwap(self, high=None, low=None, close=None, volume=None, offset=None, **kwargs):
|
||||
high = self._get_column(high, 'high')
|
||||
low = self._get_column(low, 'low')
|
||||
close = self._get_column(close, 'close')
|
||||
volume = self._get_column(volume, 'volume')
|
||||
result = vwap(high=high, low=low, close=close, volume=volume, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def vwma(self, close=None, volume=None, length=None, offset=None, **kwargs):
|
||||
close = self._get_column(close, 'close')
|
||||
volume = self._get_column(volume, 'volume')
|
||||
result = vwma(close=close, volume=close, length=length, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
def wma(self, close=None, length=None, offset=None, **kwargs):
|
||||
close = self._get_column(close, 'close')
|
||||
result = wma(close=close, length=length, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
# Performance Indicators
|
||||
def log_return(self, close=None, length=None, cumulative=False, percent=False, offset=None, **kwargs):
|
||||
close = self._get_column(close, 'close')
|
||||
result = log_return(close=close, length=length, cumulative=cumulative, percent=percent, offset=offset, **kwargs)
|
||||
@@ -244,4 +395,4 @@ class AnalysisIndicators(BasePandasObject):
|
||||
close = self._get_column(close, 'close')
|
||||
result = percent_return(close=close, length=length, cumulative=cumulative, percent=percent, offset=offset, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
return result
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+26
-1
@@ -27,10 +27,29 @@ def combination(**kwargs):
|
||||
return numerator // denominator
|
||||
|
||||
|
||||
def df_error_analysis(dfA, dfB, **kwargs):
|
||||
""" """
|
||||
corr_method = kwargs.pop('corr_method', 'pearson')
|
||||
|
||||
# Find their differences
|
||||
diff = dfA - dfB
|
||||
df = pd.DataFrame({'diff': diff.describe()})
|
||||
extra = pd.DataFrame([diff.var(), diff.mad(), diff.sem(), dfA.corr(dfB, method=corr_method)], index=['var', 'mad', 'sem', 'corr'])
|
||||
|
||||
# Append the differences to the DataFrame
|
||||
df = df['diff'].append(extra, ignore_index=False)[0]
|
||||
|
||||
# For plotting
|
||||
# diff.hist()
|
||||
# if diff[diff > 0].any():
|
||||
# diff.plot(kind='kde')
|
||||
|
||||
return df
|
||||
|
||||
def fibonacci(**kwargs):
|
||||
"""Fibonacci Sequence as a numpy array"""
|
||||
n = int(math.fabs(kwargs.pop('n', 2)))
|
||||
zero = kwargs.pop('zero', True)
|
||||
zero = kwargs.pop('zero', False)
|
||||
weighted = kwargs.pop('weighted', False)
|
||||
|
||||
if zero:
|
||||
@@ -71,6 +90,7 @@ def pascals_triangle(**kwargs):
|
||||
"""
|
||||
n = int(math.fabs(kwargs.pop('n', 0)))
|
||||
weighted = kwargs.pop('weighted', False)
|
||||
inverse = kwargs.pop('inverse', False)
|
||||
sink = kwargs.pop('all', False)
|
||||
|
||||
# Calculation
|
||||
@@ -88,6 +108,11 @@ def pascals_triangle(**kwargs):
|
||||
if sink:
|
||||
return triangle, triangle_sum, triangle_avg, inverted, weights, inv_weights, triangle_avg
|
||||
if weighted:
|
||||
# Needs to be fixed: n=3 => [1, 2, 1], t=4
|
||||
# weighted: [1/4, 2/4, 1/4]
|
||||
#
|
||||
# if inverse:
|
||||
# return inv_weights
|
||||
return weights
|
||||
else:
|
||||
return triangle
|
||||
|
||||
@@ -6,7 +6,7 @@ long_description = "A Python 3 Pandas Extension of Technical Analysis Indicators
|
||||
setup(
|
||||
name = "pandas_ta",
|
||||
packages = ["pandas_ta"],
|
||||
version = "0.0.4a",
|
||||
version = "0.0.5a",
|
||||
description=long_description,
|
||||
long_description=long_description,
|
||||
author = "Kevin Johnson",
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
|
||||
import pandas_ta
|
||||
@@ -0,0 +1,4 @@
|
||||
from pandas import read_csv
|
||||
|
||||
CORRELATION_THRESHOLD = 0.99 # Less than 0.99 is undesirable
|
||||
sample_data = read_csv('data/sample.csv', index_col=0, parse_dates=True, infer_datetime_format=False, keep_date_col=True)
|
||||
@@ -0,0 +1,227 @@
|
||||
from .context import pandas_ta
|
||||
from .data import sample_data, CORRELATION_THRESHOLD
|
||||
|
||||
from unittest import TestCase, skip
|
||||
import pandas.util.testing as pdt
|
||||
from pandas import DataFrame, Series
|
||||
|
||||
import talib as tal
|
||||
|
||||
VERBOSE = False
|
||||
|
||||
|
||||
class TestOverlap(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.data = sample_data
|
||||
cls.open = cls.data['open']
|
||||
cls.high = cls.data['high']
|
||||
cls.low = cls.data['low']
|
||||
cls.close = cls.data['close']
|
||||
cls.volume = cls.data['volume']
|
||||
cls.correlation_threshold = CORRELATION_THRESHOLD
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
del cls.data
|
||||
del cls.open
|
||||
del cls.high
|
||||
del cls.low
|
||||
del cls.close
|
||||
del cls.volume
|
||||
|
||||
|
||||
def setUp(self):
|
||||
self.overlap = pandas_ta.overlap
|
||||
|
||||
def tearDown(self):
|
||||
del self.overlap
|
||||
|
||||
|
||||
def test_dema(self):
|
||||
dema = self.overlap.dema(self.close)
|
||||
self.assertIsInstance(dema, Series)
|
||||
self.assertEqual(dema.name, 'DEMA_10')
|
||||
|
||||
try:
|
||||
tal_dema = tal.DEMA(self.close, 10)
|
||||
pdt.assert_series_equal(dema, tal_dema, check_names=False)
|
||||
except AssertionError as ae:
|
||||
analysis = pandas_ta.utils.df_error_analysis(dema, tal_dema)
|
||||
print(f"\nanalysis['corr']: {round(analysis['corr'], 3)}") if VERBOSE else None
|
||||
if analysis['corr'] < self.correlation_threshold:
|
||||
raise AssertionError(f"dema has low correlation: {analysis['corr']}")
|
||||
|
||||
def test_ema(self):
|
||||
ema = self.overlap.ema(self.close, presma=False)
|
||||
self.assertIsInstance(ema, Series)
|
||||
self.assertEqual(ema.name, 'EMA_10')
|
||||
|
||||
try:
|
||||
tal_ema = tal.EMA(self.close, 10)
|
||||
pdt.assert_series_equal(ema, tal_ema, check_names=False)
|
||||
except AssertionError as ae:
|
||||
analysis = pandas_ta.utils.df_error_analysis(ema, tal_ema)
|
||||
print(f"\nanalysis['corr']: {analysis['corr']}") if VERBOSE else None
|
||||
if analysis['corr'] < self.correlation_threshold:
|
||||
raise AssertionError(f"ema has low correlation: {analysis['corr']}")
|
||||
|
||||
def test_fwma(self):
|
||||
fwma = self.overlap.fwma(self.close)
|
||||
self.assertIsInstance(fwma, Series)
|
||||
self.assertEqual(fwma.name, 'FWMA_10')
|
||||
|
||||
def test_hl2(self):
|
||||
hl2 = self.overlap.hl2(self.high, self.low)
|
||||
self.assertIsInstance(hl2, Series)
|
||||
self.assertEqual(hl2.name, 'HL2')
|
||||
|
||||
def test_hlc3(self):
|
||||
hlc3 = self.overlap.hlc3(self.high, self.low, self.close)
|
||||
self.assertIsInstance(hlc3, Series)
|
||||
self.assertEqual(hlc3.name, 'HLC3')
|
||||
|
||||
try:
|
||||
tal_typicalprice = tal.TYPPRICE(self.high, self.low, self.close)
|
||||
pdt.assert_series_equal(hlc3, tal_typicalprice, check_names=False)
|
||||
except AssertionError as ae:
|
||||
analysis = pandas_ta.utils.df_error_analysis(hlc3, tal_typicalprice)
|
||||
print(f"\nanalysis['corr']: {analysis['corr']}") if VERBOSE else None
|
||||
if analysis['corr'] < self.correlation_threshold:
|
||||
raise AssertionError(f"hlc3/typicalprice has low correlation: {analysis['corr']}")
|
||||
|
||||
def test_hma(self):
|
||||
hma = self.overlap.hma(self.close)
|
||||
self.assertIsInstance(hma, Series)
|
||||
self.assertEqual(hma.name, 'HMA_10')
|
||||
|
||||
# @skip("close index requires Daily dates")
|
||||
def test_ichimoku(self):
|
||||
ichimoku = self.overlap.ichimoku(self.high, self.low, self.close)
|
||||
self.assertIsInstance(ichimoku, DataFrame)
|
||||
self.assertEqual(ichimoku.name, 'ICHIMOKU_9_26_52')
|
||||
|
||||
def test_midpoint(self):
|
||||
# talib.MIDPOINT(timeperiod >= 2)
|
||||
midpoint = self.overlap.midpoint(self.close)
|
||||
self.assertIsInstance(midpoint, Series)
|
||||
self.assertEqual(midpoint.name, 'MIDPOINT_2')
|
||||
|
||||
try:
|
||||
tal_midpoint = tal.MIDPOINT(self.close, 2)
|
||||
pdt.assert_series_equal(midpoint, tal_midpoint, check_names=False)
|
||||
except AssertionError as ae:
|
||||
analysis = pandas_ta.utils.df_error_analysis(midpoint, tal_midpoint)
|
||||
print(f"\nanalysis['corr']: {analysis['corr']}") if VERBOSE else None
|
||||
if analysis['corr'] < self.correlation_threshold:
|
||||
raise AssertionError(f"midpoint has low correlation: {analysis['corr']}")
|
||||
|
||||
def test_midprice(self):
|
||||
# talib.MIDPRICE(timeperiod >= 2)
|
||||
midprice = self.overlap.midprice(self.high, self.low)
|
||||
self.assertIsInstance(midprice, Series)
|
||||
self.assertEqual(midprice.name, 'MIDPRICE_2')
|
||||
|
||||
try:
|
||||
tal_midprice = tal.MIDPRICE(self.high, self.low, 2)
|
||||
pdt.assert_series_equal(midprice, tal_midprice, check_names=False)
|
||||
except AssertionError as ae:
|
||||
analysis = pandas_ta.utils.df_error_analysis(midprice, tal_midprice)
|
||||
print(f"\nanalysis['corr']: {analysis['corr']}") if VERBOSE else None
|
||||
if analysis['corr'] < self.correlation_threshold:
|
||||
raise AssertionError(f"midprice has low correlation: {analysis['corr']}")
|
||||
|
||||
def test_ohlc4(self):
|
||||
ohlc4 = self.overlap.ohlc4(self.open, self.high, self.low, self.close)
|
||||
self.assertIsInstance(ohlc4, Series)
|
||||
self.assertEqual(ohlc4.name, 'OHLC4')
|
||||
|
||||
def test_pwma(self):
|
||||
pwma = self.overlap.pwma(self.close)
|
||||
self.assertIsInstance(pwma, Series)
|
||||
self.assertEqual(pwma.name, 'PWMA_10')
|
||||
|
||||
def test_rma(self):
|
||||
rma = self.overlap.rma(self.close)
|
||||
self.assertIsInstance(rma, Series)
|
||||
self.assertEqual(rma.name, 'RMA_10')
|
||||
|
||||
def test_sma(self):
|
||||
sma = self.overlap.sma(self.close)
|
||||
self.assertIsInstance(sma, Series)
|
||||
self.assertEqual(sma.name, 'SMA_10')
|
||||
|
||||
try:
|
||||
tal_sma = tal.SMA(self.close, 10)
|
||||
pdt.assert_series_equal(sma, tal_sma, check_names=False)
|
||||
except AssertionError as ae:
|
||||
analysis = pandas_ta.utils.df_error_analysis(sma, tal_sma)
|
||||
print(f"\nanalysis['corr']: {analysis['corr']}") if VERBOSE else None
|
||||
if analysis['corr'] < self.correlation_threshold:
|
||||
raise AssertionError(f"sma has low correlation: {analysis['corr']}")
|
||||
|
||||
def test_t3(self):
|
||||
t3 = self.overlap.t3(self.close)
|
||||
self.assertIsInstance(t3, Series)
|
||||
self.assertEqual(t3.name, 'T3_10_0.7')
|
||||
|
||||
try:
|
||||
tal_t3 = tal.T3(self.close, 10)
|
||||
pdt.assert_series_equal(t3, tal_t3, check_names=False)
|
||||
except AssertionError as ae:
|
||||
analysis = pandas_ta.utils.df_error_analysis(t3, tal_t3)
|
||||
print(f"\nanalysis['corr']: {analysis['corr']}") if VERBOSE else None
|
||||
if analysis['corr'] < self.correlation_threshold:
|
||||
raise AssertionError(f"t3 has low correlation: {analysis['corr']}")
|
||||
|
||||
def test_tema(self):
|
||||
tema = self.overlap.tema(self.close)
|
||||
self.assertIsInstance(tema, Series)
|
||||
self.assertEqual(tema.name, 'TEMA_10')
|
||||
|
||||
try:
|
||||
tal_tema = tal.TEMA(self.close, 10)
|
||||
pdt.assert_series_equal(tema, tal_tema, check_names=False)
|
||||
except AssertionError as ae:
|
||||
analysis = pandas_ta.utils.df_error_analysis(tema, tal_tema)
|
||||
print(f"\nanalysis['corr']: {analysis['corr']}") if VERBOSE else None
|
||||
if analysis['corr'] < self.correlation_threshold:
|
||||
raise AssertionError(f"tema has low correlation: {analysis['corr']}")
|
||||
|
||||
def test_trima(self):
|
||||
trima = self.overlap.trima(self.close)
|
||||
self.assertIsInstance(trima, Series)
|
||||
self.assertEqual(trima.name, 'TRIMA_10')
|
||||
|
||||
try:
|
||||
tal_trima = tal.TRIMA(self.close, 10)
|
||||
pdt.assert_series_equal(trima, tal_trima, check_names=False)
|
||||
except AssertionError as ae:
|
||||
analysis = pandas_ta.utils.df_error_analysis(trima, tal_trima)
|
||||
print(f"\nanalysis['corr']: {analysis['corr']}") if VERBOSE else None
|
||||
if analysis['corr'] < self.correlation_threshold:
|
||||
raise AssertionError(f"trima has low correlation: {analysis['corr']}")
|
||||
|
||||
def test_vwap(self):
|
||||
vwap = self.overlap.vwap(self.high, self.low, self.close, self.volume)
|
||||
self.assertIsInstance(vwap, Series)
|
||||
self.assertEqual(vwap.name, 'VWAP')
|
||||
|
||||
def test_vwma(self):
|
||||
vwma = self.overlap.vwma(self.close, self.volume)
|
||||
self.assertIsInstance(vwma, Series)
|
||||
self.assertEqual(vwma.name, 'VWMA_10')
|
||||
|
||||
def test_wma(self):
|
||||
wma = self.overlap.wma(self.close)
|
||||
self.assertIsInstance(wma, Series)
|
||||
self.assertEqual(wma.name, 'WMA_10')
|
||||
|
||||
try:
|
||||
tal_wma = tal.WMA(self.close, 10)
|
||||
pdt.assert_series_equal(wma, tal_wma, check_names=False)
|
||||
except AssertionError as ae:
|
||||
analysis = pandas_ta.utils.df_error_analysis(wma, tal_wma)
|
||||
print(f"\nanalysis['corr']: {analysis['corr']}") if VERBOSE else None
|
||||
if analysis['corr'] < self.correlation_threshold:
|
||||
raise AssertionError(f"wma has low correlation: {analysis['corr']}")
|
||||
@@ -0,0 +1,123 @@
|
||||
from .context import pandas_ta
|
||||
from .data import sample_data
|
||||
|
||||
from unittest import TestCase
|
||||
from pandas import DataFrame
|
||||
|
||||
|
||||
|
||||
class TestOverlapExtension(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.data = sample_data
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
del cls.data
|
||||
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
|
||||
def test_dema_ext(self):
|
||||
self.data.ta.dema(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'DEMA_10')
|
||||
|
||||
def test_ema_ext(self):
|
||||
self.data.ta.ema(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'EMA_10')
|
||||
|
||||
def test_fwma_ext(self):
|
||||
self.data.ta.fwma(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'FWMA_10')
|
||||
|
||||
def test_hl2_ext(self):
|
||||
self.data.ta.hl2(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'HL2')
|
||||
|
||||
def test_hlc3_ext(self):
|
||||
self.data.ta.hlc3(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'HLC3')
|
||||
|
||||
def test_hma_ext(self):
|
||||
self.data.ta.hma(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'HMA_10')
|
||||
|
||||
def test_ichimoku_ext(self):
|
||||
self.data.ta.ichimoku(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-5], 'ISA_9')
|
||||
self.assertEqual(self.data.columns[-4], 'ISB_26')
|
||||
self.assertEqual(self.data.columns[-3], 'ITS_9')
|
||||
self.assertEqual(self.data.columns[-2], 'IKS_26')
|
||||
self.assertEqual(self.data.columns[-1], 'ICS_26')
|
||||
|
||||
def test_midpoint_ext(self):
|
||||
self.data.ta.midpoint(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'MIDPOINT_2')
|
||||
|
||||
def test_midprice_ext(self):
|
||||
self.data.ta.midprice(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'MIDPRICE_2')
|
||||
|
||||
def test_ohlc4_ext(self):
|
||||
self.data.ta.ohlc4(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'OHLC4')
|
||||
|
||||
def test_pwma_ext(self):
|
||||
self.data.ta.pwma(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'PWMA_10')
|
||||
|
||||
def test_rma_ext(self):
|
||||
self.data.ta.rma(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'RMA_10')
|
||||
|
||||
def test_sma_ext(self):
|
||||
self.data.ta.sma(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'SMA_10')
|
||||
|
||||
def test_t3_ext(self):
|
||||
self.data.ta.t3(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'T3_10_0.7')
|
||||
|
||||
def test_tema_ext(self):
|
||||
self.data.ta.tema(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'TEMA_10')
|
||||
|
||||
def test_trima_ext(self):
|
||||
self.data.ta.trima(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'TRIMA_10')
|
||||
|
||||
def test_vwap_ext(self):
|
||||
self.data.ta.vwap(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'VWAP')
|
||||
|
||||
def test_vwma_ext(self):
|
||||
self.data.ta.vwma(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'VWMA_10')
|
||||
|
||||
def test_wma_ext(self):
|
||||
self.data.ta.wma(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'WMA_10')
|
||||
@@ -1,15 +1,15 @@
|
||||
from unittest import TestCase
|
||||
import numpy.testing as npt
|
||||
import pandas.util.testing as pdt
|
||||
from pandas import DataFrame, read_csv, Series
|
||||
from .context import pandas_ta
|
||||
from .data import sample_data
|
||||
|
||||
from unittest import TestCase
|
||||
from pandas import Series
|
||||
|
||||
from pandas_ta import performance
|
||||
|
||||
|
||||
class TestPerformace(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.data = read_csv('data/sample.csv', index_col=0, parse_dates=True, infer_datetime_format=False, keep_date_col=True)
|
||||
cls.data = sample_data
|
||||
cls.close = cls.data['close']
|
||||
|
||||
@classmethod
|
||||
@@ -19,7 +19,7 @@ class TestPerformace(TestCase):
|
||||
|
||||
|
||||
def setUp(self):
|
||||
self.performance = performance
|
||||
self.performance = pandas_ta.performance
|
||||
|
||||
def tearDown(self):
|
||||
del self.performance
|
||||
@@ -39,5 +39,4 @@ class TestPerformace(TestCase):
|
||||
self.assertEqual(percent_return.name, 'PCTRET_1')
|
||||
|
||||
cumpercent_return = self.performance.percent_return(self.close, cumulative=True)
|
||||
self.assertEqual(cumpercent_return.name, 'CUMPCTRET_1')
|
||||
|
||||
self.assertEqual(cumpercent_return.name, 'CUMPCTRET_1')
|
||||
@@ -1,21 +1,21 @@
|
||||
from unittest import TestCase
|
||||
import numpy.testing as npt
|
||||
import pandas.util.testing as pdt
|
||||
from pandas import DataFrame, read_csv, Series
|
||||
from .context import pandas_ta
|
||||
from .data import sample_data
|
||||
|
||||
from unittest import TestCase
|
||||
# import numpy.testing as npt
|
||||
# import pandas.util.testing as pdt
|
||||
from pandas import DataFrame#, Series
|
||||
|
||||
import pandas_ta as ta
|
||||
|
||||
|
||||
class TestPerformaceExtension(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.data = read_csv('data/sample.csv', index_col=0, parse_dates=True, infer_datetime_format=False, keep_date_col=True)
|
||||
cls.close = cls.data['close']
|
||||
cls.data = sample_data
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
del cls.data
|
||||
del cls.close
|
||||
|
||||
|
||||
def setUp(self):
|
||||
@@ -41,9 +41,4 @@ class TestPerformaceExtension(TestCase):
|
||||
|
||||
self.data.ta.percent_return(append=True, cumulative=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'CUMPCTRET_1')
|
||||
|
||||
# Example
|
||||
# pta_sma = self.data[self.data.columns[-1]]
|
||||
# tal_sma = tal.SMA(self.close)
|
||||
# pdt.assert_series_equal(pta_sma, tal_sma)
|
||||
self.assertEqual(self.data.columns[-1], 'CUMPCTRET_1')
|
||||
+3
-2
@@ -1,4 +1,4 @@
|
||||
from pandas_ta import utils as utils
|
||||
from .context import pandas_ta
|
||||
|
||||
from unittest import TestCase
|
||||
from unittest.mock import patch
|
||||
@@ -7,9 +7,10 @@ import numpy as np
|
||||
import numpy.testing as npt
|
||||
from pandas import DataFrame
|
||||
|
||||
|
||||
class TestUtilities(TestCase):
|
||||
def setUp(self):
|
||||
self.utils = utils
|
||||
self.utils = pandas_ta.utils
|
||||
|
||||
def tearDown(self):
|
||||
del self.utils
|
||||
|
||||
Reference in New Issue
Block a user