After writing two blogs on the delights of working with the agile language Ruby, I decided to eat my own dog food and challenge myself to convert a significant piece of my portfolio returns simulation program from the statistical package R to Ruby.

The program does its work by resampling daily percentage change figures from the 46+ years of of academic portfolios available on the website of Dartmouth finance professor Ken French. The specific technique I use is the bootstrap, wherein I randomly sample with replacement many times from each of 8 lengthy portfolio vectors that house the 46 years of daily returns data. As an illustration, consider the investigation of 1 year returns for Market, a portfolio that performs much like the Wilshire 5000, generally acknowledged as the closest proxy to the overall US stock market. There are approximately 252 trading days per year, so to look at the distribution of one year Market returns, I randomly sample with replacement 252 observations from the 46+ year vector of 11,665 daily figures, computing the growth of an initial $1 investment. I repeat the process a large number of times – in this case 100,000 – to get a feel for what the sampling distribution of the $1 growth over a year  looks like. I  then compute similar distributions for 5 year, 10 year and 20 year returns, randomly sampling 5*252, 10*252, and 20*252 daily returns respectively, repeating each calculation 100,000 times. I finally look at other French portfolios, including Risk Free, Small Growth, Small Neutral, Small Value, Large Growth, Large Neutral and Large Value, performing the same calculations on each. When all is said and done, I write a pretty large file (8 portfolios*4 years*100,000 samples, a total of 3.2M records) for subsequent computations and analysis in R.

Register or login for access to this item and much more

All Information Management content is archived after seven days.

Community members receive:
  • All recent and archived articles
  • Conference offers and updates
  • A full menu of enewsletter options
  • Web seminars, white papers, ebooks

Don't have an account? Register for Free Unlimited Access