Quandl API MATLAB issues
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I would greatly appreciate to have some feedback of users of the QUANDL data source linked with MATLAB.
I am trying pull out data from Quandl into Matlab. Quandl do have an API available to be used in Matlab.
so my code is the following :
series = {500 stocks ticker}
series1 = {100 stocks ticker}
if selectedItem == 1 && selectedItem1 == 1 && selectedItem3 == 1 SD = sprintf('%02d-%02d-%04d',SMM,SDD, SYYYY) ED = sprintf('%02d-%02d-%04d',EMM,EDD, EYYYY)
for i = 1:numel(series)
for j = 1:numel(series1)
if strcmp(Tick,series{i}) && strcmp(Tick, series1{j})
Source = strcat('GOOG/NASDAQ_', Tick)
Quandl = Quandl.get(Source, 'trim_start', SD, 'trim_end', ED, 'authcode', 'jtwf2XzCdzxhAKrXxNkm')
end
end
seriesinter = ismember(series,series1);
series(~seriesinter);
seriesnyse = series(~seriesinter);
for h = 1:numel(seriesnyse)
if strcmp(Tick,seriesnyse{h})
Source = strcat('GOOG/NYSE_', Tick)
Quandl = Quandl.get(Source, 'trim_start', SD, 'trim_end', ED, 'authcode', 'jtwf2XzCdzxhAKrXxNkm')
end
end
end
When the ticker is a technological stocks, its entering the first loop, and its connected to Quandl and retrieving the data.
But whenever I call for a non technological stocks, it goes in the second loop, but it just cant retrieve the data, it gives me the following error :
Undefined variable Quandl.
Error in Equities>pushbutton2_Callback (line 919) Quandl = Quandl.get(Source, 'trim_start', SD, 'trim_end', ED, 'authcode', 'jtwf2XzCdzxhAKrXxNkm')
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in Equities (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Equities('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
which means its recognising the Quandl.get, I dont understand at all why its working in the first loop and not in the second one... When i do a step by step and I put a breakpoint before Quandl in the 2 loop, all the parameters to be used in the API function is good and when I execute it manually in MATLAB it works, but when its in the code, i get this error...
any suggestions?
Thank you very much
Davin.
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 1 Okt. 2014
Bearbeitet: Geoff Hayes
am 1 Okt. 2014
Davin - you seem to have three cell arrays of stocks. The set of all 500 stocks in series, the set of 100 NASDAQ stocks in series1, and the set of 400 NYSE stocks in seriesnyse.
The code then loops over all of the 500 stocks of series, and then has two inner loops - the first to loop over all NASDAQ stocks and the second to loop over all NYSE stocks. This checking with the two inner loops is repeated 500 times even once we have read the stock data. Is this the intent, especially as Tick, which is the stock you wish to get data from, doesn't ever change?
It may be easier to avoid the looping and just use find to see if Tick is in which cell array. This will greatly simplify the code and hopefully make it easier to debug because it isn't all that clear why the above code would fail with that error. Try the following
if selectedItem == 1 && selectedItem1 == 1 && selectedItem3 == 1
SD = sprintf('%02d-%02d-%04d',SMM,SDD, SYYYY);
ED = sprintf('%02d-%02d-%04d',EMM,EDD, EYYYY);
% use find to return the index of Tick within the cell array
idxSeries = find(strcmp(series,Tick));
idxSeries1 = find(strcmp(series1,Tick));
stockData = [];
if ~isempty(idxSeries) && ~isempty(idxSeries1)
Source = strcat('GOOG/NASDAQ_', Tick);
stockData = Quandl.get(Source, 'trim_start', SD, 'trim_end', ED, 'authcode', ...
'jtwf2XzCdzxhAKrXxNkm');
else
seriesinter = ismember(series,series1);
seriesnyse = series(~seriesinter);
idxSeriesNyse = find(strcmp(seriesnyse,Tick));
if ~isempty(idxSeriesNyse)
Source = strcat('GOOG/NYSE_', Tick);
stockData = Quandl.get(Source, 'trim_start', SD, 'trim_end', ED, 'authcode', ...
'jtwf2XzCdzxhAKrXxNkm');
end
end
if ~isempty(stockData)
% do stuff with stock data
end
end
Note how we avoid the looping and so once we've found our stocks, then we are finished.
When it came to initializing the data/output from the Quandl.get call, I replaced your local variable of Quandl with stockData because you should try and avoid naming your variables with names that already exist for some other purpose. If I tried the following lines of code
Quandl = Quandl.get('NSE/OIL');
Quandl = Quandl.get('NSE/OIL');
the first call would work, but the second would fail with the Attempt to reference field of non-structure array error. This makes sense because Quandl is now a local variable and not the package.
I tried the above code with a very simple set of data
series = {'AAON','AAPL','ARP'};
series1 = {'AAON','AAPL'};
with Tick alternating between 'ARP' and 'AAPL'.
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Whos finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!