SBI Price = 1821.35
BUY 1 lot of 1750 PUT @ 11.90
Delta = -0.22
Theta = -1.46
SELL 1 lot of 1800 PUT @ 24.10
Delta = -0.38
Theta = -1.64
Credit = 12.2
Return/Risk = 12.2/37.8
import matplotlib.pyplot as plt
Next we need floating point version of range, and the best implementation happens to be the following
def drange(start, stop, step): r = start while r < stop: yield r r += step
def processOptionStrategy(strat, price_point): strategy = strat.split(' ') if (strategy[2] == 'Stock'): volume = float(strategy[1]) price = float(strategy[3]) else: try: volume = float(strategy[1]) strike = float(strategy[2]) price = float(strategy[4]) except: print "dumbass...numbers" if strategy[0] == 'Long': if strategy[3] == 'Call': if price_point < strike: return -(price * volume) else: return (((price_point - strike) * volume) -(price * volume)) elif strategy[3] == 'Put': if price_point > strike: return -(price * volume) else: return (((strike - price_point) * volume) -(price * volume)) elif strategy[2] == 'Stock': return (price_point - price) * volume else: print "...Call or put" elif strategy[0] == 'Short': if strategy[3] == 'Call': if price_point < strike: return (price * volume) else: return ((price * volume)) - ((price_point - strike) * volume) elif strategy[3] == 'Put': if price_point > strike: return (price * volume) else: return ((price * volume)) - ((strike - price_point) * volume) elif strategy[2] == 'Stock': return (price - price_point) * volume else: print "...Call or put" else: print "...Long or short"
def plotStrategy(strats, min1=0.9, max1=1.1): stratvals = [] min = 100000 max = 0 xticks = [] for row in strats: valstr = row.split(' ')[2] if valstr == 'Stock': val = float(row.split(' ')[3]) xticks.append(val) else: val = float(valstr) if val < min: min = val if val > max: max = val stratvals.append(val) xticks.append(val) yvals = [] xvals = [] max = max * max1 min = min * min1 for i in drange(min, max, (max - min) / 200.0 ): xvals.append(i) sum = 0 for strat in strats: sum = sum + processOptionStrategy(strat, i) yvals.append(sum) if i in stratvals: xticks.append(i) if len(yvals) >3: if (abs(yvals[-1] + yvals[-2]) < abs(yvals[-1] - yvals[-2])): xticks.append(i-(max - min) / 200.0) plt.plot(xvals, yvals) plt.axhline(0, color='black') plt.xticks(xticks) plt.setp(plt.xticks()[1], rotation=60) plt.grid(b=True, which='major', color='g', linestyle='--')
import urllib import csv import os from datetime import date fi = open("symbolList.csv", "rb") symList = csv.reader(fi) dt = date.today() if not os.path.exists("./Intraday_YAHOO"): os.makedirs("./Intraday_YAHOO") direc = "./Intraday_YAHOO/"+str(dt.year)+str(dt.month).zfill(2)+ \
str(dt.day).zfill(2) if not os.path.exists(direc): os.makedirs(direc) for row in symList: print row[0],row[1] url_chart = "http://chart.finance.yahoo.com/z?s=" + row[0] + "&t=1d&q=&l=off&z=m&a=v&p=s&lang=en-US®ion=US" file_chart = direc+"/"+row[1]+".jpg" urllib.urlretrieve(url_chart, file_chart)
^NSEI,NSEI ACC.NS,ACC AMBUJACEM-EQ.NS,AMBUJACEM-EQ AXISBANK.NS,AXISBANK
~\ | getNifty.py \---Intraday_YAHOO \---20130716 | ACC.jpg | AMBUJACEM-EQ.jpg | AXISBANK.jpg \---20130717 \---20130718 \---20130719