Monthly Archives: July 2013

Downloading Financial Data

QuantLua currently can access historical stock data from Yahoo.com and historical currency data from OandA.com.

Stock Data 

The command to download stock data is getprices. It takes one to three parameters: the stock symbol, an optional start date and an optional end date. If the start date is missing it is assumed to be January 1, 2011. If the end date is missing it is assumed to be today.

The commands

    local sd={2013,1,1}

    local ed={2013,12,31)

    p=getprices(“IBM”, sd, ed)

return the stock prices from January 1, 2013 to December 31 (or the current date if the end date is in the future). The data returned is a table. Let’s continue with the example above. Within this table is the the table values, This is a list of the adjusted stock prices over the time range. Another table is dates. This is the list of dates for the stock prices in the values table. Other components of p are:

  1. name : the name of the company
  2. open : the list of opening prices
  3. close : the list of closing prices
  4. high : the list of high prices
  5. low : the list of low prices
  6. vol : the volume traded that day.

Continuing the example, we can plot this data:

    plot({y=p.values, x=p.dates, dates=1}) 

We can do more with this data since it’s just a list of numbers. For example we can find the maximum and minimum.

print(getmaxmin(p.values))

return the maximum and minimum values.

Currency data

The command to download currency data is getcurrency. It takes 2 to 4 parameters. The first is the base currency, the second is the currency converted to, The third and fourth are optional start date and optional end date. If the start date is missing it is assumed to be January 1, 2011. If the end date is missing it is assumed to be today.

The commands

    local sd={2013,1,1}

    local ed={2013,12,31)

    p=getcurrency(“USD”, “JPY”, sd, ed)

return a table with the following: dates is a table containing dates and values is a table containing the currency values corresponding to the dates.

In both stocks and currency data downloading the date can be entered in three different but compatible ways.

The first way is as above, a table of the form {year, month, day}. The second way is as a ql.Date object. The third way is as a number corresponding to an Excel date.