mirror of
https://github.com/wassname/pandas-ta.git
synced 2026-06-27 16:10:07 +08:00
BLD + ta.adjusted property & updated example nb
This commit is contained in:
@@ -121,7 +121,9 @@ data/datas.csv
|
||||
data/SPY_5min.csv
|
||||
data/SPY_1min.csv
|
||||
data/tulip.csv
|
||||
examples/taplot.py
|
||||
examples/ib_trader.ipynb
|
||||
examples/example2.ipynb
|
||||
setup.cfg
|
||||
.README.md
|
||||
README
|
||||
|
||||
@@ -6,15 +6,24 @@ Technical Analysis (TA) is an easy to use library that is built upon Python's Pa
|
||||
This version contains both the orignal code branch as well as a newly refactored branch with the option to use [Pandas DataFrame Extension](https://pandas.pydata.org/pandas-docs/stable/extending.html) mode.
|
||||
All the indicators return a named Series or a DataFrame in uppercase underscore parameter format. For example, MACD(fast=12, slow=26, signal=9) will return a DataFrame with columns: ['MACD_12_26_9', 'MACDH_12_26_9', 'MACDS_12_26_9'].
|
||||
|
||||
## New Changes
|
||||
|
||||
## Features
|
||||
|
||||
* Over 80 indicators.
|
||||
* __*Updated*__ Example Jupyter Notebook under the examples directory.
|
||||
* Example Jupyter Notebook under the examples directory.
|
||||
* Abbreviated Indicator names as listed below.
|
||||
* *Extended Pandas DataFrame* as 'ta'. See examples below.
|
||||
* Parameter names are more consistent.
|
||||
* Refactoring indicators into categories similar to [TA-lib](https://github.com/mrjbq7/ta-lib/tree/master/docs/func_groups).
|
||||
|
||||
|
||||
## Recent Changes
|
||||
|
||||
* Updated the example notebook.
|
||||
* Trend Return, ```ta.trend_return()```, has a proper index. More consistent with the module.
|
||||
* Added an 'adjusted' property to the 'ta' extension so you can override the default 'close' column. By default, ```df.ta.adjusted = None```. If the adjusted close column is 'adj_close' for example, then set ```df.ta.adjusted = 'adj_close'```.
|
||||
|
||||
|
||||
### What is a Pandas DataFrame Extension?
|
||||
|
||||
A [Pandas DataFrame Extension](https://pandas.pydata.org/pandas-docs/stable/extending.html), extends a DataFrame allowing one to add more functionality and features to Pandas to suit your needs. As such, it is now easier to run Technical Analysis on existing Financial Time Series without leaving the current DataFrame. This extension by default returns the Indicator result or, inclusively, it can append the result to the existing DataFrame by including the parameter
|
||||
@@ -77,6 +86,17 @@ help(pd.DataFrame().ta.log_return)
|
||||
```
|
||||
|
||||
|
||||
## New ta DataFrame Property: *adjusted*
|
||||
|
||||
```python
|
||||
# Set ta to default to an adjusted column, 'adj_close', overriding default 'close'
|
||||
df.ta.adjusted = 'adj_close'
|
||||
df.ta.sma(length=10, append=True)
|
||||
|
||||
# To reset back to 'close', set adjusted back to None
|
||||
df.ta.adjusted = None
|
||||
```
|
||||
|
||||
|
||||
# Technical Analysis Indicators (by Category)
|
||||
|
||||
|
||||
+466
-408
File diff suppressed because one or more lines are too long
+21
-3
@@ -96,6 +96,8 @@ class AnalysisIndicators(BasePandasObject):
|
||||
>>> apo = df.ta(kind='apo', timed=True)
|
||||
>>> print(apo.timed)
|
||||
"""
|
||||
_adjusted = None
|
||||
|
||||
def __call__(self, kind=None, alias=None, timed=False, **kwargs):
|
||||
try:
|
||||
if isinstance(kind, str):
|
||||
@@ -126,6 +128,18 @@ class AnalysisIndicators(BasePandasObject):
|
||||
self.help()
|
||||
|
||||
|
||||
@property
|
||||
def adjusted(self) -> str:
|
||||
"""property: df.ta.adjusted"""
|
||||
return self._adjusted
|
||||
|
||||
@adjusted.setter
|
||||
def adjusted(self, value:str) -> None:
|
||||
if value is not None and isinstance(value, str):
|
||||
self._adjusted = value
|
||||
else:
|
||||
self._adjusted = None
|
||||
|
||||
def _append(self, result=None, **kwargs):
|
||||
"""Appends a Pandas Series or DataFrame columns to self._df."""
|
||||
if 'append' in kwargs and kwargs['append']:
|
||||
@@ -149,7 +163,7 @@ class AnalysisIndicators(BasePandasObject):
|
||||
return series
|
||||
# Apply default if no series nor a default.
|
||||
elif series is None or default is None:
|
||||
return df[default]
|
||||
return df[self.adjusted] if self.adjusted is not None else df[default]
|
||||
# Ok. So it's a str.
|
||||
elif isinstance(series, str):
|
||||
# Return the df column since it's in there.
|
||||
@@ -204,7 +218,8 @@ class AnalysisIndicators(BasePandasObject):
|
||||
def indicators(self, **kwargs):
|
||||
"""Indicator list"""
|
||||
header = f"pandas.ta - Technical Analysis Indicators"
|
||||
helper_methods = ['indicators', 'constants'] # Public non-indicator methods
|
||||
helper_methods = ['indicators', 'constants'] # Public non-indicator methods
|
||||
ta_properties = ['adjusted']
|
||||
exclude_methods = kwargs.pop('exclude', None)
|
||||
as_list = kwargs.pop('as_list', False)
|
||||
ta_indicators = list((x for x in dir(pd.DataFrame().ta) if not x.startswith('_') and not x.endswith('_')))
|
||||
@@ -212,6 +227,9 @@ class AnalysisIndicators(BasePandasObject):
|
||||
for x in helper_methods:
|
||||
ta_indicators.remove(x)
|
||||
|
||||
for x in ta_properties:
|
||||
ta_indicators.remove(x)
|
||||
|
||||
if isinstance(exclude_methods, list) and exclude_methods in ta_indicators and len(exclude_methods) > 0:
|
||||
for x in exclude_methods:
|
||||
ta_indicators.remove(x)
|
||||
@@ -592,7 +610,7 @@ class AnalysisIndicators(BasePandasObject):
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
def trend_return(self, close=None, trend=None, log=None, cumulative=None, offset=None, trend_reset=None, **kwargs):
|
||||
def trend_return(self, close=None, trend=None, log=True, cumulative=None, offset=None, trend_reset=None, **kwargs):
|
||||
close = self._get_column(close, 'close')
|
||||
trend = self._get_column(trend, f"{trend}")
|
||||
from pandas_ta.performance.trend_return import trend_return
|
||||
|
||||
@@ -4,7 +4,7 @@ from .log_return import log_return
|
||||
from .percent_return import percent_return
|
||||
from ..utils import get_offset, verify_series, zero
|
||||
|
||||
def trend_return(close, trend, log=None, cumulative=None, offset=None, trend_reset=0, **kwargs):
|
||||
def trend_return(close, trend, log=True, cumulative=None, offset=None, trend_reset=0, **kwargs):
|
||||
"""Indicator: Trend Return"""
|
||||
# Validate Arguments
|
||||
close = verify_series(close)
|
||||
@@ -31,7 +31,7 @@ def trend_return(close, trend, log=None, cumulative=None, offset=None, trend_res
|
||||
tsum = return_
|
||||
result.append(tsum)
|
||||
|
||||
trend_return = Series(result)
|
||||
trend_return = Series(result, index=close.index)
|
||||
|
||||
# Offset
|
||||
if offset != 0:
|
||||
|
||||
@@ -6,7 +6,7 @@ long_description = "An easy to use Python 3 Pandas Extension with 80+ Technical
|
||||
setup(
|
||||
name ="pandas_ta",
|
||||
packages =['pandas_ta', 'pandas_ta.momentum', 'pandas_ta.overlap', 'pandas_ta.performance', 'pandas_ta.statistics', 'pandas_ta.trend', 'pandas_ta.volatility', 'pandas_ta.volume'],
|
||||
version ="0.1.35b",
|
||||
version ="0.1.36b",
|
||||
description =long_description,
|
||||
long_description =long_description,
|
||||
author ="Kevin Johnson",
|
||||
|
||||
Reference in New Issue
Block a user