mirror of
https://github.com/wassname/pandas-ta.git
synced 2026-06-27 16:10:07 +08:00
Added lookahead interface to ichimoku and dpo indicators
Indicators with potential data leak should handle lookahead=False kwargs
This commit is contained in:
@@ -85,7 +85,7 @@ _Pandas Technical Analysis_ (**Pandas TA**) is an easy to use library that lever
|
||||
* Have the need for speed? By using the DataFrame _strategy_ method, you get **multiprocessing** for free! __Conditions permitting__.
|
||||
* Easily add _prefixes_ or _suffixes_ or _both_ to columns names. Useful for Custom Chained Strategies.
|
||||
* Example Jupyter Notebooks under the [examples](https://github.com/twopirllc/pandas-ta/tree/main/examples) directory, including how to create Custom Strategies using the new [__Strategy__ Class](https://github.com/twopirllc/pandas-ta/tree/main/examples/PandaTA_Strategy_Examples.ipynb)
|
||||
* Potential Data Leaks: **ichimoku** and **dpo**. See indicator list below for details.
|
||||
* Potential Data Leaks: **ichimoku** and **dpo**. See indicator list below for details. Set ```lookahead=False``` to disable.
|
||||
|
||||
<br/>
|
||||
|
||||
@@ -733,7 +733,7 @@ df = df.ta.cdl_pattern(name=["doji", "inside"])
|
||||
* _Holt-Winter Moving Average_: **hwma**
|
||||
* _Ichimoku Kinkō Hyō_: **ichimoku**
|
||||
* Returns two DataFrames. For more information: ```help(ta.ichimoku)```.
|
||||
* Drop the Chikou Span Column, the final column of the first resultant DataFrame, remove potential data leak.
|
||||
* ```lookahead=False``` drops the Chikou Span Column to prevent potential data leak.
|
||||
* _Kaufman's Adaptive Moving Average_: **kama**
|
||||
* _Linear Regression_: **linreg**
|
||||
* _McGinley Dynamic_: **mcgd**
|
||||
@@ -807,7 +807,7 @@ Use parameter: cumulative=**True** for cumulative results.
|
||||
* Formally: **linear_decay**
|
||||
* _Decreasing_: **decreasing**
|
||||
* _Detrended Price Oscillator_: **dpo**
|
||||
* Set ```centered=False``` to remove potential data leak.
|
||||
* Set ```lookahead=False``` to disable centering and remove potential data leak.
|
||||
* _Increasing_: **increasing**
|
||||
* _Long Run_: **long_run**
|
||||
* _Parabolic Stop and Reverse_: **psar**
|
||||
|
||||
+2
-2
@@ -1196,11 +1196,11 @@ class AnalysisIndicators(BasePandasObject):
|
||||
result = kama(close=close, length=length, fast=fast, slow=slow, offset=offset, **kwargs)
|
||||
return self._post_process(result, **kwargs)
|
||||
|
||||
def ichimoku(self, tenkan=None, kijun=None, senkou=None, offset=None, **kwargs):
|
||||
def ichimoku(self, tenkan=None, kijun=None, senkou=None, include_chikou=True, offset=None, **kwargs):
|
||||
high = self._get_column(kwargs.pop("high", "high"))
|
||||
low = self._get_column(kwargs.pop("low", "low"))
|
||||
close = self._get_column(kwargs.pop("close", "close"))
|
||||
result, span = ichimoku(high=high, low=low, close=close, tenkan=tenkan, kijun=kijun, senkou=senkou, offset=offset, **kwargs)
|
||||
result, span = ichimoku(high=high, low=low, close=close, tenkan=tenkan, kijun=kijun, senkou=senkou, include_chikou=include_chikou, offset=offset, **kwargs)
|
||||
self._add_prefix_suffix(result, **kwargs)
|
||||
self._add_prefix_suffix(span, **kwargs)
|
||||
self._append(result, **kwargs)
|
||||
|
||||
@@ -4,7 +4,7 @@ from .midprice import midprice
|
||||
from pandas_ta.utils import get_offset, verify_series
|
||||
|
||||
|
||||
def ichimoku(high, low, close, tenkan=None, kijun=None, senkou=None, offset=None, **kwargs):
|
||||
def ichimoku(high, low, close, tenkan=None, kijun=None, senkou=None, include_chikou=True, offset=None, **kwargs):
|
||||
"""Indicator: Ichimoku Kinkō Hyō (Ichimoku)"""
|
||||
tenkan = int(tenkan) if tenkan and tenkan > 0 else 9
|
||||
kijun = int(kijun) if kijun and kijun > 0 else 26
|
||||
@@ -14,6 +14,8 @@ def ichimoku(high, low, close, tenkan=None, kijun=None, senkou=None, offset=None
|
||||
low = verify_series(low, _length)
|
||||
close = verify_series(close, _length)
|
||||
offset = get_offset(offset)
|
||||
if not kwargs.get("lookahead", True):
|
||||
include_chikou = False
|
||||
|
||||
if high is None or low is None or close is None: return None, None
|
||||
|
||||
@@ -65,8 +67,10 @@ def ichimoku(high, low, close, tenkan=None, kijun=None, senkou=None, offset=None
|
||||
span_b.name: span_b,
|
||||
tenkan_sen.name: tenkan_sen,
|
||||
kijun_sen.name: kijun_sen,
|
||||
chikou_span.name: chikou_span,
|
||||
}
|
||||
if include_chikou:
|
||||
data[chikou_span.name] = chikou_span
|
||||
|
||||
ichimokudf = DataFrame(data)
|
||||
ichimokudf.name = f"ICHIMOKU_{tenkan}_{kijun}_{senkou}"
|
||||
ichimokudf.category = "overlap"
|
||||
@@ -121,6 +125,7 @@ Args:
|
||||
tenkan (int): Tenkan period. Default: 9
|
||||
kijun (int): Kijun period. Default: 26
|
||||
senkou (int): Senkou period. Default: 52
|
||||
include_chikou (bool): Whether to include chikou component. Default: True
|
||||
offset (int): How many periods to offset the result. Default: 0
|
||||
|
||||
Kwargs:
|
||||
|
||||
@@ -9,6 +9,8 @@ def dpo(close, length=None, centered=True, offset=None, **kwargs):
|
||||
length = int(length) if length and length > 0 else 20
|
||||
close = verify_series(close, length)
|
||||
offset = get_offset(offset)
|
||||
if not kwargs.get("lookahead", True):
|
||||
centered = False
|
||||
|
||||
if close is None: return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user