Code

Introduction to PortfolioAnalytics

This is a guest post by Ross Bennett. Ross is currently enrolled in the University of Washington Master of Science in Computational Finance & Risk Management program with an expected graduation date of December 2014. He worked on the PortfolioAnalytics package as part of the Google Summer of Code 2013 project and continues to work on the package as a Research Assistant at the University of Washington. His work on the package focused on implementing a portfolio specification to separate and modularize assets, constraints, and objectives.

quantstrat is slow

The complaint I hear most frequently about quantstrat is that it’s slow, especially for large data. Some of this slow performance is due to quantstrat treating all strategies as path-dependent by default. Path dependence requires rules to be re-evaluated for each timestamp with a signal. More signals equates to longer run-times. If your strategy is not path-dependent, you can get a fairly substantial performance improvement by turning path-dependence off. If your strategy truly is path-dependent, keep reading…

A New plot.xts

The Google Summer of Code (2012) project to extend xts has produced a very promising new plot.xts function. Michael Weylandt, the project’s student, wrote R-SIG-Finance to request impressions, feedback, and bug reports. The function is housed in the xtsExtra package of the xts project on R-Forge. Please try xtsExtra::plot.xts and let us know what you think. A sample of the eye-candy produced by the code in Michael’s email is below. Granted, this isn’t a one-liner, but it’s certainly impressive!

R in Google Summer of Code 2012

This post is a slightly revised (and “blogified”) version of the message Brian Peterson has sent to various R mailing lists. Once again, R has been accepted as a mentoring organization for the Google Summer of Code (2012). We invite students interested in this program to learn more about it. A good starting point is the R GSoC wiki. Students participating in the program receive US$5,000 for successful completion of a GSoC project, a great resume item, and an opportunity to work with R package authors.

Tactical asset allocation using quantstrat

As promised in the introduction to quantstrat, here is an example strategy. I thought I’d start with the obligatory tactical asset allocation (TAA) strategy. This post will replicate the strategy in the post, tactical asset allocation using blotter. The “faber” demo in the quanstrat package contains a TAA strategy but it uses a slightly different approach than the code we’re trying to replicate. There are two major differences: The blotter TAA code initiates a position at the first observation where the close is above the SMA.

Historical / Future Volatility Correlation Stability

Michael Stokes, author of the MarketSci blog recently published a thought-provoking post about the correlation between historical and future volatility (measured as the standard deviation of daily close price percentage changes). This post is intended as an extension of his “unfinished thought”, not a critique. He suggests using his table of volatility correlations as a back-of-the-envelope approach to estimate future volatility, which led me to question the stability of the correlations in his table.

Tactical asset allocation using blotter

NOTE: If you simply want to test strategies in R, please see the post: Tactical Asset Allocation Using quantstrat. quantstrat uses blotter behind the scenes, but provides a higher level of abstraction. blotter is an R package that tracks the P&L of your trading systems (or simulations), even if your portfolio spans many security types and/or currencies. This post uses blotter to track a simple two-ETF trading system. The contents of this post borrow heavily from code and comments in the “longtrend” demo script in the blotter package.

David Varadi's RSI(2) alternative

Here’s a quick R implementation of David Varadi’s alternative to the RSI(2). Michael Stokes over at the MarketSci blog has three great posts exploring this indicator: Varadi’s RSI(2) Alternative: The DV(2) RSI(2) vs. DV(2) Last Couple of Notes on DV(2) Here’s the R code: DV <- function(HLC, n=2, bounded=FALSE) { # "HLC" is an _xts_ object with "High", "Low", and "Close" # columns, in that order. # This is David Varadi's alternative to the RSI(2).

RSI(2) Evaluation

This post continues the series of investigating the RSI(2) strategy. The first post replicated this simple RSI(2) strategy from the MarketSci Blog using R. The second post showed how to replicate the strategy that scales in/out of RSI(2). If you like the RSI(2), be sure to check out David Varadi’s RSI(2) alternative! This post will use the PerformanceAnalytics package to evaluate the rules that scale in/out of positions. I’ve also provided a simple function that provides some summary statistics.

RSI(2) with Position Sizing

Though it’s more than two weeks later, here’s the second post in the series that will demonstrate how to build, test, and implement a trading strategy with R. You can find the first post here. The first post replicated this simple RSI(2) strategy from the MarketSci Blog. This second post will demonstrate how to replicate this strategy that scales in/out of RSI(2). A couple notes before moving to the code: