getYahoo downloads financial time series from Yahoo Finance and optionally plots them using a customizable three-panel layout
getTickers, getYahoo and getFundamentals can be used jointly to build a complete workflow: from the selection of representative market tickers, to the retrieval and dynamic interactive plot of their price time series, and finally to the extraction of their fundamental financial information.
For background on financial data and market analysis, see: Yahoo Finance API documentation https://finance.yahoo.com/
Two tickers, no plots.out
=getYahoo(ticker,
Name, Value)
out=getYahoo("ENEL.MI",'interval','1d','bottomPanelMode','macd');Bottom panel hosts the RSI index.
out=getYahoo("G.MI",'topPanelMode','ma','bottomPanelMode','rsi');
Multiple tickers.ticker passed as a cell array of characters.
ticker={'G.MI','ENEL.MI','ISP.MI'};
out = getYahoo(ticker,'plots',false,'msg',false); ticker Name
_______ __________________
"^IXIC" "Nasdaq Composite"
"AAPL" "Apple"
"MSFT" "Microsoft"
"NVDA" "NVIDIA"
"AMZN" "Amazon"
"GOOGL" "Alphabet Class A"
Requested pair range=1y, interval=1m is not supported.
Using interval=1d instead.
Processing ticker 1 of 5: AAPL
Processing ticker 2 of 5: MSFT
Processing ticker 3 of 5: NVDA
Processing ticker 4 of 5: AMZN
Processing ticker 5 of 5: GOOGL
5×1 struct array with fields:
Ticker
LastPeriod
intervalRequested
intervalActual
TimeZone
TT
Indicators
Success
Message
class
CompanyName TickerSymbol marketCap sector industry
_________________________ ____________ __________ __________________________ __________________________________
AppleInc_ {'Apple Inc.' } {'AAPL' } 3.7615e+12 {'Technology' } {'Consumer Electronics' }
MicrosoftCorporation {'Microsoft Corporation'} {'MSFT' } 2.7757e+12 {'Technology' } {'Software - Infrastructure' }
NVIDIACorporation {'NVIDIA Corporation' } {'NVDA' } 4.3115e+12 {'Technology' } {'Semiconductors' }
Amazon_com_Inc_ {'Amazon.com, Inc.' } {'AMZN' } 2.2519e+12 {'Consumer Cyclical' } {'Internet Retail' }
AlphabetInc_ {'Alphabet Inc.' } {'GOOGL'} 3.5779e+12 {'Communication Services'} {'Internet Content & Information'}
out = getYahoo('ENEL.MI','LastPeriod','1y','interval','1m','plots',false);
% Note that with 'autoFixInterval',false the previous examples fails
% out = getYahoo('ENEL.MI','LastPeriod','1y','interval','1m','autoFixInterval',false,'plots',false);
out=getYahoo('G.MI','layoutHeights',[2 1 1]);
out=getYahoo('ENEL.MI','topPanelMode','candle', ...
'bottomPanelMode','rsi','layoutHeights',[3 1 1]);
out=getYahoo('G.MI','topPanelMode','ma', ...
'bottomPanelMode','macd','layoutHeights',[1.5 1 0.7]);
out=getYahoo('G.MI','LastPeriod','5d','interval','15m', ...
'removeGaps',false,'layoutHeights',[2 1 1]);
out=getYahoo('ENEL.MI','LastPeriod','10y','interval','1mo', ...
'bottomPanelMode','williamsr','layoutHeights',[2.5 1 1]);
out = getYahoo('G.MI','LastPeriod','5d','interval','15m','removeGaps',false);
out = getYahoo('G.MI','LastPeriod','5d','interval','15m','removeGaps',true,'breakAtSession',false);
out = getYahoo('ENEL.MI','topPanelMode','line','bottomPanelMode','rsi');
Line Chart with moving averages in the top panel and crossovers.
out = getYahoo('ENEL.MI','topPanelMode','ma','maFastLen',5,'maMidLen',20,'maSlowLen',50); ticker Name
_______ __________________
"^IXIC" "Nasdaq Composite"
"AAPL" "Apple"
"MSFT" "Microsoft"
"NVDA" "NVIDIA"
"AMZN" "Amazon"
"GOOGL" "Alphabet Class A"
Requested pair range=1y, interval=1m is not supported.
Using interval=1d instead.
Processing ticker 1 of 5: AAPL
Processing ticker 2 of 5: MSFT
Processing ticker 3 of 5: NVDA
Processing ticker 4 of 5: AMZN
Processing ticker 5 of 5: GOOGL
5×1 struct array with fields:
Ticker
LastPeriod
intervalRequested
intervalActual
TimeZone
TT
Indicators
Success
Message
class
CompanyName TickerSymbol marketCap sector industry
_________________________ ____________ __________ __________________________ __________________________________
AppleInc_ {'Apple Inc.' } {'AAPL' } 3.7615e+12 {'Technology' } {'Consumer Electronics' }
MicrosoftCorporation {'Microsoft Corporation'} {'MSFT' } 2.7757e+12 {'Technology' } {'Software - Infrastructure' }
NVIDIACorporation {'NVIDIA Corporation' } {'NVDA' } 4.3115e+12 {'Technology' } {'Semiconductors' }
Amazon_com_Inc_ {'Amazon.com, Inc.' } {'AMZN' } 2.2519e+12 {'Consumer Cyclical' } {'Internet Retail' }
AlphabetInc_ {'Alphabet Inc.' } {'GOOGL'} 3.5779e+12 {'Communication Services'} {'Internet Content & Information'}
out = getYahoo('ENEL.MI','topPanelMode','ma','showMACrossovers',false);
out = getYahoo('G.MI','upColor',[0 0.4 0.8],'downColor',[0.8 0.4 0]);
out = getYahoo('G.MI','bottomPanelMode','rsi','rsiLen',10,'topRSI',70,'lowRSI',30);
out = getYahoo('G.MI','bottomPanelMode','stoch','stochLen',10,'stochSmooth',5);
out = getYahoo('ENEL.MI','bottomPanelMode','macd','macdFastLen',8,'macdSlowLen',17);
out = getYahoo('G.MI','bottomPanelMode','williamsr','wrLen',100);
out = getYahoo('ENEL.MI','LastPeriod','10y','interval','1mo');
Max history.
out = getYahoo('G.MI','LastPeriod','max','interval','1wk','plots',false); ticker Name
_______ __________________
"^IXIC" "Nasdaq Composite"
"AAPL" "Apple"
"MSFT" "Microsoft"
"NVDA" "NVIDIA"
"AMZN" "Amazon"
"GOOGL" "Alphabet Class A"
Requested pair range=1y, interval=1m is not supported.
Using interval=1d instead.
Processing ticker 1 of 5: AAPL
Processing ticker 2 of 5: MSFT
Processing ticker 3 of 5: NVDA
Processing ticker 4 of 5: AMZN
Processing ticker 5 of 5: GOOGL
5×1 struct array with fields:
Ticker
LastPeriod
intervalRequested
intervalActual
TimeZone
TT
Indicators
Success
Message
class
CompanyName TickerSymbol marketCap sector industry
_________________________ ____________ __________ __________________________ __________________________________
AppleInc_ {'Apple Inc.' } {'AAPL' } 3.7615e+12 {'Technology' } {'Consumer Electronics' }
MicrosoftCorporation {'Microsoft Corporation'} {'MSFT' } 2.7757e+12 {'Technology' } {'Software - Infrastructure' }
NVIDIACorporation {'NVIDIA Corporation' } {'NVDA' } 4.3115e+12 {'Technology' } {'Semiconductors' }
Amazon_com_Inc_ {'Amazon.com, Inc.' } {'AMZN' } 2.2519e+12 {'Consumer Cyclical' } {'Internet Retail' }
AlphabetInc_ {'Alphabet Inc.' } {'GOOGL'} 3.5779e+12 {'Communication Services'} {'Internet Content & Information'}
With help.
out = getYahoo('G.MI','showPanelHelp',true); ticker Name
_______ __________________
"^IXIC" "Nasdaq Composite"
"AAPL" "Apple"
"MSFT" "Microsoft"
"NVDA" "NVIDIA"
"AMZN" "Amazon"
"GOOGL" "Alphabet Class A"
Requested pair range=1y, interval=1m is not supported.
Using interval=1d instead.
Processing ticker 1 of 5: AAPL
Processing ticker 2 of 5: MSFT
Processing ticker 3 of 5: NVDA
Processing ticker 4 of 5: AMZN
Processing ticker 5 of 5: GOOGL
5×1 struct array with fields:
Ticker
LastPeriod
intervalRequested
intervalActual
TimeZone
TT
Indicators
Success
Message
class
CompanyName TickerSymbol marketCap sector industry
_________________________ ____________ __________ __________________________ __________________________________
AppleInc_ {'Apple Inc.' } {'AAPL' } 3.7615e+12 {'Technology' } {'Consumer Electronics' }
MicrosoftCorporation {'Microsoft Corporation'} {'MSFT' } 2.7757e+12 {'Technology' } {'Software - Infrastructure' }
NVIDIACorporation {'NVIDIA Corporation' } {'NVDA' } 4.3115e+12 {'Technology' } {'Semiconductors' }
Amazon_com_Inc_ {'Amazon.com, Inc.' } {'AMZN' } 2.2519e+12 {'Consumer Cyclical' } {'Internet Retail' }
AlphabetInc_ {'Alphabet Inc.' } {'GOOGL'} 3.5779e+12 {'Communication Services'} {'Internet Content & Information'}
tickers=["G.MI","ENEL.MI"]; out = getYahoo(tickers,'plots',false); disp(tickers(1)) disp(out(1)) disp(tickers(2)) disp(out(2))
getYahoo('G.MI','bottomPanelMode','rsi');
getYahoo('G.MI','bottomPanelMode','macd');
out = getYahoo('G.MI','LastPeriod','3mo','interval','1d','topPanelMode','ma',...
'maFastLen',7,'maMidLen',21,'maSlowLen',50,'bottomPanelMode','rsi');
ticker='G.MI'; out = getYahoo(ticker,'plots',false); TT = out.TT; plot(TT.t,TT.Close); title(ticker)
T = getTickers('market','London','Source','dynamic','nStocks',15);
disp(T)
% Retrieve price data
out = getYahoo(T.ticker(2:end));
% Retrieve valuation metrics
F = getFundamentals(T.ticker(2:end),'Fields','valuation');
disp(F)ticker — Ticker symbol(s).
Character, string or cell array of char.It can be: - a character scalar, for example 'G.MI' - a string scalar or string array, for example "G.MI" or ["G.MI" "ENEL.MI"] - a cell array of character vectors, for example {'G.MI','ENEL.MI'} The function downloads OHLCV data from Yahoo Finance for each supplied ticker and returns the results inside a structure array.
Example - 'G.MI'
Data Types: char | string | cell
Specify optional comma-separated pairs of Name,Value arguments.
Name is the argument name and Value
is the corresponding value. Name must appear
inside single quotes (' ').
You can specify several name and value pair arguments in any order as
Name1,Value1,...,NameN,ValueN.
'LastPeriod','6mo'
, 'interval','1d'
, 'widthFactor',1.2
, 'layoutHeights',[2 1 1]
, 'removeGaps',false
, 'breakAtSession',false
, 'nTicks',10
, 'topPanelMode','ma'
, 'maFastLen',5
, 'maMidLen',20
, 'maSlowLen',100
, 'showMACrossovers',false
, 'upColor',[0 0.5 0]
, 'downColor',[0.7 0 0]
, 'bottomPanelMode','macd'
, 'topRSI',70
, 'lowRSI',30
, 'topStoch',80
, 'lowStoch',20
, 'topWilliams',-20
, 'lowWilliams',-80
, 'rsiLen',10
, 'stochLen',10
, 'stochSmooth',5
, 'macdFastLen',8
, 'macdSlowLen',17
, 'macdSigLen',5
, 'rocLen',6
, 'wrLen',10
, 'showPanelHelp',true
, 'autoFixInterval',false
, 'plots',false
, 'msg',false
LastPeriod
—Period to analyze.character | string scalar.Possible values are: '1d' '5d' '1mo' '3mo' '6mo' '1y' '2y' '5y' '10y' 'ytd' 'max' Default is '1y'.
Example: 'LastPeriod','6mo'
Data Types: char | string
interval
—Sampling interval requested to Yahoo Finance.character | string scalar.Possible values are: '1m','2m','5m','15m','30m','60m','90m','1h','1d','5d','1wk','1mo','3mo' Default is '1m'. If the pair LastPeriod/interval is not admissible, the interval is replaced automatically if option autoFixInterval=true.
Example: 'interval','1d'
Data Types: char | string
widthFactor
—Candle width scaling factor.scalar.It is used only when topPanelMode='candle'.
Default is 1.5.
Example: 'widthFactor',1.2
Data Types: double
layoutHeights
—Relative heights of the three panels.numeric vector.Vector with three positive elements controlling the relative heights of: 1) top panel = price / candles / moving averages;
2) middle panel= volume;
3) bottom panel= technical indicator.
The actual heights are obtained by normalizing the vector so that its elements sum to 1.
Default is [1 1 1], which gives the same height to the three panels.
For example: - [2 1 1] makes the top panel occupy about half of the plotting area and the other two panels about one quarter each.
- [3 1 1] gives even more emphasis to the top panel.
- [1.5 1 0.7] gives moderate emphasis to the top panel and reduces the space of the bottom panel.
Example: 'layoutHeights',[2 1 1]
Data Types: double
removeGaps
—Remove night or weekend gaps in x-axis.boolean.If true, x-axis is based on the progressive index of the time series.
If false, x-axis is based on actual datetime.
Default is true.
Example: 'removeGaps',false
Data Types: logical
breakAtSession
—Add separators between sessions.boolean.Used only when removeGaps=true.
Default is true.
Example: 'breakAtSession',false
Data Types: logical
nTicks
—Number of ticks shown on x-axis when removeGaps=true.positive integer scalar.Default is 8.
Example: 'nTicks',10
Data Types: double
topPanelMode
—Type of plot in the first panel.string | char.Possible values are: 'candle' = candlestick chart 'line' = close price only 'ma' = close price and moving averages Default is 'candle'.
Example: 'topPanelMode','ma'
Data Types: char | string
maFastLen
—Fast moving average length.positive scalar integer.Used only when topPanelMode='ma'.
Default is 10.
Example: 'maFastLen',5
Data Types: double
maMidLen
—Medium moving average length.positive scalar integer.Used only when topPanelMode='ma'.
Default is 30.
Example: 'maMidLen',20
Data Types: double
maSlowLen
—Slow moving average length.positive scalar integer.Used only when topPanelMode='ma'.
Default is 60. Note that maSlowLen > maMidLen > maFastLen.
Example: 'maSlowLen',100
Data Types: double
showMACrossovers
—Show moving average crossover markers.boolean.Used only when topPanelMode='ma'.
Default is true.
Example: 'showMACrossovers',false
Data Types: logical
upColor
—Color for up candles (top panel) and bars (mid panel).rGB row vector.Default is [0 0.7 0].
Example: 'upColor',[0 0.5 0]
Data Types: double
downColor
—Color for down candles (top panel) and bars (mid panel).rGB row vector.Default is [0.85 0 0].
Example: 'downColor',[0.7 0 0]
Data Types: double
bottomPanelMode
—Type of indicator shown in the third panel.string | char.Possible values are: 'rsi' = Relative Strength Index 'stoch' = Stochastic oscillator 'macd' = MACD 'williamsr' = Williams %R 'roc' = Rate of Change Default is 'stoch'.
Example: 'bottomPanelMode','macd'
Data Types: char | string
topRSI
—Upper RSI threshold.scalar in in the interval [50 100].Default is 80.
Example: 'topRSI',70
Data Types: double
lowRSI
—Lower RSI threshold.scalar in in the interval [0 50].Default is 20.
Example: 'lowRSI',30
Data Types: double
topStoch
—Upper stochastic threshold.scalar in in the interval [50 100].Default is 70.
Example: 'topStoch',80
Data Types: double
lowStoch
—Lower stochastic threshold.scalar in in the interval [0 50].Default is 30.
Example: 'lowStoch',20
Data Types: double
topWilliams
—Upper Williams %R threshold.scalar in in the interval [-50 0].Default is -30.
Example: 'topWilliams',-20
Data Types: double
lowWilliams
—Lower Williams %R threshold.scalar in in the interval [-100 -50].Default is -70.
Example: 'lowWilliams',-80
Data Types: double
stochLen
—Stochastic lookback length.scalar.Default is 14.
Example: 'stochLen',10
Data Types: double
stochSmooth
—Stochastic smoothing length for %%D.scalar.Default is 3.
Example: 'stochSmooth',5
Data Types: double
macdFastLen
—MACD fast EMA length.positive scalar integer.Default is 12.
Example: 'macdFastLen',8
Data Types: double
macdSlowLen
—MACD slow EMA length.positive scalar integer.Default is 26.
Example: 'macdSlowLen',17
Data Types: double
macdSigLen
—MACD signal EMA length.positive scalar integer.Default is 9.
Example: 'macdSigLen',5
Data Types: double
rocLen
—ROC lag length.positive scalar integer.Default is 12.
Example: 'rocLen',6
Data Types: double
showPanelHelp
—Display textual explanation in Command Window.boolean.Default is false.
Example: 'showPanelHelp',true
Data Types: logical
autoFixInterval
—Replace invalid range/interval combinations automatically.boolean.Default is true.
Example: 'autoFixInterval',false
Data Types: logical
plots
—Produce plots.boolean.If true (default) the three-panel figure is created for each ticker. If false only the data are downloaded and stored in the output structure.
Example: 'plots',false
Data Types: logical
msg
—Display progress messages.boolean.If true (default), progress messages and warnings are shown.
Example: 'msg',false
Data Types: logical
out — description
StructureStructure array containing the following fields
| Value | Description |
|---|---|
Ticker |
ticker symbol. |
LastPeriod |
requested period. |
intervalRequested |
requested interval after validation. |
intervalActual |
actual data granularity returned by Yahoo. |
TimeZone |
exchange timezone. |
TT |
timetable with variables Open, High, Low, Close, Volume. |
Indicators |
structure containing RSI, StochK, StochD, MACD, MACDSignal, MACDHist, WilliamsR, ROC, maFast, maMid and maSlow. |
Success |
true if download and processing succeeded. |
Message |
message describing the result. |
class |
'getYahoo'. |
Damodaran, A. (2012), "Investment Valuation: Tools and Techniques for Determining the Value of Any Asset", 3rd Edition, Wiley.
Cochrane, J. H. (2023), "Asset Pricing, Revised Edition", Princeton University Press, Princeton.
Koller, T., Goedhart, M., and Wessels, D. (2020), "Valuation: Measuring and Managing the Value of Companies, 7th Edition", Wiley, Hoboken.
getTickers
|
getFundamentals
|
rsindex
|
candle
|
movavg