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
http://www.sliksvn.com/en/download

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/
E:\R-Package\blotter\pkg>dir

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.

Congratulations!

Posted in Software | Tagged | Leave a 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