|
9 | 9 | % series, and finally to the extraction of their fundamental financial |
10 | 10 | % information. |
11 | 11 | % For background on financial data and market analysis, see: |
12 | | -% Yahoo Finance API documentation https://finance.yahoo.com/ |
| 12 | +% Yahoo Finance API documentation https://finance.yahoo.com/ |
13 | 13 | % |
14 | 14 | % Required input arguments: |
15 | 15 | % |
|
284 | 284 | end |
285 | 285 |
|
286 | 286 | % Rank constituents |
287 | | - U.MarketCap = localGetMarketCaps(U.ticker, msg); |
| 287 | + U.MarketCap = localGetMarketCaps(U.ticker); |
288 | 288 |
|
289 | 289 | [~,ord] = sort(U.MarketCap, 'descend', 'MissingPlacement','last'); |
290 | 290 | U = U(ord,:); |
|
1119 | 1119 |
|
1120 | 1120 | end |
1121 | 1121 | % ------------------------------------------------------------------------- |
1122 | | -function mc = localGetMarketCaps(symbols, msg) |
| 1122 | +function mc = localGetMarketCaps(symbols) |
1123 | 1123 |
|
1124 | 1124 | n = numel(symbols); |
1125 | 1125 | mc = nan(n,1); |
1126 | 1126 |
|
1127 | | -try |
1128 | | - F = getFundamentals(symbols,'Fields',{'TickerSymbol','marketCap'}); |
1129 | | - if ismember('TickerSymbol', F.Properties.VariableNames) && ... |
1130 | | - ismember('marketCap', F.Properties.VariableNames) |
1131 | | - |
1132 | | - fsym = string(F.TickerSymbol); |
1133 | | - fmc = F.marketCap; |
1134 | | - |
1135 | | - for i = 1:n |
1136 | | - idx = find(fsym == string(symbols(i)),1,'first'); |
1137 | | - if ~isempty(idx) |
1138 | | - if isnumeric(fmc) |
1139 | | - mc(i) = fmc(idx); |
1140 | | - elseif iscell(fmc) |
1141 | | - if isempty(fmc{idx}) |
1142 | | - mc(i) = NaN; |
1143 | | - elseif isnumeric(fmc{idx}) || islogical(fmc{idx}) |
1144 | | - mc(i) = double(fmc{idx}); |
1145 | | - end |
| 1127 | + |
| 1128 | +F = getFundamentals(symbols,'Fields',{'TickerSymbol','marketCap'}); |
| 1129 | +if ismember('TickerSymbol', F.Properties.VariableNames) && ... |
| 1130 | + ismember('marketCap', F.Properties.VariableNames) |
| 1131 | + |
| 1132 | + fsym = string(F.TickerSymbol); |
| 1133 | + fmc = F.marketCap; |
| 1134 | + |
| 1135 | + for i = 1:n |
| 1136 | + idx = find(fsym == string(symbols(i)),1,'first'); |
| 1137 | + if ~isempty(idx) |
| 1138 | + if isnumeric(fmc) |
| 1139 | + mc(i) = fmc(idx); |
| 1140 | + elseif iscell(fmc) |
| 1141 | + if isempty(fmc{idx}) |
| 1142 | + mc(i) = NaN; |
| 1143 | + elseif isnumeric(fmc{idx}) || islogical(fmc{idx}) |
| 1144 | + mc(i) = double(fmc{idx}); |
1146 | 1145 | end |
1147 | 1146 | end |
1148 | 1147 | end |
1149 | | - return |
1150 | | - end |
1151 | | -catch |
1152 | | - if msg |
1153 | | - fprintf('getFundamentals unavailable or failed. Falling back to individual retrieval.\n'); |
1154 | 1148 | end |
| 1149 | + return |
1155 | 1150 | end |
1156 | 1151 |
|
1157 | 1152 | for i = 1:n |
|
0 commit comments