pqf.research.statistics

Functions

annualized_returns(returns)

Calculate the annualized return from a series of daily log returns.

estimate_market_returns(...)

Estimate the market returns based on the constituent returns.

sharpe_ratio(returns, risk_free_rate)

Calculate the Sharpe ratio.

pqf.research.statistics.annualized_returns(returns: Series | Expr) Series | Expr | None[source]

Calculate the annualized return from a series of daily log returns.

The annualized return is calculated using the formula:

e^(sum of log returns * 365 / period of days) - 1

Parameters:

returns (pl.Series | pl.Expr) – Series or expression representing daily log returns.

Returns:

A series of the cumulative annualized returns or None if not calculable.

Return type:

pl.Series | pl.Expr | None

pqf.research.statistics.estimate_market_returns(market_constituent_returns: LazyFrame | DataFrame, date_column: str) LazyFrame | DataFrame[source]

Estimate the market returns based on the constituent returns.

Parameters:
  • market_constituent_returns (pl.LazyFrame | pl.DataFrame) – DataFrame containing constituent returns.

  • date_column (str) – Name of the column containing dates.

Returns:

DataFrame with selected date column and calculated market return.

Return type:

pl.LazyFrame | pl.DataFrame

pqf.research.statistics.sharpe_ratio(returns: Series | Expr, risk_free_rate: float) float | Expr | None[source]

Calculate the Sharpe ratio.

Parameters:
  • returns (pl.Series | pl.Expr) – Series or expression representing returns.

  • risk_free_rate (float) – The risk-free rate.

Raises:

TypeError – If standard deviation of returns cannot be calculated.

Returns:

The calculated Sharpe ratio or None if not calculable.

Return type:

float | pl.Expr | None