Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backtest/backtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestBacktestAllAssetsAndStrategies(t *testing.T) {

htmlReport := backtest.NewHTMLReport(outputDir)
bt := backtest.NewBacktest(repository, htmlReport)
bt.Workers = 16

err = bt.Run()
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions backtest/html_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path"
"path/filepath"
"slices"
"sync"
"text/template"
"time"

Expand All @@ -39,6 +40,9 @@ type HTMLReport struct {
// outputDir is the output directory for the generated reports.
outputDir string

// mu is a mutex that ensures thread safety.
mu sync.Mutex

// assetResults is the mapping from the asset name to strategy results.
assetResults map[string][]*htmlReportResult

Expand Down Expand Up @@ -102,6 +106,9 @@ func (h *HTMLReport) Begin(assetNames []string, _ []strategy.Strategy) error {

// AssetBegin is called when backtesting for the given asset begins.
func (h *HTMLReport) AssetBegin(name string, strategies []strategy.Strategy) error {
h.mu.Lock()
defer h.mu.Unlock()

_, ok := h.assetResults[name]
if ok {
return fmt.Errorf("asset has already begun: %s", name)
Expand Down Expand Up @@ -136,6 +143,9 @@ func (h *HTMLReport) Write(assetName string, currentStrategy strategy.Strategy,
go helper.Drain(snapshots)
}

h.mu.Lock()
defer h.mu.Unlock()

// Get asset strategy results.
results, ok := h.assetResults[assetName]
if !ok {
Expand All @@ -157,6 +167,9 @@ func (h *HTMLReport) Write(assetName string, currentStrategy strategy.Strategy,

// AssetEnd is called when backtesting for the given asset ends.
func (h *HTMLReport) AssetEnd(name string) error {
h.mu.Lock()
defer h.mu.Unlock()

results, ok := h.assetResults[name]
if !ok {
return fmt.Errorf("asset has not begun: %s", name)
Expand Down
252 changes: 252 additions & 0 deletions backtest/testdata/repository/brk-c.csv

Large diffs are not rendered by default.

252 changes: 252 additions & 0 deletions backtest/testdata/repository/brk-d.csv

Large diffs are not rendered by default.

252 changes: 252 additions & 0 deletions backtest/testdata/repository/brk-e.csv

Large diffs are not rendered by default.

252 changes: 252 additions & 0 deletions backtest/testdata/repository/brk-f.csv

Large diffs are not rendered by default.

252 changes: 252 additions & 0 deletions backtest/testdata/repository/brk-g.csv

Large diffs are not rendered by default.

252 changes: 252 additions & 0 deletions backtest/testdata/repository/brk-h.csv

Large diffs are not rendered by default.

252 changes: 252 additions & 0 deletions backtest/testdata/repository/brk-i.csv

Large diffs are not rendered by default.

Loading