What people don’t see about SIPs

I have had this conversation with many friends now. Many people think SIP (systematic investment plans) is THE best way of investing in stock market. Sure, having discipline to invest in systematic manner is a virtue which I admire. But there are some glaring myths about SIPs which bother me whenever someone mentions SIP and I have to list them down.

Myth#1 : SIP reduce volatility of your investment

What bothers me most is the fact that people believe that they reduce volatility of their portfolio by investing via SIP. This is plain wrong. Volatility is nothing but standard deviation of returns over series of periods. It has no bearing on how much capital you have in your account but rather on when the capital is kept aside for investment. That is, unless you have all the cash that you are ever going to invest in SIP and calculate return on the whole amount such that initial large portion of capital is earning fixed return, you are really not reducing volatility of your investments by investing in SIP

Myth#2 : Drawdowns are reduced in SIP by LARGE amount / Drawdowns are more palatable.

Yes, SIP MAY reduce drawdowns. But, from many tests I have done, during crisis periods they are not reduced to levels which people are comfortable with.
Finally, I would like to share this graph which shows comparison of SIP into SPX vs. SIP into 10Y US Treasuries (with R code of the analysis at the end of post)
Comparision of SIP in SPX vs 10Y UST
Note that at end of 2010 i.e. after 20 years of starting the SIP investments, you would have ended up with similar amounts in both cases.

In conclusion, SIP investments in stock markets do provide you disciplined way of getting exposure to stock markets but they definitely don’t shield you from the volatilities and drawdowns of the stock market.
Code to reproduce above graph

getSymbols("SPX", from="1989-01-01")
SPX <- to.quarterly(Ad(SPX), drop.time = FALSE, indexAt = 'endof')
SPX <- cbind(Cl(SPX), Return.calculate(Cl(SPX)))
names(SPX) <- c("close", "ret")
RFR <- getSymbols("DGS10", src="FRED", from="1989-01-01", auto.assign = FALSE)
names(RFR) <- "RFR"
SPX <- cbind(SPX, lag(RFR[index(SPX)]/400))['1990/']
SPXIndCumRets <- do.call(cbind, sapply(1:nrow(SPX), function(i) cumprod(SPX$ret[i:nrow(SPX)]+1)))
RFRIndCumRets <- do.call(cbind, sapply(1:nrow(SPX), function(i) cumprod(SPX$RFR[i:nrow(SPX)]+1)))
SPXSIPEq <- xts(rowSums(SPXIndCumRets, na.rm=T), order.by = index(SPXIndCumRets))
RFRSIPEq <- xts(rowSums(RFRIndCumRets, na.rm=T), order.by = index(RFRIndCumRets))
Comparison <- cbind(SPXSIPEq, RFRSIPEq)
names(Comparison) <- c("SPX_SIP", "Treas10Y_SIP")
plot.xts(Comparison, legend.loc = 'topleft', cex = 1)
Posted in Uncategorized | Leave a comment

Short talk on xts package at RUGS May 2014

Recently, at on of our monthly R Users Group Singapore meetup, I gave a short talk on xts package.

I still find many people, especially the beginner R users, struggling with common time series data tasks. My goal with this presentation was to showcase some of the awesome feature set that xts brings to the table to make our lives easier :)

Here are my slides from that talk.

Posted in Software | Tagged | Leave a comment

Installing quantstrat.

I have been asked couple of times about how to install latest version of quantstrat after my talk, so I decided put up detailed instructions for those who are new to R and quantstrat.

The following assumes you have R installed. If not, please install R first.

You will need to install Rtools to build package from source as well. You can download latest version of Rtools from http://cran.r-project.org/bin/windows/Rtools/

You will also need svn installed. You can download simple SVN client from

Once R, RTools, SVN are installed on your windows system, you will need to make sure that your Environment PATH variable has all the following directories included.

  • full path\Rtools\bin
  • full path\Rtools\gcc-4.6.3\bin
  • full path\R\bin
  • full path\SlikSvn\bin

See example below

PATH=c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Java\jre7\bin;C:\curl;E:\R\bin;C:\Program Files\SlikSvn\bin

Now time to install quanstrat.

Note that these packages have several dependencies (other packages including xts, quantmod) that
you may or may not have already installed. The best way to install these packages is through the R console.

There are two methods to install ‘blotter’ family of packages

Using pre-built binaries from R-Forge.

You can install FinancialInstrument , blotter and quantstrat by specifying their repository, like this:

R> install.packages("FinancialInstrument",repos="http://r-forge.r-project.org")
R> install.packages("blotter",repos="http://r-forge.r-project.org")
R> install.packages("quantstrat",repos="http://r-forge.r-project.org")

This is unreliable though and doesn’t work for every package, including RTAQ.

R> install.packages("RTAQ", repos="http://r-forge.r-project.org")
Warning message:
package ‘RTAQ’ is not available (for R version 2.15.1)

A more reliable way to install this bleeding-edge code is to get it onto your computer.

Using latest source code from SVN repository

Open a console prompt and navigate to directory where you would like to download the source code. Then execute following command
(Note: in example below E:\R-Package is directory where source code will be downloaded)

E:\R-Package>svn checkout svn://svn.r-forge.r-project.org/svnroot/blotter/

From here, cd to what you just downloaded and see what you got.

E:\R-Package>cd blotter/pkg/

Directory of E:\R-Package\blotter\pkg

12/08/2012 01:12 AM <DIR> .
12/08/2012 01:12 AM <DIR> ..
12/08/2012 01:12 AM <DIR> blotter
12/08/2012 01:13 AM <DIR> FinancialInstrument
12/08/2012 01:11 AM <DIR> quantstrat
12/08/2012 01:12 AM <DIR> RTAQ

Now you can install FinancialInstrument package first using following command

E:\R-Package\blotter\pkg>R CMD INSTALL FinancialInstrument

You should see following messages on successful installation

* installing to library 'E:/R/library'
* installing *source* package 'FinancialInstrument' ...
** R
** data
** demo
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
*** arch - x64

* DONE (FinancialInstrument)

Similarly you can install rest of packages with following commands

E:\R-Package\blotter\pkg>R CMD INSTALL blotter
E:\R-Package\blotter\pkg>R CMD INSTALL quantstrat

You should now have the code to begin implementing your trading strategy in R.


Posted in Software | Tagged | 1 Comment

Fetch 1 second bar data from Interactive Brokers with R

It’s no secret, that I love R and I love Interactive Brokers. Interactive Brokers is one of the best broker for semi-professional independent traders.

One of the most important aspect of systematic trading is getting right data. Thanks for excellent IBrokers package by Jeffery Ryan, it is very easy to fetch historical data from IB directly into R.

Following is one of the script I just cooked up to download historical 1S bar data for any IB contract. (ofcourse provided IB supports that frequency data for the given contract).

Posted in Resources, Software | Tagged , , | Leave a comment

Trading with R

I recently had opportunity to speak at R Users group Singapore about Trading with R.

While most of the audience members were non-traders, they were still amazed at things you can do in R.

R being my primary research tool, I am quite glad that I might have convinced atleast a few more people to use R for trading research.

Posted in Resources, Software | Tagged , | 1 Comment

Components of Algorithmic Trading Strategy Development.

For any rules based strategy to be successful, it has to go through rigorous testing. While the level of rigor required, is topic of debate, there are some key steps which every rules based trader undertake to ensure survival in the field of trading.

Algorithmic trading strategy development workflow is quite similar to that of any scientific research project. Your goal as strategy developer is to take an idea to execution.

Strategy Development

The core component of any trading  strategy development is the idea. The idea can originate from any of the 3 remaining components. One might get his trading idea by active research, or while doing validation of any previous idea or even execution of previously validated idea.

I plan/hope to post more about each of these component individually in future posts.



Posted in Trading Psychology | Leave a comment

Tools of the Trade

I tend to use best tool that I know for the problem at hand.  I believe every tool (programming language, backtesting platform et al. ) has it’s strengths and weaknesses and I like to use the right tool for right job.

Ofcourse, in some cases, choice of tool is also dependent on overall project at hand. For example, I certainly love to use R graphics but if I am trying to build interactive visualization to be hosted on web, I might have to resort to some other tool (say D3).

Anyways, following are the tools I use for my day to day Systematic trading :

R : R is certainly one my most favorite tool and I use it mainly for analysis of backtesting data generated from other backtesting softwares. R does have quantstrat package for backtesting systematic trading strategies. However, it is under heavy development, and as a business decision, we decided to use other softwares specifically developed for backtesting. Having said that, I see great potential in quantstrat and certainly see it as best free open source backtesting tool out there.

TradingBlox : TradingBlox is one of the most advanced backtesting tool that I have used till now. It’s most powerful feature is true portfolio level backtesting, which is one of the main reason, all my backtesting still happens of TradingBlox. TradingBlox’s uses Basic-like  scripting language for coding strategies and has powerful concept of “Blox” which allows for easy re-usability of code.

Multicharts : Multicharts is one the newer programmes that I have started using for backtesting. Like Tradestation, you can write strategy code using EasyLanguage (which happens to be really easy language even for the traders who are new to programming). It allows you to do your backtesting using actual Bid / Ask data to make your backtesting as accurate as possible. It also has portfolio backtester functionality, although I find it bit rudimentary at the moment.



Posted in Resources, Software | Leave a comment

What kind of trader am I?

I have been trading for living for more than 18 months for now, and along the way, I have discovered what kind of trader I am going to be.

As with most traders, I started with discretionary trading as side investment / hobby. I think my first trade was buying a Call Option on ATVI before the release of much awaited expansion pack of it’s massively popular MMORPG. Stock was trading around 10 and I bought 9 month call options strike at 13. I didn’t do much of vol analysis, neither any technical analysis. Just glanced over chart of ATVI and concluded that after every major game release, ATVI stock popped. So there I went betting good couple of grands on ATVI call, only to loose all of it to theta decay. And, I dropped trading again.

I started Trading again couple of years later – this time with FOREX. Success of Kostas1 with his trading system really inspired me to try it out and I spent couple of months trying “imitate” Kostas1′s  success for myself. Along the way, I learnt a lot of psychological aspects of trading.

After quitting corporate job, to do trading full time, I have realized that all these trading related endeavors were really more about discovering myself.

Now, I know what kind of person I am. I am a person who doesn’t like to take unknown risk. I am much more comfortable knowing my maximum downside limited to certain fraction of total equity. Risk management, I believe, is far more important than having a very good trading signal. To manage my risk effectively, I understand that I can’t be too fixated on making every trade a winner and making every trade ‘swinging-for-fences’ (in American terms) or a ‘sixer’ (in Indian terms)

Similarly, over past year, I have studied importance of testing statistical significance of any trading strategy. Backtesting has so many more aspects to it than just checking whether equity curve is pointing up.

I am not full-fledged quantitative trader yet, but I think I have understood benefits of rules based trading enough to make it major portion of my trading portfolio.

Even if I don’t manage to make living out of trading, I certainly know how my personal investments portfolio going to evolve.

I will continue with more posts about Trading psychology and my learnings about it.

Posted in Trading Psychology | Leave a comment

Hello world!

Inaugural post of geektrader.me!

Looking forward to sharing my thoughts and research via this website.

Posted in Uncategorized | Leave a comment