Skip to content

Commit 424d6a4

Browse files
% Convert LastPeriod='max' into the longest range compatible with the
% requested interval, to avoid Yahoo silent downsampling. if strcmpi(LastPeriod,'max') switch interval case {'1m'} LastPeriod = '5d'; case {'2m' '5m' '15m' '30m' '90m'} LastPeriod = '1mo'; case {'60m' '1h' } LastPeriod = '3mo'; otherwise LastPeriod = '10y'; end disp(['Maximum allowed period for ' num2str(interval) ' interval is: ' num2str(LastPeriod)]) end
1 parent fe6a6b5 commit 424d6a4

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

toolbox/utilities/getYahoo.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,22 @@
794794
'ticker must be a char, a cell array of char, or a string array.');
795795
end
796796

797+
% Convert LastPeriod='max' into the longest range compatible with the
798+
% requested interval, to avoid Yahoo silent downsampling.
799+
if strcmpi(LastPeriod,'max')
800+
switch interval
801+
case {'1m'}
802+
LastPeriod = '5d';
803+
case {'2m' '5m' '15m' '30m' '90m'}
804+
LastPeriod = '1mo';
805+
case {'60m' '1h' }
806+
LastPeriod = '3mo';
807+
otherwise
808+
LastPeriod = '10y';
809+
end
810+
disp(['Maximum allowed period for ' num2str(interval) ' interval is: ' num2str(LastPeriod)])
811+
end
812+
797813
% Validate range/interval pair
798814
[intervalValidated, isValidPair] = validateYahooRangeInterval(LastPeriod, interval, autoFixInterval);
799815

@@ -802,6 +818,8 @@
802818
fprintf('Using interval=%s instead.\n', intervalValidated);
803819
end
804820

821+
822+
805823
hf = ["User-Agent", "Mozilla/5.0"; ...
806824
"Accept", "application/json,text/plain,*/*"];
807825
opts = weboptions('ContentType','json','Timeout',30,'HeaderFields',hf);
@@ -835,6 +853,8 @@
835853

836854
url = "https://query1.finance.yahoo.com/v8/finance/chart/" + tickerNow;
837855

856+
857+
838858
try
839859
raw = webread(url, 'interval', intervalValidated, 'range', LastPeriod, opts);
840860
catch ME

0 commit comments

Comments
 (0)