Skip to main content

Core Type System

Doc map: alphaswarm_docs/index.md · Full Symbol class diagram: alphaswarm_docs/class-diagram.md#1-symbol--core-enums.

AlphaSwarm 0.3 ports Lean's data model into Python with minimal surface area, full backward compatibility, and strict dataclass-only value objects.

Quick map

Lean (C#)AlphaSwarm (Python)File
SliceSlicealphaswarm/core/slice.py
BaseDataBarData (alias TradeBar), QuoteBar, TickData (alias Tick)alphaswarm/core/types.py
SubscriptionDataConfigSubscriptionDataConfigsame
Resolution / TickTypeResolution / TickTypesame
DataNormalizationModeDataNormalizationModesame
Symbol / SecurityIdentifierSymbol (composite ticker.exchange)same
Security / SecurityHoldingSecurityHolding (extends PositionData)same
Cash / CashBookCash / CashBooksame
Order / OrderTicket / OrderEventOrderData / OrderTicket / OrderEventsame
IndicatorBase<T> / RollingWindow<T>IndicatorBase[T] / RollingWindow[T]alphaswarm/core/indicators.py
MarketHoursDatabaseMarketHoursDatabasealphaswarm/core/exchange_hours.py
MapFile / FactorFileMapFile / FactorFilealphaswarm/core/corporate_actions.py

Migration notes

  • BarData is unchanged. TradeBar is a type alias; existing backtest code keeps working.
  • TickData is unchanged. Tick is an alias.
  • PositionData is unchanged. The richer SecurityHolding is additive — convert via SecurityHolding.from_position(pos).
  • on_bar(bar, ctx) remains the supported strategy entry point. Strategies that implement on_data(slice, ctx) get called once per timestamp instead of once per symbol; the engine auto-detects which method to call.
  • Orders now surface as tickets. The engine populates BacktestResult.tickets with :class:OrderTicket objects that carry the full OrderEvent stream for each order.

Indicator registry

25 built-in indicators, all subclasses of IndicatorBase. Resolve by string via build_indicator("SMA", period=20) or import directly.

from alphaswarm.core.indicators import SimpleMovingAverage, warmup

sma = SimpleMovingAverage(20)
print(warmup(sma, [100, 101, 102])) # NaN until 20 samples

Subscription routing

Every downstream consumer (backtest engine, paper engine, RL env, factor job) reads data through :class:SubscriptionDataConfig via :class:alphaswarm.data.subscription.SubscriptionManager. That swap enables normalisation-aware queries and composite history providers without touching strategy code.

Type relationships