BacktestSimplePricingModel#

tradeexecutor.backtest.backtest_pricing.BacktestSimplePricingModel class.

class BacktestSimplePricingModel[source]#

Bases: PricingModel

Look up the historical prices.

  • Candle close price is used

  • This is a simple model and does not use liquidity data for the price impact estimation

  • We provide data_delay_tolerance to deal with potential gaps in price data

__init__(candle_universe, routing_model, data_delay_tolerance=Timedelta('2 days 00:00:00'), candle_timepoint_kind='close', very_small_amount=Decimal('0.10'))[source]#
Parameters
  • candle_universe (GroupedCandleUniverse) – Candles where our backtesing date comes from

  • routing_model (RoutingModel) – How do we route trades between different pairs TODO: Now ignored

  • data_delay_tolerance

    How long time gaps we allow in the backtesting data before aborting the backtesting with an exception. This is an safety check for bad data.

    Sometimes there cannot be trades for days if the blockchain has been halted, and thus no price data available.

  • candle_timepoint_kind – Do we use opening or closing price in backtesting

  • very_small_amount – What kind o a test amount we do use for a trade when we do not know the actual size of the trade.

Methods

__init__(candle_universe, routing_model[, ...])

param candle_universe

check_supported_quote_token(pair)

get_buy_price(ts, pair, reserve)

Get the sell price for an asset.

get_mid_price(ts, pair)

Get the mid price by the candle.

get_pair_for_id(internal_id)

Look up a trading pair.

get_sell_price(ts, pair, quantity)

Get the sell price for an asset.

quantize_base_quantity(pair, quantity[, ...])

Convert any base token quantity to the native token units by its ERC-20 decimals.

__init__(candle_universe, routing_model, data_delay_tolerance=Timedelta('2 days 00:00:00'), candle_timepoint_kind='close', very_small_amount=Decimal('0.10'))[source]#
Parameters
  • candle_universe (GroupedCandleUniverse) – Candles where our backtesing date comes from

  • routing_model (RoutingModel) – How do we route trades between different pairs TODO: Now ignored

  • data_delay_tolerance

    How long time gaps we allow in the backtesting data before aborting the backtesting with an exception. This is an safety check for bad data.

    Sometimes there cannot be trades for days if the blockchain has been halted, and thus no price data available.

  • candle_timepoint_kind – Do we use opening or closing price in backtesting

  • very_small_amount – What kind o a test amount we do use for a trade when we do not know the actual size of the trade.

get_pair_for_id(internal_id)[source]#

Look up a trading pair.

Useful if a strategy is only dealing with pair integer ids.

Parameters

internal_id (int) –

Return type

Optional[TradingPairIdentifier]

get_sell_price(ts, pair, quantity)[source]#

Get the sell price for an asset.

Parameters
  • ts (datetime) – When to get the price. Used in backtesting. Live models may ignore.

  • pair (TradingPairIdentifier) – Trading pair we are intereted in

  • quantity (Optional[Decimal]) – If the sel quantity is known, get the price with price impact.

Return type

USDollarAmount

get_buy_price(ts, pair, reserve)[source]#

Get the sell price for an asset.

Parameters
  • ts (datetime) – When to get the price. Used in backtesting. Live models may ignore.

  • pair (TradingPairIdentifier) – Trading pair we are intereted in

  • reserve (Optional[Decimal]) – If the buy token quantity quantity is known, get the buy price with price impact.

Return type

USDollarAmount

get_mid_price(ts, pair)[source]#

Get the mid price by the candle.

Parameters
Return type

USDollarAmount

quantize_base_quantity(pair, quantity, rounding='ROUND_DOWN')[source]#

Convert any base token quantity to the native token units by its ERC-20 decimals.

Parameters
Return type

Decimal