Nov 23, 2011

Volume by Price Charts using R

R-Bloggers is a wonderful site which offers some great ideas for analysis.

While I have been busy of late, hence could not do much with R, I was inspired by this post by Eric Nguyen on Volume by Price chart. 

This chart can be used with a great effect in ones trading strategies. It helps in identifying the support and resistance zones, and a breakout from these levels used as entry/exit points

Extending the work done by Eric, and making few changes in his original code, here is what I have achieved.

Reliance EOD Volume by Price chart

Aug 11, 2011

Plotting Cumulative FII & DII Inflow against Nifty spot index

Now that I have the FII and DII Inflow along with Nifty Index, I tried my hands on charting!

The objective is to plot the Cumulative FII, DII and Net Inflow and Nifty Index for current year (2011) on a single graph. This post takes inspiration from Deepak Shenoy's post, wherein he has plotted some nice graphs.

The approach is to read the file created earlier for FII & DII Stats, convert the object as zoo (package used is quantmod), filter the data to contain only current years figure values, and then calculate cumulative sum using cumsum() fuction.

The extra effort done here is the use of right axis to display Nifty Index values using axis() function.

The graph contains 4 lines on the same plot, with the legends. If you observe, there is a high co-relation between Nifty spot and Net FII inflow. 68% is what the following line tell. Does this mean our markets trends are dictated by FIIs?


Cumulative Institutional inflow in 2011

Aug 4, 2011

FII and DII turnover with effect on Nifty Downloader

My thirst for statistics has been increasing. IV had another requirement, which would eventually be useful to me as well. He currently downloads FII and DII buy and sell values and its impact on Nifty manually in Excel. He suggested me to try and automate this process in R. Wow! Some more learning of R, which would eventually help me in building my strategies!

Unlike in NSE EOD Bhavcopy and BSE EOD Bhavcopy downloaders, I tried a different approach to download FII + DII stats from NSEIndia website (as if I had a choice), along with the index Nifty values and change over previous day. The National Stock Exchange of India has different structures for different pages. To download index values, you have to refer to the link whereas for FII and DII stats, you need to visit

Both of these pages are HTML forms, you have to enter parameters like index name, start and end dates. Another challenge is that each of these pages displays a maximum of 100 rows in table and if you need all rows (more than 100), you have to download a csv (dynamically generated in temp location). I faced problem in accessing the csv, as for older dates, the link generated was not valid. Hence, I decided to read the page itself, parse the table to be consumed as data frame. For instances, where the parameters generate more than 100 rows, I decided to use while loop.

OK, now here is the solution for it.

Jul 24, 2011

BSE Bhavcopy with Delivery Quantity

One of my TI forum members IV had a requirement for BSE Quotes along with Delivery Quantity. This made me implement "merge" function of R (thanks to the great work done by people behind various packages and guidance available on R Mailing lists).

The task involves downloading files from two separate links and merging it on the basis of Symbol on any given date.

The output is a single file for one trading day. With a slight tweak in the code, single file can be generated for a week, a month, a year , or from beginning to end. If anyone is interested, let me know, and will offer the solution for the same

Without much write-up here is the code for the same.

For those, who want to take a shortcut, here are historical quotes