bbgo_origin/pkg/indicator/psar_test.go

42 lines
929 B
Go
Raw Normal View History

2022-12-19 09:11:08 +00:00
package indicator
import (
"encoding/json"
"testing"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/stretchr/testify/assert"
)
/*
import pandas as pd
import pandas_ta as ta
data = pd.Series([0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9])
out = ta.psar(data, data)
print(out)
*/
func Test_PSAR(t *testing.T) {
var randomPrices = []byte(`[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]`)
var input []fixedpoint.Value
if err := json.Unmarshal(randomPrices, &input); err != nil {
panic(err)
}
psar := PSAR{
IntervalWindow: types.IntervalWindow{Window: 2},
}
var klines []types.KLine
for _, v := range input {
klines = append(klines, types.KLine{
High: v,
Low: v,
})
}
psar.CalculateAndUpdate(klines)
assert.Equal(t, psar.Length(), 29)
assert.Equal(t, psar.AF, 0.04)
assert.Equal(t, psar.Last(), 0.16)
}