Capital Market Line
Calculate the Capital Market Line and Security Market Line of the benchmark and where an investment portfolio or asset stands against them (Sharpe, 1964), with the regression epsilon of Bacon (2008).
The formulas are as follows:
\[\text{Capital Market Line Slope} = \frac{\operatorname{Mean}(\text{Benchmark Excess Return})}{\text{Standard Deviation}(\text{Benchmark Return})}\] \[\text{Capital Market Line Return} = \operatorname{Mean}(\text{Risk Free Rate}) + \text{Capital Market Line Slope} \cdot \text{Standard Deviation}(\text{Return})\] \[\text{Security Market Line Slope} = \operatorname{Mean}(\text{Benchmark Excess Return})\] \[\text{Regression Epsilon} = \text{Excess Return of the Period} - \text{Alpha} - \text{Beta} \cdot \text{Benchmark Excess Return of the Period}\]The first three are per day, from the daily returns within each period. The CML slope is the benchmark’s Sharpe ratio, the extra return the market paid per unit of volatility; the CML return is what a mix of the benchmark and the risk free asset with the asset’s volatility earned per day, so an asset whose mean daily return lies below it was not rewarded for its total risk. The SML slope is the market risk premium per day, the extra return the CAPM gives per unit of Beta. The Regression Epsilon is the part of the period’s excess return the CAPM regression (Alpha and Beta per day, fitted on the daily excess returns) does not predict.
Also known as: CML, SML, capital allocation line of the market, regression epsilon.
Example · AAPL, KO · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_capital_market_line:
from financetoolkit import Toolkit
toolkit = Toolkit(
["AAPL", "KO"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.performance.get_capital_market_line().xs("KO", level=0, axis=1).T
Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:
What were the slopes of the capital market line and the security market line for Coca-Cola in each year from 2021 to 2025?
Which returns:
| Item | 2021 | 2022 | 2023 | 2024 | 2025 |
|---|---|---|---|---|---|
| Capital Market Line Slope | 0.1274 | -0.0523 | 0.0983 | 0.0947 | 0.0457 |
| Capital Market Line Return | 0.0012 | -0.0005 | 0.0010 | 0.0009 | 0.0007 |
| Security Market Line Slope | 0.0010 | -0.0008 | 0.0008 | 0.0008 | 0.0006 |
| Regression Epsilon | -0.0104 | 0.1790 | -0.1686 | 0.0357 | 0.1063 |
4 rows
Parameters
get_capital_market_line accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The period to use for the calculation. Options are: “daily”, “weekly”, “monthly”, “quarterly”, “yearly”. Defaults to “quarterly” if the Toolkit is initialised with quarterly=True, otherwise “yearly”. | "weekly" |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise). | 2 |
growth | bool | Whether to calculate the growth of the ratios. Defaults to False. | True |
lag | int | list[int] | The lag to use for the growth calculation. Defaults to 1. | 4 |
standardize | bool | Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. | True |
show_columns | str | list[str] | None | The columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column. | None, which keeps every column |
References
- Paper Sharpe, W.F. (1964). “Capital Asset Prices: A Theory of Market Equilibrium under Conditions of Risk.” Journal of Finance, 19(3), 425-442.
- Paper Bacon, C.R. (2008). “Practical Portfolio Performance Measurement and Attribution.” 2nd edition, John Wiley & Sons, p. 71.
- Library Referenced against PerformanceAnalytics (R)’s CAPM.CML.slope
- Library Referenced against PerformanceAnalytics (R)’s CAPM.SML.slope
- Library Referenced against PerformanceAnalytics (R)’s CAPM.epsilon