ADD: added first version
This commit is contained in:
32
internal/backtest/result.go
Normal file
32
internal/backtest/result.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package backtest
|
||||
|
||||
import (
|
||||
"alpaca-bot/internal/model"
|
||||
"fmt"
|
||||
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
func ExportToExcel(trades []model.Trade, path string) error {
|
||||
f := excelize.NewFile()
|
||||
sheet := "Backtest"
|
||||
f.NewSheet(sheet)
|
||||
|
||||
headers := []string{"Time", "Symbol", "Side", "Price", "Qty", "Cash"}
|
||||
for i, h := range headers {
|
||||
cell, _ := excelize.CoordinatesToCellName(i+1, 1)
|
||||
f.SetCellValue(sheet, cell, h)
|
||||
}
|
||||
|
||||
for i, t := range trades {
|
||||
row := i + 2
|
||||
f.SetCellValue(sheet, fmt.Sprintf("A%d", row), t.Time)
|
||||
f.SetCellValue(sheet, fmt.Sprintf("B%d", row), t.Symbol)
|
||||
f.SetCellValue(sheet, fmt.Sprintf("C%d", row), t.Side)
|
||||
f.SetCellValue(sheet, fmt.Sprintf("D%d", row), t.Price)
|
||||
f.SetCellValue(sheet, fmt.Sprintf("E%d", row), t.Qty)
|
||||
f.SetCellValue(sheet, fmt.Sprintf("F%d", row), t.Cash)
|
||||
}
|
||||
|
||||
return f.SaveAs(path)
|
||||
}
|
||||
Reference in New Issue
Block a user