Download code

Jump to: navigation, search

Back to Thomson_Financial_DataStream_data_access_(Matlab)

Download for Windows: single file, zip

Download for UNIX: single file, zip, tar.gz, tar.bz2

datastream2struct.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Thomson_Financial_DataStream_data_access_(Matlab)?oldid=19334
14 
15 function data = datastream2struct( vals)
16 % DATASTREAM2STRUCT - convert
17 % example:
18 %   ds_connection = datastream('login', 'password','Datastream');
19 %   vals          = fetch(ds_connection, 'F:RENU', {'P', 'PO', 'PH', 'PL', 'VO'})
20 %   data          = datastream2struct(vals)
21 
22 
23 
24 instr = vals.Instrument;
25 d     = findstr(instr, '~=');
26 sname = instr(d+2:end);
27 d     = [0, findstr(sname, ','), length(sname)+1];
28 names = {};
29 for i=1:length(d)-1
30     names{end+1} = sname(d(i)+1:d(i+1)-1);
31 end
32 
33 nval  = repmat(nan,length(vals.DATE), length(names));
34 for n=1:length(names)
35    nval(:,n) = cellfun(@(x)(str2num(x)), vals.(names{n}));
36 end
37 
38 dts = cellfun(@(x)(datenum(x, 'yyyy-mm-ddTHH:MM:SS')), vals.DATE);
39 
40 data = struct('title', vals.DISPNAME, 'value', nval, 'date', dts, 'names', {names}, ...
41               'symbol', struct('type', 'datastream', 'value', vals.SYMBOL), 'currency', vals.CCY);
42 


hijacker
hijacker
hijacker
hijacker