

As the map step, for any given ticker symbol we download the data, extract the adjusted closing prices and rename the column to its ticker symbol. Under the hood, readYahooAdjClose uses a map-reduce structure. Hence, we strive for a much faster result using julia’s parallel computing capabilities, and this is already implemented as function readYahooAdjClose. However, as we have 500 stocks, this procedure would already take approximately 15 minutes if each individual stock took only 2 seconds.

Now that we already have a list of all ticker symbols, in principle we could apply the same procedure as before: download each stock, extract the adjusted closing prices, and join all individual price series. Missing values will be replaced by NA, so that we now get an object of type Timenum, as Timematr objects are not allowed to contain NAs. We do not want to lose any data at this step, so that we will use an outer join in order to get a row for each date that occurs for at least one of the individual stocks. Therefore, we join individual stocks at the their idx entries. When we focus on one variable for each stock only, we can store the data more concisely in a single TimeData object.

The output will be an Array of type Any, with individual entries being of type Timematr. Using comprehension, the function readYahooFinance can be applied to all ticker symbols in an Array. As a format for storing time series data I always rely on the TimeData package from the official package repository:

We also will make use of julia’s parallel computing capabilities, in order to tremendously speed up the downloading and processing steps compared to my original code in R.īefore we start, we first need to make sure that we have all relevant packages installed. Hence, in this post I will describe how one could use julia to download stock price data from Yahoo!Finance in general, and – as an advanced use case – how to download adjusted closing prices for all SP500 constituents. I obviously wanted to also enjoy the convenience of downloading stock price data directly in julia. Meanwhile, however, I shifted all of my coding to the new and very promising technical computing language julia. In a previous post I already described how to download stock price data for all constituents of the SP500 with R. GetDataset("SP500") # load data into session workspace Using EconDatasets # download data into package subdirectory data With this package, you also can download the same data with just two lines of code: Pkg.add("EconDatasets") It basically bundles many download routines for different datasets in a common interface, and is more easy to keep maintain through automated testing on travis. In order to provide a more convenient and stable way of getting data, I meanwhile started the Julia package EconDatasets.jl.
