Yahoo Finance API (2025)

This is a simple way to use the Yahoo web API in MATLAB.
86 download
Aggiornato 7 ago 2025

Visualizza la licenza

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 1-day interval.
  • Returns a struct array (one element per symbol) with fields:
  • o (open), h (high), l (low), c (close), v (volume)
  • 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)
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)
Output
  • data — struct array (length = numel(symbol)) with fields:
  • o, h, l, c, v, s, t (see above)
Example
symbols = {'AAPL','MSFT'};
start = '2025-01-01';
finish = '2025-03-01';
data = yfinanceAPI(symbols, start, finish);
% 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.

Cita come

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

Compatibilità della release di MATLAB
Creato con R2025a
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Versione Pubblicato Note della release
1.0.0