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.

Best Answer

  • 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

Answers

  • 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