background preloader

Finance in R

Facebook Twitter

It is "simply" the average value. For some obscure reasons, simple things are usually supposed to be simple.

It is "simply" the average value

Recently, on the internet, I saw a lot of posts on the "average time in which you hold a stock", and two rather different values are mentioned "Take any stock in the United States. The average time in which you hold a stock is – it's gone up from 20 seconds to 22 seconds in the last year" (Michael Hudson on or "The founder of Tradebot, in Kansas City, Mo., told students in 2008 that his firm typically held stocks for 11 seconds" (on among many others"Based on the NYSE index data, the mean duration of holding period by US investors was around 7 years in 1940.

This stayed the same for the next 35 years. The average holding period had fallen to under 2 years by the time of the 1987 crash. How comes that on the one hand, some people talk about less than 20 sec. for the "average time in which you hold a stock", and on the other, around a year. Random matrix theory and APT’s daily global model. Someone emailed me recently and asked about how APT uses random matrix theory in their factor model.

Random matrix theory and APT’s daily global model

Another question I was asked is whether my package tawny could be used to replace APT or any other multi-factor model. The short answer is no. An R script for estimating future inflation via the Treasury market. One factor that is critical for any financial planning is estimating what future inflation will be.

An R script for estimating future inflation via the Treasury market

For example, if you’re saving money in an instrument that gains 3% per year, and inflation is estimated to be 4% per year, well then you’re losing money in real terms. There are a variety of ways to estimate the rate of future inflation. You could, for example, use past rates as an estimate of future rates. However, the Treasury market provides an estimate of what the market thinks annual inflation will be over the next 5, 10, 20, and 30 years. Basically, the Treasury issue two types of securities: nominal securities that pay a nominal interest rate (fixed percentage of your principal), and inflation-indexed securities (TIPS) that pay an interest rate that is applied to your principal adjusted by the consumer price index (CPI).

Finance (R news & tutorials) - Part 3. Error Handling in Lyx & Sweave: using Quantmod (and R, of course) I do reports for clients with LyX and Sweave.

Finance (R news & tutorials) - Part 3

It took me an extremely long time to get them working, but now that they’re working I can do more in an hour and thus charge more per hour. If you’re not familiar, here’s a rundown: LaTeX is the stand... Portfolio diversity. How many baskets are your eggs in?

Portfolio diversity

Meucci diversity Attilio Meucci directly addresses the adage: Dates and times in R. Asynchrony in market data. Be careful if you have global daily data.

Asynchrony in market data

The issue Markets around the world are open at different times. November 21 for the Tokyo stock market is different from November 21 for the London stock market. The New York stock market has yet a different November 21. Cross Sectional Correlation. Simple Spatial Correlograms for Cross-Country Analysis in R. Accounting for temporal dependence in econometric analysis is important, as the presence of temporal dependence violates the assumption that observations are independent units.

Simple Spatial Correlograms for Cross-Country Analysis in R

Historically, much less attention has been paid to correcting for spatial dependence, which, if present, also violates this independence assumption. The comparability of temporal and spatial dependence is useful for illustrating why spatial dependence may matter. For example, a time-series analysis of a county’s GDP would examine how related this year’s figure was to preceding years, whereas a spatial analysis would examine how related one country’s figure was to that of their neighbours. However, these temporal and spatial issues are not completely analogous. Rdatamarket Tutorial. Garch() uncertainty. Skew of Bonds. Time Series Data Library now on DataMarket. Quickly Visualize Your Whole Dataset. Getting Started with R Markdown, knitr, and Rstudio 0.96. Slides for R/Finance 2012. Another succeessful* year of R/Finance is behind us.

Slides for R/Finance 2012

It was certainly more: a larger crowd, a longer session, more seminars, more presentations, more sponsors – perhaps even to the point where we’ve reaching a certain capacity. What began as an interesting idea among a few friends has more than credible momentum – it’s now more of a cannonball. Forecasting the Eurozone Misery index. Is Miss Stagflation coming to visit?

Forecasting the Eurozone Misery index

The Misery index is the sum of inflation and unemployment rate. We would like them both to stay naturally low, and we are miserable when they are not. The index is currently floating in it’s record scratching levels. Grexit stage left: visualizing the online discussion around Greece’s possible Euro exit. While Tsipras and his Syriza coalition have been busy in Greek parliament, the Internet has been a-buzz with speculation that their platform will result in a Greek exit from the Euro currency.

Grexit stage left: visualizing the online discussion around Greece’s possible Euro exit

This prospect, affectionately dubbed “Grexit” by Citi in February, has been making the rounds on Twitter under the hashtag #grexit. We think the amount of traffic on this hashtag is a good representation of market fear; by measuring and analyzing this traffic, we can help businesses quantify their political and currency risk in real-time. The Twitter visualizations below are a sneak peek of Twitter research reports produced in partnership with Solid Logic Inc. These reports are produced with a combination of R, ggplot2, gephi, Pentaho, and skilled writers, in just the right blend.

Quick View on Correlations of Different Instruments. In this post, I will demonstrate how to quickly visualize correlations using the PerformanceAnalytics package. Thanks to the package creators, it is really easy correlation and many other performance metrics. The first chart looks at the rolling 252 day correlation of nine sector ETFs using SPY as the benchmark. As expected the correlation is rather high because the sector ETFs are part of the S&P 500 index, but has been even more pronounced the last few years. Forecasting: Principles and Practice.

Trend Following Factors from Hsieh and Fung. Download and parse EDHEC hedge fund indexes. System from Trend Following Factors. Using R.Net in an Excel Add in. Term structure of interest rate spread volatility : Unit root test. Recently, I was working on my master's thesis and came across an interesting observation regarding the term structure of interest rate spread volatility that I wish to share.

Let me first try and throw some light on the jargon that I have used. To begin with, term structure of interest rates is basically a curve plotting the market expectation of nominal interest for different maturities. How do we get this term structure? Well, the trading of bonds (i.e fixed income securities) happen in the secondary market for debt instruments. Since, bonds have fixed coupon payments at fixed period of time, we can actually look at combinations of discount rates for these different (but fixed) time periods and discount these future coupon payments by their respective discount rates to arrive at the current price, i.e the one discovered in the market (simple application of the present value principal).

Let me start by plotting the daily interest rates from the term structure starting February 2003. Volatility Quantiles. Today I want to examine the performance of stocks in the S&P 500 grouped into Quantiles based on one year historical Volatility. The idea is very simple: each week we will form Volatility Quantiles portfolios by grouping stocks in the S&P 500 into Quantiles using one year historical Volatility. Next we will backtest each portfolio and check if low historical volatility corresponds to the low realized volatility. Let’s start by loading historical prices for all companies in the S&P 500 and create SPY and Equal Weight benchmarks using the Systematic Investor Toolbox: Next let’s divide stocks in the S&P 500 into Quantiles using one year historical Volatility and create backtest for each quantile.

Evaluation of Tactical Approaches. Autoplot: Graphical Methods with ggplot2. Background As of ggplot2 0.9.0 released in March 2012, there is a new generic function autoplot. Time series cross-validation 4: forecasting the S&P 500. Data distillation with Hadoop and R. Density Estimation of High-Frequency Financial Data.

Rook Tutorial at useR! 2012. Pretty Correlation Map of PIMCO Funds. Ggplot2 Time Series Heatmaps. Why You Shouldn’t Conclude "No Effect" from Statistically Insignificant Slopes. Video: Getting staRted with R: An accelerated primer by Lyndon Walker – Melbourne R Users. Beta is not volatility. The missing link between beta and volatility is correlation. Quantitative finance and computational systems. Borrowing Ideas from Timely Portfolio. Simple Moving Average Strategy with a Volatility Filter: Follow-Up Part 1. Multiple Factor Model – Fundamental Data.

Tutorial. Download Prices From Yahoo In Parallel. 20 free R tutorials (and one reference card) Structural Breaks (Bull or Bear?) French Global Factors. Cross-sectional skewness and kurtosis: stocks and portfolios. Volatility Position Sizing to improve Risk Adjusted Performance. Time Series Analysis and Mining with R. AIB Stock Price, EGARCH-M, and rgarch. Major changes to the forecast package.

Algorithms - Period detection of a generic time series. Measuring time series characteristics. Correlations, dimension, and risk measure.