Kalman filter is, in certain sense, a way to give the moving average of a time series. It keeps track on a vector of state variables with its corresponding covariance matrix. The Kalman algorithm usually give a converging covariance matrix after several iterations of prediction-update. A common use is to give educated guess of the current state, and prediction (in range of value) of a future state with level of confidence. In the case of value-at-risk of a portfolio, we will need the covariance matrix of return of the assets in the portfolio. Therefore we might be able to make use of Kalman filter to find the VaR.

Below are some related papers that I found. The symbols we used are standardized at the bottom (adapted from the Kalman cheatsheet).

## Arnold et al (2008) A simplified approach to understanding the Kalman filter technique

```
@article{
author = {Tom Arnold and Mark J. Bertus and Jonathan Godbey},
title = {A simplified approach to understanding the Kalman filter technique},
journal = {The Engineering Journal},
volume = 53,
pages = {140--155},
year = 2008,
issn = {0013-791X},
doi = {10.1080/00137910802058574},
url = {https://scholarship.richmond.edu/finance-faculty-publications/8/},
}
```

This paper is not about VaR but this is an interesting paper to explain how to use Kalman filter for price prediction, without matrix notation and use scalar instead, and with algorithm examples in Excel.

The paper covers only the single variable time series, with the equations:

- State transition:
- Prediction:
- Measurement error:
- Update:
- Kalman gain:

In the paper, we assumed is known, and are constant over time, are drawn from normal distribution with zero mean and constant variance. The best result is when the predicted measurement fits the observation. Very often we do not know how to set these model parameters. But we can figure out the best fit parameters by maximum likelihood. Over periods, the probability of seeing given we assumed (normal distribution) is:

and taking log will become

By maximizing (expectation maximization (EM) algorithm) the above quantity over model variables , we obtain the optimal filter result.

The paper gives an example and implemented the Kalman algorithm in Excel. Assume in oil market, we have spot market which the price is not observable but oil futures are actively traded on organized exchange with observable price. Assume spot price as state variable and future price is the future value of spot price with interest rate and maturity :

The paper generate a random time series with the gBm on and computed the corresponding in Excel. Then assume we do not know the but only is observable and operate on the logarithm domain, and . Then the Kalman algorithm is provided by:

And in Excel, for convenience of composing the equation, two MLE metrics are computed as well:

which are the two summation terms in the log-likelihood equation above. The paper suggest to use the solver add-on in Excel to optimize for the maximum likelihood and find the best-fit parameters for the model (fit only to as is assumed not available).

## Xu & Zhang (2015) Application of Kalman filter in prediction of stock price

```
@inproceedings{
author = {Yan Xu and Guosheng Zhang},
title = {Application of Kalman Filter in the Prediction of Stock Price},
booktitle = {Proc International Symposium on Knowledge Acquisition and Modeling (KAM)},
year = 2015,
}
```

This is a 2-page paper giving an easy-to-understand example of using Kalman filter to predict stock price in short future. Here we have only one time series and the state variable is observable up to present (). Represent the price as , the system is modelled as:

or in matrix form,
and . is used for simplicity. And the
Kalman equations:

(initialization)

(prediction)

(Kalman gain)

(update)

where and are the variance “matrices” (scalar in this case) of noise terms and . And we define . It is common to have both and in the state variable in this sort of use case.

## Bassett et al (1991) Kalman filter estimation for valuing nontrading securities

```
@article{
author = {Gilbert W. Bassett, Jr and Virginia G. France and Stanley R. Pliska},
title = {Kalman Filter Estimation for Valuing Nontrading Securities, with Applications to the MMI Cash-Future Spread on October 19 and 20, 1987},
journal = {Review of Quantitative Finance and Accounting},
volume = 1,
pages = 135--151,
year = 1991,
url = {https://gib.people.uic.edu/Kalman%20Filter.pdf},
}
```

Another example of using Kalman filter for prediction. It uses a 0-1 matrix as measurement matrix (direct observation to price but only some of them) and use the predicted price in place of non-observed prices. The state variable is the true price, measured every minute, and the measurement is the traded subset of , i.e., the trade price.

This paper suggested some ways to set up the parameters: The covariance matrix of the state transition noise is the empirical covariance from the whole last day. The covariance matrix of the measurement noise is chosen based on the bid-ask spread of 1/8 tick size, . The initial state is chosen to be the last closing price. The tricky part is the initial variance . It is evaluated from previous data on non-trading minutes. It answers the question of what will best fit the dispersion on state variable if there is no measurement for periods (minutes). By measuring the dispersion over past non-trading minutes, variance is computed.

## Cortazar et al (2003) Term structure estimation in low-frequency transaction markets

```
@techreport{
author = {Gonzalo Cortazar and Eduardo S. Schwartz and Lorenzo Naranjo},
title = {Term Structure Estimation in Low-Frequency Transaction Markets: A Kalman Filter Approach with Incomplete Panel-Data},
institution = {EFA 2004 Maastricht Meetings Paper},
number = 3102,
month = March,
year = 2004,
url = {https://papers.ssrn.com/sol3/papers.cfm?abstract_id=567090},
url = {https://pdfs.semanticscholar.org/f164/1f1f36b36a8e4df549091afb1655421b8228.pdf},
}
```

This paper focus on thin (illiquid) markets. It uses Kalman filter to estimate the missing observations. Then use historical price data and a dynamic model to estimate the current term structure.

As the paper concerns bond but not stock price, it uses Vasicek (1977) model for interest rates, which is an Ornstein-Uhlenbeck process governed by the SDE

for some constant drift , and parameters . Generalized into matrix form for to become a vector of factors:

where is an diagonal matrix with strictly positive diagonal terms. are -vector such that . is a vector of the market price of risk.

This equation models the *mean reversion*, which the reversion rate is given by
, and instantaneous interest rate depends on the factors (state variables)
:

The mean reversion model means that every perturbation is reduced by half in units of time, for the corresponding diagonal term on matrix .

Given the interest rate model, we can model the price of a bond (pure discount or coupon), and its yield to maturity. Derivation is in the paper.

To the issue of thin market, once we modelled the price movement in a state space (prediction equations in Kalman algorithm), the problem is that the measurement is always incomplete: Only some of the state is observable at a time due to illiquid market. Depends on the subset of state variables observed, we adjust the matrix accordingly. Indeed, we skip the update step in Kalman algorithm in case of missing data.

## Nkomo & Kabundi (2013) Kalman filtering and online learning algorithms for portfolio selection

```
@techreport{
title = {Kalman filtering and online learning algorithms for portfolio selection},
author = {Raphael Nkomo and Alain Kabundi},
year = 2013,
month = Nov,
institution = {Economic Research Southern Africa},
number = {working paper 394},
}
```

This paper uses Kalman filter as a replacement for moving average for dynamic portfolio selection.

In a market of assets with closing price of asset at time denoted by , price relative is defined as . A portfolio is defined as a -vector , which and for all .

Assume initial capital of , the wealth at end of time is

If the portfolio is time-varying, we denote the portfolio vector at trading period , then the wealth will be

which the period return is and is the log-utility function. Maximizing maximizes .

As a baseline, a buy-and-hold (BAH) strategy will be fixed and never rebalance the portfolio. This results in the portfolio vector given by:

where denotes elementwise multiplication between vectors and . BAH assumes stock market to grow over time and will perform badly in case of severe market correction.

Another strategy is constant rebalancing (CBAL), which maintains a fixed portfolio weight for all trading period . It takes advantage of market fluctuations but subject to transaction cost.

The portfolio selection algorithm in this paper is to find the optimal based on past data. The approach is named cyclically adjusted price relative (CAPR): If we remove the noise from the price relative time series , we can capture both the price momentum and price reversal and make use of that to adjust the portfolio.

Common way to remove noise from a time series is the moving average (or EWMA) but the moving average will change the statistical properties of the time series. For example, it will fail to capture large deviation from average as a sign of price reversal but contribute that to momentum. In CAPR, we maintain a Kalman filtered price and keep track on the ratio , which offset from 1 represents how much over sold or over bought of the stock. The paper derived that this ratio is Gaussian distributed.

The Kalman model for is as follows: It starts with initial estimate with mean and variance , then the prediction:

and update:

With this, the paper reuses the Anticor algorithm from Borodin (2006). This algorithm is based on equal size periods (windows) and trading is on the end of window, to transfer wealth from recently high-performing assets to anti-correlated low-performing assets. Precisely, for stocks if in the last window and , then transfer wealth from to . The Anticor algorithm is as follows:

For stocks and window of length , at each time we have a -vector of and define two consecutive window as matrices:

Let be the -th column of and be the mean and variance of . The cross-covariance matrix between columns of is

and the cross-correlation matrix:

and the amount to move from to is

## Berardi et al (2002) Estimating value at risk with the Kalman filter

```
@techreport{
author = {Andrea Berardi and Stefano Corradin and Cristina Sommacamagna},
title = {Estimating Value at Risk with the Kalman Filter},
month = December,
year = 2002,
}
```

Value-at-risk in percentage terms of a portfolio is given by VaR which the variance of portfolio return is , is a vector of weights, the confidence level, is the time horizon and the covariance matrix of asset returns. If we anchor to the market return , we can use the CAPM to express the return of each asset in a portfolio as . If we use a vector for all assets, the VaR can be redefined as , with the estimated market index variance .

This paper is to use Kalman filter to estimate vector and thus the VaR can be found using the above formula. The system equation for a single asset is

In vector form, defining

and the return of stock, and the state variable, then we will have the Kalman equations as in the summary at the bottom of this page. The matrices and the variances of noises are to be estimated by expectation-maximization.

## Date & Bustreo (2016) Value-at-risk for fixed-income portfolios

```
@article{
author = {P. Date and R. Bustreo},
title = {Value-at-Risk for fixed-income portfolios: a Kalman filtering approach},
journal = {IMA Journal of Management Mathematics},
volume = 27,
number = 4,
pages = 557--573,
month = Oct,
year = 2016,
doi = {https://doi.org/10.1093/imaman/dpv016},
url = {https://bura.brunel.ac.uk/bitstream/2438/12202/1/Fulltext.pdf},
}
```

Another example of VaR calculation, but this one is based on bonds.

This paper mentions a test (Kupiec, 1995) for the VaR by chi-squared statistics. We introduce indicator variable for 1 if the actual loss of portfolio is greater than VaR and 0 otherwise. We expect follows a binomial distribution

which for the level chosen for VaR. Then the null hypothesis is and

which for 1 DoF, 95% CI, we reject null hypothesis if $LR>3.841$.

## Idea of using Kalman filter for VaR calculation

The literature above should give a good insight on how VaR is calculated. In case of a portfolio, VaR is with the covariance matrix of returns of assets in the portfolio. is a parameter of choice and corresponds to the portfolio. The only unknown is covariance matrix .

Kalman filter equations also involves covariance matrix in the state transition. We may run the history of asset returns as state variables and determine the matrix . This approach can incorporate illiquid assets in the portfolio as the measurement of Kalman algorithm can handle missing (unobserved) data. The Kalman parameters: state gain , and output gain are easy to decide. However, we also introduced two unknown noise covariance matrices and , which their value affects the quality of the result.

## Brief summary of Kalman filter

Variables:

usage | dimension | symbols |
---|---|---|

State | , approx by and | |

Control input | ||

Measurement output | ||

State gain | ||

Input gain | ||

Output gain | ||

Process noise | ||

Process noise covariance | ||

Measurement noise | ||

Measurement noise covariance | ||

A priori covariance | ||

A posteriori covariance | ||

Kalman gain |

Discrete time system: State transition and measurement

Prediction (a priori):

Pre-fit residual:

Kalman gain:

Update (a posteriori):

Post-fit residual: