linear_decay indicator added

This commit is contained in:
Kevin Johnson
2019-05-21 10:54:07 -07:00
parent aa07f72093
commit 4cd4dd372d
7 changed files with 81 additions and 2 deletions
+2 -1
View File
@@ -163,7 +163,7 @@ Use parameter: cumulative=**True** for cumulative results.
|:--------:|
| ![Example Z Score](/images/SPY_ZScore.png) |
## _Trend_ (10)
## _Trend_ (11)
* _Average Directional Movement Index_: **adx**
* _Archer Moving Averages Trends_: **amat**
@@ -171,6 +171,7 @@ Use parameter: cumulative=**True** for cumulative results.
* _Decreasing_: **decreasing**
* _Detrended Price Oscillator_: **dpo**
* _Increasing_: **increasing**
* _Linear Decay_: **linear_decay**
* _Long Run_: **long_run**
* _Q Stick_: **qstick**
* _Short Run_: **short_run**
+1
View File
@@ -83,6 +83,7 @@ from .trend.aroon import aroon
from .trend.decreasing import decreasing
from .trend.dpo import dpo
from .trend.increasing import increasing
from .trend.linear_decay import linear_decay
from .trend.long_run import long_run
from .trend.qstick import qstick
from .trend.short_run import short_run
+7
View File
@@ -660,6 +660,13 @@ class AnalysisIndicators(BasePandasObject):
self._append(result, **kwargs)
return result
def linear_decay(self, close=None, length=None, offset=None, **kwargs):
close = self._get_column(close, 'close')
from .trend.linear_decay import linear_decay
result = linear_decay(close=close, length=length, offset=offset, **kwargs)
self._append(result, **kwargs)
return result
def long_run(self, fast=None, slow=None, length=None, offset=None, **kwargs):
if fast is None and slow is None: return self._df
else:
+60
View File
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
from pandas import DataFrame
from ..utils import get_offset, verify_series
def linear_decay(close, length=None, offset=None, **kwargs):
"""Indicator: Linear Decay"""
# Validate Arguments
close = verify_series(close)
length = int(length) if length and length > 0 else 5
offset = get_offset(offset)
# Calculate Result
diff = close.shift(1) - (1 / length)
diff[0] = close[0]
tdf = DataFrame({'close': close, 'diff': diff, '0': 0})
ld = tdf.max(axis=1)
# Offset
if offset != 0:
ld = ld.shift(offset)
# Handle fills
if 'fillna' in kwargs:
ld.fillna(kwargs['fillna'], inplace=True)
if 'fill_method' in kwargs:
ld.fillna(method=kwargs['fill_method'], inplace=True)
# Name and Categorize it
ld.name = f"LDECAY_{length}"
ld.category = 'trend'
return ld
linear_decay.__doc__ = \
"""Linear Decay
Adds a linear decay moving forward from prior signals like crosses.
Sources:
https://tulipindicators.org/decay
Calculation:
Default Inputs:
length=5
max(close, close[-1] - (1 / length), 0)
Args:
close (pd.Series): Series of 'close's
length (int): It's period. Default: 1
offset (int): How many periods to offset the result. Default: 0
Kwargs:
fillna (value, optional): pd.DataFrame.fillna(value)
fill_method (value, optional): Type of fill method
Returns:
pd.Series: New feature generated.
"""
+1 -1
View File
@@ -6,7 +6,7 @@ long_description = "An easy to use Python 3 Pandas Extension of Technical Analys
setup(
name = "pandas_ta",
packages = ["pandas_ta"],
version = "0.1.25b",
version = "0.1.26b",
description=long_description,
long_description=long_description,
author = "Kevin Johnson",
+5
View File
@@ -91,6 +91,11 @@ class TestTrend(TestCase):
self.assertIsInstance(result, Series)
self.assertEqual(result.name, 'INC_1')
def test_linear_decay(self):
result = pandas_ta.linear_decay(self.close)
self.assertIsInstance(result, Series)
self.assertEqual(result.name, 'LDECAY_5')
def test_long_run(self):
result = pandas_ta.long_run(self.close, self.open)
self.assertIsInstance(result, Series)
+5
View File
@@ -53,6 +53,11 @@ class TestTrendExtension(TestCase):
self.assertIsInstance(self.data, DataFrame)
self.assertEqual(self.data.columns[-1], 'INC_1')
def test_linear_decay_ext(self):
self.data.ta.linear_decay(append=True)
self.assertIsInstance(self.data, DataFrame)
self.assertEqual(self.data.columns[-1], 'LDECAY_5')
def test_long_run_ext(self):
# Nothing passed, return self
self.assertEqual(self.data.ta.long_run(append=True).shape, self.data.shape)