2022-04-22 10:02:26 +00:00
|
|
|
package indicator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_VIDYA(t *testing.T) {
|
|
|
|
vidya := &VIDYA{IntervalWindow: types.IntervalWindow{Window: 16}}
|
|
|
|
vidya.Update(1)
|
2023-05-31 11:35:44 +00:00
|
|
|
assert.Equal(t, vidya.Last(0), 1.)
|
2022-04-22 10:02:26 +00:00
|
|
|
vidya.Update(2)
|
|
|
|
newV := 2./17.*2. + 1.*(1.-2./17.)
|
2023-05-31 11:35:44 +00:00
|
|
|
assert.Equal(t, vidya.Last(0), newV)
|
2022-04-22 10:02:26 +00:00
|
|
|
vidya.Update(1)
|
2023-05-31 11:35:44 +00:00
|
|
|
assert.Equal(t, vidya.Last(0), vidya.Index(1))
|
2022-04-22 10:02:26 +00:00
|
|
|
}
|