Tradewind
Copyright 2026 Papers With Backtest

Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this software except in compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0.

Tradewind is an independent, clean-room implementation. It is compatible with the
public API of backtrader but shares no code with it. Where its design follows
QuantConnect's Lean (Apache License 2.0), the attribution is recorded in this file.

Design attributions to QuantConnect Lean (https://github.com/QuantConnect/Lean,
Copyright QuantConnect Corporation, Apache License 2.0):

* spec/05-interfaces.md follows the decomposition of Lean's Security, SymbolProperties,
  SecurityHolding, CashBook, IFeeModel, IFillModel, ISlippageModel, IBuyingPowerModel,
  ISettlementModel, IShortableProvider, IMarginInterestRateModel, ISecurityPortfolioModel,
  SecurityChanges and SecurityExchangeHours, and the phase order of its
  AlgorithmManager time loop. The Python interfaces are Tradewind's own.
* src/tradewind/calendars.py and clock.ExchangeClock follow the shape of Lean's
  MarketHoursDatabase / SecurityExchangeHours (per exchange: time zone, weekly sessions,
  holidays, early closes) and its fill-forward of minute slices. The holiday rules and
  the code are Tradewind's own, written from the exchanges' published rules.
* spec/07-live-ibkr.md and src/tradewind/live/ follow two concepts of Lean's live trading:
  a brokerage behind one interface the algorithm never sees (IBrokerage), and a warm-up
  during which orders are refused. The Python code is Tradewind's own.

Optional dependency, not distributed with Tradewind: ib_async (BSD 2-Clause License,
https://github.com/ib-api-reloaded/ib_async), installed by the `ibkr` extra and imported
only by tradewind.live.ibkr when it connects.
* spec/06-intraday-and-options.md, src/tradewind/consolidators.py and
  src/tradewind/options.py follow the concepts of Lean's TradeBarConsolidator (bins by
  period and by count, bars stamped at their end, Scan), QCAlgorithm.Consolidate, Option
  securities and OptionSymbolProperties (contract multiplier), OptionChain and
  OptionFilterUniverse (Strikes, Expiration, CallsOnly, PutsOnly, FrontMonth), its
  Black-Scholes price model and the exercise of options at expiry. The code and the
  formulas (from their textbook definitions) are Tradewind's own.
* spec/09-futures.md and src/tradewind/futures.py follow the concepts of Lean's Future
  securities (contract multiplier, tick size), its futures margin model (initial and
  maintenance margin per contract), the expiry of a contract and its continuous contracts
  with their back-adjustment modes (ratio, difference). The code is Tradewind's own.
* spec/08-typed-api-and-analyzers.md, src/tradewind/typed.py and src/tradewind/performance.py
  follow the shape of Lean's QCAlgorithm (Initialize, OnData, OnOrderEvent,
  OnSecuritiesChanged, OnEndOfAlgorithm, SetHoldings, Liquidate, IsWarmingUp, Schedule.On)
  and the list of statistics of its backtest report (Sharpe and Sortino ratios,
  probabilistic Sharpe ratio, alpha, beta, drawdown, portfolio turnover, estimated strategy
  capacity). The Python classes, the formulas (the Papers With Backtest catalogue's, and
  Bailey and López de Prado's for the probabilistic Sharpe ratio) and the capacity method
  are Tradewind's own.
* src/tradewind/realistic.py and the currency handling of src/tradewind/broker.py follow
  the decomposition of Lean's realistic models -- a fee, fill, slippage, buying-power,
  settlement, shortable and margin-interest model per security; SecurityMarginModel and
  CashBuyingPowerModel; DelayedSettlementModel; MarginCallModel; a CashBook whose balances
  are converted at rates from forex securities. The rules (Reg T margins, settlement
  periods) are the regulators' published ones; the code is Tradewind's own.
* src/tradewind/universe.py, src/tradewind/corporate.py and the corporate-action model of
  src/tradewind/models.py follow the concepts of Lean's SecurityChanges and
  OnSecuritiesChanged (securities added to and removed from a universe), its Split,
  Dividend, Delisting and SymbolChangedEvent data events, and its DataNormalizationMode
  (raw, split-adjusted and adjusted prices). The code is Tradewind's own.

Optional dependencies, not distributed with Tradewind:

* matplotlib (Matplotlib License, BSD-style, https://matplotlib.org), installed by the `plot`
  and `tearsheets` extras and imported only by tradewind.plots and tradewind.tearsheets when a
  figure is drawn. The plots of src/tradewind/plots.py (equity curve, drawdown, monthly
  returns, exposure and turnover) are Tradewind's own code.
* pyfolio-reloaded, alphalens-reloaded and empyrical-reloaded (Apache License 2.0; originally
  Copyright Quantopian, Inc., maintained by Stefan Jansen at
  https://github.com/stefan-jansen/pyfolio-reloaded,
  https://github.com/stefan-jansen/alphalens-reloaded and
  https://github.com/stefan-jansen/empyrical-reloaded), installed by the `tearsheets` extra
  and imported only by tradewind.tearsheets. Tradewind contains none of their code: that
  module reshapes a run into the inputs their documented functions take and calls them.
