mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
types: add total net profit field to trade states
Signed-off-by: c9s <yoanlin93@gmail.com>
This commit is contained in:
parent
1617005114
commit
32c76105b0
|
@ -16,6 +16,8 @@ type TradeStats struct {
|
||||||
Losses []fixedpoint.Value `json:"losses" yaml:"losses"`
|
Losses []fixedpoint.Value `json:"losses" yaml:"losses"`
|
||||||
MostProfitableTrade fixedpoint.Value `json:"mostProfitableTrade" yaml:"mostProfitableTrade"`
|
MostProfitableTrade fixedpoint.Value `json:"mostProfitableTrade" yaml:"mostProfitableTrade"`
|
||||||
MostLossTrade fixedpoint.Value `json:"mostLossTrade" yaml:"mostLossTrade"`
|
MostLossTrade fixedpoint.Value `json:"mostLossTrade" yaml:"mostLossTrade"`
|
||||||
|
ProfitFactor fixedpoint.Value `json:"profitFactor" yaml:"profitFactor"`
|
||||||
|
TotalNetProfit fixedpoint.Value `json:"totalNetProfit" yaml:"totalNetProfit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TradeStats) Add(pnl fixedpoint.Value) {
|
func (s *TradeStats) Add(pnl fixedpoint.Value) {
|
||||||
|
@ -30,6 +32,7 @@ func (s *TradeStats) Add(pnl fixedpoint.Value) {
|
||||||
s.GrossLoss = s.GrossLoss.Add(pnl)
|
s.GrossLoss = s.GrossLoss.Add(pnl)
|
||||||
s.MostLossTrade = fixedpoint.Min(s.MostLossTrade, pnl)
|
s.MostLossTrade = fixedpoint.Min(s.MostLossTrade, pnl)
|
||||||
}
|
}
|
||||||
|
s.TotalNetProfit = s.TotalNetProfit.Add(pnl)
|
||||||
|
|
||||||
// The win/loss ratio is your wins divided by your losses.
|
// The win/loss ratio is your wins divided by your losses.
|
||||||
// In the example, suppose for the sake of simplicity that 60 trades were winners, and 40 were losers.
|
// In the example, suppose for the sake of simplicity that 60 trades were winners, and 40 were losers.
|
||||||
|
@ -39,6 +42,8 @@ func (s *TradeStats) Add(pnl fixedpoint.Value) {
|
||||||
} else {
|
} else {
|
||||||
s.WinningRatio = fixedpoint.NewFromFloat(float64(s.NumOfProfitTrade) / float64(s.NumOfLossTrade))
|
s.WinningRatio = fixedpoint.NewFromFloat(float64(s.NumOfProfitTrade) / float64(s.NumOfLossTrade))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.ProfitFactor = s.GrossProfit.Div(s.GrossLoss)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TradeStats) String() string {
|
func (s *TradeStats) String() string {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user