def pvt(close, volume, drift=None, offset=None, **kwargs): """Indicator: Price-Volume Trend (PVT)""" # Validate arguments close = verify_series(close) volume = verify_series(volume) drift = get_drift(drift) offset = get_offset(offset) # Calculate Result pv = roc(close=close, length=drift) * volume pvt = pv.cumsum() # Offset if offset != 0: pvt = pvt.shift(offset) # Handle fills if "fillna" in kwargs: pvt.fillna(kwargs["fillna"], inplace=True) if "fill_method" in kwargs: pvt.fillna(method=kwargs["fill_method"], inplace=True) # Name and Categorize it pvt.name = f"PVT" pvt.category = "volume" return pvt
def nvi(close, volume, length=None, initial=None, offset=None, **kwargs): """Indicator: Negative Volume Index (NVI)""" # Validate arguments close = verify_series(close) volume = verify_series(volume) length = int(length) if length and length > 0 else 1 min_periods = int( kwargs["min_periods"]) if "min_periods" in kwargs and kwargs[ "min_periods"] is not None else length initial = int(initial) if initial and initial > 0 else 1000 offset = get_offset(offset) # Calculate Result roc_ = roc(close=close, length=length) signed_volume = signed_series(volume, initial=1) nvi = signed_volume[signed_volume < 0].abs() * roc_ nvi.fillna(0, inplace=True) nvi.iloc[0] = initial nvi = nvi.cumsum() # Offset if offset != 0: nvi = nvi.shift(offset) # Handle fills if "fillna" in kwargs: nvi.fillna(kwargs["fillna"], inplace=True) if "fill_method" in kwargs: nvi.fillna(method=kwargs["fill_method"], inplace=True) # Name and Categorize it nvi.name = f"NVI_{length}" nvi.category = "volume" return nvi
def pvi(close, volume, length=None, initial=None, offset=None, **kwargs): """Indicator: Positive Volume Index (PVI)""" # Validate arguments length = int(length) if length and length > 0 else 1 # min_periods = int(kwargs["min_periods"]) if "min_periods" in kwargs and kwargs["min_periods"] is not None else length initial = int(initial) if initial and initial > 0 else 1000 close = verify_series(close, length) volume = verify_series(volume, length) offset = get_offset(offset) if close is None or volume is None: return # Calculate Result signed_volume = signed_series(volume, 1) pvi = roc(close=close, length=length) * signed_volume[signed_volume > 0].abs() pvi.fillna(0, inplace=True) pvi.iloc[0] = initial pvi = pvi.cumsum() # Offset if offset != 0: pvi = pvi.shift(offset) # Handle fills if "fillna" in kwargs: pvi.fillna(kwargs["fillna"], inplace=True) if "fill_method" in kwargs: pvi.fillna(method=kwargs["fill_method"], inplace=True) # Name and Categorize it pvi.name = f"PVI_{length}" pvi.category = "volume" return pvi