ezyquant.backtesting.context.Context#

class ezyquant.backtesting.context.Context(ts: Timestamp, symbol: str = '', signal: Any = nan, close_price: float = nan, volume: float = nan, cost_price: float = nan, cash: float = nan, total_cost_value: float = nan, total_market_value: float = nan, port_value: float = nan)#

Context class for backtest.

Context.buy_pct_port(pct_port)

Calculate buy volume from the percentage of the portfolio.

Context.buy_pct_position(pct_position)

Calculate buy volume from the percentage of the current position.

Context.buy_value(value)

Calculate buy volume from the given value.

Context.sell_pct_port(pct_port)

Calculate sell volume from the percentage of the portfolio.

Context.sell_pct_position(pct_position)

Calculate sell volume from the percentage of the current position.

Context.sell_value(value)

Calculate sell volume from the given value.

Context.target_pct_port(pct_port)

Calculate buy/sell volume to make the current position reach the target percentage of the portfolio.

Context.target_value(value)

Calculate buy/sell volume to make the current position reach the target value.

Context.cash

Available cash.

Context.close_price

Close price.

Context.cost_price

Cost price.

Context.port_value

Total portfolio value.

Context.signal

Signal.

Context.symbol

Selected symbol.

Context.total_cost_value

Sum of all stock market value in portfolio.

Context.total_market_value

Sum of all stock cost value in portfolio.

Context.volume

Current Volume.

Context.ts

Current timestamp.