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 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