From 1337d36e4976de16362c58469badd9f66bea8b9a Mon Sep 17 00:00:00 2001 From: Onur Cinar Date: Sat, 30 Dec 2023 17:23:18 -0800 Subject: [PATCH] Updated backtest tool with all strategies. --- README.md | 2 +- cmd/indicator-backtest/main.go | 3 +++ strategy/README.md | 10 ++++++++++ strategy/strategy.go | 7 +++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3484a7a..6393e55 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ The [Backtest functionality](strategy/README.md#type-backtest), using the [Outco ```go backtest := strategy.NewBacktest(repository, outputDir) backtest.Names = append(backtest.Names, "brk-b") -backtest.Strategies = append(backtest.Strategies, strategy.NewApoStrategy()) +backtest.Strategies = append(backtest.Strategies, trend.NewApoStrategy()) err = backtest.Run() if err != nil { diff --git a/cmd/indicator-backtest/main.go b/cmd/indicator-backtest/main.go index 028e930..de9d1a2 100644 --- a/cmd/indicator-backtest/main.go +++ b/cmd/indicator-backtest/main.go @@ -14,6 +14,7 @@ import ( "github.com/cinar/indicator/asset" "github.com/cinar/indicator/strategy" "github.com/cinar/indicator/strategy/trend" + "github.com/cinar/indicator/strategy/volatility" ) func main() { @@ -37,7 +38,9 @@ func main() { backtest := strategy.NewBacktest(repository, outputDir) backtest.Workers = workers backtest.Names = append(backtest.Names, flag.Args()...) + backtest.Strategies = append(backtest.Strategies, strategy.AllStrategies()...) backtest.Strategies = append(backtest.Strategies, trend.AllStrategies()...) + backtest.Strategies = append(backtest.Strategies, volatility.AllStrategies()...) err := backtest.Run() if err != nil { diff --git a/strategy/README.md b/strategy/README.md index 74059d2..1277a7d 100644 --- a/strategy/README.md +++ b/strategy/README.md @@ -42,6 +42,7 @@ The information provided on this project is strictly for informational purposes - [func \(b \*BuyAndHoldStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#BuyAndHoldStrategy.Report>) - [type Result](<#Result>) - [type Strategy](<#Strategy>) + - [func AllStrategies\(\) \[\]Strategy](<#AllStrategies>) @@ -253,4 +254,13 @@ type Strategy interface { } ``` + +### func [AllStrategies]() + +```go +func AllStrategies() []Strategy +``` + +AllStrategies returns a slice containing references to all available base strategies. + Generated by [gomarkdoc]() diff --git a/strategy/strategy.go b/strategy/strategy.go index 584cd52..a2b0b95 100644 --- a/strategy/strategy.go +++ b/strategy/strategy.go @@ -49,3 +49,10 @@ func ComputeWithOutcome(s Strategy, c <-chan *asset.Snapshot) (<-chan Action, <- return actions[1], outcomes } + +// AllStrategies returns a slice containing references to all available base strategies. +func AllStrategies() []Strategy { + return []Strategy{ + NewBuyAndHoldStrategy(), + } +}