PaperBroker and Paper Execution
PaperBroker is AQE’s execution simulator for:
- backtesting
- paper trading
- validating insight lifecycle behaviour
It handles:
- order submission
- fills
- cancels
- close requests
- bracket legs
- trailing stop execution
- trade event emission
- account and equity state
It is also responsible for preventing invalid paper account states, such as orders that would exceed available buying power.
YahooFinanceDataFeed
Section titled “YahooFinanceDataFeed”YahooFinanceDataFeed provides:
- ticker metadata
- historical bars
- latest quotes
- latest bars
- live bar stream subscription
That is the default market-data path used for historical research and paper-oriented runtime workflows.
Asset fee model
Section titled “Asset fee model”AQE models asset fees separately from gross trade PnL. Asset.fees contains:
commission.entry.longandcommission.entry.shortfor opening long and short positionscommission.exit.longandcommission.exit.shortfor closing long and short positionsswap.longandswap.shortfor overnight financing or credit on long and short positions
Long and short refer to the position side, not just the immediate order action. A buy order that opens exposure uses the long entry fee. A sell order that opens exposure uses the short entry fee. When a position closes, AQE applies the exit fee and swap for the original position side, so commission.exit.short is the close fee for a short position even though the close action is a buy.
Commission and swap use the same public fee kind enum, AssetFee. The available fee kinds are:
AssetFee::NoneAssetFee::Points(points), used for point-based swap calculationAssetFee::PercentageFee(rate), where0.001means 0.1% of traded notionalAssetFee::FixedFee(amount), a fixed amount per fillAssetFee::PerContractFee(amount), multiplied by traded quantityAssetFee::PercentagePerContractFee(rate), applied asprice * contract_size * quantity * rate
Commission calculations accept positive PercentageFee, FixedFee, PerContractFee, and PercentagePerContractFee values. Points is present on the shared enum because swap needs it; if used in a commission field, AQE treats it as zero.
Swap values may be positive or negative. A positive swap increases PnL and a negative swap reduces PnL. On paper execution, AQE calculates net close PnL as:
gross PnL + swap - entry commission - exit commissionConfiguring PaperBroker fees
Section titled “Configuring PaperBroker fees”Use with_asset_fees(...) when creating the paper execution broker. Backtests generated by AQS use the same path.
use aq_engine::core::broker::paper_broker::PaperBroker;use aq_engine::core::broker::types::{ AccountType, AssetCommissionFees, AssetFee, AssetFees, AssetSideFees, AssetSwapFees,};
let fees = AssetFees { commission: AssetCommissionFees { entry: AssetSideFees { long: AssetFee::PercentageFee(0.0005), short: AssetFee::PercentageFee(0.0007), }, exit: AssetSideFees { long: AssetFee::FixedFee(1.0), short: AssetFee::FixedFee(1.0), }, }, swap: AssetSwapFees { long: AssetFee::PerContractFee(-3.25), short: AssetFee::PercentagePerContractFee(0.000041), }, ..AssetFees::default()};
let execution = PaperBroker::new(AccountType::Paper, 100_000.0, 1).with_asset_fees(fees);The legacy entry and exit fields on AssetFees are still accepted as a compatibility fallback when the side-specific commission object is empty. New configurations should use the commission and swap objects.
Related source
Section titled “Related source”aq-engine/src/core/broker/paper_broker.rsaq-engine/src/core/broker/types/mod.rsaq-engine/src/core/broker/data_feeds/yahoo.rs
We use essential cookies and storage for sign-in, account security, colour theme preferences, this notice, and required PostHog internal usage, session quality, and reliability metrics. We do not use advertising cookies.
