point

Remember me

Stephen Rush's Blog

Timing csv File Reading in R and Python

I am currently working with trade data organized in large csv files. I took this as an opportunity to learn the Pandas package in Python mostly for the HDF5 integration. As a sanity check, I decided to time three methods: read.csv in R base, fread in the data.table package in R, and read.csv in the Pandas package in Python. Let me first say that I am not a programmer. This test is not a definitive benchmark of the three methods. It is a benchmark of the “out-of-the-box”...

Two-way Sorting in R

One of the popular ways to motivate a two dimensional model is to double sort your data based on quantiles. This makes empirical asset pricing models exceedingly easy to understand. If I had already defined the breakpoints of the sort, I could just use a function like “plyr” to apply a function like “mean” to the data subsets. For my application, I want to create five portfolios based on one characteristic and then form five portfolio within each of the first five based...

Managerial Game Theory

One of the first models covered in game theory is the Prisoner’s Dilemma. I’m sure you’ve heard of it or at least recognize it from episodes of Law and Order. Let’s look at the simple model with 2 individual players so we can eliminate mixed strategy equilibria and focus strictly on pure strategies. The two strategies for each player are “productive” and “exploitive”. The payoffs for the two players can be summarized on the usual grid. Employee Productive...

The Decreasing Marginal Utility of Donuts

This morning I ran through the Dunkin Donuts to pick up two donuts for me and two donuts for my wife. Four donuts cost \$3.85 while 6 donuts cost a little over \$4.00. The cashier tried to convince me that buying 6 donuts would be cheaper. Understandably, the cashier would not know that I was ordering for only two people or that we prefer not to stuff ourselves with more than two donuts each. Still, I feel like the cashier never quite believes that I understand the cost per donut is lower with an...

Benchmark Investing Stock Selection

A particular insurance company’s investment department measures stock performance against the S&P500 index on an annual basis. The portfolio is long only with no derivatives. The portfolio manager eases into new positions and takes smaller positions outside of the index. The department operates on a monthly trading schedule where all trades for the next month are set within the last week of the current month. Regardless of how much the portfolio outperforms its benchmark, full bonuses...

Graphing Fed Data

The quantmod package is great for grabbing various financial data series from online sources like Google, Yahoo, Oanda, and the Federal Reserve. It also has some nifty technical charts that look very nice but are rather difficult to modify. One such problem is charting multiple data series. In quantmod, you could do this: library(quantmod) variables=c(“INDPRO”,”TCU”); names=c(“Industrial Production”,”Capacity Utilization SA”)...

Value Creation

I hear a lot of opinions on how economic value is created. Some of these opinions are supported by secondhand anecdotal evidence and most of them are used to support various political or social positions. Some of the most absurd theories on value creation even come from wealthy and/or successful people so someone without a business education may be forgiven for believing that this is a philosophical question that can only be answered through a belief in some set of principles. I would like to...

Correlation Graph

Earlier this week, I saw a message in my Twitter feed talking about an unusual correlation pattern between the S&P 500 and the Dow. Unfortunately, the graph produced by the Greg Mankiw recommended site AssetCorrelation.com was grossly inaccurate showing periods of zero correlation between the indices. A few lines of code using the Quantmod package in R can easily replicate the functionality of the site and a prudent analyst can simply load a more reliable data source before arriving at any...