fetch

Request data from Yahoo! Finance

Syntax

  • d = fetch(c,s,f) example
  • d = fetch(c,s,f,date) example
  • d = fetch(c,s,f,fromdate,todate) example
  • d = fetch(c,s,f,fromdate,todate,period) example

Description

example

d = fetch(c,s) returns data for all fields from Yahoo!® web site for the indicated security.

    Note:   This function does not support retrieving multiple securities at once. You must fetch a single security at a time.

example

d = fetch(c,s,date) returns all security data for the requested date.

example

d = fetch(c,s,fromdate,todate) returns security data for the date range fromdate through todate.

example

d = fetch(c,s,fromdate,todate,period) returns security data with the indicated period.

example

d = fetch(c,s,f) returns data for the specified fields.

example

d = fetch(c,s,f,date) returns security data on the requested date.

example

d = fetch(c,s,f,fromdate,todate) returns security data for the date range fromdate through todate.

example

d = fetch(c,s,f,fromdate,todate,period) returns security data with the indicated period.

Examples

expand all

Retrieve Data for a Single Security

Connect to Yahoo! Finance.

c = yahoo;

Obtain the security data for IBM®.

d = fetch(c,'IBM')
d = 

    Symbol: {'IBM'}
      Last: 173.84
      Date: 735529.00
      Time: 0.42
    Change: 0.98
      Open: 173.23
      High: 173.84
       Low: 172.95
    Volume: 1132526.00

fetch returns a structure with the security name, last price, date, time, change, open price, high price, low price, and volume.

Close Yahoo! connection.

close(c)

Retrieve Data on a Specified Date

Connect to Yahoo! Finance.

c = yahoo;

Obtain the security data for IBM with today's date.

d = fetch(c,'IBM',now)
d =

     735528.00        174.42        174.75        172.63        172.86    7079500.00        172.86

fetch returns the date, open price, high price, low price, closing price, volume, and adjusted close price.

Close Yahoo! connection.

close(c)

Retrieve the Last Prices for a Set of Equities

Connect to Yahoo! Finance.

c = yahoo;

Obtain the last prices for the 'ko', 'pep', and 'mcd' equities.

FastFood = fetch(c,{'ko', 'pep', 'mcd'},'Last')
FastFood = 
    Last: [3x1 double]

fetch returns a structure with the last prices.

Display the last prices.

FastFood.Last
ans =
         42.96
         45.71
         23.70

Close Yahoo! connection.

close(c)

Retrieve a Closing Price on a Specified Date

Connect to Yahoo! Finance.

c = yahoo;

Obtain the closing price for the 'ko' equity on April 6, 2010.

ClosePrice = fetch(c,'ko','Close','Apr 6 2010')
ClosePrice =

     734234.00         54.29

fetch returns the date in the first column and the closing price in the second column.

Close Yahoo! connection.

close(c)

Retrieve a Closing Price with a Date Range

Connect to Yahoo! Finance.

c = yahoo;

Obtain the closing price for IBM from August 1, 1999 to August 25, 1999.

ClosePrice = fetch(c,'IBM','Close','08/01/99','08/25/99')
ClosePrice =

     730357.00        122.37
     730356.00        122.00
     730355.00        124.44
     730352.00        121.75
     730351.00        122.94
    ...

fetch returns the date in the first column and the closing price in the second column.

Close Yahoo! connection.

close(c)

Retrieve a Security Data with a Date Range

Connect to Yahoo! Finance.

c = yahoo;

Obtain data for IBM from February 1, 2000 through February 20, 2000.

d = fetch(c,'IBM','2/1/2000','2/20/2000')
d =

     730534.00        115.25        115.94        111.50        112.50    7673400.00         94.80
     730533.00        116.50        118.87        115.75        116.75    5237500.00         98.38
     730532.00        116.50        117.31        115.25        115.75    3966900.00         97.54
     730531.00        115.87        117.44        113.87        117.12    5177500.00         98.69
     730530.00        116.00        116.37        114.50        116.06    4544000.00         97.80
     ...

fetch returns the date, open price, high price, low price, closing price, volume, and adjusted close price in the columns. A row contains data for each trading day.

Close Yahoo! connection.

close(c)

Retrieve the Daily Volume

Connect to Yahoo! Finance.

c = yahoo;

Obtain the daily volume for IBM for the last 300 days.

d = fetch(c,'IBM','Volume',now-300,now-1,'d')
d =

     735528.00    7079500.00
     735525.00   10548000.00
     735524.00   22358300.00
     735523.00    6615300.00
     735522.00    3365100.00
     ...

fetch returns the date in the first column and the volume in the second column.

Close Yahoo! connection.

close(c)

Retrieve Stock Dividend Data

Connect to Yahoo! Finance.

c = yahoo;

Obtain the cash dividend data for IBM for the last 300 days.

d = fetch(c,'IBM',now-300,now-1,'v')
d =

     735453.00          0.95
     735362.00          0.95
     735271.00          0.85

fetch returns the date in the first column and cash dividend in the second column.

Close Yahoo! connection.

close(c)

Input Arguments

expand all

c — Yahoo! connectionconnection object

Yahoo! connection, specified as a connection object created using yahoo.

s — Security liststring | cell array

Security list, specified as a string for one security or a cell array of strings for more than one security. Security strings must be in a format recognizable by the Yahoo! server.

    Note:   Retrieving historical data for multiple securities at one time is not supported for Yahoo!. You can fetch historical data for a single security at a time.

Data Types: char | cell

date — Request datestring | serial date number

Request date, specified as a string or a serial date number indicating the date for the requested data. If you enter today's date, fetch returns yesterday's data.

Data Types: double | char

fromdate — Beginning datescalar | vector | matrix | string | cell array

Beginning date for the historical data, specified as a double scalar, double vector, double matrix, string, or cell array of strings. You can specify dates in any format supported by datestr and datenum that show a year, month, and day.

Data Types: double | char | cell

todate — End datescalar | vector | matrix | string | cell array

End date for the historical data, specified as a double scalar, double vector, double matrix, string, or cell array of strings. You can specify dates in any format supported by datestr and datenum that show a year, month, and day.

Data Types: double | char | cell

period — Periodstring

Period within a date range, specified as a string. Possible values are:

  • 'd': daily

  • 'w': weekly

  • 'm': monthly

  • 'v': dividends

Data Types: char

f — Request fieldsstring | cell array

Request fields, specified as a string or cell array of strings indicating the data fields for which to retrieve data. A partial list of supported values for current market data are:

  • 'Symbol'

  • 'Last'

  • 'Date'

  • 'Time'

      Note:   'Date' and 'Time' are MATLAB® date numbers. ('Time' is a fractional part of a date number. For example, 0.5 = 12:00:00 PM.)

  • 'Change'

  • 'Open'

  • 'High'

  • 'Low'

  • 'Volume'

A partial list of supported values for historical data are:

  • 'Close'

  • 'Date'

  • 'High'

  • 'Low'

  • 'Open'

  • 'Volume'

  • 'Adj Close'

For a complete list of supported values for market and historical data, see yhfields.mat.

Data Types: char | cell

Output Arguments

expand all

d — Output datastructure | matrix

Output data, returned as a structure or double matrix containing the requested data retrieved from Yahoo! Finance.

See Also

| | |

Was this topic helpful?