Versions in this module Expand all Collapse all v0 v0.1.1 Jul 16, 2026 v0.1.0 Jul 16, 2026 Changes in this version + var ErrNoBars = errors.New("backtest: data has no bars") + var ErrOutOfMoney = errors.New("backtest: out of money") + type Backtest struct + func New(data *Data, strategy Strategy, opts Options) *Backtest + func (bt *Backtest) Run() (*Result, error) + type Bar struct + Close float64 + High float64 + Low float64 + Open float64 + Time time.Time + Volume float64 + type Commission interface + func FixedPlusPct(fixed, rate float64) Commission + func Pct(rate float64) Commission + type CommissionFunc func(size, price float64) float64 + type Data struct + func FromBars(bars []Bar) *Data + func FromCSV(path string) (*Data, error) + func FromOHLCV(t []time.Time, open, high, low, close, volume []float64) (*Data, error) + func (d *Data) AddColumn(name string, vals []float64) error + func (d *Data) Bars() []Bar + func (d *Data) Close() Series + func (d *Data) Column(name string) (Series, bool) + func (d *Data) FullLen() int + func (d *Data) High() Series + func (d *Data) Len() int + func (d *Data) Low() Series + func (d *Data) Open() Series + func (d *Data) Time() []time.Time + func (d *Data) TimeAt(i int) time.Time + func (d *Data) Volume() Series + type EquityPoint struct + Equity float64 + Time time.Time + type HeatmapEntry struct + Params Params + Stats Stats + Value float64 + type Indicator struct + func (ind *Indicator) At(i int) float64 + func (ind *Indicator) Last() float64 + func (ind *Indicator) Len() int + func (ind *Indicator) Series() Series + type IndicatorOption func(*Indicator) + func Color(hex string) IndicatorOption + func Overlay() IndicatorOption + type IndicatorSeries struct + Color string + Name string + Overlay bool + Values []float64 + type MultiBacktest struct + func NewMultiBacktest(datasets []*Data, build func() Strategy, opts Options) *MultiBacktest + func (m *MultiBacktest) MeanStat(riskFreeRate float64, sel func(Stats) float64) (float64, error) + func (m *MultiBacktest) Run() ([]*Result, error) + func (m *MultiBacktest) Stats(riskFreeRate float64) ([]Stats, error) + func (m *MultiBacktest) Workers(n int) *MultiBacktest + type OpenTrade struct + func (o *OpenTrade) EntryPrice() float64 + func (o *OpenTrade) IsLong() bool + func (o *OpenTrade) IsShort() bool + func (o *OpenTrade) SL() float64 + func (o *OpenTrade) SetSL(price float64) + func (o *OpenTrade) SetTP(price float64) + func (o *OpenTrade) Size() float64 + func (o *OpenTrade) TP() float64 + type OptimizeOptions struct + Constraint func(Params) bool + MaxTries int + Maximize string + MaximizeFunc func(Stats) float64 + RandomSeed int64 + ReturnHeatmap bool + RiskFreeRate float64 + Workers int + type OptimizeResult struct + Best Params + BestStats Stats + BestValue float64 + Heatmap []HeatmapEntry + func Optimize(data *Data, opts Options, build func(Params) Strategy, space map[string][]any, ...) (*OptimizeResult, error) + type Options struct + Cash float64 + Commission Commission + ExclusiveOrders bool + FinalizeTrades bool + Hedging bool + Margin float64 + Spread float64 + TradeOnClose bool + type Order struct + Limit float64 + SL float64 + Size float64 + Stop float64 + TP float64 + Tag any + type OrderHandle struct + func (h OrderHandle) Cancel() + func (h OrderHandle) Size() float64 + type Params map[string]any + type Position struct + func (p *Position) Close() + func (p *Position) IsLong() bool + func (p *Position) IsShort() bool + func (p *Position) PL() float64 + func (p *Position) Size() float64 + type Result struct + EquityCurve []EquityPoint + FinalEquity float64 + InPositionBars []bool + Indicators []IndicatorSeries + StartBar int + Trades []Trade + type Series []float64 + func (s Series) At(i int) float64 + func (s Series) Last() float64 + func (s Series) Len() int + type State struct + func (s *State) Buy(o Order) OrderHandle + func (s *State) ClosedTrades() []Trade + func (s *State) Data() *Data + func (s *State) Equity() float64 + func (s *State) I(name string, compute func() []float64, opts ...IndicatorOption) *Indicator + func (s *State) OpenTrades() []*OpenTrade + func (s *State) Orders() []OrderHandle + func (s *State) Position() *Position + func (s *State) Sell(o Order) OrderHandle + func (s *State) Trades() []Trade + type Stats struct + AlphaPct float64 + AvgDrawdownDur time.Duration + AvgDrawdownPct float64 + AvgTradeDur time.Duration + AvgTradePct float64 + BestTradePct float64 + Beta float64 + BuyHoldReturnPct float64 + CAGRPct float64 + CalmarRatio float64 + CommissionsTotal float64 + Duration time.Duration + End time.Time + EquityFinal float64 + EquityPeak float64 + ExpectancyPct float64 + ExposureTimePct float64 + KellyCriterion float64 + MaxDrawdownDur time.Duration + MaxDrawdownPct float64 + MaxTradeDur time.Duration + NumTrades int + ProfitFactor float64 + ReturnAnnPct float64 + ReturnPct float64 + SQN float64 + SharpeRatio float64 + SortinoRatio float64 + Start time.Time + VolatilityAnnPct float64 + WinRatePct float64 + WorstTradePct float64 + func Compute(r *Result, d *Data, riskFreeRate float64) Stats + func (s Stats) String() string + type Strategy interface + Init func(*State) + Next func(*State) + type Trade struct + Commissions float64 + EntryBar int + EntryPrice float64 + EntryTime time.Time + ExitBar int + ExitPrice float64 + ExitTime time.Time + PL float64 + ReturnPct float64 + Size float64 + Tag any