question

Upvotes
Accepted
5 0 1 2

How can I run Rhistory in a loop?

What I would like to do is to run RHistoryQuery get the results from callback event OnImage and pass it to AdInterp function. Is it possible to loop the following steps for different Instrument lists (for the Rhistory) and retrieve only the results from the Adinterp?

Best Regards,

Adam

eikoneikon-com-apicallback
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
Accepted
39.2k 75 11 27

Yes, it's possible and there's more than one way of doing it.

First of all you can retrieve multiple instruments in a single request, just like you can with RHistory worksheet function.

Then, if for whatever reason you need to retrieve your instruments one by one, you can do this by introducing a module level counter. You will need to initialize it and call the data requesting procedure for the first instrument in the list. In the OnImage event handler you can apply AdInterp function and output the result. Then you can increment the counter, check if the counter is still in range for your list of instruments, and if yes call the requesting procedure for the next instrument from the list. This process will break if there are any invalid instruments in the list. To handle it you'll also need to implement the same logic in the OnError event handler.

Finally, you can create an instance of RHistoryQuery object per instrument, and place all these objects into a collection, so they remain in memory while the data is being retrieved. In this case to manage the event handling you will need to create a custom class.

These are your options.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
5 0 1 2

Thank you Alex! I need to interpolate a spread for a list of instruments, hence asking for the Rhistory loop. By the way, do you happen to have an example of the module level counter...it would definitely save me some time.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
39.2k 75 11 27

I cannot say I understand why you prefer retrieving timeseries one instrument at a time over retrieving them all at once, which will be faster. Once you've retrieved the timeseries you can apply whatever analytics you want to the data you retrieved. Whatever you rationale, attached is an example of doing both: retrieving the list of instruments in one request and retrieving the list in a loop one instrument at a time. I hope you find it useful.

rhistoryverybasicsample.zip


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
5 0 1 2

Thank you so much Alex! This is exactly what I needed. I have number of chain RICs from which I intended to get the Spread curves, which were used in the Adinterp function.

Thanks again!

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea