benchmarks¶
Functions for comparing portfolio performance against a benchmark. These metrics measure active return, market sensitivity, and relative performance.
benchmarks ¶
Benchmark-relative metrics: alpha, correlation, R-squared, capture ratios, batting average.
alpha ¶
alpha(
returns: Series,
benchmark: Series,
rf: float = DEFAULT_RISK_FREE_RATE,
periods_per_year: int = TRADING_DAYS_PER_YEAR,
as_result: bool = False,
) -> float | MetricResult
Jensen's alpha: the portfolio's annualized excess return unexplained by its beta exposure to the benchmark.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
returns
|
Series
|
Periodic portfolio returns. |
required |
benchmark
|
Series
|
Periodic benchmark returns, aligned to |
required |
rf
|
float
|
Annual risk-free rate used to compute excess returns. |
DEFAULT_RISK_FREE_RATE
|
periods_per_year
|
int
|
Number of return periods per year, used for annualization. |
TRADING_DAYS_PER_YEAR
|
as_result
|
bool
|
If True, return a |
False
|
Returns:
| Type | Description |
|---|---|
float | MetricResult
|
Annualized alpha, or a |
Source code in src/portpy/metrics/benchmarks.py
correlation ¶
Pearson correlation coefficient between returns and benchmark.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
returns
|
Series
|
Periodic portfolio returns. |
required |
benchmark
|
Series
|
Periodic benchmark returns, aligned to |
required |
as_result
|
bool
|
If True, return a |
False
|
Returns:
| Type | Description |
|---|---|
float | MetricResult
|
The correlation coefficient, or a |
Source code in src/portpy/metrics/benchmarks.py
r_squared ¶
Fraction of the portfolio's return variance explained by the benchmark.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
returns
|
Series
|
Periodic portfolio returns. |
required |
benchmark
|
Series
|
Periodic benchmark returns, aligned to |
required |
as_result
|
bool
|
If True, return a |
False
|
Returns:
| Type | Description |
|---|---|
float | MetricResult
|
R-squared (correlation squared), or a |
Source code in src/portpy/metrics/benchmarks.py
up_capture_ratio ¶
up_capture_ratio(
returns: Series,
benchmark: Series,
periods_per_year: int = TRADING_DAYS_PER_YEAR,
as_result: bool = False,
) -> float | MetricResult
Ratio of compounded returns during periods when the benchmark was positive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
returns
|
Series
|
Periodic portfolio returns. |
required |
benchmark
|
Series
|
Periodic benchmark returns, aligned to |
required |
periods_per_year
|
int
|
Unused; accepted only for signature consistency
with |
TRADING_DAYS_PER_YEAR
|
as_result
|
bool
|
If True, return a |
False
|
Returns:
| Type | Description |
|---|---|
float | MetricResult
|
The up-capture ratio, or a |
float | MetricResult
|
than 2 periods have a positive benchmark return. |
Source code in src/portpy/metrics/benchmarks.py
down_capture_ratio ¶
down_capture_ratio(
returns: Series,
benchmark: Series,
periods_per_year: int = TRADING_DAYS_PER_YEAR,
as_result: bool = False,
) -> float | MetricResult
Ratio of compounded returns during periods when the benchmark was negative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
returns
|
Series
|
Periodic portfolio returns. |
required |
benchmark
|
Series
|
Periodic benchmark returns, aligned to |
required |
periods_per_year
|
int
|
Unused; accepted only for signature consistency
with |
TRADING_DAYS_PER_YEAR
|
as_result
|
bool
|
If True, return a |
False
|
Returns:
| Type | Description |
|---|---|
float | MetricResult
|
The down-capture ratio, or a |
float | MetricResult
|
than 2 periods have a negative benchmark return. |
Source code in src/portpy/metrics/benchmarks.py
capture_ratio ¶
capture_ratio(
returns: Series,
benchmark: Series,
periods_per_year: int = TRADING_DAYS_PER_YEAR,
as_result: bool = False,
) -> float | MetricResult
Ratio of the portfolio's annualized return to the benchmark's annualized return, over the full contiguous series (unconditional on the benchmark's sign).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
returns
|
Series
|
Periodic portfolio returns. |
required |
benchmark
|
Series
|
Periodic benchmark returns, aligned to |
required |
periods_per_year
|
int
|
Number of return periods per year, used for annualization. |
TRADING_DAYS_PER_YEAR
|
as_result
|
bool
|
If True, return a |
False
|
Returns:
| Type | Description |
|---|---|
float | MetricResult
|
The capture ratio, or a |
Source code in src/portpy/metrics/benchmarks.py
batting_average ¶
batting_average(
returns: Series,
benchmark: Series,
as_result: bool = False,
) -> float | MetricResult
Fraction of periods in which the portfolio's return strictly exceeded the benchmark's return.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
returns
|
Series
|
Periodic portfolio returns. |
required |
benchmark
|
Series
|
Periodic benchmark returns, aligned to |
required |
as_result
|
bool
|
If True, return a |
False
|
Returns:
| Type | Description |
|---|---|
float | MetricResult
|
The batting average, or a |