Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
Docs: update to reflect change to algo tree structure
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkolbrich committed Aug 2, 2018
1 parent b15fb7e commit 668a578
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ func main() {
data.Load(symbols)
test.SetData(data)

// choose a strategy and load it into the backtest
strategy := &strategy.Basic{}
// choose a strategy
strategy := strategy.BuyAndHold()

// create an asset and append it to the strategy
strategy.SetChildren(gobacktest.NewAsset("TEST.DE"))

// load the strategy into the backtest
test.SetStrategy(strategy)

// run the backtest
Expand Down Expand Up @@ -70,8 +75,16 @@ portfolio.SetRiskManager(riskManager)

test.SetPortfolio(portfolio)

// create a strategy provider and load it into the backtest
strategy := &strategy.Basic{}
// create a new strategy with an algo stack
strategy := gobacktest.NewStrategy("basic")
strategy.SetAlgo(
algo.CreateSignal("buy"), // always create a buy signal on a data event
)

// create an asset and append to strategy
strategy.SetChildren(gobacktest.NewAsset("TEST.DE"))

// load the strategy into the backtest
test.SetStrategy(strategy)

// create an execution provider and load it into the backtest
Expand All @@ -89,13 +102,7 @@ test.SetStatistic(statistic)

## Dependencies

Only the standard library.

~~The internal calculations use the [github.com/shopspring/decimal](https://github.com/shopspring/decimal) package for arbitrary-precision fixed-point decimals.~~

~~Make sure to install it into your `$GOPATH` with~~

~~go get github.com/shopspring/decimal~~
None so far. Only the standard library.

## Basic components

Expand Down
18 changes: 11 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ func main() {

test.SetPortfolio(portfolio)

// create a strategy provider and load it into the backtest
strategy := &strategy.Basic{}
// create a new strategy with an algo stack
strategy := gbt.NewStrategy("basic")
strategy.SetAlgo(
algo.CreateSignal("buy"), // always create a buy signal on a data event
)

// create an asset and append to strategy
strategy.SetChildren(gbt.NewAsset("TEST.DE"))

// load the strategy into the backtest
test.SetStrategy(strategy)

// create an execution provider and load it into the backtest
Expand All @@ -62,11 +70,7 @@ func main() {

## Dependencies

The internal calculations use the [github.com/shopspring/decimal](https://github.com/shopspring/decimal) package for arbitrary-precision fixed-point decimals.

Make sure to install it into your `$GOPATH` with

go get github.com/shopspring/decimal
None so far.

## Basic components

Expand Down
19 changes: 19 additions & 0 deletions strategy/buy-and-hold.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package strategy

import (
gbt "github.com/dirkolbrich/gobacktest"
"github.com/dirkolbrich/gobacktest/algo"
)

// BuyAndHold is a basic strategy, which creates a buy signal on every year change
func BuyAndHold() *gbt.Strategy {
// create a new strategy with an algo stack and load into the backtest
strategy := gbt.NewStrategy("buy-and-hold-yearly")

strategy.SetAlgo(
algo.RunYearly(), // run on beginning of each year
algo.CreateSignal("buy"), // always create a buy signal on a data event
)

return strategy
}

0 comments on commit 668a578

Please sign in to comment.