Pulling historical forward curves

So, it's easy to pull forward curves via get_data. For example:

import eikon as ek
ek.set_app_key(<YOUR APP KEY>)

rics = ['0#CL:']
fields = ['CF_NAME','EXPIR_DATE','CF_CLOSE']

df, err = ek.get_data(rics,fields)

print(df)

Instrument CF_NAME EXPIR_DATE CF_CLOSE
0 CLU2 LIGHT CRUDE SEP2 2022-08-22 91.93
1 CLV2 LIGHT CRUDE OCT2 2022-09-20 91.20
2 CLX2 LIGHT CRUDE NOV2 2022-10-20 90.47
3 CLZ2 LIGHT CRUDE DEC2 2022-11-21 89.68
4 CLF3 LIGHT CRUDE JAN3 2022-12-20 88.90
.. ... ... ... ...
121 CLV32 CL OCT32 2032-09-21 66.10
122 CLX32 CL NOV32 2032-10-20 66.21
123 CLZ32 CL DEC32 2032-11-19 66.22
124 CLF33 CL JAN33 2032-12-20 66.34
125 CLG33 CL FEB33 2033-01-20 66.51

[126 rows x 4 columns]

But, I want to be able to do the same for historical curves. I.e., the same curve from a month ago. Meaning, I run the script and the pull would also show the August 2022 contract (if the script was executed prior to its the Aug expiration in July). I want to also be able to easily pull three months ago, etc. It can be separate scripts...doesn't all have to be in one script.

Is there an easy way to do this?

Tagged:

Best Answer

  • aramyan.h
    Answer ✓

    Hi @Corey.Stewart ,


    Thank you for your question. Unfortunately, you can't mix fundamental and real data with a chain instrument. However, you can extract instruments from the chain and request historical prices for the individual instrument by introducing a parameter argument as shown below:

    rics = df['Instrument'].to_list()
    fields = ['TR.CLOSEPRICE']
    parameters = {'Frq':'D','SDate': '2022-07-12','EDate': '2022-08-12'}

    prices, err = ek.get_data(rics,fields, parameters)

    prices


    Please let me know should you have any further questions.


    Best regards,

    Haykaz

Answers

  • Thanks, but I already have created something like this with continuous (CLc1, CLc2...) contracts. There's no way to pull a chain like 0#CL: when the contracts were different? I.e., last month the front contract would have been August. I'm assuming I could pull history on individual contracts (CLK1, for example), but is not very useful as this script will be used continuously and needs to update.


    TL;DR: I need data for 0#CL: as it was in certain points in history, e.g., 0#CL: on March 1, 2022.
  • Unfortunately, as I am aware (you can judge from the post here as well) you cannot get historical chains.

  • Thank you.