forked from twopirllc/pandas-ta
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into main
- Loading branch information
Showing
90 changed files
with
1,182 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# -*- coding: utf-8 -*- | ||
from pandas_ta.overlap import sma | ||
from pandas_ta.utils import get_offset, verify_series | ||
|
||
# - Standard definition of your custom indicator function (including docs)- | ||
|
||
def ni(close, length=None, centered=False, offset=None, **kwargs): | ||
""" | ||
Example indicator ni | ||
""" | ||
# Validate Arguments | ||
length = int(length) if length and length > 0 else 20 | ||
close = verify_series(close, length) | ||
offset = get_offset(offset) | ||
|
||
if close is None: return | ||
|
||
# Calculate Result | ||
t = int(0.5 * length) + 1 | ||
ma = sma(close, length) | ||
|
||
ni = close - ma.shift(t) | ||
if centered: | ||
ni = (close.shift(t) - ma).shift(-t) | ||
|
||
# Offset | ||
if offset != 0: | ||
ni = ni.shift(offset) | ||
|
||
# Handle fills | ||
if "fillna" in kwargs: | ||
ni.fillna(kwargs["fillna"], inplace=True) | ||
if "fill_method" in kwargs: | ||
ni.fillna(method=kwargs["fill_method"], inplace=True) | ||
|
||
# Name and Categorize it | ||
ni.name = f"ni_{length}" | ||
ni.category = "trend" | ||
|
||
return ni | ||
|
||
ni.__doc__ = \ | ||
"""Example indicator (NI) | ||
Is an indicator provided solely as an example | ||
Sources: | ||
https://github.com/twopirllc/pandas-ta/issues/264 | ||
Calculation: | ||
Default Inputs: | ||
length=20, centered=False | ||
SMA = Simple Moving Average | ||
t = int(0.5 * length) + 1 | ||
ni = close.shift(t) - SMA(close, length) | ||
if centered: | ||
ni = ni.shift(-t) | ||
Args: | ||
close (pd.Series): Series of 'close's | ||
length (int): It's period. Default: 20 | ||
centered (bool): Shift the ni back by int(0.5 * length) + 1. Default: False | ||
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. | ||
""" | ||
|
||
# - Define a matching class method -------------------------------------------- | ||
|
||
def ni_method(self, length=None, offset=None, **kwargs): | ||
close = self._get_column(kwargs.pop("close", "close")) | ||
result = ni(close=close, length=length, offset=offset, **kwargs) | ||
return self._post_process(result, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.