jealous / stockstats

Supply a wrapper ``StockDataFrame`` based on the ``pandas.DataFrame`` with inline stock statistics/indicators support.
Other
1.3k stars 299 forks source link

The way computing VR is wrong? #115

Open GuangLightman opened 2 years ago

GuangLightman commented 2 years ago
    def _get_vr(self, windows=None):
        if windows is None:
            window = self.VR
            column_name = 'vr'
        else:
            window = self.get_int_positive(windows)
            column_name = 'vr_{}'.format(window)

        idx = self.index
        gt_zero = np.where(self['change'] > 0, self['volume'], 0)
        av = pd.Series(gt_zero, index=idx)
        avs = self._mov_sum(av, window)

        lt_zero = np.where(self['change'] < 0, self['volume'], 0)
        bv = pd.Series(lt_zero, index=idx)
        bvs = self._mov_sum(bv, window)

        eq_zero = np.where(self['change'] == 0, self['volume'], 0)
        cv = pd.Series(eq_zero, index=idx)
        cvs = self._mov_sum(cv, window)

        self[column_name] = (avs + cvs / 2) / (bvs + cvs / 2) * 100

According to https://help.eaglesmarkets.com/hc/en-us/articles/900002867026-Summary-of-volume-variation-index

CV = n-day trading volume of stock price in n days; CVS = n-day ∑ cv

So cvs = _mov_sum(self['volume'], window) but not cvs = self._mov_sum(pd.Series(eq_zero, index=idx), window) I don't think there is a reason to look at 'change'==0 cases as they are quite rare.

GuangLightman commented 2 years ago
 self[column_name] = (avs + cvs / 2) / (bvs + cvs / 2) * 100

Also this returns non-stable value when bvs and cvs are 0's.