Skip to content

Asking your advice #170

@MarcoRianiUNIPR

Description

@MarcoRianiUNIPR

Function getYahoo has many options.

% Optional input arguments:
%
% LastPeriod : Period to analyze. Character or 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 from Yahoo Finance.
% Character or string scalar.
% Possible values are:
% '1m','2m','5m','15m','30m','60m','90m','1h','1d','5d','1wk','1mo','3mo'
% Default is '1m'. If the LastPeriod/interval pair is not
% admissible, the interval is replaced automatically if
% autoFixInterval=true.
% Example - 'interval','1d'
% Data Types - char | string
%
% widthFactor : Candle width scaling factor. Scalar.
% 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 from the x-axis. Boolean.
% If true, the x-axis is based on the progressive index of the
% time series.
% If false, the 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 the 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 or 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 or 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 the interval [50 100].
% Default is 80.
% Example - 'topRSI',70
% Data Types - double

% and many others

For example, the options

% 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

work only if you choose

'topPanelMode','ma'

as in

getYahoo('G.MI','topPanelMode','ma','maSlowLen',40)

but they have no effect if, for example, you choose

'topPanelMode','candle'

In other words, the option 'maSlowLen',40 has no effect in the call

getYahoo('G.MI','topPanelMode','candle','maSlowLen',40)

Now there are two possible approaches.

Leave everything as it is, and perhaps issue a warning for options that are unused.
Modify topPanelMode so that it can also accept a struct as input.

% topPanelMode : Type of plot in the first panel. String or char or struct.
% Possible values are:
% 'candle' = candlestick chart (with all default candle options)
% 'line' = close price only (with all default line options)
% 'ma' = close price and moving averages (with all default MA options)
%
% If, instead, topPanelMode is a struct, then it becomes
% possible to control the characteristics of the selected
% visualization.
%
% For example, if in the top panel you want to show moving
% averages with crossover signals, with fast moving average
% length = 15, medium moving average length = 25, and slow
% moving average length = 50, you can use:
%
% myoptions=struct;
% myoptions.Name='ma';
% myoptions.maFastLen=15;
% myoptions.maMidLen=25;
% myoptions.maSlowLen=50;
% myoptions.showMACrossovers=true;

and call getYahoo as follows

getYahoo('G.MI','topPanelMode',myoptions)

The same applies, for example, to the options

% 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

which apply only when the top panel mode is 'candle'.

What is your opinion?
Your feedback is highly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions