mirror of
https://github.com/wassname/pandas-ta.git
synced 2026-08-10 12:30:38 +08:00
ENH added indicator Weighted Closing Price (wcp)
This commit is contained in:
@@ -23,6 +23,7 @@ All the indicators return a named Series or a DataFrame in uppercase underscore
|
||||
- __KDJ__ (kdj)
|
||||
- __Parabolic Stop and Reverse__ (psar)
|
||||
- __Psycholigical Line__ (psl)
|
||||
- __Weighted Closing Price__ (wcp)
|
||||
* User Added Indicators:
|
||||
- __Aberration__ (aberration)
|
||||
- __BRAR__ (brar)
|
||||
@@ -148,7 +149,7 @@ df.ta.adjusted = None
|
||||
|:--------:|
|
||||
|  |
|
||||
|
||||
## _Overlap_ (24)
|
||||
## _Overlap_ (25)
|
||||
|
||||
* _Double Exponential Moving Average_: **dema**
|
||||
* _Exponential Moving Average_: **ema**
|
||||
@@ -174,6 +175,7 @@ df.ta.adjusted = None
|
||||
* _Triangular Moving Average_: **trima**
|
||||
* _Volume Weighted Average Price_: **vwap**
|
||||
* _Volume Weighted Moving Average_: **vwma**
|
||||
* _Weighted Closing Price_: **wcp**
|
||||
* _Weighted Moving Average_: **wma**
|
||||
* _Zero Lag Moving Average_: **zlma**
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ from .overlap.tema import tema
|
||||
from .overlap.trima import trima
|
||||
from .overlap.vwap import vwap
|
||||
from .overlap.vwma import vwma
|
||||
from .overlap.wcp import wcp
|
||||
from .overlap.wma import wma
|
||||
from .overlap.zlma import zlma
|
||||
|
||||
|
||||
@@ -627,6 +627,15 @@ class AnalysisIndicators(BasePandasObject):
|
||||
self._append(result, **kwargs)
|
||||
return result
|
||||
|
||||
def wcp(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')
|
||||
from .overlap.wcp import wcp
|
||||
result = wcp(high=high, low=low, close=close, 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')
|
||||
from .overlap.wma import wma
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from ..utils import get_offset, verify_series
|
||||
|
||||
def wcp(high, low, close, offset=None, **kwargs):
|
||||
"""Indicator: WCP"""
|
||||
# Validate Arguments
|
||||
high = verify_series(high)
|
||||
low = verify_series(low)
|
||||
close = verify_series(close)
|
||||
offset = get_offset(offset)
|
||||
|
||||
# Calculate Result
|
||||
wcp = (high + low + 2 * close) / 4
|
||||
|
||||
# Offset
|
||||
if offset != 0:
|
||||
wcp = wcp.shift(offset)
|
||||
|
||||
# Name & Category
|
||||
wcp.name = "WCP"
|
||||
wcp.category = 'overlap'
|
||||
|
||||
return wcp
|
||||
@@ -6,7 +6,7 @@ long_description = "An easy to use Python 3 Pandas Extension with 95+ 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.42b",
|
||||
version ="0.1.43b",
|
||||
description =long_description,
|
||||
long_description =long_description,
|
||||
author ="Kevin Johnson",
|
||||
|
||||
@@ -298,6 +298,21 @@ class TestOverlap(TestCase):
|
||||
self.assertIsInstance(result, Series)
|
||||
self.assertEqual(result.name, 'VWMA_10')
|
||||
|
||||
def test_wcp(self):
|
||||
result = pandas_ta.wcp(self.high, self.low, self.close)
|
||||
self.assertIsInstance(result, Series)
|
||||
self.assertEqual(result.name, 'WCP')
|
||||
|
||||
try:
|
||||
expected = tal.WCLPRICE(self.high, self.low, self.close)
|
||||
pdt.assert_series_equal(result, expected, check_names=False)
|
||||
except AssertionError as ae:
|
||||
try:
|
||||
corr = pandas_ta.utils.df_error_analysis(result, expected, col=CORRELATION)
|
||||
self.assertGreater(corr, CORRELATION_THRESHOLD)
|
||||
except Exception as ex:
|
||||
error_analysis(result, CORRELATION, ex)
|
||||
|
||||
def test_wma(self):
|
||||
result = pandas_ta.wma(self.close)
|
||||
self.assertIsInstance(result, Series)
|
||||
|
||||
@@ -133,6 +133,11 @@ class TestOverlapExtension(TestCase):
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'VWMA_10')
|
||||
|
||||
def test_wcp_ext(self):
|
||||
self.data.ta.wcp(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
self.assertEqual(self.data.columns[-1], 'WCP')
|
||||
|
||||
def test_wma_ext(self):
|
||||
self.data.ta.wma(append=True)
|
||||
self.assertIsInstance(self.data, DataFrame)
|
||||
|
||||
Reference in New Issue
Block a user