# MAHALANOBIS

## Description

The Mahalanobis function measures the distances of the cross-sectional point estimates from its empirical distribution. This is a multi-dimensional generalization tool in statistics. It is unitless, scale-invariant, and accounts for the correlation relationships within the data set.

For a given dataset,$$X$$, the Mahalanobis distance,$$D$$, is given by&#x20;

$$
D\_t=(X\_t-\mu) \Sigma^{-1}(X\_t-\mu)'
$$

$$
D\_t=\text{Mahalanobis distance for cross-section } t\newline
X\_t=\text{vector of asset returns for period } t\newline
\mu=\text{sample average of historical asset returns}\newline
\Sigma=\text{sample covariance matrix of asset returns}
$$

## Syntax

The following describes the function signature for use in Microsoft Excel's formula bar.

```excel-formula
=MAHALANOBIS(X, mu, covariance)
```

### Input(s)

<table><thead><tr><th width="150">Argument</th><th width="485.65217391304344">Description</th></tr></thead><tbody><tr><td><strong>X</strong></td><td>Matrix of time series returns (or values).</td></tr><tr><td><strong>mu</strong></td><td>Optional. Vector of means to measure the distance from. If the argument is not specified, it defaults to the sample average of the <strong>X</strong>.</td></tr><tr><td><strong>covariance</strong></td><td>Optional. Covariance matrix, specify a covariance matrix to normalize the distances. If the argument is not specified, it defaults to the sample covariance matrix of <strong>X</strong>.</td></tr></tbody></table>

### Output(s)

Vector of Mahalanobis distance values for the corresponding data, $$X$$. Vector will have the same length as $$X$$.

## Example

![](/files/-ML9nbPdbg6SDVajlh8J)

{% file src="/files/-ML9nw7N3O1nehODTWjB" %}
Example Workbook
{% endfile %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://excelhelp.windhamlabs.com/functions/scenario-analysis/mahalanobis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
