Performance metrics#
-
sigtech.framework.analytics.performance.metrics.adjusted_sharpe_ratio(ts: Series, cash: Series, independent_trials: int) float
Calculate a Sharpe Ratio adjusted for the number of independent trials, implemented according to the Harvey-Liu paper.
- Parameters:
ts – Timeseries of cumulative total returns.
cash – Timeseries of cumulative cash returns.
independent_trials – Number of independent trials.
- Returns:
Adjusted Sharpe Ratio.
-
sigtech.framework.analytics.performance.metrics.annualised_return(ts: Series, start: Optional[date] = None, use_returns: Optional[bool] = True) float
Calculate the annualised return (only annualised if over 1 year).
- Parameters:
ts – TimeSeries of levels.
start – Starting date (optional).
use_returns – Set to use the percentage returns rather than profit (default is
'True'
).
- Returns:
Annualised return for history provided.
-
sigtech.framework.analytics.performance.metrics.benchmark_metrics(cumulative_return_df, cumulative_benchmark_return)
Calculate benchmark statistics, including:
information_ratio
1_year_upside_capture
1_year_downside_capture
3_year_upside_capture
3_year_downside_capture
full_year_upside_capture
full_year_downside_capture
- Parameters:
cumulative_return_df – DataFrame of cumulative return series.
cumulative_benchmark_return – Timeseries of cumulative benchmark returns.
- Returns:
DataFrame of statistics.
-
sigtech.framework.analytics.performance.metrics.deflated_sharpe_ratio(df: DataFrame, cash: Optional[Series] = None, sharpe_type: str = 'arithmetic') float
Calculate the deflated Sharpe Ratio based on trial data, implemented according to the Bailey-de Prado paper.
- Parameters:
df – Trial data in DataFrame, last column is the target strategy.
cash – Cash history to calculate excess return.
sharpe_type –
'arithmetic'
or'compounding'
, mode to determine whether compounding returns are used (default is'arithmetic'
).
- Returns:
Deflated Sharpe Ratio percentile.
-
sigtech.framework.analytics.performance.metrics.deflated_sharpe_ratio_raw(sr: float, n: int, variance: float, t: int, skewness: float, kurtosis: float) float
Calculate the deflated Sharpe Ratio based on statistics, implemented according to the Bailey-de Prado paper.
- Parameters:
sr – Sharpe Ratio of the strategy.
n – Number of independent trials carried out.
variance – Variance of the backtest results of sharpe ratios.
t – Sample length.
skewness – Skewness of the returns.
kurtosis – Kurtosis of the returns.
- Returns:
Deflated Sharpe Ratio percentile.
-
sigtech.framework.analytics.performance.metrics.drawdown_series(ts: Series, use_returns: Optional[bool] = True) Series
Calculate the rolling max drawdown.
- Parameters:
ts – Timeseries of values.
use_returns – Set to use the percentage returns rather than profit (default is
'True'
).
- Returns:
Drawdown timeseries.
-
sigtech.framework.analytics.performance.metrics.excess_return_series(ts: Series, cash: Series) Series
Calculate the excess return timeseries.
- Parameters:
ts – Timeseries of cumulative total return.
cash – Cash timeseries of cumulative cash return.
- Returns:
Cumulative excess returns.
-
sigtech.framework.analytics.performance.metrics.frequency(ts: Series) str
Estimate the frequency of a timeseries by the number of elements compared to day count fraction.
- Parameters:
ts – Input timeseries.
- Returns:
Frequency identifier.
-
sigtech.framework.analytics.performance.metrics.geometric_average_return(price_series: Series, risk_factor: float) float
Calculate the geometric average return from the supplied price series. We protect the calculation from zero division and ensure the geometric mean is not complex.
- Parameters:
price_series –
pd.Series
of strategy prices.risk_factor – Modifier for the frequency of the returns. If daily returns (365.25 per year) then / risk_factor = 1.
- Returns:
Geometric mean return
-
sigtech.framework.analytics.performance.metrics.mar_ratio(ts: Series, start: Optional[date] = None, use_returns: Optional[bool] = True) float
Calculate the MAR ratio of a timeseries. Can be used to compute Calmar Ratio with start date 3Y prior.
- Parameters:
ts – Timeseries of cumulative total return.
start – Starting date (optional).
use_returns – Set to use the percentage returns rather than profit (optional).
- Returns:
MAR Ratio.
-
sigtech.framework.analytics.performance.metrics.monthly_returns(rets: Series)
Evaluate compounded returns for each calendar month based on a daily return series.
- Parameters:
rets – Series of daily returns.
- Returns:
Series of monthly returns.
-
sigtech.framework.analytics.performance.metrics.periods_per_year(ts: Series) int
Number of periods per year based on the estimated frequency of a timeseries.
- Parameters:
ts – Timeseries of values.
- Returns:
Integer number of periods per year.
-
sigtech.framework.analytics.performance.metrics.resample(df: DataFrame, freq: Optional[str] = None, how: str = 'last') DataFrame
Re-sample the values in a given DataFrame to the requested frequency.
- Parameters:
df – DataFrame of values.
freq – Frequency identifier.
how – Resampling mode (default is
'last'
).
- Returns:
DataFrame of re-sampled data.
-
sigtech.framework.analytics.performance.metrics.resample_single(ts: Series, freq: Optional[str] = None, how: str = 'last') Series
Re-sample the values in a given Timeseries to the requested frequency.
- Parameters:
ts – Timeseries of values.
freq – Frequency identifier.
how – Resampling mode (default is
'last'
).
- Returns:
Timeseries of re-sampled values.
-
sigtech.framework.analytics.performance.metrics.risk_annualised_return(ts: Series, risk_factor: float, use_returns: Optional[bool] = True) float
Calculate the risk annualised return (only annualised if over 1 year).
- Parameters:
ts – TimeSeries of levels.
risk_factor – Factor used to annualise.
use_returns – Set to use the percentage returns rather than profit (default is
'True'
).
- Returns:
Annualised return for history provided.
-
sigtech.framework.analytics.performance.metrics.risk_excess_return_series(ts: Series, cash: Series) Series
Calculate the risk excess return timeseries using division of return rather than subtraction (see
excess_return_series()
).- Parameters:
ts – Timeseries of cumulative total return.
cash – Cash timeseries of cumulative cash return.
- Returns:
Cumulative excess returns.
-
sigtech.framework.analytics.performance.metrics.sharpe_ratio(ts: Series, cash: Optional[Series] = None, sharpe_type: str = 'arithmetic') float
Calculate the Sharpe Ratio of a timeseries.
- Parameters:
ts – Timeseries of cumulative total return.
cash – Cumulative cash total return (if None, a constant cash value is used).
sharpe_type –
'arithmetic'
or'compounding'
, mode to determine whether compounding returns are used (default is'arithmetic'
).
- Returns:
Sharpe Ratio.
-
sigtech.framework.analytics.performance.metrics.summary(df: DataFrame, cash: Optional[Series] = None, use_returns: Optional[bool] = True) DataFrame
Calculate the summary statistics for a DataFrame.
- Parameters:
df – DataFrame of cumulative total return series.
cash – Cumulative cash return timeseries.
use_returns – Provide relative returned based metrics rather than profit based.
- Returns:
DataFrame of statistics.
-
sigtech.framework.analytics.performance.metrics.summary_rolling_averages(df: DataFrame, cash: Optional[Series] = None, period: int = 756) DataFrame
Calculate the statistics of the rolling metric series, including:
Mean Annualised Return
Mean Annualised Excess Return
Mean Volatility
Mean Drawdown
Mean Sharpe(0%)
Mean Sharpe(vs Cash)
Mean Sortino(0%)
Mean Sortino(vs Cash)
Median Annualised Return
Median Annualised Excess Return
Median Volatility
Median Drawdown
Median Sharpe(0%)
Median Sharpe(vs Cash)
Median Sortino(0%)
Median Sortino(vs Cash)
10th Percentile Annualised Return
10th Percentile Annualised Excess Return
10th Percentile Volatility
10th Percentile Drawdown
10th Percentile Sharpe(0%)
10th Percentile Sharpe(vs Cash)
10th Percentile Sortino(0%)
10th Percentile Sortino(vs Cash)
90th Percentile Annualised Return
90th Percentile Annualised Excess Return
90th Percentile Volatility
90th Percentile Drawdown
90th Percentile Sharpe(0%)
90th Percentile Sharpe(vs Cash)
90th Percentile Sortino(0%)
90th Percentile Sortino(vs Cash)
- Parameters:
df – DataFrame of cumulative total return series.
cash – Timeseries of cumulative cash return.
period – Period window to use for rolling metrics.
- Returns:
DataFrame of statistics.
-
sigtech.framework.analytics.performance.metrics.summary_rolling_ccy_series(ts: Series, cash: Optional[Series] = None, period: int = 756, compound_metrics: bool = False, min_periods: int = None) DataFrame
Calculate the rolling statistics, in the strategy currency, including:
Annualised Return
Annualised Excess Return
Volatility
Drawdown
Sharpe (vs 0%)
Sortino (vs 0%)
- Parameters:
ts – Timeseries of cumulative total return.
cash – Timeseries of cumulative cash return (deprecated).
period – Period window to calculate the rolling statistics over.
compound_metrics – Whether to compound metrics (as for a fund) or not (default =
False
).min_periods – Minimum number of observations in window required to have a value (if not set, period value will be used).
- Returns:
DataFrame of rolling statistics.
-
sigtech.framework.analytics.performance.metrics.summary_rolling_series(ts: Series, cash: Optional[Series] = None, period: int = 756, compound_metrics: bool = False, min_periods: int = None) DataFrame
Calculate the rolling statistics, including:
Annualised Return
Annualised Excess Return
Volatility
Drawdown
Sharpe (vs 0%)
Sharpe (vs Cash)
Sortino (vs 0%)
Sortino (vs Cash)
- Parameters:
ts – Timeseries of cumulative total return.
cash – Timeseries of cumulative cash return.
period – Period window to calculate the rolling statistics over.
compound_metrics – Whether to compound metrics (as for a fund) or not (default =
False
).min_periods – Minimum number of observations in window required to have a value (if not set, period value will be used).
- Returns:
DataFrame of rolling statistics.
-
sigtech.framework.analytics.performance.metrics.summary_single(ts: Series, cash: Optional[Series] = None, complete_summary: Optional[bool] = True) dict
Calculate summary statistics using the relative returns.
These statistics include:
Annualised Return
Annualised Excess Return
Annualised Standard Deviation
Annualised Sharpe Ratio (0%)
Annualised Sharpe Ratio (vs Cash)
Annualised Sortino Ratio (0%)
Annualised Sortino Ratio (vs Cash)
Drawdown
Max Drawdown
Annualised Downside Deviation (0%)
Annualised Downside Deviation (vs Cash)
Annualised Upside Deviation (0%)
Annualised Upside Deviation (vs Cash)
1 Month Return
1 Year Return
3 Month Return
3 Year Return (Annualised)
Mean
Standard Deviation
Kurtosis
Skewness
Daily Var 95%
Daily Var 99%
Daily CVar 95%
Daily CVar 99%
Best Return
Worst Return
Mean Positive Return
Mean Negative Return
Proportion Positive Returns
Series Start Date
Series End Date
Series Length
Series Start Value
Series End Value
Frequency
Annualisation Factor
Max Drawdown Start Date
Max Drawdown End Date
Max Drawdown Period
Max Drawdown Period Units
Max Drawdown Recovery Date
Max Drawdown Recovery Period
Max Drawdown Recovery Period Units
MAR Ratio
Risk Annualised Return
Risk Annualised Excess Return
Risk Annualised Standard Deviation
Risk Annualised Excess Standard Deviation
Risk Information Ratio
Risk Sharpe Ratio
Max DD/Vol
- Parameters:
ts – Timeseries of cumulative total returns.
cash – Timeseries of cumulative cash returns.
complete_summary – Calculate VaR, CVaR, MaR and Calmar as well as Risk return metrics if true.
- Returns:
dict of statistics.
-
sigtech.framework.analytics.performance.metrics.summary_single_ccy(ts: Series, complete_summary: Optional[bool] = True) dict
Calculate summary statistics that are based on the strategies absolute returns i.e. profit in the strategy currency.
These statistics include:
Total Return
Annualised Return
Annualised Standard Deviation
Annualised Sharpe Ratio (0% Cash)
Annualised Sortino Ratio (0% Cash)
Drawdown
Max Drawdown
Annualised Downside Deviation
Annualised Upside Deviation
1 Month Return
1 Year Return
3 Month Return
3 Year Return (Annualised)
Mean
Standard Deviation
Kurtosis
Skewness
Daily Var 95%
Daily Var 99%
Daily CVar 95%
Daily CVar 99%
Best Return
Worst Return
Mean Positive Return
Mean Negative Return
Proportion Positive Returns
Series Start Date
Series End Date
Series Length
Series Start Value
Series End Value
Frequency
Annualisation Factor
Max Drawdown Start Date
Max Drawdown End Date
Max Drawdown Period
Max Drawdown Period Units
Max Drawdown Recovery Date
Max Drawdown Recovery Period
Max Drawdown Recovery Period Units
MAR Ratio
Calmar Ratio
Max DD/Vol
- Parameters:
ts – Timeseries of cumulative total returns.
complete_summary – Calculate VaR, CVaR, MaR and Calmar metrics if true.
- Returns:
dict of statistics.
-
sigtech.framework.analytics.performance.metrics.upside_downside_capture(rets, bmk_rets)
Calculate upside/downside ratios vs a benchmark series.
- Parameters:
rets – Series of daily returns.
bmk_rets – Series of benchmark.
- Returns:
pandas Series.
-
sigtech.framework.analytics.performance.metrics.win_ratio_returns(ts, freq='daily')
Calculate the proportion of positive returns for a given frequency.
- Parameters:
ts – Daily returns.
freq – Frequency, i.e.
'daily'
,'monthly'
. Default is'daily'
.
- Returns:
Proportion of positive returns.
-
sigtech.framework.analytics.performance.metrics.year_to_dates(df: DataFrame) DataFrame
Evaluate yearly returns of DataFrame.
- Parameters:
df – DataFrame of cumulative returns.
- Returns:
DataFrame of yearly returns.
-
sigtech.framework.analytics.performance.metrics.year_to_dates_single(ts: Series) Series
Evaluate yearly returns from Timeseries.
- Parameters:
ts – Timeseries of cumulative return.
- Returns:
Timeseries of yearly returns.