Core Type System
Doc map: alphaswarm_docs/index.md · Full
Symbolclass 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 |
|---|---|---|
Slice | Slice | alphaswarm/core/slice.py |
BaseData | BarData (alias TradeBar), QuoteBar, TickData (alias Tick) | alphaswarm/core/types.py |
SubscriptionDataConfig | SubscriptionDataConfig | same |
Resolution / TickType | Resolution / TickType | same |
DataNormalizationMode | DataNormalizationMode | same |
Symbol / SecurityIdentifier | Symbol (composite ticker.exchange) | same |
Security / SecurityHolding | SecurityHolding (extends PositionData) | same |
Cash / CashBook | Cash / CashBook | same |
Order / OrderTicket / OrderEvent | OrderData / OrderTicket / OrderEvent | same |
IndicatorBase<T> / RollingWindow<T> | IndicatorBase[T] / RollingWindow[T] | alphaswarm/core/indicators.py |
MarketHoursDatabase | MarketHoursDatabase | alphaswarm/core/exchange_hours.py |
MapFile / FactorFile | MapFile / FactorFile | alphaswarm/core/corporate_actions.py |
Migration notes
BarDatais unchanged.TradeBaris a type alias; existing backtest code keeps working.TickDatais unchanged.Tickis an alias.PositionDatais unchanged. The richerSecurityHoldingis additive — convert viaSecurityHolding.from_position(pos).on_bar(bar, ctx)remains the supported strategy entry point. Strategies that implementon_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.ticketswith :class:OrderTicketobjects that carry the fullOrderEventstream 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.