BacktestSimplePricingModel#

API documentation for tradeexecutor.backtest.backtest_pricing.BacktestSimplePricingModel Python class in Trading Strategy framework.

class BacktestSimplePricingModel[source]#

Bases: PricingModel

Look up the historical prices.

  • By default, assume we can get buy/sell at open price of the timestamp

  • Different pricing model can be used for rebalances (more coarse) and stop losses (more granular)

  • 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='open', very_small_amount=Decimal('0.10'), time_bucket=None, allow_missing_fees=False)[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.

  • time_bucket (Optional[TimeBucket]) –

    The granularity of the price data.

    Currently used for diagnostics and debug only.

  • allow_missing_fees

    Allow trading pairs with missing fee information.

    All trading pairs should have good fee information by default, unless dealing with legacy tests.

Methods

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

param candle_universe:

check_supported_quote_token(pair)

get_buy_price(ts, pair, reserve)

Get the price for a buy transaction.

get_mid_price(ts, pair)

Get the mid price by the candle.

get_pair_fee(ts, pair)

Figure out the fee from a pair or a routing.

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='open', very_small_amount=Decimal('0.10'), time_bucket=None, allow_missing_fees=False)[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.

  • time_bucket (Optional[TimeBucket]) –

    The granularity of the price data.

    Currently used for diagnostics and debug only.

  • allow_missing_fees

    Allow trading pairs with missing fee information.

    All trading pairs should have good fee information by default, unless dealing with legacy tests.

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.

Returns:

Price structure for the trade.

Return type:

TradePricing

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

Get the price for a buy transaction.

Parameters:
Return type:

TradePricing

get_mid_price(ts, pair)[source]#

Get the mid price by the candle.

Parameters:
Return type:

float

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

get_pair_fee(ts, pair)[source]#

Figure out the fee from a pair or a routing.

Parameters:
Return type:

Optional[float]