indicator/v2: rename volume profile indicator and fix tests

This commit is contained in:
c9s 2023-12-14 15:48:51 +08:00
parent 29301cbe7f
commit 4d84308b99
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 8 additions and 8 deletions

View File

@ -16,11 +16,11 @@ const DefaultValueAreaPercentage = 0.68
type VolumeProfileStream struct {
*types.Float64Series
VP VolumeProfile
VP VolumeProfileDetails
window int
}
// VolumeProfile is a histogram of market price and volume.
// VolumeProfileDetails is a histogram of market price and volume.
// Intent is to show the price points with most volume during a period.
// The profile gives key features such as:
//
@ -31,7 +31,7 @@ type VolumeProfileStream struct {
// Value area low (VAL)
//
// Session High/Low
type VolumeProfile struct {
type VolumeProfileDetails struct {
// Bins is the histogram bins.
Bins []float64
@ -65,7 +65,7 @@ type VolumeLevel struct {
Volume float64
}
func NewVolumeProfile(source KLineSubscription, window int) *VolumeProfileStream {
func VolumeProfile(source KLineSubscription, window int) *VolumeProfileStream {
prices := HLC3(source)
volumes := Volumes(source)

View File

@ -24,14 +24,14 @@ func TestVolumeProfile(t *testing.T) {
stream := &types.StandardStream{}
kLines := KLines(stream, "", "")
ind := NewVolumeProfile(kLines, 10)
ind := VolumeProfile(kLines, 10)
for _, candle := range candles {
stream.EmitKLineClosed(candle)
}
assert.InDelta(t, 36512.7, ind.VP.Low, 0.01, "VP.LOW")
assert.InDelta(t, 36512.7, ind.VP.VAL, 0.01, "VP.VAL")
assert.InDelta(t, 36518.574, ind.VP.POC, 0.01, "VP.POC")
assert.InDelta(t, 36530.322, ind.VP.VAH, 0.01, "VP.VAH")
assert.InDelta(t, 36600.811, ind.VP.VAL, 0.01, "VP.VAL")
assert.InDelta(t, 36612.559, ind.VP.POC, 0.01, "VP.POC")
assert.InDelta(t, 36618.433, ind.VP.VAH, 0.01, "VP.VAH")
assert.InDelta(t, 36617.433, ind.VP.High, 0.01, "VP.HIGH")
}