pvbt

command module
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

README

pvbt

CI Go License

Every quantitative strategy begins as a simple idea -- buy momentum, hedge with bonds, rebalance monthly. Then the infrastructure arrives: data pipelines, date alignment, survivorship bias, split adjustments, slippage models. Before long the idea is buried under ten thousand lines of plumbing.

pvbt inverts that ratio. You write the thirty lines that express your thesis; the engine supplies the ten thousand underneath. The same strategy code backtests against two decades of history or trades live tomorrow.

Highlights

  • No data plumbing. Fetch through universes; the engine discovers your requirements, routes requests to providers, and caches results. You never write a loader.
  • Survivorship-bias-free universes. Index membership resolves historically -- the S&P 500 on January 3, 2008 returns exactly the stocks in the index that day, not today's composition.
  • 60+ performance metrics, including taxes. Sharpe, Sortino, Calmar, drawdowns, and dozens more -- plus long- and short-term capital gains, qualified dividends, and safe withdrawal rates.
  • Market-aware scheduling. Write @monthend instead of manual last-trading-day logic. Tradecron knows holidays, half-days, and market hours.
  • DataFrames that compose. Chain df.Pct(1).Rolling(20).Mean() with automatic error propagation. Columns are contiguous []float64, directly compatible with gonum.
  • One codebase, backtest to production. The API never exposes whether you are in a simulation or trading live.

Quick Example

Accelerating Dual Momentum:

type ADM struct {
	RiskOn  universe.Universe `pvbt:"riskOn"  desc:"equity universe" default:"SPY,GLD,VWO"`
	RiskOff universe.Universe `pvbt:"riskOff" desc:"safe-haven"      default:"TLT"`
}

func (s *ADM) Name() string { return "adm" }

func (s *ADM) Setup(_ *engine.Engine) {}

func (s *ADM) Describe() engine.StrategyDescription {
	return engine.StrategyDescription{
		Schedule:  "@monthend",
		Benchmark: "SPY",
	}
}

func (s *ADM) Compute(ctx context.Context, eng *engine.Engine, p portfolio.Portfolio, batch *portfolio.Batch) error {
	mom := signal.Momentum(ctx, s.RiskOn, portfolio.Months(3), data.MetricClose)
	if err := mom.Err(); err != nil {
		return nil
	}

	riskOffDF, err := s.RiskOff.At(ctx, data.MetricClose)
	if err != nil {
		return nil
	}

	portfolio.MaxAboveZero(data.MetricClose, riskOffDF).Select(mom)
	plan, err := portfolio.EqualWeight(mom)
	if err != nil {
		return nil
	}
	batch.RebalanceTo(ctx, plan...)
	return nil
}

The engine handles data loading, order execution, commission/slippage, and performance measurement.

Installation

Requires Go 1.25.6 or later.

go get github.com/penny-vault/pvbt

How It Works

A strategy implements three methods:

Method Purpose
Name() Returns the strategy's short identifier
Setup(eng *Engine) Optional initialization after fields are populated
Compute(ctx, eng, p, batch) Runs at each scheduled step to make allocation decisions

The engine runs in three phases:

  1. Setup -- populates strategy fields from struct tags, registers universes, and builds a data loading plan.
  2. Computation -- steps through time according to the schedule, calling Compute at each step.
  3. Results -- the returned portfolio provides access to the transaction log and performance metrics over its full history.

Documentation

  • Strategy Author's Guide -- complete walkthrough from first strategy to testing
  • Overview -- introduction and design principles
  • Engine -- configuration, strategy interface, data access, trade preview
  • Universes -- asset groups, index tracking, historical membership
  • Data -- metrics, data providers, DataFrames, signals
  • Portfolio -- construction, order types, risk middleware, performance measurement
  • Performance Metrics -- 60+ metrics reference, custom metrics, MFE/MAE
  • Broker -- broker interface, tastytrade, Alpaca, and Schwab integrations, order groups
  • Scheduling -- tradecron syntax and schedule configuration
  • Configuration -- struct tags, presets, and strategy parameterization

Performance

Good strategy research means running backtests often -- tweaking a parameter, testing a variant, checking a hunch. The engine is designed to keep that loop tight so you spend your time thinking, not waiting. A 30-year backtest of Accelerating Dual Momentum finishes in about 4 seconds on an M-series MacBook.

  • Zero-copy DataFrame views. Windowing, filtering by metric, and selecting assets share the underlying data instead of copying it, keeping chained transformations cheap over decades of daily history.
  • Shared metric computation. The 85+ built-in metrics share intermediate results -- when 26 metrics all need the same windowed returns, they compute them once.
  • Low allocation pressure. Per-column storage and view-based slicing minimize GC pauses, so performance stays consistent across long backtests.

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package asset defines the Asset type representing a tradeable instrument identified by a CompositeFigi and a human-readable Ticker.
Package asset defines the Asset type representing a tradeable instrument identified by a CompositeFigi and a human-readable Ticker.
Package broker defines the interface between the portfolio and a brokerage.
Package broker defines the interface between the portfolio and a brokerage.
alpaca
Package alpaca implements broker.Broker for the Alpaca brokerage.
Package alpaca implements broker.Broker for the Alpaca brokerage.
etrade
Package etrade implements broker.Broker for E*TRADE (Morgan Stanley).
Package etrade implements broker.Broker for E*TRADE (Morgan Stanley).
ibkr
Package ibkr implements broker.Broker for the Interactive Brokers brokerage.
Package ibkr implements broker.Broker for the Interactive Brokers brokerage.
schwab
Package schwab implements broker.Broker for the Charles Schwab brokerage.
Package schwab implements broker.Broker for the Charles Schwab brokerage.
tastytrade
Package tastytrade implements broker.Broker for the tastytrade brokerage.
Package tastytrade implements broker.Broker for the tastytrade brokerage.
tradestation
Package tradestation implements broker.Broker for the TradeStation brokerage.
Package tradestation implements broker.Broker for the TradeStation brokerage.
tradier
Package tradier implements broker.Broker for the Tradier brokerage.
Package tradier implements broker.Broker for the Tradier brokerage.
webull
Package webull implements broker.Broker for the Webull brokerage using the official Webull OpenAPI platform.
Package webull implements broker.Broker for the Webull brokerage using the official Webull OpenAPI platform.
cli
Package cli provides the command-line interface for pvbt strategies.
Package cli provides the command-line interface for pvbt strategies.
summary
Package summary builds and renders backtest summary reports to a terminal.
Package summary builds and renders backtest summary reports to a terminal.
Package data provides the core types for working with financial time-series data in pvbt.
Package data provides the core types for working with financial time-series data in pvbt.
Package engine is the main entry point for pvbt, a backtesting engine library.
Package engine is the main entry point for pvbt, a backtesting engine library.
middleware/risk
Package risk provides portfolio middleware for enforcing risk constraints.
Package risk provides portfolio middleware for enforcing risk constraints.
middleware/tax
Package tax provides portfolio middleware for tax-loss harvesting.
Package tax provides portfolio middleware for tax-loss harvesting.
examples
momentum-rotation command
Momentum Rotation is a simple strategy that rotates into the asset with the highest trailing return over a configurable lookback period.
Momentum Rotation is a simple strategy that rotates into the asset with the highest trailing return over a configurable lookback period.
Package library manages discovery, installation, listing, and removal of pvbt strategy plugins.
Package library manages discovery, installation, listing, and removal of pvbt strategy plugins.
Package portfolio is where strategy decisions become trades.
Package portfolio is where strategy decisions become trades.
Package signal provides reusable computations that derive new time series from market data (prices, volume, fundamentals, economic indicators).
Package signal provides reusable computations that derive new time series from market data (prices, volume, fundamentals, economic indicators).
Package study provides a framework for running a strategy multiple times with different configurations and synthesizing the results into a report.
Package study provides a framework for running a strategy multiple times with different configurations and synthesizing the results into a report.
optimize
Package optimize implements the parameter-optimization study type.
Package optimize implements the parameter-optimization study type.
report
Package report defines the Report interface for Vue-based HTML reports and provides a Render function that produces self-contained HTML files.
Package report defines the Report interface for Vue-based HTML reports and provides a Render function that produces self-contained HTML files.
stress
Package stress implements the stress test study type.
Package stress implements the stress test study type.
Package tradecron extends standard cron syntax with awareness of trading calendars.
Package tradecron extends standard cron syntax with awareness of trading calendars.
Package universe defines the investable space for a strategy.
Package universe defines the investable space for a strategy.

Jump to

Keyboard shortcuts

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