/securitiesdb

Securities master database for algorithmic trading, backtesting, and data mining.

Primary LanguageRubyMIT LicenseMIT

securitiesdb

This project populates a local Postgres database with security symbols, un-adjusted EOD data, splits, dividends, company fundamentals, and options data. Economic indicators - employment and labor statistics, inflation rates, interest rates, exchange rates, imports/exports, domestic production stats, treasury rates, debt, tax revenues, etc. - are also available.

Michael Halls-Moore, the guy behind quantstart.com, described and popularized the idea of a securities master database in his two excellent articles - (1) Securities Master Databases for Algorithmic Trading and (2) Securities Master Database with MySQL and Python. This project is an implementation of his idea of a securities master database.

Getting Started

  1. git clone this project

    git clone https://github.com/davidkellis/securitiesdb.git
    
  2. [Optional] If you want any data from Quandl.com, create an account at Quandl.com and configure project with your Quandl API key and version information:

    1. Register for an account at Quandl.com
    2. Look up your API key:
      1. Go to Account Settings at https://www.quandl.com/account
      2. Click the API Key link in the navigation bar on the left-hand side of the Account Settings page
      3. Note the API Key and version information
    3. Create a config/application.yml file by copying the config/application.sample.yml file into config/application.yml
    4. Open config/application.yml and change the lines that read:
      quandl:
         api_key: abc123
         api_version: "2015-04-09"
      
      so that they api_key and api_version match the values you noted from Quandl.com
    5. Save your changes to config/application.yml
  3. [Optional] If you want any historical options data from OptionData.net:

    1. Place an order for data
    2. Download the zipped data sets from the link they send you by e-mail
    3. Copy the downloaded zip files into the data/ directory within the securitiesdb project directory
  4. Install Postgres libraries so that step 7 can install the pg gem (this is only applicable if using MRI, as JRuby doesn't need the pg gem).

  5. Install Ruby or JRuby

    rbenv install 2.2.3
    

    OR

    rbenv install jruby-9.0.4.0
    

    Set the JRUBY_OPTS environment variable in your ~/.bash_profile to a few GB of memory:

    export JRUBY_OPTS=-J-Xmx8g
    
  6. Install bundler (if not already installed)

    gem install bundler
    
  7. bundle install

    bundle install
    
  8. Change database connection string in application.yml

  9. Setup Database

    script/setup_db
    
  10. Import data

Import all data

script/import --all

Import all stock symbols, EOD prices, fundamentals

script/import --csi --quandl-eod --quandl-fundamentals

Import all stock symbols and options

script/import --csi -o data/options2006.zip

Reset Database

script/reset_db