Skip to content

Commit 8d74f58

Browse files
committed
2 new indicators
1 parent ec9ddb1 commit 8d74f58

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

docs/source/indicators.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ Typical Price
184184
...
185185
186186
187+
PVT (Price Volume Trend)
188+
------------------------
189+
190+
.. code:: python
191+
192+
bars['pvt'] = bars.pvt()
193+
...
194+
187195
188196
Rolling Minimum
189197
---------------
@@ -331,6 +339,15 @@ VWAP
331339
...
332340
333341
342+
Z-Score
343+
-------
344+
345+
.. code:: python
346+
347+
bars['zscore'] = bars.zscore(window=20, stds=1, col='close')
348+
...
349+
350+
334351
-----
335352

336353

qtpylib/indicators.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,19 @@ def stoch(bars, window=14, slow=False, slow_ma=3):
380380

381381
return pd.DataFrame(index=bars.index, data={ 'k': k, 'r': r })
382382

383+
# ---------------------------------------------------------
384+
def zscore(bars, window=20, stds=1, col='close'):
385+
""" get zscore of price """
386+
std = bars[col].rolling(window).std() * stds
387+
mean = bars[col].rolling(window).mean()
388+
return (bars[col]-mean) / std
389+
390+
# ---------------------------------------------------------
391+
def pvt(bars):
392+
""" Price Volume Trend """
393+
pvt = ((bars['close'] - bars['close'].shift(1)) / bars['close'].shift(1)) * bars['volume']
394+
return pvt.cumsum()
395+
383396
# ---------------------------------------------------------
384397
PandasObject.session = session
385398
PandasObject.atr = atr
@@ -402,6 +415,8 @@ def stoch(bars, window=14, slow=False, slow_ma=3):
402415
PandasObject.rolling_std = rolling_std
403416
PandasObject.rsi = rsi
404417
PandasObject.stoch = stoch
418+
PandasObject.zscore = zscore
419+
PandasObject.pvt = pvt
405420
PandasObject.true_range = true_range
406421
PandasObject.mid_price = mid_price
407422
PandasObject.typical_price = typical_price

0 commit comments

Comments
 (0)