mirror of
https://github.com/wassname/pandas-ta.git
synced 2026-09-09 11:28:26 +08:00
ENH #163 Adding Price Volume indicator, missing file
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from pandas_ta.momentum import roc
|
||||
from pandas_ta.utils import get_offset, signed_series, verify_series
|
||||
from numpy import nan as npNaN
|
||||
from pandas import Series
|
||||
|
||||
|
||||
def pvr(close, volume):
|
||||
""" Indicator: Price Volume Rank"""
|
||||
# Validate arguments
|
||||
close = verify_series(close)
|
||||
volume = verify_series(volume)
|
||||
|
||||
# Calculate Result
|
||||
close_diff = close.diff().fillna(0)
|
||||
volume_diff = volume.diff().fillna(0)
|
||||
pvr_ = Series(npNaN, index=close.index)
|
||||
pvr_.loc[(close_diff >= 0) & (volume_diff >= 0)] = 1
|
||||
pvr_.loc[(close_diff >= 0) & (volume_diff < 0)] = 2
|
||||
pvr_.loc[(close_diff < 0) & (volume_diff >= 0)] = 3
|
||||
pvr_.loc[(close_diff < 0) & (volume_diff < 0)] = 4
|
||||
|
||||
# Name and Categorize it
|
||||
pvr_.name = f"PVR"
|
||||
pvr_.category = "volume"
|
||||
|
||||
return pvr_
|
||||
|
||||
pvr.__doc__ = \
|
||||
"""Price Volume Rank
|
||||
|
||||
The Price Volume Rank was developed as a simple indicator that could be calculated even without a computer. The basic interpretation is to buy when the PV Rank is below 2.5 and sell when it is above 2.5.
|
||||
The Price Volume Rank was developed by Anthony J. Macek and is described in his article in the June, 19994 issue of Technical Analysis of Stocks & Commodities magazine.
|
||||
|
||||
Sources:
|
||||
https://www.fmlabs.com/reference/default.htm?url=PVrank.htm
|
||||
|
||||
Calculation:
|
||||
if 'close change' >= 0 and 'volume change' >= 0
|
||||
return 1
|
||||
if 'close change' >= 0 and 'volume change' < 0
|
||||
return 2
|
||||
if 'close change' < 0 and 'volume change' >= 0
|
||||
return 3
|
||||
if 'close change' < 0 and 'volume change' < 0
|
||||
return 4
|
||||
Args:
|
||||
close (pd.Series): Series of 'close's
|
||||
volume (pd.Series): Series of 'volume's
|
||||
|
||||
Returns:
|
||||
pd.Series: New feature generated.
|
||||
"""
|
||||
Reference in New Issue
Block a user