-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
126 lines (105 loc) · 8.86 KB
/
Copy pathapp.py
File metadata and controls
126 lines (105 loc) · 8.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#Option Strategy Web Applet
from flask import Flask, render_template, request, redirect, session
from datetime import date
app = Flask(__name__,static_folder="static")
host = 'http://127.0.0.1:5000/'
year = date.today().year
@app.route('/', methods=['GET'])
def index():
return render_template('home.html',Year=year)
@app.route('/strategies.html', methods=['GET'])
def strats():
delta = request.args.get('delta')
gamma = request.args.get('gamma')
theta = request.args.get('theta')
vega = request.args.get('vega')
net = request.args.get('net')
Strategies = get_strats(delta,gamma,theta,vega,net)
return render_template('strategies.html',Strategies=Strategies,greeks=[delta,gamma,theta,vega,net],Year=year)
@app.route('/strategy.html',methods=['GET'])
def strat():
return render_template('strategy.html',strategy=strategy(request.args.get('strategy')),Year=year)
def get_strats(delta,gamma,theta,vega,net):
strats = []
if delta == 'Long':
strats.extend(strategies['ldelta'])
elif delta == 'Neutral':
strats.extend(strategies['ndelta'])
elif delta == 'Short':
strats.extend(strategies['sdelta'])
else:
strats = [y for x in strategies.values() for y in x]
if gamma == 'Long':
strats = list(set(strats) & set(strategies['lgamma']))
elif gamma == 'Neutral':
strats = list(set(strats) & set(strategies['ngamma']))
elif gamma == 'Short':
strats = list(set(strats) & set(strategies['sgamma']))
if theta == 'Long':
strats = list(set(strats) & set(strategies['ltheta']))
elif theta == 'Neutral':
strats = list(set(strats) & set(strategies['ntheta']))
elif theta == 'Short':
strats = list(set(strats) & set(strategies['stheta']))
if vega == 'Long':
strats = list(set(strats) & set(strategies['lvega']))
elif vega == 'Neutral':
strats = list(set(strats) & set(strategies['nvega']))
elif vega == 'Short':
strats = list(set(strats) & set(strategies['svega']))
if net == 'Credit':
strats = list(set(strats) & set(strategies['credit']))
elif net == 'Debit':
strats = list(set(strats) & set(strategies['debit']))
strats = list(set(strats))
strats.sort(key=lambda x: order[x])
for c,i in enumerate(strats):
strats[c] = [i,descriptions[i]]
return strats
def strategy(name):
return [name,descriptions[name]]
strategies = {
'ldelta':['Long Call','Short Put','Bull Call Spread','Bull Put Spread'],
'lgamma':['Long Call','Long Put','Long Straddle','Long Strangle','Reverse Iron Butterfly','Reverse Iron Condor','Short Call Butterfly','Short Call Condor','Short Put Butterfly','Short Put Condor'],
'ltheta':['Short Call','Short Put','Iron Butterfly','Iron Condor','Long Call Butterfly','Long Call Condor','Long Put Butterfly','Long Put Condor','Short Straddle','Short Strangle'],
'lvega':['Long Call','Long Put','Long Straddle','Long Strangle','Reverse Iron Butterfly','Reverse Iron Condor','Short Call Butterfly','Short Put Butterfly','Short Call Condor','Short Put Condor'],
'ndelta':['Iron Butterfly','Iron Condor','Long Call Butterfly','Long Call Condor','Long Put Butterfly','Long Put Condor','Long Strangle','Long Straddle','Reverse Iron Butterfly','Reverse Iron Condor','Short Call Butterfly','Short Call Condor','Short Put Butterfly','Short Put Condor','Short Strangle','Short Straddle'],
'ngamma':['Bull Call Spread','Bull Put Spread','Bear Call Spread','Bear Put Spread'],
'ntheta':['Bull Call Spread','Bull Put Spread','Bear Call Spread','Bear Put Spread'],
'nvega':['Bull Call Spread','Bull Put Spread','Bear Call Spread','Bear Put Spread'],
'sdelta':['Short Call','Long Put','Bear Call Spread','Bear Put Spread'],
'sgamma':['Short Call','Short Put','Iron Butterfly','Iron Condor','Long Call Butterfly','Long Call Condor','Long Put Butterfly','Long Put Condor','Short Straddle','Short Strangle'],
'stheta':['Long Call','Long Put','Long Straddle','Long Strangle','Reverse Iron Butterfly','Reverse Iron Condor','Short Call Butterfly','Short Call Condor','Short Put Butterfly','Short Put Condor'],
'svega':['Short Call','Short Put','Iron Butterfly','Iron Condor','Long Call Butterfly','Long Call Condor','Long Put Butterfly','Long Put Condor','Short Straddle','Short Strangle'],
'credit':['Short Call','Short Put','Bull Put Spread','Bear Call Spread','Short Straddle','Short Strangle','Short Call Butterfly','Short Put Butterfly','Iron Butterfly','Short Call Condor','Short Put Condor','Iron Condor'],
'debit':['Long Call','Long Put','Bull Call Spread','Bear Put Spread','Long Straddle','Long Strangle','Long Call Butterfly','Long Put Butterfly','Reverse Iron Butterfly','Long Call Condor','Long Put Condor','Reverse Iron Condor']
}
descriptions = {
'Long Call':"Buying a single call option. Limited risk with unliimited potential profit. Bullish. Net debit.",
'Long Put':"Buying a single put option. Limited risk with unlimited potential profit. Bearish. Net debit.",
'Short Call':"Selling a single call option. Unlimited risk with limited potenital profit. Bearish. Net credit.",
'Short Put':"Selling a single put option. Unlimited risk with limited potenital profit. Bullish. Net credit.",
'Bull Call Spread':"Simple bullish spread made with calls. Limited risk with limited potential profit. Net debit.",
'Bull Put Spread':"Simple bullish spread made with puts. Limited risk with limited potential profit. Net credit.",
'Bear Call Spread':"Simple bearish spread made with calls. Limited risk with limited potential profit. Net credit.",
'Bear Put Spread':"Simple bearish spread made with puts. Limited risk with limited potential profit. Net debit.",
'Long Straddle':"A non-directional, two legged strategy made by buying a call and a put an the same strike price. Profits when there is significant price movement. Limited risk with unlimited potential profit. Net debit.",
'Short Straddle':"A non-directional, two legged strategy made by selling a call and a put at the same strike price. Profits when there is little price movement. Unlimited risk with limited potential profit. Net credit.",
'Long Strangle':"A non-directional, two legged strategy made by buying a calls and a put. Profits when there is significant price movement. Limited risk with unlimited potential profit. Net debit.",
'Short Strangle':"A non-directional, two legged strategy made by selling a call and a put. Profits when there is little price movement. Unlimited risk with limited potential profit. Net credit.",
'Long Call Butterfly':"A non-directional, three legged strategy made with calls. Profits when there is little price movement. Limited risk with limited potential profit. Net debit",
'Long Put Butterfly':"A non-directional, three legged strategy made with puts. Profits when there is little price movement. Limited risk with limited potential profit. Net debit",
'Short Call Butterfly':"A non-directional, three legged strategy made with calls. Profits when there is significant price movement. Limited risk with limited potential profit. Net credit.",
'Short Put Butterfly':"A non-directional, three legged strategy made with puts. Profits when there is significant price movement. Limited risk with limited potential profit. Net credit.",
'Iron Butterfly':"A non-directional, four legged strategy made with both calls and puts. Profits when there is little price movement. Limited risk with limited potential profit. Net Credit",
'Reverse Iron Butterfly':"A non-directional, four legged strategy made with both calls and puts. Profits when there is significiant price movement. Limited risk with limited potential profit. Net Debit",
'Long Call Condor':"A non-directional, four legged strategy made with calls. Profits when there is little price movement. Limited risk with limited potential profit. Net debit.",
'Long Put Condor':"A non-directional, four legged strategy made with puts. Profits when there is significant price movement. Limited risk with limited potential profit. Net debit.",
'Short Call Condor':"A non-directional, four legged strategy made with calls. Profits when there is little price movement. Limited risk with limited potential profit. Net credit.",
'Short Put Condor':"A non-directional, four legged strategy made with puts. Profits when there is little price movement. Limited risk with limited potential profit. Net credit.",
'Iron Condor':"A non-directional, four legged strategy made with both calls and puts. Profits when there is little price movement. Limited risk with limited potential profit. Net credit.",
'Reverse Iron Condor':"A non-directional, four legged strategy made with both calls and puts. Profits when there is significant price movement. Limited risk with limited potential profit. Net debit."
}
order = {i:c for c,i in enumerate(descriptions.keys())}
if __name__ == "__main__":
app.run(debug=True)