Skip to content

Commit

Permalink
use volume > mean + 2*std for volume check
Browse files Browse the repository at this point in the history
  • Loading branch information
narumiruna committed Jan 16, 2025
1 parent 64db1b9 commit 4dc8ae3
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions pkg/strategy/sentinel/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
volumes := s.extractVolumes(s.klines)
samples := s.generateSamples(volumes)

if s.shouldSkipIsolationForest(volumes, samples) {
s.logSkipIsolationForest(samples, volumes, kline)
lastVolume := volumes[len(volumes)-1]
lastMean := samples[len(samples)-1][0]
lastStd := samples[len(samples)-1][1]

// isVolumeSignificantlyAboveMean
if lastVolume < lastMean+2*lastStd {
log.Infof("Volume is not significantly above mean, skipping isolation forest calculation, symbol: %s, volume: %f, mean: %f, std: %f", s.Symbol, lastVolume, lastMean, lastStd)
return
}

Expand Down Expand Up @@ -145,21 +150,11 @@ func (s *Strategy) generateSamples(volumes floats.Slice) [][]float64 {

mean := subset.Mean()
std := subset.Std()
samples = append(samples, []float64{mean, std})
samples = append(samples, []float64{mean, std, subset[len(subset)-1]})
}
return samples
}

func (s *Strategy) shouldSkipIsolationForest(volumes floats.Slice, samples [][]float64) bool {
volumeMean := volumes.Mean()
lastMovingMean := samples[len(samples)-1][0]
return lastMovingMean < volumeMean
}

func (s *Strategy) logSkipIsolationForest(samples [][]float64, volumes floats.Slice, kline types.KLine) {
log.Infof("Skipping isolation forest calculation for symbol: %s, last moving mean: %f, average volume: %f, kline: %s", s.Symbol, samples[len(samples)-1][0], volumes.Mean(), kline.String())
}

func (s *Strategy) fitIsolationForest(samples [][]float64) {
if s.retrainingRateLimiter.Allow() {
s.IsolationForest = iforest.New()
Expand Down

0 comments on commit 4dc8ae3

Please sign in to comment.