Great FAJ Article on Statistical Measure of Financial Turbulence Part 2

[This article was first published on Timely Portfolio, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

faj abstract

I did not intend for this to be a multi-part series, but after some clear thinking at the beach over the weekend, I decided that it needed some more analysis.  For those of you that read the article or know Mahalanobis distance, the measure I presented in my post Great FAJ Article on Statistical Measure of Financial Turbulence was a derivative of actual Mahalanobis distance.  To close the gap between the actual calculation and my measure, I thought I should show both calculations.

From TimelyPortfolio
From TimelyPortfolio

The Mahalanobis calculation here is based on the entire dataset.  Of course, we do not have the luxury of hindsight in trading, so I think my real-time measure works well as displayed by the system shown in the first post.


R code:


#get data from St. Louis Federal Reserve (FRED)
getSymbols(“GS20″,src=”FRED”) #load 20yTreasury; 20y has gap 86-93; 30y has gap in early 2000s
getSymbols(“GS30″,src=”FRED”) #load 30yTreasury to fill 20y gap 86-93
#getSymbols(“BAA”,src=”FRED”) #load BAA
getSymbols(“SP500″,src=”FRED”) #load SP500

#get CRB data from a csv file

#fill 20y gap from discontinued 20y Treasuries with 30y

#do a little manipulation to get the data lined up on monthly basis
#get monthly format to yyyy-mm-dd with the first day of the month
#my CRB data is end of month; could change but more fun to do in R

#let’s merge all this into one xts object; CRB starts latest in 1956
#use ROC for SP500 and CRB and momentum for yield data
#get Covariances and multiply to by 100000 for 20y to sp500 and crb and 1000 for sp500 to crb to standardize
#don’t like this manual intervention; next post will use correlation instead

Sx <- cov(assetROC)
mahalanobisturbulence <- mahalanobis(assetROC, colMeans(assetROC), Sx)



chart.TimeSeries(turbulencecompare,main=”Mahalanobis Distance Compared to My Measure”,

To leave a comment for the author, please follow the link and comment on their blog: Timely Portfolio. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)