AllassoTradeMachine
AllassoTradeMachine.sequential
classmethod
AllassoTradeMachine.run
EnvironmentBuilder
build().
Parameters
EnvironmentBuilder.with_datafeed
datafeed instead of the default local one.
build() then requires a matching resolver from with_resolver.
EnvironmentBuilder.with_resolver
resolver instead of the default local resolver registry.
EnvironmentBuilder.with_broker
broker instead of the default SimulationBroker.
EnvironmentBuilder.with_portfolio
portfolio instead of one built from initial_equity.
Its own fee calculator stands: with_fee_calculator is then ignored.
EnvironmentBuilder.with_pulse_index
pulse_index as the clock, in preference to any calendar.
build() still derives the underlyings’ common settlements when with_datetimes
is absent; only the resulting value goes unused.
EnvironmentBuilder.with_datetimes
datetimes instead of on the underlyings’ common settlements.
Copied, and ignored if with_pulse_index supplies a clock of its own. Mutually
exclusive with with_date_range: an explicit calendar is already bounded.
EnvironmentBuilder.with_date_range
available_settlements, so the calendar is bisected rather than
derived whole and trimmed. Mutually exclusive with with_datetimes, and ignored if
with_pulse_index supplies a clock of its own.
Parameters
EnvironmentBuilder.with_fee_calculator
fee_calculator to the default Portfolio built by build().
Ignored if a portfolio was already supplied via with_portfolio.
EnvironmentBuilder.build
ExecutionResult
dataclass
TradingEnvironment
dataclass
TradingEnvironment.attach_to_strategy
Broker
ABC
Broker class that serves as a base for different broker implementations.
Brokers are responsible for managing orders and executing them into trades.
Pulse method should return the trades that were executed during the pulse.
Broker.open_orders
property
Broker.orders
property
Broker.pulse
abstractmethod
Broker.create_order
abstractmethod
SimulationBroker that happens during the broker step of the same pulse, at that
pulse’s market data (no execution delay and no slippage).
Parameters
SimulationBroker
Broker
Backtest broker that fills every open order in full on the pulse it is stepped on.
Orders are filled at that pulse’s market data, so there is no execution delay, no partial fill
and no slippage: a trade’s open_datetime is the pulse its order was placed on. Only market
orders exist; pass fill_price to create_order to model a haircut.
SimulationBroker.create_order
Raises
SimulationBroker.pulse
TradesSummary
dataclass
Strategy.calculate_trades_summary, which is how a strategy reads a multi-leg
structure as one position. The greeks and iv default to None and are filled from the
legs that carry them, so a futures or spot leg contributes 0 to a greek total and drops out of
the iv average.
Attributes
Order
Initialize an Order object.
Raises
Order.id
property
Order.instrument
property
Order.quantity
property
Order.open_datetime
property
Order.execution_datetime
property
Order.tags
property
Order.fill_price
property
Order.is_lots
property
Order.source_id
property
Portfolio
init_stats seeds the history lists and must run before the first pulse, which marks the
open trades, queues their fee events, closes what is due and nets the pulse’s fees against
equity. The portfolio keeps no greek aggregate: book exposure is the sum of
Trade.delta_contract over open_trades, computed where it is needed.
Parameters
Attributes
Portfolio.trades
property
Portfolio.open_trades
property
Portfolio.pulse_total_pnl
property
pulse_abs_pnl across all open trades for the most recent pulse.
Returns
Portfolio.pulse_total_pnl_history
property
datetimes (one entry per pulse).
Returns
Portfolio.daily_datetimes
property
Portfolio.daily_total_pnl_history
property
Portfolio.equity_history
property
Portfolio.datetimes
property
Portfolio.current_equity
property
Portfolio.initial_equity
property
Portfolio.equity_pct_change
property
Portfolio.equity_pct_change_history
property
Portfolio.pulse_fees
property
pulse() used to zero the
accumulator on its way out, so this could only ever answer 0.0 however much was charged.
Portfolio.pulse_fees_history
property
datetimes (one entry per pulse).
Portfolio.total_fees
property
init_stats.
Portfolio.init_stats
Portfolio.add_trade
Portfolio.pulse
Portfolio.close_all
Portfolio.__charge_exit_fee
trade._close_price
is guaranteed to be set by _instant_trade_close immediately prior.
The event is drained alongside entries/rebalances at end of pulse().
Portfolio.__close_trades
_close_on_pulse_end.
Parameters
InstrumentDictSerializer
Bases: Serializer
Serializer for Instrument objects.
InstrumentDictSerializer.serialize
staticmethod
InstrumentDictSerializer.deserialize
staticmethod
OrderDictSerializer
Bases: Serializer
Serializer for Order objects.
OrderDictSerializer.serialize
staticmethod
OrderDictSerializer.deserialize
staticmethod
PortfolioDictSerializer
Bases: Serializer
Serializer for Portfolio objects.
PortfolioDictSerializer.serialize
staticmethod
PortfolioDictSerializer.deserialize
staticmethod
PulseIndexDictSerializer
Bases: Serializer
Serializer for PulseIndex objects.
PulseIndexDictSerializer.serialize
staticmethod
PulseIndexDictSerializer.deserialize
staticmethod
SimulationBrokerBrokerDictSerializer
Bases: Serializer
Serializer for Broker objects.
SimulationBrokerBrokerDictSerializer.serialize
staticmethod
SimulationBrokerBrokerDictSerializer.deserialize
staticmethod
StatsDictSerializer
Bases: Serializer
Serializer for Stats objects.
StatsDictSerializer.serialize
staticmethod
_finite have None, NaN and inf coerced to 0.0. The equity
totals and the date strings pass through untouched; return_table and the legacy flat
trade fields are still coerced, to {} and 0, by their own or fallbacks.
StatsDictSerializer.deserialize
staticmethod
StrategyDictSerializer
Bases: Serializer
Serializer for Strategy objects.
StrategyDictSerializer.serialize
staticmethod
StrategyDictSerializer.deserialize
staticmethod
TradeDictSerializer
Bases: Serializer
Serializer for Trade objects.
TradeDictSerializer.serialize
staticmethod
TradeDictSerializer.deserialize
staticmethod
TradeListPandasSerializer
Bases: Serializer
Serializer for a list of Trade objects, as a DataFrame with one row per trade.
TradeListPandasSerializer.serialize
staticmethod
TradeDictSerializer.serialize, so
nested values (the instrument, the tag list, the per-pulse histories) stay as objects in
their cell. An empty list gives an empty frame with no columns at all.
TradeListPandasSerializer.deserialize
staticmethod
Strategy
on_update() and trade through self.
on_update() runs once per pulse, after the clock has advanced and before the broker
fills that pulse’s orders. The collaborators it reaches for (datafeed, resolver,
broker, portfolio, pulse_index) are attached by the TradingEnvironment when
the run starts, which is why they are not constructor arguments.
Initialize the Strategy with its underlying id(s), a name and a description.
Parameters
Strategy.id
property
Strategy.underlying_id
property
Strategy.pulse_index
property
Strategy.last_pulse
property
Strategy.open_trades
property
Strategy.has_open_trades
property
Strategy.trades
property
Strategy.broker
property
Strategy.portfolio
property
Strategy.current_equity
property
Strategy.initial_equity
property
Strategy.pnl
property
current_equity - initial_equity. Includes the impact of fees
(because both terms are post-fee).
Strategy.pnl_pct
property
pnl / abs(current_equity). The denominator is the current
portfolio equity, so this is the live, sizing-aware return of the whole
strategy. Same basis as TradesSummary.pnl_pct; differs from
Trade.pnl_pct, which is fixed to each trade’s equity-at-open
snapshot. abs keeps the sign coming from pnl. Returns 0.0 if
current_equity is 0.
Strategy.pnl_pct_of_initial_equity
property
pnl / abs(initial_equity). Stable denominator across the entire
run, mirroring Trade.pnl_pct_of_initial_equity and
TradesSummary.pnl_pct_of_initial_equity. Returns 0.0 if
initial_equity is 0.
Strategy.datafeed
property
Strategy.resolver
property
Strategy.stats
property
Strategy.set_datafeed
Strategy.set_resolver
Strategy.set_broker
Strategy.set_portfolio
Strategy.set_pulse_index
Strategy.on_update
Strategy.pulse
Strategy.create_order
Strategy.buy
Strategy.sell
Strategy.close_all
Strategy.calculate_stats
Returns
Strategy.get_trades_by_tags
Returns
Strategy.close_trades_by_tags
Strategy.calculate_trades_summary
TradesSummary, marked at the current pulse.
Parameters
Returns
Raises
Strategy.get_trades_summary_by_tags
Returns
PulseIndex
PulseIndex.datetimes
property
PulseIndex.last_pulse
property
PulseIndex.pulses_per_year
cached property
len(datetimes) * 365 / span_calendar_days.
Examples: SPX daily backtest (~252 datetimes spanning ~365 days) -> ~252.
BTC hourly 24/7 (~8760 over 365 days) -> ~8760. SPX hourly 6.5h sessions
(~1638 over 365 days) -> ~1638.
Cached on first access. Invalidated by append.
PulseIndex.index
property
PulseIndex.__clear_cache
pulses_per_year so the next access recomputes over the new calendar.
functools.cached_property stores its value in the instance __dict__ under the
property’s own name (shadowing the descriptor); popping it re-exposes the getter. No-op
when the property was never accessed.
PulseIndex.append
PulseIndex.extend
datetimes is assumed
sorted. The cursor stays where it is, so a finished run resumes on the first new datetime.
Parameters
PulseIndex.pulse
PulseIndex.has_next
PulseIndex.peek_next
pulse would land on, or None at the end.
Lets callers test “is this the next pulse” without reaching into the index arithmetic.
Returns
PulseIndex.advance_to
<= target (assumes sorted datetimes).
A one-shot seek used to skip a leading span without pulsing through it step by step. When
target precedes the first datetime the cursor stays at index 0; when it is at or past the
last, it lands on the last.
Parameters
PulseIndex.pulse_history
Returns
Trade
Order into.
Construction is two-phase. __init__ records what was filled; Portfolio.add_trade then
calls init_stats, which reads the opening mark off the datafeed and sets the prices, greeks,
notional and history lists. Until it has run the trade cannot be pulsed and none of that marked
state can be read. pulse marks the trade once per pulse thereafter, skipping the pulse it
opened on.
Parameters
Trade.trade_id
property
Trade.order_id
property
Trade.open_price
property
Trade.open_quantity
property
Trade.fill_price
property
Trade.settlement_price_at_open
property
Trade.close_price
property
Trade.instrument
property
Trade.quantity
property
Trade.is_lots
property
Trade.contract_size
property
Trade.price_format_multiplier
property
Trade.units
property
contract_size).
Trade.sign
property
Trade.open_datetime
property
Trade.close_datetime
property
Trade.is_open
property
Trade.tags
property
Trade.source_id
property
pulse.core.order.Order that filled into this trade. None for trades not
attributed to a sleeve (e.g. classic single-strategy use).
Trade.pnl
property
Trade.pnl_pct
property
pnl / abs(equity_at_open). Sizing-aware - tells you how this trade
moved the account at the moment it was taken. Denominator is wrapped
in abs so a gain on a negative-equity account still reads
positive. Returns 0.0 if equity_at_open is 0.
Trade.initial_equity
property
Portfolio.add_trade.
Trade.equity_at_open
property
current_equity at the pulse this trade opens on,
captured by Portfolio.add_trade.
Trade.pnl_pct_of_initial_equity
property
pnl / abs(initial_equity). Stable denominator across the run -
directly comparable across trades. Returns 0.0 if
initial_equity is 0.
Trade.pulse_abs_pnl
property
Trade.pulse_pct_pnl
property
Trade.datetimes
property
Trade.abs_pnl_history
property
Trade.pct_pnl_history
property
Trade.pulse_abs_pnl_history
property
datetimes (one entry per pulse).
Trade.pulse_pct_pnl_history
property
datetimes (one entry per pulse).
Trade.daily_datetimes
property
Trade.daily_abs_pnl_history
property
Trade.daily_pct_pnl_history
property
Trade.daily_abs_pnl
property
datetimes[-1].date()).
For daily cadence this equals pulse_abs_pnl.
Trade.daily_pct_pnl
property
Trade.quantity_history
property
Trade.price_history
property
Trade.notional_history
property
Trade.delta
property
Trade.gamma
property
Trade.theta
property
Trade.vega
property
Trade.delta_contract
property
Trade.gamma_contract
property
Trade.theta_contract
property
Trade.vega_contract
property
Trade.delta_history
property
datetimes (one entry per pulse).
Trade.gamma_history
property
datetimes (one entry per pulse).
Trade.theta_history
property
datetimes (one entry per pulse).
Trade.vega_history
property
datetimes (one entry per pulse).
Trade.delta_contract_history
property
datetimes (one entry per pulse).
Trade.gamma_contract_history
property
datetimes (one entry per pulse).
Trade.theta_contract_history
property
datetimes (one entry per pulse).
Trade.vega_contract_history
property
datetimes (one entry per pulse).
Trade.underlying_price_history
property
price_format_multiplier.
Length matches datetimes (one entry per pulse).
Trade.iv_history
property
None for a future or spot.
Length matches datetimes (one entry per pulse).
Trade.init_stats
Trade.values_at
_mark) and summarising
(Strategy.calculate_trades_summary) cannot disagree about what a data gap means. Because
the carried value is the record the data layer actually returned, a dark futures or spot leg
keeps its real shape: it has no delta attribute, exactly as on a healthy pulse, so it
stays out of the greek aggregates instead of being pulled into them by a stand-in.
strict=True re-raises instead, for a caller that needs a real row: opening a trade needs
a real price, and the framework’s shadow repricer wants an unpriceable leg to surface.
Only the data layer’s own LookupError counts as “this contract is absent”. KeyError
and IndexError are subclasses of it raised by faults inside the reader (a missing column,
a bisect off a truncated file), so those propagate rather than being carried forward as a
flat mark for the rest of the run.
Trade.add_tag
Trade.has_tag
Trade has tag or list of tags.
Parameters
Returns
Trade.rebalance
Raises
Trade.pulse
Trade.close
Stats
dataclass
Stats.from_data
classmethod
Returns
Stats.from_strategy
classmethod
Returns
Stats.calculate
run_sequentially
EnvironmentBuilder per strategy, built from that strategy’s own underlying_id,
so a sweep is just a list of strategies here. Every strategy gets its own portfolio, broker
and pulse index; the datafeed and resolver are shared, which is what makes the warmed readers
worth paying for once.
The pulse calendar is the underlyings’ common settlements, optionally bounded by
start_datetime / end_datetime, which are handed to pdc’s available_settlements
and are inclusive at both ends. datetimes replaces that calendar outright instead, so it
cannot be combined with the bounds.
Parameters
Raises
Returns

