The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Dividends in Matlab fetch resolved
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  

Posts: 2
Registered: 11/23/12
Dividends in Matlab fetch resolved
Posted: Nov 23, 2012 8:12 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hello all
Here is the code to retrieve dividend information from yahoo (make it simple).
function[gfdata, gfstatus,url,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 (

% 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'])
if (~ischar(Ticker) || ~ischar(StartDate) ||~ischar(EndDate))
error([mfilename,'No valid stock symbol provided, please provide one (string)'])
if (datenum(EndDate)-datenum(StartDate) <= 0)
error([mfilename,'Invalid StarDate and EndDate expressions'])

%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)];
[Y2 M2 D2] = datevec(EndDate);
M2 = M2-1; %January is month zero according to yahoo
if M2 < 10
url = ['',Ticker,'&a=',M1,'&b=',num2str(D1), ...

%get data
[gfdata, gfstatus] = urlread(url);

if gfstatus

%Organice the data with coma delimeter
scandata = textscan(gfdata,'%s%s','delimiter',','); = scandata{1};
data.div = scandata{2};
error(['Unable to retrieve data from Yahoo Finance for ',Ticker])

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.