# Feature: Capital Asset Pricing Model

We just finished implementing a new indicator for TuringTrader: The Capital Asset Pricing Model, namely calculation of Alpha and Beta. These are very useful functions to have for creating efficient portfolios.

The calculation is based on exponentially-weighted statistics, making it very fast. See Tony Finch’s paper Incremental calculation of weighted mean and variance, University of Cambridge Computing Service, February 2009, for further explanation. Our own contribution to the methods outlined in chapter 9 is the calculation of the co-variance, based on the calculation of variance given in the paper. See our repository for a peek at the code.

The indicators can be calculated on instruments, or time series. Here is a simple demo project, plotting rolling 3-months betas for a set of sector ETFs. I hope you enjoy how sweet and concise this is, thanks to the new indicators:

The demo produces the plot below. On the left side of the chart, all betas begin with an initial value of 1.0, until they slowly approach their correct values:

Happy coding!