Note that I no longer use github.
A friend of mine uses Gnucash to manage their personal finances. They configured and used Gnucash to retrieve online price quotes from the NSE or the BSE through Yahoo Finance. Unfortunately since the past few months, they could not retrieve these stock quotes to get a correct picture of their Portfolio.
This meant they had to either decide to enter the Quotes manually (very labor intensive), or to migrate away from Gnucash to a different personal finance tool. The constraint being they wanted a tool that worked both on Linux & Windows.
They approached me to see if there was a method to get away from Yahoo Finance and use something else like Google Finance. I know of one product called JStock, that I recommended they use as a stop-gap till a solution is found for Gnucash. JStock is available on many platforms. All they had to do was to enter their list of stocks into it, and track it, away from the core Gnucash they were used to. They could manually enter the closing prices into the PMumbaiStock.pmrice Editor in Gnucash from JStock. Inefficient, but it works.
A drawback is that they could not monitor Mutual Fund NAVs as it did not retrieve those values from the AMFI website, but retrieved what it could from Google Finance. Therefore, to overcome this situation, here is what I did for them.
Looked over the internet to see if there is any other source that can provide the stock quotes. Found that the Bombay Stock Exchange (BSE) website had something called a bhavcopy. Bhavcopy is nothing but stock information at end of a trading day. At end of day, the BSE puts up an updated bhavcopy at this link http://www.bseindia.com/download/BhavCopy/Equity/eq141013_csv.zip. You can download this file to get a comma-delimited record for each BSE stock from EQ141013.CSV as on 14th October, 2013.
On viewing the EQ141013.CSV file, we find that stock quotes are available for all stocks in a comma-delimited format. This now implies that the stock prices are available in a similar style as the AMFI India Mutual Fund NAVs text file. Only, the AMFI NAV text file is delimited by semi-colons. We can use this information to at least get the closing prices for all the stocks in one go and then fill them into the prices for Gnucash.
Technical Solution (The Beauty of Open Source):
Based on above information, and a hunt through the internet, and major thanks to this post http://stephan.paukner.cc/syslog/archives/401-How-to-add-new-quote-sources-to-GnuCash.html by Stephan, we can create our own perl module to use the Bombay Stock Exchange’s bhavcopy through Get Quotes. If you look more closely at the IndiaMutual.pm perl module within the /usr/share/perl5/Finance/IndiaMutual.pm code, you will find that you can easily adapt it, because, IndiaMutual.pm also relies on a text file from the amfiindia.com website published by them at end of day’s trading. With a bit of understanding, here is what was done. Below is the method intended for those who know what they are doing and have the technical knowledge to do so. If you are an end user, please go to this other blog post.
|1||Backup the files Quote.pm and create MumbaiStock.pm from IndiaMutual.pm
|2||Make a copy of MumbaiStock.pm in your local home folder for modification
Open MumbaiStock.pm for editing using mousepad / gedit.
|3||Download the following bhavcopy file from the BSE India website to your home folder
MumbaiStock.pmOpen the file using mousepad / gedit.
|4||Replace AMFI strings in MumbaiStock.pm as follows:
a. Locate AMFI (Capitals) and replace with MSTK.
b. Locate amfi (small) and replace with mstk.
c. Locate IndiaMutual and replace with MumbaiStock.
You can refer to the https://github.com/geetuvaswani/mumbaistock to view the source code of MumbaiStock.pm.
We will copy it over to /usr/share/perl5/Finance/Quote later.
Not much to change here, other than to add MumbaiStock to the list of available modules. Open the file using mousepad or gedit.
Search for @modules.Just before IndiaMutual, add MumbaiStock, save the file and you are done.
|8||Copy MumbaiStock.pm into Finance/Quotes
|9||Test MumbaiStock.pm without starting Gnucash
To test the module without starting Gnucash, open a terminal window and enter following command:$
where 500010 is a stock symbol of HDFC on the Bombay Stock Exchange.If all works, you will see:Finance::Quote fields Gnucash uses:
symbol: 500010 <=== required
date: 10/14/2013 <=== required
currency: INR <=== required
nav: 803.80 <=== one of these
timezone: <=== optional
You can also add printf statements in the file MumbaiStock.pm to debug variable values as you test. Do not forget to remove the printf statements when done.You should also open another terminal window and look for the files coming into the /tmp folder.Remember, we are to look for mumbaistocklist.txt or mumbaistocklist.zip just to make sure we get the right data. Only after you confirm it works fine, should you then modify the Security Codes in Gnucash Security or Price Editor.
|10||Once satisfied, you can start up Gnucash and change the stocks quote source in Security Editor for MumbaiStock and retrieve them using Price Editor. This module does not retrieve real-time quotes. Look elsewhere if you need real-time updates.|