planner

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package planner turns a strategy's intent into concrete, finalized broker requests. It owns the business logic that sits between signal generation (strategy) and execution (engine/broker): the regime and max-spread gates, fill-price adjustment, initial-stop placement, and position sizing.

Strategies emit strategy.Signal values; PlanSignal converts them into StrategyPlans that the engine submits to the broker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultPlanner

type DefaultPlanner struct{}

DefaultPlanner is the behavior-preserving extraction of the logic that used to live inline in the backtest run loop. It is stateless.

func (DefaultPlanner) PlanSignal

PlanSignal translates a strategy.Signal into a finalized StrategyPlan using the same gates and order-construction logic as Plan.

  • Flat + !CloseAll → hold; return empty plan immediately.
  • CloseAll=true → close ALL open lots (time-based / band-reversion exits).
  • Directional + !CloseAll → reversal-close opposing lots only.
  • Directional side → open a new position at candle close; then run the full Plan pipeline (regime gate, max-spread gate, fill-price, sizing).

type PlanContext

type PlanContext interface {
	Instrument() string
	Account() *execution.Account
	Exit() strategy.ExitStrategy
	Regime() strategy.RegimeFilter
	Candle() market.CandleTime
	Slippage() market.Price
	MaxSpread() market.Price
	// DefaultStopPips returns a fallback stop distance (in deci-pips) applied
	// when neither the strategy signal nor the exit strategy supplies a stop.
	// 0 means no fallback is configured.
	DefaultStopPips() market.Pips
}

PlanContext is the read/compute view a Planner needs to finalize a plan against the current bar: the account (for sizing), the active exit strategy and regime filter, the current candle, and the configured execution-cost parameters.

type Stats

type Stats struct {
	SpreadFiltered int          // opens suppressed by the max-spread gate
	SpreadOpened   int          // opens accepted (denominator for avg-spread)
	SpreadSum      market.Price // sum of candle AvgSpread over accepted opens
}

Stats reports the execution-cost bookkeeping a Planner produces while finalizing a plan. Callers fold these into their run state.

Jump to

Keyboard shortcuts

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