Yahoo Finance API (2025)

This is a simple way to use the Yahoo web API in MATLAB.
178 Downloads
Aktualisiert 6. Jan 2026

Lizenz anzeigen

yfinanceAPI — Download daily stock prices from Yahoo Finance into MATLAB
Pull historical daily OHLCV data for one or more tickers using Yahoo Finance’s public chart endpoint, returned as a MATLAB struct array. Includes an optional demo that renders a candlestick chart.
What this does
  • Fetches Open, High, Low, Close, Volume for each requested symbol at a user specified interval (default is 1d).
  • Returns a struct array (one element per symbol) with fields:
  • o (open), h (high), l (low), c (close), v (volume), a (adjusted close), s (symbol), t (timestamp as MATLAB datenum)
  • Works for multiple tickers in one call (e.g., {'AAPL','GOOGL'}).
  • Adds realistic HTTP headers to reduce blocked requests.
  • Includes a self-demo: run with no inputs to see a candlestick plot.
Syntax
data = yfinanceAPI(symbol, start_date, end_date, interval)
Inputs
  • symbol — cell array of char, e.g. {'AAPL','GOOGL'}
  • start_date — char/ string, 'YYYY-MM-DD' (inclusive)
  • end_date — char/ string, 'YYYY-MM-DD' (inclusive)
  • interval — char/ string, '1d' (inclusive)
Output
  • data — struct array (length = numel(symbol)) with fields:
  • o, h, l, c, v, a, s, t (see above)
Example
symbols = {'AAPL','MSFT'};
start = '2025-01-01';
finish = '2025-03-01';
interval = '1d';
data = yfinanceAPI(symbols, start, finish, interval);
% Convert first symbol’s timestamps to datetime and plot close
t = datetime(datestr(data(1).t));
plot(t, data(1).c, 'LineWidth', 1.2);
grid on; xlabel('Date'); ylabel('Close ($)');
title(sprintf('%s Close', data(1).s));
Candlestick demo
Calling with no arguments downloads AAPL by default and renders a candlestick chart (requires Financial Toolbox for candle).
yfinanceAPI();
Notes & caveats
  • Unofficial endpoint. Yahoo Finance’s chart API is undocumented and may change or throttle. This code adds common headers and a timeout, but availability isn’t guaranteed.
  • Time zone & trading days. Timestamps are daily bars from Yahoo; holidays/weekends are omitted.
  • Financial Toolbox (optional). Only needed for the candlestick demo; data download works without it.
  • Networking. Requires internet access and permission for webread.
Tested with
  • MATLAB R2021a (should work back to R2018b+ with datetime/posixtime).
  • Windows 11; should be OS-agnostic.

Zitieren als

Darin Koblick (2026). Yahoo Finance API (2025) (https://de.mathworks.com/matlabcentral/fileexchange/181747-yahoo-finance-api-2025), MATLAB Central File Exchange. Abgerufen.

Kompatibilität der MATLAB-Version
Erstellt mit R2025a
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux
Version Veröffentlicht Versionshinweise
2.0.2

added time and NaN filter so outputs are consistent.

2.0.1

added adjusted closing price when interval is set to 1d

2.0.0

added interval input

1.0.0