Thursday 16 May 2013

Pair Trading Using Machine Learning : Intraday Strategy Results

I have tried to implement an Intraday Strategy on Pairs. An important point to consider when selecting a good pair is that they should be from same sector as well common characteristics even while looking at fundamentals. For e.g. GOLD ETF can be good pair with GOLD Futures, SBI bank as well ICICI Bank can also fall into that category and CAIRN and ONGC to name few.

I have selected SBI Bank as well ICICI Bank for my machine learning pair trading strategy and produced some backtested results in terms of Total Profit & Loss, number of profitable trades and number of losing trades in R.

You can suggest me any pair which you want the strategy to be run on any day data in Indian as well international markets. Please bear with the formatting as of now as these I preliminary formatting as I was curious to share the details of  results. In future posts relating to this strategy I would be posting nice graphs showing the results as well trades.

I have haven't considered transaction costs and impact costs in my backtested results which should be taken into account while going live on a trading platform. Further, no optimization has been done as I believe there are great enhancement in returns once optimization is done.

It is done using 1 minute data and you can see from the output the time at which trades are placed. I would be using this strategy and test it on 1 second data and I am sure it would be much more.

I have defined it for 1 shares of x and share of Y(in proportion of x). So I have just used ratio and rounded it off to 2 or 1 depending upon prices. In the below case it is 1 SBI shares for 2 ICICI Bank shares and results is for today i.e. 17/05/2013.

Here is an excerpt of the trades done via backtesting using this algo:


Total Profit Rs. 242.25
Total Winning Trades 126
Total Losing trades 6


How to read below text is like this


For example for the first line:


Line 1 : Entry Date - 20130517 , Time :09:45 am, Sold 1 SBI bank stock at Rs. 2398.2 and bought 2 ICICI Bank stocks at 1205.05

Line 2 : Exit Time :09:46 am, Bought 1 SBI bank stock at Rs. 2399.05 and sold 2 ICICI Bank stocks at 1207.3

Line3: Entry prices for SBI at Rs. 2398.2 and ICICIBANK at Rs.1205.05

Line 4: Quantity bought of SBIN = 1 and quanitity bought of ICICIBANK=2

Line 5: Profit in Rs.3.69


Entry 20130517 Time 945Sell 1SBIN @ 2398.25Buy 2ICICIBANK @ 1205.05
Exiting  Time@946Buy 1SBIN @ 2399.05Sell 2ICICIBANK @ 1207.3
Entry Price 1=2398.25Entry Price 2=1205.05
Qty 1=1Qty2=2
Profit is 3.69999999999982

Entry 20130517 Time 947Sell 1SBIN @ 2398Buy 2ICICIBANK @ 1205.05
Exiting  Time@948Buy 1SBIN @ 2397.15Sell 2ICICIBANK @ 1205.2
Entry Price 1=2398Entry Price 2=1205.05
Qty 1=1Qty2=2
Profit is 1.15000000000009

Entry 20130517 Time 949Buy 1SBIN @ 2398.25Sell 2 ICICIBANK @ 1205.7
Exiting20130517 Time950Sell 1SBIN@ 2397.2Buy 2ICICIBANK @ 1204.25
Entry Price 1=2398.25Entry Price 2=1205.7
Qty 1=1Qty2=2
Profit is 1.84999999999991

Entry 20130517 Time 951Sell 1SBIN @ 2400.8Buy 2ICICIBANK @ 1205.4
Exiting  Time@953Buy 1SBIN @ 2403.3Sell 2ICICIBANK @ 1206.85
Entry Price 1=2400.8Entry Price 2=1205.4
Qty 1=1Qty2=2
Profit is 0.399999999999636

Entry 20130517 Time 954Buy 1SBIN @ 2404.5Sell 2 ICICIBANK @ 1206.5
Exiting20130517 Time955Sell 1SBIN@ 2408.9Buy 2ICICIBANK @ 1206.85
Entry Price 1=2404.5Entry Price 2=1206.5
Qty 1=1Qty2=2
Profit is 3.70000000000027

Entry 20130517 Time 956Sell 1SBIN @ 2407.1Buy 2ICICIBANK @ 1207.5
Exiting  Time@958Buy 1SBIN @ 2407Sell 2ICICIBANK @ 1209.05
Entry Price 1=2407.1Entry Price 2=1207.5
Qty 1=1Qty2=2
Profit is 3.19999999999982

Entry 20130517 Time 959Sell 1SBIN @ 2409Buy 2ICICIBANK @ 1210
Exiting  Time@1003Buy 1SBIN @ 2406.95Sell 2ICICIBANK @ 1210.55
Entry Price 1=2409Entry Price 2=1210
Qty 1=1Qty2=2
Profit is 3.15000000000009

Entry 20130517 Time 1004Buy 1SBIN @ 2406.5Sell 2 ICICIBANK @ 1209.75
Exiting20130517 Time1006Sell 1SBIN@ 2407.3Buy 2ICICIBANK @ 1209.4
Entry Price 1=2406.5Entry Price 2=1209.75
Qty 1=1Qty2=2
Profit is 1.5

Entry 20130517 Time 1007Sell 1SBIN @ 2408.35Buy 2ICICIBANK @ 1209.85
Exiting  Time@1008Buy 1SBIN @ 2408.4Sell 2ICICIBANK @ 1210.05
Entry Price 1=2408.35Entry Price 2=1209.85
Qty 1=1Qty2=2
Profit is 0.349999999999909

Entry 20130517 Time 1009Buy 1SBIN @ 2408.95Sell 2 ICICIBANK @ 1210
Exiting20130517 Time1011Sell 1SBIN@ 2409Buy 2ICICIBANK @ 1209.8
Entry Price 1=2408.95Entry Price 2=1210
Qty 1=1Qty2=2
Profit is 0.450000000000273

Entry 20130517 Time 1012Sell 1SBIN @ 2408.8Buy 2ICICIBANK @ 1210.55
Exiting  Time@1014Buy 1SBIN @ 2406.35Sell 2ICICIBANK @ 1209.5
Entry Price 1=2408.8Entry Price 2=1210.55
Qty 1=1Qty2=2
Profit is 0.350000000000364

Entry 20130517 Time 1015Sell 1SBIN @ 2406.2Buy 2ICICIBANK @ 1208.15
Exiting  Time@1018Buy 1SBIN @ 2406.9Sell 2ICICIBANK @ 1209.65
Entry Price 1=2406.2Entry Price 2=1208.15
Qty 1=1Qty2=2
Profit is 2.29999999999973

Entry 20130517 Time 1019Sell 1SBIN @ 2408.05Buy 2ICICIBANK @ 1208.75
Exiting  Time@1021Buy 1SBIN @ 2407.3Sell 2ICICIBANK @ 1210
Entry Price 1=2408.05Entry Price 2=1208.75
Qty 1=1Qty2=2
Profit is 3.25

Entry 20130517 Time 1022Buy 1SBIN @ 2408.85Sell 2 ICICIBANK @ 1209.85
Exiting20130517 Time1025Sell 1SBIN@ 2415.4Buy 2ICICIBANK @ 1209.7
Entry Price 1=2408.85Entry Price 2=1209.85
Qty 1=1Qty2=2
Profit is 6.84999999999991

Entry 20130517 Time 1026Sell 1SBIN @ 2414.05Buy 2ICICIBANK @ 1209.55
Exiting  Time@1029Buy 1SBIN @ 2410.85Sell 2ICICIBANK @ 1210.5
Entry Price 1=2414.05Entry Price 2=1209.55
Qty 1=1Qty2=2
Profit is 5.10000000000036

Entry 20130517 Time 1030Sell 1SBIN @ 2410.85Buy 2ICICIBANK @ 1211
Exiting  Time@1033Buy 1SBIN @ 2415.4Sell 2ICICIBANK @ 1215
Entry Price 1=2410.85Entry Price 2=1211
Qty 1=1Qty2=2
Profit is 3.44999999999982

Entry 20130517 Time 1034Buy 1SBIN @ 2415.9Sell 2 ICICIBANK @ 1214.5
Exiting20130517 Time1035Sell 1SBIN@ 2418Buy 2ICICIBANK @ 1214.8
Entry Price 1=2415.9Entry Price 2=1214.5
Qty 1=1Qty2=2
Profit is 1.5

Entry 20130517 Time 1036Sell 1SBIN @ 2416.35Buy 2ICICIBANK @ 1214.8
Exiting  Time@1037Buy 1SBIN @ 2415.35Sell 2ICICIBANK @ 1214.95
Entry Price 1=2416.35Entry Price 2=1214.8
Qty 1=1Qty2=2
Profit is 1.30000000000018

Entry 20130517 Time 1038Sell 1SBIN @ 2414.8Buy 2ICICIBANK @ 1214.6
Exiting  Time@1040Buy 1SBIN @ 2416.5Sell 2ICICIBANK @ 1219.2
Entry Price 1=2414.8Entry Price 2=1214.6
Qty 1=1Qty2=2
Profit is 7.50000000000045

Entry 20130517 Time 1041Buy 1SBIN @ 2418.05Sell 2 ICICIBANK @ 1217.95
Exiting20130517 Time1042Sell 1SBIN@ 2417.85Buy 2ICICIBANK @ 1216.6
Entry Price 1=2418.05Entry Price 2=1217.95
Qty 1=1Qty2=2
Profit is 2.5

Entry 20130517 Time 1043Sell 1SBIN @ 2417.5Buy 2ICICIBANK @ 1216.7
Exiting  Time@1044Buy 1SBIN @ 2417.4Sell 2ICICIBANK @ 1217.4
Entry Price 1=2417.5Entry Price 2=1216.7
Qty 1=1Qty2=2
Profit is 1.5

Entry 20130517 Time 1045Buy 1SBIN @ 2418Sell 2 ICICIBANK @ 1218.05
Exiting20130517 Time1046Sell 1SBIN@ 2422Buy 2ICICIBANK @ 1218.85
Entry Price 1=2418Entry Price 2=1218.05
Qty 1=1Qty2=2
Profit is 2.40000000000009

Entry 20130517 Time 1047Sell 1SBIN @ 2420.7Buy 2ICICIBANK @ 1218.1
Exiting  Time@1051Buy 1SBIN @ 2412.9Sell 2ICICIBANK @ 1215.55
Entry Price 1=2420.7Entry Price 2=1218.1
Qty 1=1Qty2=2
Profit is 2.69999999999982

Entry 20130517 Time 1052Buy 1SBIN @ 2412.3Sell 2 ICICIBANK @ 1214.6
Exiting20130517 Time1053Sell 1SBIN@ 2412.05Buy 2ICICIBANK @ 1214.5
Entry Price 1=2412.3Entry Price 2=1214.6
Qty 1=1Qty2=2
Profit is -0.0500000000001819

Entry 20130517 Time 1054Sell 1SBIN @ 2411.15Buy 2ICICIBANK @ 1214.4
Exiting  Time@1055Buy 1SBIN @ 2410Sell 2ICICIBANK @ 1215
Entry Price 1=2411.15Entry Price 2=1214.4
Qty 1=1Qty2=2
Profit is 2.34999999999991

Entry 20130517 Time 1056Sell 1SBIN @ 2409.8Buy 2ICICIBANK @ 1214.65
Exiting  Time@1058Buy 1SBIN @ 2405Sell 2ICICIBANK @ 1214.45
Entry Price 1=2409.8Entry Price 2=1214.65
Qty 1=1Qty2=2
Profit is 4.40000000000009

Entry 20130517 Time 1059Buy 1SBIN @ 2406.75Sell 2 ICICIBANK @ 1214.45
Exiting20130517 Time1104Sell 1SBIN@ 2411.15Buy 2ICICIBANK @ 1216.7
Entry Price 1=2406.75Entry Price 2=1214.45
Qty 1=1Qty2=2
Profit is -0.0999999999999091

Entry 20130517 Time 1105Buy 1SBIN @ 2410.4Sell 2 ICICIBANK @ 1216.6
Exiting20130517 Time1110Sell 1SBIN@ 2408.5Buy 2ICICIBANK @ 1215.9
Entry Price 1=2410.4Entry Price 2=1216.6
Qty 1=1Qty2=2
Profit is -0.500000000000455

Entry 20130517 Time 1111Buy 1SBIN @ 2407.1Sell 2 ICICIBANK @ 1215.9
Exiting20130517 Time1114Sell 1SBIN@ 2409.35Buy 2ICICIBANK @ 1217.3
Entry Price 1=2407.1Entry Price 2=1215.9
Qty 1=1Qty2=2
Profit is -0.549999999999727

Entry 20130517 Time 1115Buy 1SBIN @ 2410.45Sell 2 ICICIBANK @ 1216.95
Exiting20130517 Time1118Sell 1SBIN@ 2411Buy 2ICICIBANK @ 1217.2
Entry Price 1=2410.45Entry Price 2=1216.95
Qty 1=1Qty2=2
Profit is 0.0500000000001819

Entry 20130517 Time 1119Buy 1SBIN @ 2410.9Sell 2 ICICIBANK @ 1217.4
Exiting20130517 Time1120Sell 1SBIN@ 2410.9Buy 2ICICIBANK @ 1217.4
Entry Price 1=2410.9Entry Price 2=1217.4
Qty 1=1Qty2=2
Profit is 0

Entry 20130517 Time 1121Buy 1SBIN @ 2409.35Sell 2 ICICIBANK @ 1217.5
Exiting20130517 Time1122Sell 1SBIN@ 2410.1Buy 2ICICIBANK @ 1217
Entry Price 1=2409.35Entry Price 2=1217.5
Qty 1=1Qty2=2
Profit is 1.75

Entry 20130517 Time 1123Buy 1SBIN @ 2409Sell 2 ICICIBANK @ 1216.4
Exiting20130517 Time1124Sell 1SBIN@ 2408.55Buy 2ICICIBANK @ 1215.7
Entry Price 1=2409Entry Price 2=1216.4
Qty 1=1Qty2=2
Profit is 0.950000000000273

Entry 20130517 Time 1125Sell 1SBIN @ 2407.25Buy 2ICICIBANK @ 1215.3
Exiting  Time@1126Buy 1SBIN @ 2405.8Sell 2ICICIBANK @ 1215
Entry Price 1=2407.25Entry Price 2=1215.3
Qty 1=1Qty2=2
Profit is 0.849999999999909

Entry 20130517 Time 1128Buy 1SBIN @ 2408.55Sell 2 ICICIBANK @ 1215.7
Exiting20130517 Time1129Sell 1SBIN@ 2409.1Buy 2ICICIBANK @ 1214.75
Entry Price 1=2408.55Entry Price 2=1215.7
Qty 1=1Qty2=2
Profit is 2.44999999999982

Entry 20130517 Time 1130Sell 1SBIN @ 2407.4Buy 2ICICIBANK @ 1214.1
Exiting  Time@1132Buy 1SBIN @ 2405Sell 2ICICIBANK @ 1213.7
Entry Price 1=2407.4Entry Price 2=1214.1
Qty 1=1Qty2=2
Profit is 1.60000000000036

Entry 20130517 Time 1133Sell 1SBIN @ 2404.5Buy 2ICICIBANK @ 1213.2
Exiting  Time@1134Buy 1SBIN @ 2401.55Sell 2ICICIBANK @ 1212.9
Entry Price 1=2404.5Entry Price 2=1213.2
Qty 1=1Qty2=2
Profit is 2.34999999999991

Entry 20130517 Time 1135Sell 1SBIN @ 2405Buy 2ICICIBANK @ 1213.4
Exiting  Time@1137Buy 1SBIN @ 2399Sell 2ICICIBANK @ 1212.25
Entry Price 1=2405Entry Price 2=1213.4
Qty 1=1Qty2=2
Profit is 3.69999999999982

Entry 20130517 Time 1138Sell 1SBIN @ 2402Buy 2ICICIBANK @ 1212.6
Exiting  Time@1139Buy 1SBIN @ 2403.1Sell 2ICICIBANK @ 1213.8
Entry Price 1=2402Entry Price 2=1212.6
Qty 1=1Qty2=2
Profit is 1.30000000000018

Entry 20130517 Time 1140Buy 1SBIN @ 2403.1Sell 2 ICICIBANK @ 1213.35
Exiting20130517 Time1145Sell 1SBIN@ 2407.05Buy 2ICICIBANK @ 1213.95
Entry Price 1=2403.1Entry Price 2=1213.35
Qty 1=1Qty2=2
Profit is 2.75

Entry 20130517 Time 1146Buy 1SBIN @ 2405.55Sell 2 ICICIBANK @ 1213.9
Exiting20130517 Time1149Sell 1SBIN@ 2405.6Buy 2ICICIBANK @ 1213.7
Entry Price 1=2405.55Entry Price 2=1213.9
Qty 1=1Qty2=2
Profit is 0.449999999999818

Entry 20130517 Time 1150Buy 1SBIN @ 2405Sell 2 ICICIBANK @ 1213.9
Exiting20130517 Time1151Sell 1SBIN@ 2404.85Buy 2ICICIBANK @ 1213.7
Entry Price 1=2405Entry Price 2=1213.9
Qty 1=1Qty2=2
Profit is 0.25

Entry 20130517 Time 1152Buy 1SBIN @ 2402.05Sell 2 ICICIBANK @ 1213.2
Exiting20130517 Time1153Sell 1SBIN@ 2403.1Buy 2ICICIBANK @ 1212.9
Entry Price 1=2402.05Entry Price 2=1213.2
Qty 1=1Qty2=2
Profit is 1.64999999999964

Entry 20130517 Time 1154Sell 1SBIN @ 2403.6Buy 2ICICIBANK @ 1213.05
Exiting  Time@1155Buy 1SBIN @ 2404.5Sell 2ICICIBANK @ 1213.85
Entry Price 1=2403.6Entry Price 2=1213.05
Qty 1=1Qty2=2
Profit is 0.699999999999818

Entry 20130517 Time 1156Sell 1SBIN @ 2405.55Buy 2ICICIBANK @ 1213.95
Exiting  Time@1157Buy 1SBIN @ 2405Sell 2ICICIBANK @ 1213.85
Entry Price 1=2405.55Entry Price 2=1213.95
Qty 1=1Qty2=2
Profit is 0.349999999999909

Entry 20130517 Time 1158Buy 1SBIN @ 2405Sell 2 ICICIBANK @ 1213.75
Exiting20130517 Time1159Sell 1SBIN@ 2405.1Buy 2ICICIBANK @ 1213.65
Entry Price 1=2405Entry Price 2=1213.75
Qty 1=1Qty2=2
Profit is 0.299999999999727

Entry 20130517 Time 1200Buy 1SBIN @ 2404.8Sell 2 ICICIBANK @ 1215
Exiting20130517 Time1201Sell 1SBIN@ 2405.45Buy 2ICICIBANK @ 1214.6
Entry Price 1=2404.8Entry Price 2=1215
Qty 1=1Qty2=2
Profit is 1.44999999999982

Entry 20130517 Time 1202Sell 1SBIN @ 2406Buy 2ICICIBANK @ 1214.45
Exiting  Time@1203Buy 1SBIN @ 2405.65Sell 2ICICIBANK @ 1214.9
Entry Price 1=2406Entry Price 2=1214.45
Qty 1=1Qty2=2
Profit is 1.25

Entry 20130517 Time 1204Sell 1SBIN @ 2406.5Buy 2ICICIBANK @ 1214.35
Exiting  Time@1205Buy 1SBIN @ 2403Sell 2ICICIBANK @ 1214.55
Entry Price 1=2406.5Entry Price 2=1214.35
Qty 1=1Qty2=2
Profit is 3.90000000000009

Entry 20130517 Time 1206Sell 1SBIN @ 2403.95Buy 2ICICIBANK @ 1214.65
Exiting  Time@1208Buy 1SBIN @ 2407.05Sell 2ICICIBANK @ 1217.6
Entry Price 1=2403.95Entry Price 2=1214.65
Qty 1=1Qty2=2
Profit is 2.79999999999927

Entry 20130517 Time 1209Buy 1SBIN @ 2407Sell 2 ICICIBANK @ 1217.45
Exiting20130517 Time1210Sell 1SBIN@ 2407.25Buy 2ICICIBANK @ 1217.2
Entry Price 1=2407Entry Price 2=1217.45
Qty 1=1Qty2=2
Profit is 0.75

Entry 20130517 Time 1211Sell 1SBIN @ 2408.55Buy 2ICICIBANK @ 1218.15
Exiting  Time@1213Buy 1SBIN @ 2410Sell 2ICICIBANK @ 1221.4
Entry Price 1=2408.55Entry Price 2=1218.15
Qty 1=1Qty2=2
Profit is 5.05000000000018

Entry 20130517 Time 1214Sell 1SBIN @ 2407.5Buy 2ICICIBANK @ 1220.6
Exiting  Time@1216Buy 1SBIN @ 2406.4Sell 2ICICIBANK @ 1221.4
Entry Price 1=2407.5Entry Price 2=1220.6
Qty 1=1Qty2=2
Profit is 2.70000000000027

Entry 20130517 Time 1217Sell 1SBIN @ 2403.3Buy 2ICICIBANK @ 1219.1
Exiting  Time@1219Buy 1SBIN @ 2404.15Sell 2ICICIBANK @ 1221.25
Entry Price 1=2403.3Entry Price 2=1219.1
Qty 1=1Qty2=2
Profit is 3.45000000000027

Entry 20130517 Time 1220Buy 1SBIN @ 2404.75Sell 2 ICICIBANK @ 1221.6
Exiting20130517 Time1222Sell 1SBIN@ 2408.45Buy 2ICICIBANK @ 1224.05
Entry Price 1=2404.75Entry Price 2=1221.6
Qty 1=1Qty2=2
Profit is -1.20000000000027

Entry 20130517 Time 1223Buy 1SBIN @ 2409.45Sell 2 ICICIBANK @ 1223.45
Exiting20130517 Time1224Sell 1SBIN@ 2411.35Buy 2ICICIBANK @ 1222.9
Entry Price 1=2409.45Entry Price 2=1223.45
Qty 1=1Qty2=2
Profit is 3

Entry 20130517 Time 1225Sell 1SBIN @ 2408.35Buy 2ICICIBANK @ 1221.5
Exiting  Time@1226Buy 1SBIN @ 2408.1Sell 2ICICIBANK @ 1222.3
Entry Price 1=2408.35Entry Price 2=1221.5
Qty 1=1Qty2=2
Profit is 1.84999999999991

Entry 20130517 Time 1227Buy 1SBIN @ 2410.8Sell 2 ICICIBANK @ 1223.35
Exiting20130517 Time1228Sell 1SBIN@ 2413.15Buy 2ICICIBANK @ 1223.9
Entry Price 1=2410.8Entry Price 2=1223.35
Qty 1=1Qty2=2
Profit is 1.24999999999955

Entry 20130517 Time 1229Buy 1SBIN @ 2412.05Sell 2 ICICIBANK @ 1223.5
Exiting20130517 Time1230Sell 1SBIN@ 2411.1Buy 2ICICIBANK @ 1222.55
Entry Price 1=2412.05Entry Price 2=1223.5
Qty 1=1Qty2=2
Profit is 0.949999999999818

Entry 20130517 Time 1231Sell 1SBIN @ 2406.9Buy 2ICICIBANK @ 1222.05
Exiting  Time@1232Buy 1SBIN @ 2406.15Sell 2ICICIBANK @ 1222.4
Entry Price 1=2406.9Entry Price 2=1222.05
Qty 1=1Qty2=2
Profit is 1.45000000000027

Entry 20130517 Time 1233Buy 1SBIN @ 2407.6Sell 2 ICICIBANK @ 1222.45
Exiting20130517 Time1234Sell 1SBIN@ 2408.8Buy 2ICICIBANK @ 1221.8
Entry Price 1=2407.6Entry Price 2=1222.45
Qty 1=1Qty2=2
Profit is 2.50000000000045

Entry 20130517 Time 1235Buy 1SBIN @ 2408Sell 2 ICICIBANK @ 1220
Exiting20130517 Time1236Sell 1SBIN@ 2408Buy 2ICICIBANK @ 1219
Entry Price 1=2408Entry Price 2=1220
Qty 1=1Qty2=2
Profit is 2

Entry 20130517 Time 1237Sell 1SBIN @ 2409.6Buy 2ICICIBANK @ 1219.05
Exiting  Time@1238Buy 1SBIN @ 2408.55Sell 2ICICIBANK @ 1218.55
Entry Price 1=2409.6Entry Price 2=1219.05
Qty 1=1Qty2=2
Profit is 0.0499999999997272

Entry 20130517 Time 1239Sell 1SBIN @ 2407.05Buy 2ICICIBANK @ 1216.7
Exiting  Time@1241Buy 1SBIN @ 2406.5Sell 2ICICIBANK @ 1218
Entry Price 1=2407.05Entry Price 2=1216.7
Qty 1=1Qty2=2
Profit is 3.15000000000009

Entry 20130517 Time 1242Sell 1SBIN @ 2407.05Buy 2ICICIBANK @ 1218.25
Exiting  Time@1243Buy 1SBIN @ 2406Sell 2ICICIBANK @ 1217.85
Entry Price 1=2407.05Entry Price 2=1218.25
Qty 1=1Qty2=2
Profit is 0.25

Entry 20130517 Time 1244Sell 1SBIN @ 2407.15Buy 2ICICIBANK @ 1217.3
Exiting  Time@1245Buy 1SBIN @ 2406.15Sell 2ICICIBANK @ 1217.2
Entry Price 1=2407.15Entry Price 2=1217.3
Qty 1=1Qty2=2
Profit is 0.800000000000182

Entry 20130517 Time 1246Sell 1SBIN @ 2406.05Buy 2ICICIBANK @ 1217
Exiting  Time@1247Buy 1SBIN @ 2405.15Sell 2ICICIBANK @ 1216.65
Entry Price 1=2406.05Entry Price 2=1217
Qty 1=1Qty2=2
Profit is 0.200000000000273

Entry 20130517 Time 1248Sell 1SBIN @ 2406.75Buy 2ICICIBANK @ 1217.2
Exiting  Time@1249Buy 1SBIN @ 2406.4Sell 2ICICIBANK @ 1217.8
Entry Price 1=2406.75Entry Price 2=1217.2
Qty 1=1Qty2=2
Profit is 1.54999999999973

Entry 20130517 Time 1250Sell 1SBIN @ 2406.65Buy 2ICICIBANK @ 1218.5
Exiting  Time@1251Buy 1SBIN @ 2405.5Sell 2ICICIBANK @ 1219.05
Entry Price 1=2406.65Entry Price 2=1218.5
Qty 1=1Qty2=2
Profit is 2.25

Entry 20130517 Time 1252Sell 1SBIN @ 2406.5Buy 2ICICIBANK @ 1218.5
Exiting  Time@1255Buy 1SBIN @ 2406.95Sell 2ICICIBANK @ 1220.7
Entry Price 1=2406.5Entry Price 2=1218.5
Qty 1=1Qty2=2
Profit is 3.95000000000027

Entry 20130517 Time 1256Buy 1SBIN @ 2411.1Sell 2 ICICIBANK @ 1221
Exiting20130517 Time1257Sell 1SBIN@ 2411Buy 2ICICIBANK @ 1220.2
Entry Price 1=2411.1Entry Price 2=1221
Qty 1=1Qty2=2
Profit is 1.5

Entry 20130517 Time 1258Buy 1SBIN @ 2410Sell 2 ICICIBANK @ 1220.3
Exiting20130517 Time1259Sell 1SBIN@ 2411.25Buy 2ICICIBANK @ 1220.15
Entry Price 1=2410Entry Price 2=1220.3
Qty 1=1Qty2=2
Profit is 1.54999999999973

Entry 20130517 Time 1300Buy 1SBIN @ 2411.45Sell 2 ICICIBANK @ 1220.65
Exiting20130517 Time1301Sell 1SBIN@ 2413Buy 2ICICIBANK @ 1220.5
Entry Price 1=2411.45Entry Price 2=1220.65
Qty 1=1Qty2=2
Profit is 1.85000000000036

Entry 20130517 Time 1302Buy 1SBIN @ 2412.25Sell 2 ICICIBANK @ 1219.45
Exiting20130517 Time1303Sell 1SBIN@ 2413.3Buy 2ICICIBANK @ 1218.5
Entry Price 1=2412.25Entry Price 2=1219.45
Qty 1=1Qty2=2
Profit is 2.95000000000027

Entry 20130517 Time 1304Buy 1SBIN @ 2413.25Sell 2 ICICIBANK @ 1218.95
Exiting20130517 Time1305Sell 1SBIN@ 2416.15Buy 2ICICIBANK @ 1220.3
Entry Price 1=2413.25Entry Price 2=1218.95
Qty 1=1Qty2=2
Profit is 0.200000000000273

Entry 20130517 Time 1306Buy 1SBIN @ 2417Sell 2 ICICIBANK @ 1221.75
Exiting20130517 Time1307Sell 1SBIN@ 2415.5Buy 2ICICIBANK @ 1220.3
Entry Price 1=2417Entry Price 2=1221.75
Qty 1=1Qty2=2
Profit is 1.40000000000009

Entry 20130517 Time 1308Sell 1SBIN @ 2414.2Buy 2ICICIBANK @ 1220.15
Exiting  Time@1310Buy 1SBIN @ 2411.7Sell 2ICICIBANK @ 1219.55
Entry Price 1=2414.2Entry Price 2=1220.15
Qty 1=1Qty2=2
Profit is 1.29999999999973

Entry 20130517 Time 1311Buy 1SBIN @ 2413Sell 2 ICICIBANK @ 1219.9
Exiting20130517 Time1312Sell 1SBIN@ 2413.05Buy 2ICICIBANK @ 1219.65
Entry Price 1=2413Entry Price 2=1219.9
Qty 1=1Qty2=2
Profit is 0.550000000000182

Entry 20130517 Time 1313Sell 1SBIN @ 2412.5Buy 2ICICIBANK @ 1220.75
Exiting  Time@1314Buy 1SBIN @ 2413.5Sell 2ICICIBANK @ 1221.95
Entry Price 1=2412.5Entry Price 2=1220.75
Qty 1=1Qty2=2
Profit is 1.40000000000009

Entry 20130517 Time 1315Buy 1SBIN @ 2414.15Sell 2 ICICIBANK @ 1222.4
Exiting20130517 Time1316Sell 1SBIN@ 2415.4Buy 2ICICIBANK @ 1222
Entry Price 1=2414.15Entry Price 2=1222.4
Qty 1=1Qty2=2
Profit is 2.05000000000018

Entry 20130517 Time 1317Sell 1SBIN @ 2413.9Buy 2ICICIBANK @ 1221.3
Exiting  Time@1318Buy 1SBIN @ 2413.1Sell 2ICICIBANK @ 1221.5
Entry Price 1=2413.9Entry Price 2=1221.3
Qty 1=1Qty2=2
Profit is 1.20000000000027

Entry 20130517 Time 1319Buy 1SBIN @ 2413Sell 2 ICICIBANK @ 1221.2
Exiting20130517 Time1322Sell 1SBIN@ 2410.7Buy 2ICICIBANK @ 1219.5
Entry Price 1=2413Entry Price 2=1221.2
Qty 1=1Qty2=2
Profit is 1.09999999999991

Entry 20130517 Time 1323Sell 1SBIN @ 2410.45Buy 2ICICIBANK @ 1219.55
Exiting  Time@1324Buy 1SBIN @ 2410Sell 2ICICIBANK @ 1220.4
Entry Price 1=2410.45Entry Price 2=1219.55
Qty 1=1Qty2=2
Profit is 2.15000000000009

Entry 20130517 Time 1325Sell 1SBIN @ 2410.65Buy 2ICICIBANK @ 1220.8
Exiting  Time@1326Buy 1SBIN @ 2410.1Sell 2ICICIBANK @ 1221.1
Entry Price 1=2410.65Entry Price 2=1220.8
Qty 1=1Qty2=2
Profit is 1.15000000000009

Entry 20130517 Time 1327Sell 1SBIN @ 2412.35Buy 2ICICIBANK @ 1221.4
Exiting  Time@1328Buy 1SBIN @ 2413.05Sell 2ICICIBANK @ 1222.45
Entry Price 1=2412.35Entry Price 2=1221.4
Qty 1=1Qty2=2
Profit is 1.39999999999964

Entry 20130517 Time 1329Buy 1SBIN @ 2416Sell 2 ICICIBANK @ 1222.7
Exiting20130517 Time1330Sell 1SBIN@ 2417Buy 2ICICIBANK @ 1222.9
Entry Price 1=2416Entry Price 2=1222.7
Qty 1=1Qty2=2
Profit is 0.599999999999909

Entry 20130517 Time 1331Sell 1SBIN @ 2417.15Buy 2ICICIBANK @ 1221.8
Exiting  Time@1332Buy 1SBIN @ 2417Sell 2ICICIBANK @ 1223.3
Entry Price 1=2417.15Entry Price 2=1221.8
Qty 1=1Qty2=2
Profit is 3.15000000000009

Entry 20130517 Time 1333Sell 1SBIN @ 2421.85Buy 2ICICIBANK @ 1224.85
Exiting  Time@1334Buy 1SBIN @ 2416Sell 2ICICIBANK @ 1224.95
Entry Price 1=2421.85Entry Price 2=1224.85
Qty 1=1Qty2=2
Profit is 6.05000000000018

Entry 20130517 Time 1335Buy 1SBIN @ 2415.8Sell 2 ICICIBANK @ 1224.4
Exiting20130517 Time1337Sell 1SBIN@ 2413.5Buy 2ICICIBANK @ 1223.1
Entry Price 1=2415.8Entry Price 2=1224.4
Qty 1=1Qty2=2
Profit is 0.300000000000182

Entry 20130517 Time 1338Buy 1SBIN @ 2409.15Sell 2 ICICIBANK @ 1223.05
Exiting20130517 Time1340Sell 1SBIN@ 2414.6Buy 2ICICIBANK @ 1223.7
Entry Price 1=2409.15Entry Price 2=1223.05
Qty 1=1Qty2=2
Profit is 4.14999999999964

Entry 20130517 Time 1341Sell 1SBIN @ 2414.8Buy 2ICICIBANK @ 1222.7
Exiting  Time@1342Buy 1SBIN @ 2413.7Sell 2ICICIBANK @ 1223.1
Entry Price 1=2414.8Entry Price 2=1222.7
Qty 1=1Qty2=2
Profit is 1.90000000000009

Entry 20130517 Time 1343Sell 1SBIN @ 2413Buy 2ICICIBANK @ 1222.85
Exiting  Time@1344Buy 1SBIN @ 2412.55Sell 2ICICIBANK @ 1223.5
Entry Price 1=2413Entry Price 2=1222.85
Qty 1=1Qty2=2
Profit is 1.75

Entry 20130517 Time 1345Buy 1SBIN @ 2415Sell 2 ICICIBANK @ 1224.95
Exiting20130517 Time1346Sell 1SBIN@ 2413.3Buy 2ICICIBANK @ 1224
Entry Price 1=2415Entry Price 2=1224.95
Qty 1=1Qty2=2
Profit is 0.200000000000273

Entry 20130517 Time 1347Sell 1SBIN @ 2416.15Buy 2ICICIBANK @ 1224.65
Exiting  Time@1350Buy 1SBIN @ 2418Sell 2ICICIBANK @ 1225.95
Entry Price 1=2416.15Entry Price 2=1224.65
Qty 1=1Qty2=2
Profit is 0.75

Entry 20130517 Time 1351Sell 1SBIN @ 2415.4Buy 2ICICIBANK @ 1224
Exiting  Time@1352Buy 1SBIN @ 2413.55Sell 2ICICIBANK @ 1224.9
Entry Price 1=2415.4Entry Price 2=1224
Qty 1=1Qty2=2
Profit is 3.65000000000009

Entry 20130517 Time 1353Buy 1SBIN @ 2413Sell 2 ICICIBANK @ 1225.05
Exiting20130517 Time1355Sell 1SBIN@ 2409.9Buy 2ICICIBANK @ 1223.15
Entry Price 1=2413Entry Price 2=1225.05
Qty 1=1Qty2=2
Profit is 0.699999999999818

Entry 20130517 Time 1356Buy 1SBIN @ 2410.55Sell 2 ICICIBANK @ 1223.45
Exiting20130517 Time1358Sell 1SBIN@ 2409.3Buy 2ICICIBANK @ 1221
Entry Price 1=2410.55Entry Price 2=1223.45
Qty 1=1Qty2=2
Profit is 3.65000000000009

Entry 20130517 Time 1359Buy 1SBIN @ 2406.5Sell 2 ICICIBANK @ 1219.95
Exiting20130517 Time1401Sell 1SBIN@ 2410.45Buy 2ICICIBANK @ 1219.65
Entry Price 1=2406.5Entry Price 2=1219.95
Qty 1=1Qty2=2
Profit is 4.54999999999973

Entry 20130517 Time 1402Sell 1SBIN @ 2410.05Buy 2ICICIBANK @ 1220.1
Exiting  Time@1406Buy 1SBIN @ 2409Sell 2ICICIBANK @ 1220.4
Entry Price 1=2410.05Entry Price 2=1220.1
Qty 1=1Qty2=2
Profit is 1.65000000000055

Entry 20130517 Time 1407Buy 1SBIN @ 2409.2Sell 2 ICICIBANK @ 1219.55
Exiting20130517 Time1408Sell 1SBIN@ 2409.5Buy 2ICICIBANK @ 1219.5
Entry Price 1=2409.2Entry Price 2=1219.55
Qty 1=1Qty2=2
Profit is 0.400000000000091

Entry 20130517 Time 1409Sell 1SBIN @ 2410.45Buy 2ICICIBANK @ 1220.35
Exiting  Time@1410Buy 1SBIN @ 2409.05Sell 2ICICIBANK @ 1220.65
Entry Price 1=2410.45Entry Price 2=1220.35
Qty 1=1Qty2=2
Profit is 2

Entry 20130517 Time 1411Buy 1SBIN @ 2408.7Sell 2 ICICIBANK @ 1220.7
Exiting20130517 Time1412Sell 1SBIN@ 2407.25Buy 2ICICIBANK @ 1219.6
Entry Price 1=2408.7Entry Price 2=1220.7
Qty 1=1Qty2=2
Profit is 0.750000000000455

Entry 20130517 Time 1413Buy 1SBIN @ 2405Sell 2 ICICIBANK @ 1219
Exiting20130517 Time1415Sell 1SBIN@ 2405.9Buy 2ICICIBANK @ 1219
Entry Price 1=2405Entry Price 2=1219
Qty 1=1Qty2=2
Profit is 0.900000000000091

Entry 20130517 Time 1416Buy 1SBIN @ 2403.05Sell 2 ICICIBANK @ 1217.95
Exiting20130517 Time1417Sell 1SBIN@ 2404Buy 2ICICIBANK @ 1218
Entry Price 1=2403.05Entry Price 2=1217.95
Qty 1=1Qty2=2
Profit is 0.849999999999909

Entry 20130517 Time 1418Buy 1SBIN @ 2403.6Sell 2 ICICIBANK @ 1217.9
Exiting20130517 Time1419Sell 1SBIN@ 2404Buy 2ICICIBANK @ 1217.55
Entry Price 1=2403.6Entry Price 2=1217.9
Qty 1=1Qty2=2
Profit is 1.10000000000036

Entry 20130517 Time 1420Buy 1SBIN @ 2405.8Sell 2 ICICIBANK @ 1218
Exiting20130517 Time1421Sell 1SBIN@ 2406.15Buy 2ICICIBANK @ 1217.5
Entry Price 1=2405.8Entry Price 2=1218
Qty 1=1Qty2=2
Profit is 1.34999999999991

Entry 20130517 Time 1422Buy 1SBIN @ 2405.9Sell 2 ICICIBANK @ 1217.8
Exiting20130517 Time1423Sell 1SBIN@ 2406.55Buy 2ICICIBANK @ 1217.7
Entry Price 1=2405.9Entry Price 2=1217.8
Qty 1=1Qty2=2
Profit is 0.849999999999909

Entry 20130517 Time 1424Buy 1SBIN @ 2406.5Sell 2 ICICIBANK @ 1217.95
Exiting20130517 Time1426Sell 1SBIN@ 2407.15Buy 2ICICIBANK @ 1217.8
Entry Price 1=2406.5Entry Price 2=1217.95
Qty 1=1Qty2=2
Profit is 0.950000000000273

Entry 20130517 Time 1427Buy 1SBIN @ 2407.9Sell 2 ICICIBANK @ 1218.8
Exiting20130517 Time1428Sell 1SBIN@ 2407.95Buy 2ICICIBANK @ 1218.5
Entry Price 1=2407.9Entry Price 2=1218.8
Qty 1=1Qty2=2
Profit is 0.649999999999636

Entry 20130517 Time 1429Sell 1SBIN @ 2407.05Buy 2ICICIBANK @ 1219.15
Exiting  Time@1430Buy 1SBIN @ 2405Sell 2ICICIBANK @ 1220.7
Entry Price 1=2407.05Entry Price 2=1219.15
Qty 1=1Qty2=2
Profit is 5.15000000000009

Entry 20130517 Time 1431Buy 1SBIN @ 2403Sell 2 ICICIBANK @ 1220.05
Exiting20130517 Time1432Sell 1SBIN@ 2404.7Buy 2ICICIBANK @ 1220
Entry Price 1=2403Entry Price 2=1220.05
Qty 1=1Qty2=2
Profit is 1.79999999999973

Entry 20130517 Time 1433Sell 1SBIN @ 2406Buy 2ICICIBANK @ 1220.8
Exiting  Time@1434Buy 1SBIN @ 2406.35Sell 2ICICIBANK @ 1221.4
Entry Price 1=2406Entry Price 2=1220.8
Qty 1=1Qty2=2
Profit is 0.850000000000364

Entry 20130517 Time 1435Buy 1SBIN @ 2408.5Sell 2 ICICIBANK @ 1223
Exiting20130517 Time1436Sell 1SBIN@ 2408.5Buy 2ICICIBANK @ 1223.05
Entry Price 1=2408.5Entry Price 2=1223
Qty 1=1Qty2=2
Profit is -0.0999999999999091

Entry 20130517 Time 1437Sell 1SBIN @ 2407.3Buy 2ICICIBANK @ 1222.8
Exiting  Time@1438Buy 1SBIN @ 2408Sell 2ICICIBANK @ 1223.6
Entry Price 1=2407.3Entry Price 2=1222.8
Qty 1=1Qty2=2
Profit is 0.900000000000091

Entry 20130517 Time 1439Buy 1SBIN @ 2408.5Sell 2 ICICIBANK @ 1223.35
Exiting20130517 Time1440Sell 1SBIN@ 2411.75Buy 2ICICIBANK @ 1224.8
Entry Price 1=2408.5Entry Price 2=1223.35
Qty 1=1Qty2=2
Profit is 0.349999999999909

Entry 20130517 Time 1441Buy 1SBIN @ 2410.8Sell 2 ICICIBANK @ 1225.2
Exiting20130517 Time1443Sell 1SBIN@ 2411Buy 2ICICIBANK @ 1224.25
Entry Price 1=2410.8Entry Price 2=1225.2
Qty 1=1Qty2=2
Profit is 2.09999999999991

Entry 20130517 Time 1444Sell 1SBIN @ 2409.35Buy 2ICICIBANK @ 1223.8
Exiting  Time@1445Buy 1SBIN @ 2409Sell 2ICICIBANK @ 1224.7
Entry Price 1=2409.35Entry Price 2=1223.8
Qty 1=1Qty2=2
Profit is 2.15000000000009

Entry 20130517 Time 1446Sell 1SBIN @ 2409Buy 2ICICIBANK @ 1224.5
Exiting  Time@1447Buy 1SBIN @ 2410Sell 2ICICIBANK @ 1225.35
Entry Price 1=2409Entry Price 2=1224.5
Qty 1=1Qty2=2
Profit is 0.699999999999818

Entry 20130517 Time 1448Sell 1SBIN @ 2410.8Buy 2ICICIBANK @ 1224.85
Exiting  Time@1449Buy 1SBIN @ 2410.2Sell 2ICICIBANK @ 1225
Entry Price 1=2410.8Entry Price 2=1224.85
Qty 1=1Qty2=2
Profit is 0.900000000000546

Entry 20130517 Time 1450Sell 1SBIN @ 2410.25Buy 2ICICIBANK @ 1223.5
Exiting  Time@1451Buy 1SBIN @ 2408.6Sell 2ICICIBANK @ 1223.75
Entry Price 1=2410.25Entry Price 2=1223.5
Qty 1=1Qty2=2
Profit is 2.15000000000009

Entry 20130517 Time 1452Buy 1SBIN @ 2409.8Sell 2 ICICIBANK @ 1224.25
Exiting20130517 Time1453Sell 1SBIN@ 2410Buy 2ICICIBANK @ 1223.75
Entry Price 1=2409.8Entry Price 2=1224.25
Qty 1=1Qty2=2
Profit is 1.19999999999982

Entry 20130517 Time 1454Buy 1SBIN @ 2411.5Sell 2 ICICIBANK @ 1224.75
Exiting20130517 Time1457Sell 1SBIN@ 2416Buy 2ICICIBANK @ 1225
Entry Price 1=2411.5Entry Price 2=1224.75
Qty 1=1Qty2=2
Profit is 4

Entry 20130517 Time 1458Buy 1SBIN @ 2414Sell 2 ICICIBANK @ 1223.95
Exiting20130517 Time1459Sell 1SBIN@ 2414.5Buy 2ICICIBANK @ 1223.8
Entry Price 1=2414Entry Price 2=1223.95
Qty 1=1Qty2=2
Profit is 0.800000000000182

Entry 20130517 Time 1500Sell 1SBIN @ 2413.55Buy 2ICICIBANK @ 1223.85
Exiting  Time@1501Buy 1SBIN @ 2414Sell 2ICICIBANK @ 1224.8
Entry Price 1=2413.55Entry Price 2=1223.85
Qty 1=1Qty2=2
Profit is 1.45000000000027

Entry 20130517 Time 1502Sell 1SBIN @ 2416Buy 2ICICIBANK @ 1224.8
Exiting  Time@1503Buy 1SBIN @ 2416.7Sell 2ICICIBANK @ 1225.65
Entry Price 1=2416Entry Price 2=1224.8
Qty 1=1Qty2=2
Profit is 1.00000000000045

Entry 20130517 Time 1504Buy 1SBIN @ 2416Sell 2 ICICIBANK @ 1226.7
Exiting20130517 Time1507Sell 1SBIN@ 2422Buy 2ICICIBANK @ 1228.8
Entry Price 1=2416Entry Price 2=1226.7
Qty 1=1Qty2=2
Profit is 1.80000000000018

Entry 20130517 Time 1508Sell 1SBIN @ 2422.5Buy 2ICICIBANK @ 1230.7
Exiting  Time@1511Buy 1SBIN @ 2430.15Sell 2ICICIBANK @ 1234.8
Entry Price 1=2422.5Entry Price 2=1230.7
Qty 1=1Qty2=2
Profit is 0.549999999999727

Entry 20130517 Time 1512Sell 1SBIN @ 2429.2Buy 2ICICIBANK @ 1233.85
Exiting  Time@1513Buy 1SBIN @ 2423.55Sell 2ICICIBANK @ 1232.95
Entry Price 1=2429.2Entry Price 2=1233.85
Qty 1=1Qty2=2
Profit is 3.84999999999991

Entry 20130517 Time 1514Buy 1SBIN @ 2424.05Sell 2 ICICIBANK @ 1232.3
Exiting20130517 Time1515Sell 1SBIN@ 2425.8Buy 2ICICIBANK @ 1232.7
Entry Price 1=2424.05Entry Price 2=1232.3
Qty 1=1Qty2=2
Profit is 0.949999999999818

Entry 20130517 Time 1516Sell 1SBIN @ 2428.65Buy 2ICICIBANK @ 1233.95
Exiting  Time@1518Buy 1SBIN @ 2425.65Sell 2ICICIBANK @ 1233.75
Entry Price 1=2428.65Entry Price 2=1233.95
Qty 1=1Qty2=2
Profit is 2.59999999999991

Entry 20130517 Time 1519Buy 1SBIN @ 2427.7Sell 2 ICICIBANK @ 1233.7
Exiting20130517 Time1521Sell 1SBIN@ 2426.5Buy 2ICICIBANK @ 1230.25
Entry Price 1=2427.7Entry Price 2=1233.7
Qty 1=1Qty2=2
Profit is 5.70000000000027

Entry 20130517 Time 1522Sell 1SBIN @ 2426.75Buy 2ICICIBANK @ 1229.95
Exiting  Time@1523Buy 1SBIN @ 2425.1Sell 2ICICIBANK @ 1229.8
Entry Price 1=2426.75Entry Price 2=1229.95
Qty 1=1Qty2=2
Profit is 1.34999999999991

Entry 20130517 Time 1524Sell 1SBIN @ 2426.65Buy 2ICICIBANK @ 1228.85
Exiting  Time@1526Buy 1SBIN @ 2425.6Sell 2ICICIBANK @ 1229.8
Entry Price 1=2426.65Entry Price 2=1228.85
Qty 1=1Qty2=2
Profit is 2.95000000000027

Entry 20130517 Time 1527Buy 1SBIN @ 2427Sell 2 ICICIBANK @ 1229.95

Monday 31 December 2012

Extracting 1 minutes /5 minutes Bar from Google Finance

Many retail traders or wanna be traders hit the road block on how to get the intraday data for NSE stocks. There are many paid services/databases available which can be subscribed to get the data. However if you are just starting to test your strategy and do not want to spend on getting the historical data, then here's the alternative. This post will explain you the R code using which you shall be able to download intraday 1 min, 5 min ... data from google finance for free. You need not to be a technical person to use this.


First of all you will need to download R software which is free. Here's the link to download R for windows OS.
Once downloaded and installed R, you shall see a R icon on your desktop like below. Double click to open 

 

It will open RGui. Go to File --> New Script.

 

Copy paste the R code below in the new script window.

symbol = "CIPLA"  
 noDays = 1  
 interval = 60 #Seconds  
 dirPath = "C:/Umesh/Data/"  
 fileName = paste(dirPath,symbol,".csv",sep="")  
   
 download.file(paste("http://www.google.com/finance/getprices?q=",symbol,"&x=NSE&i=",interval,"&p=",noDays,"d&f=d,o,h,l,c,v,t",sep=""), fileName)  
   
 unix2POSIXct <- function (time)  structure(time, class = c("POSIXt", "POSIXct"))  
 data = read.table(fileName,sep=",",col.names=c("DATE1","CLOSE","HIGH","LOW","OPEN","VOLUME"),fill=TRUE)  
 data$DATE = 0  
 data$TIME = 0  
   
 for (i in 8:nrow(data))  
 {  
  if(i==8 || substr(as.vector((data$DATE1[i])),1,1) == "a")  
  {  
   tempDate = unix2POSIXct(as.numeric(substr(as.vector((data$DATE1[i])),2,nchar(as.vector((data$DATE1[i]))))))    
   data$DATE[i] = as.numeric(format(tempDate,format="%Y%m%d"))  
   data$TIME[i] = as.numeric(format(tempDate,format="%H%M"))  
  } else {  
   tempDate1 = tempDate + as.numeric(as.vector(data$DATE1[i]))*interval   
   data$DATE[i] = as.numeric(format(tempDate1,format="%Y%m%d"))  
   data$TIME[i] = as.numeric(format(tempDate1,format="%H%M"))  
  }   
 }  
 data1=as.data.frame(data)  
 data1=(data1[data1$TIME>915 & data1$TIME<=1530,])  
   
 finalData = data.frame(DATE=as.vector(data1$DATE),TIME=as.vector(data1$TIME),CLOSE=as.vector(data1$CLOSE),HIGH=as.vector(data1$HIGH),LOW=as.vector(data1$LOW),OPEN=as.vector(data1$OPEN),VOLUME=as.vector(data1$VOLUME))  
 finalData = data.frame(DATE=data1$DATE,TIME=data1$TIME,CLOSE=data1$CLOSE,HIGH=data1$HIGH,LOW=data1$LOW,OPEN=data1$OPEN,VOLUME=data1$VOLUME)  
 write.csv(finalData,file=fileName,row.names=FALSE) 
 
  

In the above code, change the first four lines shown below.

symbol = "CIPLA"  
 noDays = 1  
 interval = 60 #Seconds  
 dirPath = "C:/Umesh/Data/"  
  

1. The first line is the symbol name.

2. Second line sets the number of days for which data is to be downloaded. Note that, longer history data is not available. 

3. Third line sets the time interval/frequency of data. It's in seconds.

4. Fourth line sets the folder where data is to be stored.

Once done, select all lines and press F5 to run the code. And data will be stored in the specified directory with symbol name.

Now, enjoy downloading data. Later on I will explain how to create an automated job in windows to download daily data automatically. 



Friday 16 November 2012

Applying PCA: Swap Spread Price Discovery in an Illiquid Market



During the global financial crisis there was an absence of liquidity in the USD swap market. This absence of liquidity was most pronounced during the thinner Asian trading hours. This presented challenges for market users who rely on accurate market information to construct yield curves to price a whole slew of products ranging from interest rate swaps and options to FX forwards and FX options. Trading desks use cash treasury prices and broker screens for IRS spreads to build a blended yield curve. A typical Reuters screen is presented below.
These swap spreads are quoted in basis points over on-the-run treasury yields1.Many brokers, including Totan-Icap have a policy of adjusting their screens only when there is a bid or offer of a minimum amount shown in the market. This is to ensure the integrity of the market and transparency of the screens. In a normal functioning market an interbank market maker will "adjust" the screens by quoting an outright bid/offer spread or a spread against a more liquid tenor to adjust stale tenors.

This process broke down during the financial crisis and broker screens were not reliable especially for the less liquid tenors. The only alternative market users had was to speak to their broker and ask where he/she thought the levels are. The broker would do his/her best to provide colour on where the interests are in the market and where he/she thinks it may trade.
In 2008 an interesting paper surfaced by Leonardo M. Nogueira that offered an alternative2.In that paper, the author presented a principal component based method of inferring a yield curve given an analysts' forecast of selected tenors. This method offered a solution to the problem of inferring swap spreads in an illiquid market. Below is a specific example of the adaptation of the results of that paper for our purposes.
An input into our model is a time series of daily historical swap spreads. It is important for the data to be sampled at the most liquid times in a day. In our example we use a historical database extracted from ICAP NY sampled at 4:45 PM NY time. The close is an important time with chances of a stale print for any given tenor minimized. Below is a screenshot of the data.
We calculated a time series of daily changes and it can be seen that the individual series are highly correlated. Also worth noting is the spike in volatility seen in 2008.

For our purposes we used a rolling window of 40 observations to construct a covariance matrix.
We then carried out principal component analysis and extract the eigenvalues and eigenvectors as presented below.
We can see that the first principal component explains 77% of the variation in the data. The second principal component explains an additional 11% of the variation of the data. The largest three principal components cumulatively explain 92% of the variation in the data series. Below we present a plot of the eigenvectors of the first two principal components. We can see that the first component represents a parallel move in all swap spreads while the second represents a flattening of the swap spread curve.
For our example we assume that on 25th of August 2008 NY closing levels were:
A few hours later when Asia's markets open assume that there is an active market for 5 year and 10 year swaps spreads with 41.00 and 24.75 mid. With slight variation of Nogueira's 1st Theorem we can infer the entire swap spread curve.
With
where is our implied swap spread curve, is the latest swap spread curve observed at NY close, D is a diagonal matrix of standard deviations, W is sub-matrix of the eigenvectors, V is a matrix that takes on 1 for each observed swaps spread tenor and 0 otherwise, and finally is the change in swap spread that we observe in the market from its NY close. In the spreadsheet that accompanies this paper we have:
is repeated here again
is simply observed change in the 5 year swap spread +.25 and the change in 10 year swap spread -.50.
D is below
We only use the first two eigenvectors since we only have two observations in the market.
Applying Nogueira's 1st Theorem to our data we get the following results:
The bottom row is the implied swap spread curve based on only two observed swap spreads that are assumed to be in the market. Graphically the change looks reasonable.
We presented here a viable solution to building a USD Libor yield curve in an illiquid market. This approach was used in Asia to infer a full USD swap spread curve during the financial crisis3 . The implied swap spread curve was then combined with on-the-run treasury curve to build a full USD Libor yield curve. This method also allowed for informed placement of bids and/or offers in the market despite poor liquidity.

1For a good explanation of swap spreads and market conventions see Amir Sadr, Interest Rate Swaps and Their Derivatives, A Practitioner's Guide, Wiley Finance series, John Wiley and Sons, 2009
2Nogueira, Leonardo M., Updating the Yield Curve to Analyst's Views (March 18, 2008). Available at SSRN: http://ssrn.com/abstract=1107653 or http://dx.doi.org/10.2139/ssrn.1107653
3 This example is a simplification of the approach used. Most important difference is the adjustment required to historical swap spreads due to new treasury issues. As a new on-the-run bond is auctioned the swap spread is adjusted for the roll.

Thursday 8 November 2012

Hedge Fund dead: Long live the king !!!!

The number of hedge fund closures reached 232 in the first three months of this year. Let's rewind and look back a bit comparing this figure with the first three months of 2010, the rate of liquidations were 192 in the second quarter, according to data from Hedge Fund Research.

A very fruitful research paper was borne in 2004 in the Fall edition of the Journal of Portfolio Management by Alex Grecu, Burton Malkiel and Atanu Saha. They found an inverse relationship between death of hedge fund and its age. In case, the hedge fund survived first few years it would live its life. The chart below shows the lifespan of hedge funds in the widely quoted TASS hedge fund database. (Note: funds that were still alive by April 2004, the date of the study, were treated as having a “duration” equal to their age by that date).


The data was transformed into maximum likelihood of failure and found the rate to start decreasing from Year 5 which is about 12% chance of failure on an annual basis. The same story goes with what has happened in the mutual fund industry where failure rate decreases from year 10 onwards.


“Investors are concerned about small and medium-sized firms that have small operations, and are not willing to invest,” said Kenneth Heinz, president of HFR. “Larger ones are more capable of handling regulatory requirements. They have an established department for compliance [and although] it is an increased cost they can handle it.”

The industry is seeing some of the big hedge funds growing much bigger. They are replicating the true story of too big too fail. Is this industry becoming oligopoly where its too hard to enter and exit is smoother?

In the coming post I would be discussing about the strategies that hedge fund followed and how the industry is going to be in emerging markets like India where it has just started.