For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
1 0 0 1

Eikon Codebook - Matplotlib Bar Chart Open Interest by Strike

Hi Everyone,

I am using python in codebook and trying to graph open interest by strike in a chart. I am trying to get it to illustrate the calls in one color and the puts in another color. I can get as far as the graph, however, I can not figure out how to break out the PUTCALLIND to illustrate put vs call with different colors. Any guidance would be greatly apprecaited. Thanks!


import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

%matplotlib inline

import seaborn as sns

plt.style.use('seaborn-dark-palette')

import warnings

warnings.filterwarnings('ignore')


import eikon as tr

tr.set_app_key('DEFAULT_CODE_BOOK_APP_KEY')

df, e= tr.get_data('0#IBM*.U',fields = ['PUTCALLIND','STRIKE_PRC','OPINT_1'])

df

df1 = df.groupby(['STRIKE_PRC']).sum()

df1.plot(figsize=(12,5), title='Total Open Interest Per Strike Price', kind='bar');

eikoneikon-data-apiworkspaceworkspace-data-apirefinitiv-dataplatform-eikonpythoncodebook
1615833642088.png (10.8 KiB)
1615833593538.png (24.9 KiB)
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.

1 Answer

Upvotes
Accepted
23k 22 9 14

Hello @brandonwarnecke,

Try:

import numpy as 
import pandas as 
import matplotlib.pyplot as p
%matplotlib inli
import seaborn as sns

plt.style.use('seaborn-dark-palette')

import warnings

warnings.filterwarnings('ignore')

import eikon as tr

tr.set_app_key('DEFAULT_CODE_BOOK_APP_KEY')

df, e= tr.get_data('0#IBM*.U',fields = ['PUTCALLIND','STRIKE_PRC','OPINT_1'])

df1 = df.groupby(['STRIKE_PRC','PUTCALLIND']).sum()
                   
df1.unstack().plot(figsize=(12,5), title='Total Open Interest Per Strike Price', kind='bar', color =['black','red']);

For me results in:


putcall.gif (13.6 KiB)
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