init
This commit is contained in:
40
demo/bar_stat.go
Normal file
40
demo/bar_stat.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package demo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/banbox/banbot/config"
|
||||
"github.com/banbox/banbot/strat"
|
||||
"github.com/banbox/banexg/log"
|
||||
"go.uber.org/zap"
|
||||
"slices"
|
||||
)
|
||||
|
||||
type Stat struct {
|
||||
rates []float64
|
||||
}
|
||||
|
||||
func BarStat(pol *config.RunPolicyConfig) *strat.TradeStrat {
|
||||
return &strat.TradeStrat{
|
||||
WarmupNum: 50,
|
||||
OnStartUp: func(s *strat.StratJob) {
|
||||
s.More = &Stat{}
|
||||
},
|
||||
OnBar: func(s *strat.StratJob) {
|
||||
m, _ := s.More.(*Stat)
|
||||
// rate := genCurFutProbs(s.Env)[0]
|
||||
m.rates = append(m.rates, 0)
|
||||
},
|
||||
OnShutDown: func(s *strat.StratJob) {
|
||||
m, _ := s.More.(*Stat)
|
||||
slices.Sort(m.rates)
|
||||
var sum float64
|
||||
var outs []string
|
||||
for _, v := range m.rates {
|
||||
sum += v
|
||||
outs = append(outs, fmt.Sprintf("%.2f", v*100))
|
||||
}
|
||||
log.Info("", zap.Float64("avg", sum/float64(len(m.rates))),
|
||||
zap.Strings("arr", outs))
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user