stockstats
stockstats copied to clipboard
The way computing VR is wrong?
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.
self[column_name] = (avs + cvs / 2) / (bvs + cvs / 2) * 100
Also this returns non-stable value when bvs and cvs are 0's.