MATLAB: Is there a way to query the Datastream source to find the start date of a time series when using the Datafeed Toolbox 3.3 (R2009a)

Datafeed Toolbox

I am using the FETCH command with the Datastream server and would like to be able to specify an arbitrary start date for the timeseries. MATLAB should then retrieve data that is available for any dates after the specified start date.
I need to do this because I am not aware of the date from which data is available for a particular security. Currently, if I have specified a start date that is earlier than the date from which data is available, I get an error message.
CONNECT = datastream(username,passwd,'Datastream',...
'<http://dataworks.thomson.com/Dataworks/Enterprise/1.0'>);
res = fetch(CONNECT,'CNGDP...D',[],'1950-01-01','2009-03-01');
disp(res)
% This request crashes - '1940-01-01' is too early a startdate.
res2 = fetch(CONNECT,'CNGDP...D',[],'1940-01-01','2009-03-01');
res2 = fetch(CONNECT,'CNGDP...D',[],'1940-01-01','2009-03-01');
??? Error using ==> datastream.fetch at 219
Invalid Start Date

Best Answer

The Datafeed toolbox (R2009a) does not support the usage of dates for which data is not available. When an earlier date is specified MATLAB throws an error. To determine the first valid date for a security, one can execute the following code
x = fetch(d,'IBM~REP','BDATE')
x.BDATE will show the start date of the data for the security.
Another workaround is to wrap the call to FETCH in a TRY-CATCH construct. As an example,
startdate = datenum('01-Jan-1940');
while(true)
try
fetch(....., trydate);
break;
catch MException
trydate+1;
disp(['Trying start day: ', datestr(trydate)])
end %end of CATCH
end % end of WHILE