Category Archives: Programming

Where Does the S&P 500 Stand?

Last week was brutal for pretty much all markets. Surprisingly, it was bad even for the US dollar. The sharp and straight downward move was reminiscent of the descent of 2011. It’s time to review where does the major index stands from technical point of view.
Read More

Tradelib is Open Source

Tradelib is my framework which I have been using for backtesting and signal generation in my futures trading. My feeling is that it might be useful to others, and I have decided to open source it.

Unfortunately, I don’t have the time at the moment to open source any strategy implemented with it, and I am also too lazy to provide a step-by-step guide for it. If you have an interesting strategy which you don’t mind sharing with the rest of the world, let me know, and I may consider implementing it and adding it to the repository as an illustrative example.

Trading Moving Averages with Less Whipsaws

Using a simple moving average to time markets has been a successful strategy over a very long period of time. Nothing to brag home about, but it cuts the drawdown of a buy and hold by about a half, sacrificing less than 1% of the CAGR in the process. In two words, simple yet effective. Here are the important numbers (using the S&P 500 index from 1994 to 2013, inclusive):

Read More

A Better ZigZag

There are a lot of “winning” strategies for bull markets floating around. “Buy the pullbacks” is certainly one of them. Does this sound simple enough to implement to you? While I am no Sheldon Cooper (although I have a favorite couch seat), I still like to live in a somewhat well defined world, a world in which, there is much more information attached to a tip like “Buy the pullbacks”. Let’s start with a chart of the recent history of the S&P 500 ETF:

Read More

Moved Quantscript to GitHub

Quantscript is an old project of mine, which was hosted on google.code. Since google.code is shutting down, I had to either scrap it or migrate it to GitHub. I am not using this code on a daily basis anymore, and since the project is relatively small – the natural thing would have been to scrap it. However, I found myself a few times over the years pulling out the source code of the project to follow as an example how to do different things in Python. Hence, I thought better to spend the time to migrate the project.

Read More

Parallelism via “parSapply”

In an earlier post, I used mclapply to kick off parallel R processes and to demonstrate inter-process synchronization via the flock package. Although I have been using this approach to parallelism for a few years now, I admit, it has certain important disadvantages. It works only on a single machine, and also, it doesn’t work on Windows.

Read More

Storing Forecasts in a Database

In my last post I mentioned that I started using RSQLite to store computed results. No rocket science here, but my feeling is that this might be useful to others, hence, this post. This can be done using any database, but I will use (R)SQLite as an illustration.

Read More

Synchronization for R with the flock Package

Have you tried synchronizing R processes? I did and it wasn’t straightforward. In fact, I ended up creating a new package – flock.

One of the improvements I did not too long ago to my R back-testing infrastructure was to start using a database to store the results. This way I can compute all interesting models (see the “ARMA Models for Trading” series for an example) once and store the relevant information (mean forecast, variance forecast, AIC, etc) into the database. Then, I can test whatever I want without further heavy lifting.

Read More

Shortcuts for quantmod

Over the years, there have been a couple of issues I have been trying to address in my daily use of this excellent package. Both are “cosmetic” improvements, they only improve the usability of the package. Let me share them and see whether they can be improved further.:)

Read More