mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
improve/profitStatsTracker: use CsvFormatter interface
This commit is contained in:
parent
1a90cd0322
commit
6e54972304
|
@ -108,15 +108,8 @@ func (r *AccumulatedProfitReport) Rotate(ps *types.ProfitStats, ts *types.TradeS
|
||||||
r.profitFactorPerInterval.Update(ts.ProfitFactor.Float64())
|
r.profitFactorPerInterval.Update(ts.ProfitFactor.Float64())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output Accumulated profit report to a TSV file
|
// CsvHeader returns a header slice
|
||||||
func (r *AccumulatedProfitReport) Output() {
|
func (r *AccumulatedProfitReport) CsvHeader() []string {
|
||||||
if r.TsvReportPath != "" {
|
|
||||||
tsvwiter, err := tsv.AppendWriterFile(r.TsvReportPath)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer tsvwiter.Close()
|
|
||||||
// Output title row
|
|
||||||
titles := []string{
|
titles := []string{
|
||||||
"#",
|
"#",
|
||||||
"Symbol",
|
"Symbol",
|
||||||
|
@ -128,12 +121,18 @@ func (r *AccumulatedProfitReport) Output() {
|
||||||
"profitFactor",
|
"profitFactor",
|
||||||
fmt.Sprintf("%s%d Trades", r.Interval, r.Window),
|
fmt.Sprintf("%s%d Trades", r.Interval, r.Window),
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(r.strategyParameters); i++ {
|
for i := 0; i < len(r.strategyParameters); i++ {
|
||||||
titles = append(titles, r.strategyParameters[i][0])
|
titles = append(titles, r.strategyParameters[i][0])
|
||||||
}
|
}
|
||||||
_ = tsvwiter.Write(titles)
|
|
||||||
|
|
||||||
// Output data row
|
return titles
|
||||||
|
}
|
||||||
|
|
||||||
|
// CsvRecords returns a data slice
|
||||||
|
func (r *AccumulatedProfitReport) CsvRecords() [][]string {
|
||||||
|
var data [][]string
|
||||||
|
|
||||||
for i := 0; i <= r.Window-1; i++ {
|
for i := 0; i <= r.Window-1; i++ {
|
||||||
values := []string{
|
values := []string{
|
||||||
strconv.Itoa(i + 1),
|
strconv.Itoa(i + 1),
|
||||||
|
@ -149,7 +148,27 @@ func (r *AccumulatedProfitReport) Output() {
|
||||||
for j := 0; j < len(r.strategyParameters); j++ {
|
for j := 0; j < len(r.strategyParameters); j++ {
|
||||||
values = append(values, r.strategyParameters[j][1])
|
values = append(values, r.strategyParameters[j][1])
|
||||||
}
|
}
|
||||||
_ = tsvwiter.Write(values)
|
|
||||||
|
data = append(data, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output Accumulated profit report to a TSV file
|
||||||
|
func (r *AccumulatedProfitReport) Output() {
|
||||||
|
if r.TsvReportPath != "" {
|
||||||
|
// Open specified file for appending
|
||||||
|
tsvwiter, err := tsv.AppendWriterFile(r.TsvReportPath)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer tsvwiter.Close()
|
||||||
|
|
||||||
|
// Column Title
|
||||||
|
_ = tsvwiter.Write(r.CsvHeader())
|
||||||
|
|
||||||
|
// Output data rows
|
||||||
|
_ = tsvwiter.WriteAll(r.CsvRecords())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user