Documentation
¶
Overview ¶
Package backtest runs a strategy of an agent over the candles of a period, as the controller asks for it (see Config), on a paper wallet and a feed of files only: never a broker. It models the costs and the uncertainties of the fills (see exchange.PaperExecution), the margin of a leverage, the volume steps of the symbols, the breakeven and trailing stop of the agent and its daily limits, on the clock of the candles, without any future data (see exchange.BacktestFeed); and writes a report of the run (see Report).
Index ¶
Constants ¶
const ( StatusSucceeded = agentapi.BacktestStatusSucceeded StatusCanceled = agentapi.BacktestStatusCanceled StatusFailed = agentapi.BacktestStatusFailed StatusBudgetExhausted = agentapi.BacktestStatusBudgetExhausted ReasonMarket = agentapi.BacktestReasonMarket ReasonLimit = agentapi.BacktestReasonLimit ReasonStopEntry = agentapi.BacktestReasonStopEntry ReasonStopLoss = agentapi.BacktestReasonStopLoss ReasonTakeProfit = agentapi.BacktestReasonTakeProfit ReasonDailyLimit = agentapi.BacktestReasonDailyLimit ReasonStopOut = agentapi.BacktestReasonStopOut ReasonHours = agentapi.BacktestReasonHours )
The statuses of a report and the reasons of the trades, see agentapi.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
func Run(ctx context.Context, settings xtrader.Settings, strat strategy.Strategy, files []string, fileTimeframe string, cfg Config, hooks Hooks) error
Run runs strat over files, a CSV of the candles of each pair of settings in their order, of fileTimeframe (the strategy's when empty), as cfg says (see the package and Config), and writes the report of cfg: whatever the outcome, a failure in it too. The error returned is the one of the run; nil for a run canceled, the report saying so.
Types ¶
type CandleSource ¶
type CandleSource interface {
CandlesByLimit(ctx context.Context, pair, period string, limit int) ([]model.Candle, error)
}
CandleSource reads the last candles of a symbol, complete ones only: in a backtest, the ones closed by its simulated now.
type Config ¶
type Config = agentapi.BacktestConfig
Config is the backtest a run of an agent makes, see agentapi.BacktestConfig.
func ReadConfig ¶
ReadConfig reads the config of a backtest from path, validated.
type Hooks ¶
type Hooks struct {
Options []xtrader.Option
Prepare func(feed *exchange.BacktestFeed)
Candles func(source CandleSource)
Extra func() (json.RawMessage, string)
Warnings []string
// Gate, when set, takes the assets of the window of the trading hours
// open, as the controller tells them live (see agentapi.PairGate)
Gate *agentapi.PairGate
}
Hooks are what a strategy adds to its backtest: options of the bot (eg: the decisions of an LLM); Prepare, told the feed before the run (eg: the clock of an LLM); Candles, told before the run what reads the candles closed by the simulated now of any symbol of the run, the references included (see CandleSource), eg: the reference of an intermarket filter; Extra, the extra of the report and a status replacing the one of the run (eg: StatusBudgetExhausted), "" for none; and Warnings, the warnings of the report the agent adds, eg: a setting of the config it ignores.
type OpenPosition ¶
type OpenPosition = agentapi.BacktestOpen
The report of a backtest and its parts, see agentapi.BacktestReport.
type Point ¶
type Point = agentapi.BacktestPoint
The report of a backtest and its parts, see agentapi.BacktestReport.
type Report ¶
type Report = agentapi.BacktestReport
The report of a backtest and its parts, see agentapi.BacktestReport.
type Summary ¶
type Summary = agentapi.BacktestSummary
The report of a backtest and its parts, see agentapi.BacktestReport.
type Symbol ¶
type Symbol = agentapi.BacktestSymbol
Symbol is what a backtest knows of a symbol, see agentapi.BacktestSymbol.
type Trade ¶
type Trade = agentapi.BacktestTrade
The report of a backtest and its parts, see agentapi.BacktestReport.