Retrieve multiple stocks with fetch function

3 visualizzazioni (ultimi 30 giorni)
gcicceri
gcicceri il 4 Gen 2022
Risposto: VINAYAK LUHA il 13 Set 2023
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

Risposte (1)

VINAYAK LUHA
VINAYAK LUHA il 13 Set 2023
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

Categorie

Scopri di più su Financial Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by