Retrieve multiple stocks with fetch function

3 ビュー (過去 30 日間)
gcicceri
gcicceri 2022 年 1 月 4 日
回答済み: VINAYAK LUHA 2023 年 9 月 13 日
Good morning everyone.
The goal is to retrieve a lot of stocks by using 'fetch' function. Is there an existing function to do this or should I use loop cycle?
Thanks in advance.
url = 'https://fred.stlouisfed.org/';
c = fred(url);
t0 = datetime(2020,6,1); %start data
t1 = datetime('today'); % end data
series = { 'SP500','DEXUSEU', 'CPF1M'};
for loop:
d = fetch(c,series{i},t0, t1)
.......
time= datetime(d.Data(:,1),'ConvertFrom','datenum');
stocks_data = = d.Data(:,2);
end
Thanks

回答 (1 件)

VINAYAK LUHA
VINAYAK LUHA 2023 年 9 月 13 日
Hi Gcicceri,
It is my understanding that you wish to know an efficient approach to retrieve large number of stocks data of multiple series from the “FRED” data server using the fetch function in Computational Finance Toolbox.
To address your query, instead of using a loop, you can pass the array of series directly to the “fetch” function and retrieve a (1 x number of series) structure from which data of a series can be retrieved as below.
x=fetch(c,series,t0,t1);
x(i).Data;
Here "i" is the index of a series in the series array
Refer to the documentation on how to request data from FRED server as follows
Hope this helps.
Regards,
Vinayak Luha

カテゴリ

Help Center および File ExchangeFinancial Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by