New posts are disabled while we improve the user experience.

You can browse the site, or for urgent issues, raise a query at MyAccount.

question

Upvotes
Accepted
18 0 0 5

Retrieving historic options volume across all expiries and strikes on a contract in python

Hi,

I am looking for a method to find all of the options volume that was traded yesterday (across all strikes for all expiries) on the children of the ric 0#CFI2+. As in to answer the question 'how many EUA options traded yesterday in total?'.

For futures I have used this method:

all_rics = ['CFI2' + 'c{}'.format(x) for x in range(1, 17)]
rd.get_history(universe = all_rics,
              fields = ['ACVOL_UNS'], 
              interval = 'daily' ,
              start = (datetime.today() - timedelta(days=2)).strftime('%Y-%m-%d ') + '00:00:00',
              end = (datetime.today() - timedelta(days=1)).strftime('%Y-%m-%d ') + '00:00:00',
                    )

I understand that I could do it specifying all the individual contracts manually but this is something I would really like to avoid. Any help would be much appreciated.

Thanks.

python#technology#contentvolume
icon clock
10 |1500

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

Upvote
Accepted
7.5k 18 2 8

Hi @david.hartley ,


Thank you for your question. I would suggest the following approach:

First, we can get the list of chains for the asset you are after using rd.discovery.Chain. Please see below:

efom_chains = list(rd.discovery.Chain('0#EFOM+'))
efom_chains

screenshot-2023-02-08-at-095733.png


Next, we can pass the chain rics from eom_chains above to rd.get_history function to get the historical data for the all options under the chain:

chain_ric = rd.discovery.Chain(efom_chains[0])
rd.get_history(universe = chain_ric,
              fields = ['ACVOL_UNS', 'ELG_ACVOL', 'BLKVOLUM'], 
              interval = 'daily' ,
              start = (datetime.today() - timedelta(days=2)).strftime('%Y-%m-%d ') + '00:00:00',
              end = (datetime.today() - timedelta(days=1)).strftime('%Y-%m-%d ') + '00:00:00',
                    )

screenshot-2023-02-08-at-100247.png

I hope this helps, please let me know should you have any further questions.


Best regards,

Haykaz


icon clock
10 |1500

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

Upvote
18 0 0 5

Hi Haykaz,


Thank you this solution works perfectly. Had been trying to get this to work for ages so really appreciate the help.


Best,
David

icon clock
10 |1500

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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