Skip to content

Commit

Permalink
Volume Price Trend (VPT) is added.
Browse files Browse the repository at this point in the history
  • Loading branch information
cinar committed Jan 14, 2022
1 parent d2ff829 commit 6f36958
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions volume_indicators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
13 changes: 13 additions & 0 deletions volume_indicators.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions volume_indicators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 6f36958

Please sign in to comment.