Script provided to import stock history from csv file

Carl's Avatar


03 Sep, 2009 05:02 PM

I am playing with the trial version hoping to replace Quicken. Others have asked about importing stock history from .csv files. I get very clean end-of-day price history from QuotesPlus and don't want to use the error prone data from Yahoo. Being a programmer I was delighted to find MoneyDance had a Python Interface and wrote a script to import historical stock price data from .csv files. I'm not certain where to post the script so I've attached a file to this message.

QuotesPlus exports .CSV data as "symbol,mm/dd/yy,open,high,low,close,volume". Comments in the script should help others modify the code to match their data format. The Script expects a list of symbols (XOM, IBM, MO), one symbol per line, in a file named Symbol.txt. Each symbol should have a corresponding file named .csv, such as XOM.CSV for example. The first line of the script identifies the directory containing the Symbols.txt and .csv files.

Before you can run this script you must install the Python Interface extension. Starting the Python Interface will pop-up the Python Console. Click the "Read from file" button, navigate to the directory containing the loadhistory.mdpy script and open the script to execute it. This isn't a particularly speed process, until you contemplate entering this data by hand, so you might start with one stock to make sure your data is properly formatted and everything is working for you. I couldn't not figure out how to flush the print statements to the Python Console (the standard sys.stdout.flush() didn't work ) so you won't see the list of modified stocks until the process is complete.

If this isn't the correct forum to post scripts, please point me in the right direction or feel free to move the message and file.



  1. 1 Posted by randyfinger on 09 Sep, 2009 11:24 AM

    randyfinger's Avatar

    Carl -

    Thanks for the script. I got it to work after realizing my .csv files did not need column headers. However, I did find one thing that seemed to be a little off. Regardless of how many stocks were listed in my symbols.txt file, the last stock would never import. The last letter of the symbol was never read in and got the "not a valid security error". I worked around this by just placing a dummy stock at the end of the list with no corresponding .csv file.

    I do have one question about handling stocks that have had split transactions. The prices I imported adjusted all the historical prices according to the split ratio. Thus, upon import the I had do delete out any splits and adjust the original purchase transaction to reflect the split to keep the account in balance. Is this the best way to handle this or is there a better way you know of?

    Thanks again! This was a HUGE help!


  2. 2 Posted by Ben Spencer on 11 Sep, 2009 03:22 PM

    Ben Spencer's Avatar

    Hi Carl

    Thank you so much for the contribution.

    I have copied your commentary and the script into a knowledge base article and linked back to this discussion. Here is a link to the article:


    Ben Spencer

  3. Ben Spencer closed this discussion on 14 Jun, 2010 06:17 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac