# Using phpadmin to load mysql by importing from some of these sources
# http://www.cboe.com/delayedquote/quote-table
# https://datashop.cboe.com/option-quotes-end-of-day-with-calcs
# https://www.stock-data-solutions.com/download.htm
# https://www.worldtradingdata.com/services
import mysql.connector
optionsdb = mysql.connector.connect(
host="localhost",
user="root",
#passwd=""
database="CSV_DB"
)
optionscursor = optionsdb.cursor()
optionscursor.execute("select convert(`expiration`, CHAR) as expiration, `option_type` as `T`,
convert(`strike`, CHAR) as `strike`, convert(`delta_1545`, CHAR) as `delta`, convert(`vega_1545`,
CHAR) as `vega`, convert(`theta_1545`, CHAR) as `theta` FROM `GREEKS` where `open_interest` > 50 and
ABS(`delta_1545`) > .20 and ABS(`theta_1545`) < 1
order by `expiration` asc, `option_type` asc, `strike` asc limit 100")
optionsresult = optionscursor.fetchall()
colheaders = []
colwidths = []
coldivider = '|'
colseparator = '+'
for names in optionscursor.description:
colwidths.append(11)
colheaders.append(names[0])
for w in colwidths:
coldivider += " %-"+"%ss |" % (w,)
colseparator += '-'*w + '--+'
print(colseparator)
print(coldivider % tuple(colheaders))
print(colseparator)
for coldata in optionsresult:
print(coldivider % coldata)
After running, one may get something that looks like this:

No comments:
Post a Comment