function [adj_close,date]=yahoo_prices(ticker,begin_date,end_date)
% get market data from Yahoo! Finance
% example: [adj_close,date]=yahoo_prices('QQQ','2014-02-04','2016-01-29')
% 'date' is a vector of date serial numbers
% 'adj_close' is a vector of adjusted closing prices
% JDodson 2016-02-04
[beg_year,beg_month,beg_day]=datevec(begin_date);
[end_year,end_month,end_day]=datevec(end_date);
cgi_args=['s=',strrep(ticker,'^','%5E'),'&g=d',...
    '&a=',int2str(beg_month-1),'&b=',int2str(beg_day),'&c=',int2str(beg_year) ...
    '&d=',int2str(end_month-1),'&e=',int2str(end_day),'&f=',int2str(end_year)];
cols=textscan(...
    urlread(['http://ichart.finance.yahoo.com/table.csv?',cgi_args]),...
    '%s%*f%*f%*f%*f%*d%f','Delimiter',',','HeaderLines',1);
date=datenum(cols{1}(end:-1:1));
adj_close=cols{2}(end:-1:1);
end
