Motivated by e-mail from L_K
Recently I've received several e-mails asking about downloading stock data from either the Bombay Stock Exchange (BSE) or the Indian National Stock Exchange (NSE) so I ...
>And you had no idea how to do that, right?
Uh ... yes, but I'm learning.
I've been using one of the spreadsheets (noted here) as a test.
I find that sometimes it works ... and sometimes it don't.
Anyway, there are two:
compare-to-historical-Bombay.xls and compare-to-historical-NSE.xls.
The Bombay spreadsheet looks like this (where you need to know the magic symbol, like 500325.BO):
The NSE spreadsheet looks like this (where you need to know the stock symbol):
In the NSE spreadsheet, there's an extra sheet where you enter the appropriate info and click a button and ...
>Just show the sheet!
Okay, here it is:
After downloading, the appropriate info is transferred to the "main" sheet (shown above).
>And they work?
Did I mention that sometimes they work ... and sometimesthey don't.
P.S.
A spreadsheet like the one described here often works with BSE:
Try: Yahoo-BSE.xls
There's also a similar spreadsheet for NSE. It looks like this (click on the picture to download):
In each case, the data is downloaded from Yahoo with appropriate terminations, like .BO or .NS
... and NOT from an Indian exchange.
Because of this, the symbols are truncated to 9 characters ... just in case you type in more.
For example, you type the symbol CENTURYTEX and the spreadsheet macro truncates to CENTURYTE and add the .NS so Yahoo is given CENTURYTE.NS
Thanks to Joydeep M. for helpful hints.
>If you're using Yahoo, why not just add the .NS to the name and use your "ordinary" spreadsheets?
Uh ... yeah, you could do that. For example, there's a Drawdown spreadsheet which would look like this
(with .NS-terminated symbols):
The BSE spreadsheet:
There's a macro that does the downloading ... normally from Yahoo.
It looks like this:
qurl = "http://chart.yahoo.com/table.csv?s=" & Symbol
qurl = qurl & "&a=" & Month(StartDate) - 1 & "&b=" & Day(StartDate) & _
"&c=" & Year(StartDate) & "&d=" & Month(EndDate) - 1 & "&e=" & _
Day(EndDate) & "&f=" & Year(EndDate) & "&g=d" & "&q=q&y=0&z=" & _
Symbol & "&x=.csv"
For the BSE spreadsheet, it's been changed to this:
qurl = "http://in.rd.yahoo.com/finance/quotes/internal/historical/download/*http://ichart.finance.yahoo.com/table.csv?s="
qurl = qurl & Symbol & "&a=" & Month(StartDate) - 1 & "&b=" & Day(StartDate) & _
"&c=" & Year(StartDate) & "&d=" & Month(EndDate) - 1 & "&e=" & _
Day(EndDate) & "&f=" & Year(EndDate) & "&g=d" & "&q=q&y=0&z=" & _
Symbol & "&x=.csv"
Not a big change, but enough to get the data from BSE.
This change should work on may of the spreadsheets decribed here: Spreadsheets
The NSE spreadsheet:
Here the ritual is more complicated.
There's an extra sheet called NSE and a macro that downloads to this extra sheet ... from the NSE site.
Hence, to use this feature:
- Add an extra sheet called NSE.
- The Start and End Dates and Symbol should go in cells P11, P12 and P13 (as shown in the above picture).
- Add a button that calls a macro like so:
Sub GetData()
Dim QuerySheet As Worksheet
Dim DataSheet As Worksheet
Dim EndDate As Date
Dim StartDate As Date
Dim Symbol As String
Dim qurl As String
Dim nQuery As Name
Application.DisplayAlerts = False
Set DataSheet = ActiveSheet
Range("C7").CurrentRegion.ClearContents
' the URL for the query
qurl = Range("O20")
QueryQuote:
With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=DataSheet.Range("A1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
End With
Range("A1").CurrentRegion.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, other:=False
With ThisWorkbook
For Each nQuery In Names
If IsNumeric(Right(nQuery.Name, 1)) Then
nQuery.Delete
End If
Next nQuery
End With
Columns("A:K").Select
Selection.ColumnWidth = 8
Range("N6").Select
' MoveData
Range("C1:C1000").Select
Selection.Copy
Sheets("Download").Select
Range("C7").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("NSE").Select
Range("E1:H1000").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Download").Select
Range("D7").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("NSE").Select
Range("J1:J1000").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Download").Select
Range("H7").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("NSE").Select
Range("I1:I1000").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Download").Select
Range("I7").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("NSE").Select
Range("N1").Select
Sheets("Download").Select
Range("J1").Select
End Sub
- Pray ...
When this macro is run, the data is downloaded (hopefully) and some of it is transferred to a sheet called Download (hopefully).
|