mirror of
https://github.com/c9s/bbgo.git
synced 2024-09-20 08:11:08 +00:00
improve/profitStatsTracker: use SMA v2
This commit is contained in:
parent
6e54972304
commit
e161deba25
|
@ -5,7 +5,7 @@ import (
|
||||||
"github.com/c9s/bbgo/pkg/data/tsv"
|
"github.com/c9s/bbgo/pkg/data/tsv"
|
||||||
"github.com/c9s/bbgo/pkg/datatype/floats"
|
"github.com/c9s/bbgo/pkg/datatype/floats"
|
||||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
"github.com/c9s/bbgo/pkg/indicator"
|
indicatorv2 "github.com/c9s/bbgo/pkg/indicator/v2"
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
@ -27,10 +27,10 @@ type AccumulatedProfitReport struct {
|
||||||
|
|
||||||
// Accumulated profit
|
// Accumulated profit
|
||||||
accumulatedProfit fixedpoint.Value
|
accumulatedProfit fixedpoint.Value
|
||||||
accumulatedProfitPerInterval floats.Slice
|
accumulatedProfitPerInterval *types.Float64Series
|
||||||
|
|
||||||
// Accumulated profit MA
|
// Accumulated profit MA
|
||||||
profitMA *indicator.SMA
|
profitMA *indicatorv2.SMAStream
|
||||||
profitMAPerInterval floats.Slice
|
profitMAPerInterval floats.Slice
|
||||||
|
|
||||||
// Profit of each interval
|
// Profit of each interval
|
||||||
|
@ -71,7 +71,8 @@ func (r *AccumulatedProfitReport) Initialize(symbol string, interval types.Inter
|
||||||
r.ShortTermProfitWindow = 7
|
r.ShortTermProfitWindow = 7
|
||||||
}
|
}
|
||||||
|
|
||||||
r.profitMA = &indicator.SMA{IntervalWindow: types.IntervalWindow{Interval: r.Interval, Window: r.ProfitMAWindow}}
|
r.accumulatedProfitPerInterval = types.NewFloat64Series()
|
||||||
|
r.profitMA = indicatorv2.SMA2(r.accumulatedProfitPerInterval, r.ProfitMAWindow)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *AccumulatedProfitReport) AddStrategyParameter(title string, value string) {
|
func (r *AccumulatedProfitReport) AddStrategyParameter(title string, value string) {
|
||||||
|
@ -86,13 +87,12 @@ func (r *AccumulatedProfitReport) AddTrade(trade types.Trade) {
|
||||||
func (r *AccumulatedProfitReport) Rotate(ps *types.ProfitStats, ts *types.TradeStats) {
|
func (r *AccumulatedProfitReport) Rotate(ps *types.ProfitStats, ts *types.TradeStats) {
|
||||||
// Accumulated profit
|
// Accumulated profit
|
||||||
r.accumulatedProfit = r.accumulatedProfit.Add(ps.AccumulatedNetProfit)
|
r.accumulatedProfit = r.accumulatedProfit.Add(ps.AccumulatedNetProfit)
|
||||||
r.accumulatedProfitPerInterval.Update(r.accumulatedProfit.Float64())
|
r.accumulatedProfitPerInterval.PushAndEmit(r.accumulatedProfit.Float64())
|
||||||
|
|
||||||
// Profit of each interval
|
// Profit of each interval
|
||||||
r.ProfitPerInterval.Update(ps.AccumulatedNetProfit.Float64())
|
r.ProfitPerInterval.Update(ps.AccumulatedNetProfit.Float64())
|
||||||
|
|
||||||
// Profit MA
|
// Profit MA
|
||||||
r.profitMA.Update(r.accumulatedProfit.Float64())
|
|
||||||
r.profitMAPerInterval.Update(r.profitMA.Last(0))
|
r.profitMAPerInterval.Update(r.profitMA.Last(0))
|
||||||
|
|
||||||
// Accumulated Fee
|
// Accumulated Fee
|
||||||
|
|
Loading…
Reference in New Issue
Block a user