Beta and Market-Relative Risk
Install and import#
npm install fintech-algorithmsimport { betaAndMarketRelativeRisk } from "fintech-algorithms/foundations/financial-risk-and-performance-statistics/beta-and-market-relative-risk";Signature#
betaAndMarketRelativeRisk(input)Divides the sample covariance between a return series and its benchmark by the benchmark's sample variance.
Parameters#
| Name | Type | Notes |
|---|---|---|
input | D00Input | Reads returns and benchmark, two aligned non-empty lists of finite periodic returns, frequency, the number of periods per year, and confidence, the quantile level used when the loss series is prepared. |
Returns#
D00Output
beta is the covariance over the benchmark variance, marketVariance is the benchmark's sample variance, and covariance is the sample covariance of the two series.
Errors#
- When
returnsorbenchmarkis absent, empty, or holds a non-finite number — throws RangeError - When
returnsandbenchmarkdiffer in length, or hold fewer than two observations — throws RangeError - When
frequencyis zero or negative — throws RangeError - When the benchmark is constant, so its sample variance is zero — throws RangeError
- When
confidenceis absent, or outside the range zero to one — the engine reads it for every topic from A04 onward, including those that never use it — throws RangeError
Complexity: time O(n log n),
space O(n).
Worked example#
verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.
Input#
{
"returns": [0.01, -0.02, 0.015, -0.01, 0.03],
"benchmark": [0.008, -0.01, 0.012, -0.006, 0.02],
"frequency": 252,
"target": 0,
"confidence": 0.8,
"riskFree": 0.0001,
"weights": [0.6, 0.4],
"covarianceMatrix": [
[0.04, 0.01],
[0.01, 0.09]
]
}Call#
betaAndMarketRelativeRisk(input)Returns#
object with 2 fields: beta, marketVariance
{
"beta": 1.5903307888040712,
"marketVariance": 0.0001572
}Diagrams#
How it works#
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References#
- Expected Shortfall — Basel Framework MAR33
- Mutual Fund Performance — William F. Sharpe
- Measures of Scale — NIST/SEMATECH e-Handbook
- Historical-example decision