backtest

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountResultSummary

type AccountResultSummary struct {
	AccountID model.AccountID              `json:"account_id"`
	Orders    []model.OrderStatusReport    `json:"orders"`
	Fills     []model.FillReport           `json:"fills"`
	Positions []model.PositionStatusReport `json:"positions"`
}

type Catalog

type Catalog interface {
	Events(context.Context) ([]Event, error)
}

type Config

type Config struct {
	Bus             *bus.Bus
	Cache           *cache.Cache
	Portfolio       *portfolio.Portfolio
	DataCatalog     data.Catalog
	ExecutionEngine *execution.Engine
	FillModel       FillModel
	OrderLatency    time.Duration
	Events          []Event
	Strategies      []strategy.Strategy
	Logger          *slog.Logger
}

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(cfg EngineConfig) *Engine

func (*Engine) AddData

func (e *Engine) AddData(event Event)

func (*Engine) AddStrategy

func (e *Engine) AddStrategy(strategy strategy.Strategy)

func (*Engine) Run

func (e *Engine) Run(ctx context.Context) (Result, error)

type EngineConfig

type EngineConfig struct {
	Bus         *bus.Bus
	Catalog     Catalog
	DataCatalog data.ReplayCatalog
}

type Event

type Event struct {
	At      time.Time
	Topic   string
	Message any
}

type FillContext

type FillContext struct {
	Order      model.OrderStatusReport
	Instrument model.Instrument
	Source     FillSource
	Price      decimal.Decimal
	Quantity   decimal.Decimal
	Timestamp  time.Time
	LimitTouch bool
	Taker      bool
}

type FillModel

type FillModel interface {
	ShouldFillLimitTouch(FillContext) bool
	ApplySlippage(FillContext, decimal.Decimal) decimal.Decimal
}

type FillModelConfig

type FillModelConfig struct {
	ProbFillOnLimit    float64
	ProbFillOnLimitSet bool
	ProbSlippage       float64
	RandomSeed         int64
}

type FillSource

type FillSource string
const (
	FillSourceTicker    FillSource = "ticker"
	FillSourceOrderBook FillSource = "order_book"
	FillSourceQuoteTick FillSource = "quote_tick"
	FillSourceTradeTick FillSource = "trade_tick"
	FillSourceBar       FillSource = "bar"
)

type Match

type Match struct {
	Source    FillSource
	Price     decimal.Decimal
	Quantity  decimal.Decimal
	Timestamp time.Time
}

type MatchingCore

type MatchingCore struct {
	// contains filtered or unexported fields
}

func NewMatchingCore

func NewMatchingCore(cfg MatchingCoreConfig) *MatchingCore

func (*MatchingCore) MatchOrderBook

func (c *MatchingCore) MatchOrderBook(req OrderBookMatchRequest) []Match

type MatchingCoreConfig

type MatchingCoreConfig struct {
	Instrument model.Instrument
	FillModel  FillModel
}

type MemoryCatalog

type MemoryCatalog struct {
	// contains filtered or unexported fields
}

func NewMemoryCatalog

func NewMemoryCatalog(events ...Event) *MemoryCatalog

func (*MemoryCatalog) Add

func (c *MemoryCatalog) Add(event Event)

func (*MemoryCatalog) Events

func (c *MemoryCatalog) Events(context.Context) ([]Event, error)

type OrderBookMatchRequest

type OrderBookMatchRequest struct {
	Order       model.OrderStatusReport
	Book        model.OrderBook
	Consumed    map[string]decimal.Decimal
	MaxQuantity decimal.Decimal
}

type ProbabilisticFillModel

type ProbabilisticFillModel struct {
	// contains filtered or unexported fields
}

func DefaultFillModel

func DefaultFillModel() *ProbabilisticFillModel

func NewFillModel

func NewFillModel(cfg FillModelConfig) (*ProbabilisticFillModel, error)

func (*ProbabilisticFillModel) ApplySlippage

func (m *ProbabilisticFillModel) ApplySlippage(ctx FillContext, price decimal.Decimal) decimal.Decimal

func (*ProbabilisticFillModel) ShouldFillLimitTouch

func (m *ProbabilisticFillModel) ShouldFillLimitTouch(ctx FillContext) bool

type Result

type Result struct {
	EventsProcessed int
	Cache           *cache.Cache
	Portfolio       *portfolio.Portfolio
	AccountIDs      []model.AccountID
	Execution       execution.Health
}

func (Result) DeterministicJSON

func (r Result) DeterministicJSON(accountIDs ...model.AccountID) ([]byte, error)

func (Result) Summary

func (r Result) Summary(accountIDs ...model.AccountID) ResultSummary

type ResultSummary

type ResultSummary struct {
	EventsProcessed int                    `json:"events_processed"`
	Accounts        []AccountResultSummary `json:"accounts"`
}

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

func NewRunner

func NewRunner(cfg Config) *Runner

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) (Result, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL