Retrieve multiple stocks with fetch function

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Financial Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by