Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

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

collapse all

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)

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)

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)

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)

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)

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)

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)

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)

Related Examples

Input Arguments

collapse all

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

Security list, specified as a character vector for one security or a cell array of character vectors for more than one security. These character vectors 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

Request date, specified as a character vector 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

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

Data Types: double | char | cell

End date for the historical data, specified as a double scalar, double vector, double matrix, character vector, or cell array of character vectors. 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 within a date range, specified as one of these values:

  • 'd' for daily

  • 'w' for weekly

  • 'm' for monthly

  • 'v' for dividends

Request fields, specified as a character vector or cell array of character vectors 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

collapse all

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

See Also

| | |

Introduced before R2006a

Was this topic helpful?