Back-test result#
This module defines cvxportfolio.BacktestResult
.
This is the object that is returned by the
cvxportfolio.MarketSimulator.backtest()
method, and also by the same method in derived classes of
cvxportfolio.MarketSimulator
.
It contains all relevant information from a back-test and implements the logic
to compute various performance metrics, in addition to the
BacktestResult.plot()
method for producing plots
and __repr__
magic method, which is invoked when the user
prints an instance.
- class cvxportfolio.BacktestResult(universe, trading_calendar, costs)#
Store the data from a back-test and produce metrics and plots.
- Parameters:
universe (pandas.Index) – Best initial guess of the trading universe.
trading_calendar (pandas.DatetimeIndex) – Best initial guess of the trading calendar.
costs (list) – Simulator cost objects whose value is logged.
- property cash_key#
The name of the cash unit used (e.g., USDOLLAR).
- Returns:
Name of the cash accounting unit.
- Return type:
str
- property periods_per_year#
Average trading periods per year in this backtest (rounded).
- Returns:
Average periods per year.
- Return type:
int
- property v#
The total value (or NAV) of the portfolio at each period.
- Returns:
Total value at each period.
- Return type:
pandas.Series
- property profit#
The total profit (PnL) in this backtest.
- Returns:
Total profit.
- Return type:
float
- property w#
The weights of the portfolio at each period.
- Returns:
Portfolio weights at each period.
- Return type:
pandas.DataFrame
- property h_plus#
The post-trade portfolio (holdings) at each period.
- Returns:
Post-trade holdings at each period.
- Return type:
pandas.DataFrame
- property w_plus#
The post-trade weights of the portfolio at each period.
- Returns:
Post-trade weights at each period.
- Return type:
pandas.DataFrame
- property leverage#
Leverage of the portfolio at each period.
This is defined as:
\[\| {(h_t)}_{1:n} \|_1 / v_t,\]where \(h_t\) is the portfolio (the holdings) at time \(t\), we exclude the cash account from the \(\ell_1\) norm, and \(v_t\) is the total value (NAV) of the portfolio at time \(t\).
- Returns:
Leverage at each period.
- Return type:
pandas.Series
- property turnover#
The turnover of the portfolio at each period.
This is defined as:
\[\| {(u_t)}_{1:n} \|_1 / (2 v_t),\]where \(u_t\) are the portfolio trades at time \(t\), we exclude the cash account from the \(\ell_1\) norm, and \(v_t\) is the total value (NAV) of the portfolio at time \(t\).
- Returns:
Turnover at each period.
- Return type:
pandas.Series
- property returns#
The portfolio returns at each period.
This is defined as:
\[R_t^\text{p} = \frac{v_{t+1} - v_t}{v_t}\]in terms of the portfolio value (NAV).
- Returns:
Portfolio returns at each period.
- Return type:
pandas.Series
- property average_return#
The average realized return \(\overline{R^\text{p}}\).
- Returns:
Average portfolio return.
- Return type:
float
- property annualized_average_return#
The average realized return, annualized.
- Returns:
Average portfolio return, annualized.
- Return type:
float
- property growth_rates#
The growth rate (or log-return) of the portfolio at each period.
This is defined as:
\[G^\text{p}_t = \log (v_{t+1} / v_t) = \log(1 + R^\text{p}_t).\]- Returns:
Growth rate of the portfolio value at each period.
- Return type:
pandas.Series
- property average_growth_rate#
The average portfolio growth rate \(\overline{G^\text{p}}\).
- Returns:
Average growth rate.
- Return type:
float
- property annualized_average_growth_rate#
The average portfolio growth rate, annualized.
- Returns:
Average growth rate, annualized.
- Return type:
float
- property volatility#
Realized volatility (standard deviation of the portfolio returns).
- Returns:
Volatility.
- Return type:
float
- property annualized_volatility#
Realized volatility, annualized.
- Returns:
Volatility, annualized.
- Return type:
float
- property quadratic_risk#
Quadratic risk, square of the realized volatility.
- Returns:
Quadratic risk.
- Return type:
float
- property annualized_quadratic_risk#
Quadratic risk, annualized.
- Returns:
Quadratic risk, annualized.
- Return type:
float
- property excess_returns#
Excess portfolio returns with respect to the cash returns.
- Returns:
Excess returns at each period.
- Return type:
pandas.Series
- property excess_volatility#
Excess volatility (standard deviation of the excess returns).
- Returns:
Average excess volatility.
- Return type:
float
- property average_excess_return#
The average excess return \(\overline{R^\text{e}}\).
- Returns:
Average excess portfolio return.
- Return type:
float
- property annualized_average_excess_return#
The average excess return, annualized.
- Returns:
Average excess portfolio return, annualized.
- Return type:
float
- property annualized_excess_volatility#
Annualized excess volatility.
- Returns:
Average excess volatility, annualized.
- Return type:
float
- property active_returns#
Portfolio returns minus benchmark returns (if defined by policy).
- Returns:
Active returns at each period if benchmark is defined, else
nan
.- Return type:
pandas.Series
- property active_volatility#
Active volatility (standard deviation of the active returns).
- Returns:
Average active volatility if benchmark is defined, else
nan
.- Return type:
float
- property average_active_return#
The average active return \(\overline{R^\text{a}}\).
- Returns:
Average active portfolio return if benchmark is defined, else
nan
.- Return type:
float
- property annualized_average_active_return#
The average active return, annualized.
- Returns:
Average active portfolio return, annualized. If benchmark is not defined,
nan
.- Return type:
float
- property annualized_active_volatility#
Annualized active volatility.
- Returns:
Average active volatility, annualized. If benchmark is not defined,
nan
.- Return type:
float
- property sharpe_ratio#
Sharpe ratio (using annualized excess portfolio returns).
This is defined as
\[\text{SR} = \overline{R^\text{e}}/\sigma^\text{e}\]where \(\overline{R^\text{e}}\) is the average excess portfolio return and \(\sigma^\text{e}\) its standard deviation. Both are annualized.
- Returns:
Sharpe Ratio.
- Return type:
float
- property information_ratio#
Information ratio (using annualized active portfolio returns).
This is defined as
\[\text{IR} = \overline{R^\text{a}}/\sigma^\text{a}\]where \(\overline{R^\text{a}}\) is the average active portfolio return and \(\sigma^\text{a}\) its standard deviation. Both are annualized.
- Returns:
Information Ratio,
nan
if benchmark is not defined.- Return type:
float
- property excess_growth_rates#
The growth rate of the portfolio, relative to cash.
This is defined as:
\[G^\text{e}_t = \log(1 + R^\text{e}_t)\]where \(R^\text{e}_t\) are the excess portfolio returns.
- Returns:
Excess growth rates at each period.
- Return type:
pandas.Series
- property average_excess_growth_rate#
The average excess growth rate \(\overline{G^\text{e}}\).
- Returns:
Average excess portfolio growth rates.
- Return type:
float
- property annualized_average_excess_growth_rate#
The average excess growth rate, annualized.
- Returns:
Average excess portfolio growth rates, annualized.
- Return type:
float
- property active_growth_rates#
The growth rate of the portfolio, relative to benchmark.
This is defined as:
\[G^\text{a}_t = \log(1 + R^\text{a}_t)\]where \(R^\text{a}_t\) are the active portfolio returns.
- Returns:
Active growth rates at each period. If benchmark is not defined,
nan
.- Return type:
pandas.Series
- property average_active_growth_rate#
The average active growth rate \(\overline{G^\text{a}}\).
- Returns:
Average active portfolio growth rates. If benchmark is not defined,
nan
.- Return type:
float
- property annualized_average_active_growth_rate#
The average active growth rate, annualized.
- Returns:
Average active portfolio growth rates, annualized. If benchmark is not defined,
nan
.- Return type:
float
- property drawdown#
The drawdown of the portfolio value over time.
- Returns:
Drawdown of portfolio value at each period.
- Return type:
pandas.Series
- property policy_times#
The computation time of the policy object at each period.
- Returns:
Policy time in seconds at each period.
- Return type:
pandas.Series
- property simulator_times#
The computation time of the simulator object at each period.
- Returns:
Simulator time in seconds at each period.
- Return type:
pandas.Series
- plot(show=True, how_many_weights=7)#
Make plot and show it.
- Parameters:
show (bool) – if True, call
matplotlib.Figure.show
, helpful when running in the interpreter.how_many_weights (int) – How many assets’ weights are shown in the weights plots. The ones with largest average absolute value are chosen.