Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Negative Volume Index can be computed without for loop #284

Open
cristiangreco94 opened this issue Jan 31, 2022 · 0 comments
Open

Comments

@cristiangreco94
Copy link

Suggested implementation

class NegativeVolumeIndexIndicator(IndicatorMixin):

def __init__(self, close: pd.Series, volume: pd.Series, fillna: bool = False):
    self._close = close
    self._volume = volume
    self._fillna = fillna
    self._run()

def _run(self):
    price_change = self._close.pct_change()
    vol_decrease = self._volume.shift(1) > self._volume
    nvi = np.where( 
        vol_decrease, 1+price_change , 1
     )
    nvi[0] = 1000.
    self._nvi = pd.Series(
        data=nvi.cumprod(), index=self._close.index, dtype="float64", name="nvi"
    )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant