Skip to content

having trouble for calculating dataframe for put call ratios #12972

Closed
@csayantan

Description

@csayantan

Code Sample, a copy-pastable example if possible

from nsepy import get_history
from datetime import date
import pandas as pd
import requests
from io import BytesIO 
import certifi
from scipy import stats
from dateutil.relativedelta import relativedelta
import numpy as np
#import matplotlib.pyplot as plt
import datetime
import numpy as np
import matplotlib.colors as colors
import matplotlib.finance as finance
import matplotlib.dates as mdates
import matplotlib.ticker as mticker
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
import talib as ta
from talib import MA_Type
import statsmodels as sm



nf_calls=[]
nf_puts=[]
wPCR=[]

#nf_calls[['VolumeCalls']]=np.nan
#nf_puts[['VolumeCalls']]=np.nan
i=min_avalable_strikes=4850
max_avalable_strike=9400
while i in range(min_avalable_strikes,max_avalable_strike):
    nf_opt_CE = get_history(symbol="NIFTY",
                         start=date(2016,4,1), 
                         end=date(2016,4,22),
                         index=True,
                         option_type="CE",
                         strike_price=i,
                         expiry_date=date(2016,4,28))

    #print(nf_opt_CE.head())
    #if nf_opt_CE['Number of Contracts'].values >0 :
    '''if nf_opt_CE.empty :
        nf_opt_CE.append(0)
    '''

    nf_opt_PE = get_history(symbol="NIFTY",
                         start=date(2016,1,1), 
                         end=date(2016,4,18),
                         index=True,
                         option_type="PE",
                         strike_price=i,
                         expiry_date=date(2016,4,28))
    print(nf_opt_PE.head())
    #print(nf_opt_PE.head())
    #print(i)
    #if nf_opt_PE['Number of Contracts'].values>0 :
    '''if nf_opt_CE.empty :
       nf_opt_PE.append(0)
    '''

    i=i+50


#print(wPCR)

'''def PCRForSym():
    return NULL
'''



if (all(nf_opt_PE['Number of Contracts'] > 0)) or ( all(nf_opt_PE['Number of Contracts'] > 0)):
    nf_calls=nf_opt_PE['Number of Contracts']* nf_opt_PE['Close']

    nf_puts= nf_opt_CE['Number of Contracts']*nf_opt_CE['Close']
print(nf_calls.head())


#wPCR=nf_puts

print(nf_opt_PE.head())

Expected Output

some what of a ratio between 0 to 2
i need to calculate summation of nf_puts/summation of nf_calls for same day And need to plot the PCR.

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.10.final.0
python-bits: 64
OS: Linux
OS-release: 4.2.0-34-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_IN

pandas: 0.18.0
nose: None
pip: 8.1.1
setuptools: 20.3.1
Cython: 0.23.5
numpy: 1.11.0
scipy: 0.17.0
statsmodels: 0.6.1
xarray: None
IPython: 4.1.2
sphinx: None
patsy: 0.4.1
dateutil: 2.5.2
pytz: 2016.3
blosc: None
bottleneck: 1.0.0
tables: None
numexpr: 2.5.1
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: 0.8.5
lxml: None
bs4: 4.4.1
html5lib: 0.999
httplib2: 0.9
apiclient: None
sqlalchemy: 1.0.12
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions