Access Chunk records in MATLAB

May I ask how to read the the following data in MATLAB?


timeSeriesRequestSetup = timeSeries.SetupDataRequest('ATGOV1YZ=R');

timeSeriesRequestSetup.WithView('DISC_FACTR');

timeSeriesRequestSetup.WithInterval(ThomsonReuters.Desktop.SDK.DataAccess.TimeSeries.CommonInterval.Daily);

timeSeriesRequestSetup.From(System.DateTime(2021,06,30));

timeSeriesRequestSetup.To(System.DateTime(2021,07,30));

timeSeriesRequestSetup.OnDataReceived(@DataReceivedCallback);

timeSeriesRequestSetup.CreateAndSend();


When DataReceivedCallback is trigged, the following line returns an empty structure.

records = chunk.Records.GetEnumerator();

Best Answer

  • @xuewei.zhu

    How many OnDataReceived events are raised when you execute your code in Matlab, and what's the value of chunk.IsLast property returned into the event handler? Can you also create an event handler for OnStatusUpdated event of ThomsonReuters.Desktop.SDK.DataAccess.TimeSeries.ITimeSeriesDataRequestSetup interface and see if this event is raised and what info you can get out of it about the status of the request?

Answers

  • @xuewei.zhu

    I can retrieve the data properly with the following code when using Visual Studio.

     request[0]= timeSeries.SetupDataRequest("ATGOV1YZ=R")
        .WithAllFields()
        .WithView("DISC_FACTR")
        .WithInterval(CommonInterval.Daily)
        .From(new DateTime(2021,6, 30))
        .To(new DateTime(2021,7,30))
        .OnDataReceived(OnTSReceived)
        .OnStatusUpdated(OnTSStatus)
        .CreateAndSend();

    The OnTSReceived callback was called twice.

    On the first call, the value of chunk.IsLast is false and the returned enumerator contains the data from 6/30/2021 to 7/30/2021.

    1629088982670.png

    On the second call, the value of chunk.IsLast is true and the returned enumerator is empty.

    1629089083640.png


  • Yes. I can retrieve data using visual studio as well. But not able to read it in to MATLAB properly.
  • @Alex Putkov.

    The OnDataReceived events are raised twice. The first one is empty but the second one is not!

    How should I read out the data returned from records.current?

    I tried ToBarCode but all properties has no value stored.


  • It's normal and expected that the OnDataReceived event may be raised several times, and that for some of these events the chunk returned into the event handler may be empty. There's a number of ways to extract the timeseries data from the chunk object. Using ToBarRecord (for a single record) or ToBarRecords (for a collection of records) should work when you retrieve the data that can be summarized into OHLC (open/high/low/close). This includes timeseries for ATGOV1YZ=R when you use .WithView("DISC_FACTR") and .WithInterval(CommonInterval.Daily). In this particular example, since there's only one value per day, only the Close property of IBarData will be populated while Open, High and Low will be empty. There may also be some records where all properties are empty (e.g. for dates that fall on a holiday). For more examples of extracting timeseries data from the chunk object see the tutorial for Timeseries data retrieval using Eikon .NET SDK.

  • I have tried again using ToBarRecord but all the properties are empty. However, I found this ToTickRecord which has the correct value in it!

    empty bar.PNGToTickRecord.PNG

  • Are you using .WithInterval(CommonInterval.Daily)? The result you got suggests you're using .WithInterval(CommonInterval.Tick).

  • timeSeriesRequestSetup.WithInterval(ThomsonReuters.Desktop.SDK.DataAccess.TimeSeries.CommonInterval.Daily);

  • My bad. Records returned for DISC_FACTR view with CommonInterval.Daily actually cannot be converted to bar records. You can convert them to tick records, as you already discovered. Or you can extract the data without any conversion using records.Current.Values property or using records.Current.AllFields property. E.g. records.Current.Values.First() returns the value of the discount factor and records.Current.Values.Last() returns the timestamp.

  • @Alex Putkov.

    I am quite interest about how to extract data without conversions because it's quite ugly to use different conversion for different data.


    I tried to use the following

    records.Current.Values.First()

    No appropriate method, property, or field 'First' for class 'System.Collections.Generic.Dictionary*ValueCollection<System*String,System*Object>'.


    Can you suggest further about how to access data without conversion for any data types? thanks.

  • I'm not sure I understand why you get this error message. System.Collections.Generic.Dictionary.ValueCollection returned by records.Current.Values implements IEnumerable interface, which in turn provides First() method. This surely works in Visual Studio. Perhaps .NET extension methods cannot be used in Matlab? I'm afraid I don't have access to Matlab right now to verify. Well, you could use the same methods to traverse the dictionary returned by records.Current.AllFields as you use to traverse the collection of records returned by chunk.Records:

    allFields = records.Current.AllFields.GetEnumerator();
    while allFields.MoveNext()
        disp(allFields.Current.Key)
        disp(allFields.Current.Value)