We Love Free Data: Replacing Yahoo Finance Market Data

In keeping with our recent theme of providing useful tidbits of algo trading practicalities, here’s an elegant solution that resolves Yahoo’s unceremonious exit from the free financial data space.
Regular readers would know that I use various tools in my algo trading stack, but the one I keep coming back to, particularly when I’m ready to start running serious simulations, is Zorro. Not only is it a fast, accurate, and powerful backtester and execution engine, the development team is clearly committed to solving issues and adding features that really matter, from a practical perspective. This is another example of the speedy and elegant resolution of a serious issue – namely, the loss of free access to good quality, properly adjusted equities data, thanks to Yahoo’s exit.
Zorro version 1.60 is currently undergoing it’s final stages of beta testing and will likely be released publicly in the coming days. The latest version includes integration with Alpha Vantage‘s API, providing access to free, high quality, properly adjusted stock and ETF price data. All you need to do to use it is sign up at Alpha Vantage for a free API key, then enter your key in Zorro’s initialization file. Then, you can use Zorro’s assetHistory()  function with the arguments Name  and FROM_AV  to download data for the stock or ETF denoted by Name  directly from the Alpha Vantage database.
From my testing, this can be used as a direct replacement in any Zorro script that previously used Yahoo data, and it seems to load even faster than Yahoo data did. Here’s a simple example that downloads daily data for a portfolio of ETFs, saves that data locally, then plots returns series for each component and a price chart for one:

#define N 5 //portfolio components
vars Returns[N];
function run()
{
    BarPeriod = 1440;
    StartDate = 20070301;
    EndDate = 20170728;
    LookBack = 1;
    // Set up returns series
    string Name;
    int n = 0;
    int i, j;
    while(Name = loop(
    "SPY", "CWI", "CSJ", "HYG", "TLT"))
    {
        if(is(INITRUN)) assetHistory(Name,FROM_AV);
        asset(Name);
        Returns[n] = series((priceClose(0)-priceClose(1))/priceClose(1));
        n++;
    }
    if(!is(LOOKBACK))
    {
        // plot returns
        set(PLOTNOW);
        PlotHeight1 = 300;
        PlotHeight2 = 120;
        PlotWidth = 600;
        plot("SPY Returns", Returns[0], NEW|BARS, BLUE);
        plot("CWI Returns", Returns[1], NEW|BARS, BLUE);
        plot("CSJ Returns", Returns[2], NEW|BARS, BLUE);
        plot("HYG Returns", Returns[3], NEW|BARS, BLUE);
        plot("TLT Returns", Returns[4], NEW|BARS, BLUE);
    }
}

And here’s the resulting plot:

Looks good! Now I just need to replace Yahoo Finance with Alpha Vantage in all those scripts….
For readers who are yet to take Zorro for a test drive, I firmly believe that it is the most useful simulation and trading tool for it’s price available on the market today (and the free version packs a mighty punch as well). I’ve watched the platform go from strength to strength as new and better features are added with almost clockwork regularity. It will undoubtedly become ubiquitous as more and more people find out about it.


To become a Zorro ninja and learn to leverage features like the one shown here, join the Robot Wealth community, where you can access courses that will get you up to speed with robust strategy development, even if you’re a novice coder. 

7 thoughts on “We Love Free Data: Replacing Yahoo Finance Market Data”

  1. “Now I just need to replace Yahoo Finance with Alpha Vantage in all those scripts….”
    you seem to hint at a possible architectural improvement:  put the AV data in an external file and reference that file in your scripts…  🙂

    Reply

Leave a Comment