ezyquant.backtesting.backtesting.backtest#

ezyquant.backtesting.backtesting.backtest(signal_df: DataFrame, backtest_algorithm: Callable[[Context], float], start_date: str, end_date: str, initial_cash: float, pct_commission: float = 0.0, pct_buy_slip: float = 0.0, pct_sell_slip: float = 0.0, price_match_mode: str = 'open', signal_delay_bar: int = 1) SETBacktestReport#

Backtest function. No trade will be made if price is nan.

Parameters:
  • signal_df (pd.DataFrame) – Dataframe of signal. Index is trade date, columns are symbol, values are signal. Missing signal in trade date will be filled with nan.

  • backtest_algorithm (Callable[[Context], float],) –

    function for calculate trade volume.

    Parameters:
    • context: Context

      context for backtest

    Return:
    • trade_volume: float

      positive for buy, negative for sell, 0 or nan for no trade

  • start_date (str) – Start date in format YYYY-MM-DD.

  • end_date (str) – End date in format YYYY-MM-DD.

  • initial_cash (float) – Initial cash.

  • pct_buy_slip (float = 0.0) – Percentage of buy slip, higher value means higher buy price (ex. 1.0 means 1% increase).

  • pct_sell_slip (float = 0.0) – Percentage of sell slip, higher value means lower sell price (ex. 1.0 means 1% decrease).

  • pct_commission (float = 0.0) – Percentage of commission fee (ex. 1.0 means 1% fee).

  • price_match_mode (str = "open") –

    Price match mode
    • open

    • high

    • low

    • close

    • median - (high + low)/2

    • typical - (high + low + close)/3

    • weighted - (high + low + close + close)/4

  • signal_delay_bar (int = 1) – Delay bar for shifting signal.

Return type:

SETBacktestReport