Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
Javier
Posts:
2
Registered:
11/23/12
|
|
Dividends in Matlab fetch resolved
Posted:
Nov 23, 2012 8:14 AM
|
|
Hello all Here is the code to retrieve dividend information from yahoo (make it simple). %%%%% function[data]=dividendyahoo(Ticker,StartDate,EndDate) % Input % Ticker : Must be in string format ('SAN.MC) % StartDate and EndDate format:'01 Jan 2000' % Output % Dividend : Dividend vector information % Autor: Mauricio Bedoya (javierma36@hotmail.com)
% Observation % You can introduce a new parameter in the function and search data in the % different database of yahoo. For example: % data = =dividendyahoo(Ticker,StartDate,EndDate,Database) % Database: 'v' for dividends % 'd' daily data % 'w' weekly data % 'm' monhtly data % However, the output must be organice according to number of columns.
clear M1 M2 D1 D2 Y1 Y2
% Error check if nargin ~= 3 error([mfilename,'Incorrect data input elements']) end if (~ischar(Ticker) || ~ischar(StartDate) ||~ischar(EndDate)) error([mfilename,'No valid stock symbol provided, please provide one (string)']) end if (datenum(EndDate)-datenum(StartDate) <= 0) error([mfilename,'Invalid StarDate and EndDate expressions']) end
%Define sql query elements database = 'v'; %Database to search dividend information [Y1 M1 D1] = datevec(StartDate); M1 = M1-1; %January is month zero according to yahoo if M1 < 10 M1 = ['0',num2str(M1)]; end [Y2 M2 D2] = datevec(EndDate); M2 = M2-1; %January is month zero according to yahoo if M2 < 10 M2=['0',num2str(M2)]; end %URL url = ['http://ichart.finance.yahoo.com/table.csv?s=',Ticker,'&a=',M1,'&b=',num2str(D1), ... '&c=',num2str(Y1),'&d=',M2,'&e=',num2str(D2),'&f=',num2str(Y2),'&g=',database,'&ignore=.csv']; %get data [gfdata, gfstatus] = urlread(url);
if gfstatus
%Organice the data with coma delimeter scandata = textscan(gfdata,'%s%s','delimiter',',');
data.date = scandata{1}; data.div = scandata{2}; else error(['Unable to retrieve data from Yahoo Finance for ',Ticker]) end
|
|
|
|