diff --git a/README.md b/README.md index 1cbe548..d7188e1 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ The following list of indicators are currently supported by this package: - [Force Index (FI)](volume_indicators.md#force-index-fi) - [Money Flow Index (MFI)](volume_indicators.md#money-flow-index-mfi) - [On-Balance Volume (OBV)](volume_indicators.md#on-balance-volume-obv) +- [Volume Price Trend (VPT)](volume_indicators.md#volume-price-trend-vpt) ## Strategies Provided diff --git a/volume_indicators.go b/volume_indicators.go index e5e5a4e..a6b8ff4 100644 --- a/volume_indicators.go +++ b/volume_indicators.go @@ -126,3 +126,17 @@ func EaseOfMovement(period int, high, low []float64, volume []int64) []float64 { func DefaultEaseOfMovement(high, low []float64, volume []int64) []float64 { return EaseOfMovement(14, high, low, volume) } + +// The Volume Price Trend (VPT) provides a correlation between the +// volume and the price. +// +// VPT = Previous VPT + (Volume * (Current Closing - Previous Closing) / Previous Closing) +// +// Returns volume price trend values. +func VolumePriceTrend(closing []float64, volume []int64) []float64 { + previousClosing := shiftRight(1, closing) + // TODO: Consider changing shiftRightBy to fill with last value. + previousClosing[0] = closing[0] + vpt := multiply(asFloat64(volume), divide(substract(closing, previousClosing), previousClosing)) + return Sum(len(vpt), vpt) +} diff --git a/volume_indicators.md b/volume_indicators.md index 7ef5733..0f0cf6b 100644 --- a/volume_indicators.md +++ b/volume_indicators.md @@ -7,6 +7,7 @@ Volumne indicators measure the strength of a trend based the volume. - [Force Index (FI)](#force-index-fi) - [Money Flow Index (MFI)](#money-flow-index-mfi) - [On-Balance Volume (OBV)](#on-balance-volume-obv) +- [Volume Price Trend (VPT)](#volume-price-trend-vpt) #### Accumulation/Distribution (A/D) @@ -95,6 +96,18 @@ OBV = OBV-Prev + 0, if Closing = Closing-Prev result := indicator.Obv(closing, volume) ``` +#### Volume Price Trend (VPT) + +The [VolumePriceTrend](https://pkg.go.dev/github.com/cinar/indicator#VolumePriceTrend) provides a correlation between the volume and the price. + +``` +VPT = Previous VPT + (Volume * (Current Closing - Previous Closing) / Previous Closing) +``` + +```Golang +result := indicator.VolumePriceTrend(closing, volume) +``` + ## Disclaimer The information provided on this project is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security. diff --git a/volume_indicators_test.go b/volume_indicators_test.go index 70a45be..e27c795 100644 --- a/volume_indicators_test.go +++ b/volume_indicators_test.go @@ -47,3 +47,12 @@ func TestDefaultEaseOfMovement(t *testing.T) { actual := roundDigitsAll(DefaultEaseOfMovement(high, low, volume), 2) testEquals(t, actual, expected) } + +func TestVolumePriceTrend(t *testing.T) { + closing := []float64{9, 11, 7, 10, 8} + volume := []int64{100, 110, 80, 120, 90} + expected := []float64{0, 24.44, -4.65, 46.78, 28.78} + + actual := roundDigitsAll(VolumePriceTrend(closing, volume), 2) + testEquals(t, actual, expected) +}