Skip to content

Commit

Permalink
Updated backtest tool with all strategies.
Browse files Browse the repository at this point in the history
  • Loading branch information
cinar committed Dec 31, 2023
1 parent f2e24e0 commit 1337d36
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions cmd/indicator-backtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions strategy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>)


<a name="ActionsToAnnotations"></a>
Expand Down Expand Up @@ -253,4 +254,13 @@ type Strategy interface {
}
```

<a name="AllStrategies"></a>
### func [AllStrategies](<https://github.com/cinar/indicator/blob/v2/strategy/strategy.go#L54>)

```go
func AllStrategies() []Strategy
```

AllStrategies returns a slice containing references to all available base strategies.

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
7 changes: 7 additions & 0 deletions strategy/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

0 comments on commit 1337d36

Please sign in to comment.