We Love Free Data: Replacing Yahoo Finance Market Data

Posted on Jul 29, 2017 by Kris Longmore
7 comments
4,294 Views

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) Comments

[…] We Love Free Data: Replacing Yahoo Finance Market Data [Robot Wealth] […]

Hans
August 22, 2017 at 2:42 am

“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…  🙂

August 23, 2017 at 7:22 pm

Thanks!

MarianoA
September 15, 2017 at 8:52 am

It may look as a stupid question but where can one see how the assets are named on alpha advantage?

September 18, 2017 at 10:07 pm

Not a stupid question at all! All the instruments I’ve used via Alpha Vantage have the same name as their ticker.

Andrew Bannerman
October 19, 2017 at 10:38 pm

I wrote a lil guide interact with the Alpha Vantage API using R
 
https://flare9xblog.wordpress.com/2017/10/18/free-data-alternative-to-yahoo-finance/

October 24, 2017 at 9:39 pm

Thanks Andrew! Nice blog!

Leave a Comment