Documentation ¶
Overview ¶
Package backtest contains the backtest functions.
This package belongs to the Indicator project. Indicator is a Golang module that supplies a variety of technical indicators, strategies, and a backtesting framework for analysis.
License ¶
Copyright (c) 2021-2024 Onur Cinar. The source code is provided under GNU AGPLv3 License. https://github.com/cinar/indicator
Disclaimer ¶
The information provided on this project is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.
Index ¶
- Constants
- func RegisterReportBuilder(name string, builder ReportBuilderFunc)
- type Backtest
- type DataReport
- func (d *DataReport) AssetBegin(name string, strategies []strategy.Strategy) error
- func (*DataReport) AssetEnd(_ string) error
- func (*DataReport) Begin(_ []string, _ []strategy.Strategy) error
- func (*DataReport) End() error
- func (d *DataReport) Write(assetName string, currentStrategy strategy.Strategy, ...) error
- type DataStrategyResult
- type HTMLReport
- func (h *HTMLReport) AssetBegin(name string, strategies []strategy.Strategy) error
- func (h *HTMLReport) AssetEnd(name string) error
- func (h *HTMLReport) Begin(assetNames []string, _ []strategy.Strategy) error
- func (h *HTMLReport) End() error
- func (h *HTMLReport) Write(assetName string, currentStrategy strategy.Strategy, ...) error
- type Report
- type ReportBuilderFunc
Constants ¶
const ( // DefaultBacktestWorkers is the default number of backtest workers. DefaultBacktestWorkers = 1 // DefaultLastDays is the default number of days backtest should go back. DefaultLastDays = 365 )
const ( // DefaultWriteStrategyReports is the default state of writing individual strategy reports. DefaultWriteStrategyReports = true )
const (
// HTMLReportBuilderName is the name for the HTML report builder.
HTMLReportBuilderName = "html"
)
Variables ¶
This section is empty.
Functions ¶
func RegisterReportBuilder ¶
func RegisterReportBuilder(name string, builder ReportBuilderFunc)
RegisterReportBuilder registers the given builder.
Types ¶
type Backtest ¶
type Backtest struct { // Names is the names of the assets to backtest. Names []string // Strategies is the list of strategies to apply. Strategies []strategy.Strategy // Workers is the number of concurrent workers. Workers int // LastDays is the number of days backtest should go back. LastDays int // Logger is the slog logger instance. Logger *slog.Logger // contains filtered or unexported fields }
Backtest function rigorously evaluates the potential performance of the specified strategies applied to a defined set of assets. It generates comprehensive visual representations for each strategy-asset pairing.
func NewBacktest ¶
func NewBacktest(repository asset.Repository, report Report) *Backtest
NewBacktest function initializes a new backtest instance.
func (*Backtest) Run ¶
Run executes a comprehensive performance evaluation of the designated strategies, applied to a specified collection of assets. In the absence of explicitly defined assets, encompasses all assets within the repository. Likewise, in the absence of explicitly defined strategies, encompasses all the registered strategies.
type DataReport ¶
type DataReport struct { // Results are the backtest results for the assets. Results map[string][]*DataStrategyResult // contains filtered or unexported fields }
DataReport is the bactest data report enablign programmatic access to the backtest results.
func NewDataReport ¶
func NewDataReport() *DataReport
NewDataReport initializes a new data report instance.
func (*DataReport) AssetBegin ¶
func (d *DataReport) AssetBegin(name string, strategies []strategy.Strategy) error
AssetBegin is called when backtesting for the given asset begins.
func (*DataReport) AssetEnd ¶
func (*DataReport) AssetEnd(_ string) error
AssetEnd is called when backtesting for the given asset ends.
type DataStrategyResult ¶
type DataStrategyResult struct { // Asset is the asset name. Asset string // Strategy is the strategy instnace. Strategy strategy.Strategy // Outcome is the strategy outcome. Outcome float64 // Action is the final action recommended by the strategy. Action strategy.Action // Transactions are the action recommendations. Transactions []strategy.Action }
DataStrategyResult is the strategy result.
type HTMLReport ¶
type HTMLReport struct { Report // WriteStrategyReports indicates whether the individual strategy reports should be generated. WriteStrategyReports bool // DateFormat is the date format that is used in the reports. DateFormat string // Logger is the slog logger instance. Logger *slog.Logger // contains filtered or unexported fields }
HTMLReport is the backtest HTML report.
func NewHTMLReport ¶
func NewHTMLReport(outputDir string) *HTMLReport
NewHTMLReport initializes a new HTML report instance.
func (*HTMLReport) AssetBegin ¶
func (h *HTMLReport) AssetBegin(name string, strategies []strategy.Strategy) error
AssetBegin is called when backtesting for the given asset begins.
func (*HTMLReport) AssetEnd ¶
func (h *HTMLReport) AssetEnd(name string) error
AssetEnd is called when backtesting for the given asset ends.
type Report ¶
type Report interface { // Begin is called when the backtest begins. Begin(assetNames []string, strategies []strategy.Strategy) error // AssetBegin is called when backtesting for the given asset begins. AssetBegin(name string, strategies []strategy.Strategy) error // Write writes the given strategy actions and outomes to the report. Write(assetName string, currentStrategy strategy.Strategy, snapshots <-chan *asset.Snapshot, actions <-chan strategy.Action, outcomes <-chan float64) error // AssetEnd is called when backtesting for the given asset ends. AssetEnd(name string) error // End is called when the backtest ends. End() error }
Report is the backtest report interface.
type ReportBuilderFunc ¶
ReportBuilderFunc defines a function to build a new report using the given configuration parameter.