-
Notifications
You must be signed in to change notification settings - Fork 0
/
rapidAPI_option_exotic_example1
105 lines (87 loc) · 4.79 KB
/
rapidAPI_option_exotic_example1
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
##### this example shows how to utilize the pricing and risk function listed on rapidAPI.com
##### for https://rapidapi.com/kiann/api/kiann_options_exotics/
##### to generate the pricing, and risk greeks given the user's own market-data
#### below are basic python modules to be loaded, when a low-level IT programmer should know
import requests
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
############# this is the set of trade and risk request input parameters ##############
strike_ = 1900 # this is the strike of the Touch Barrier Option, Vanilla Call
fwd_ = 1750 # this is the current spot price
rf_ = 0.0 # this is the risk-free rate, can set to zero if it is short-expiry
vol_ = 0.3 # this is the (BlackScholes) lognormal volatility
type_ = "Call" # this is the type of option, whether Call or Put
type_Barrier_ = "UpOut" # the type of 1-touch knock-out -> Up-and-Out, or Up-and-In, or Down-and-Out, Down-and-In
strike_Barrier_ = 2100 # this is the strike relative to type_Barrier
digital_ = 0 # this specifies whether the underlying Vanilla Call is a Digital or European
sign_ = 1 # this specifies where you want the option to Buy (1) or Sell (0)
expiry_ = "1m" # this is the expiry of the option, with 1m, 2m etc, and 1y
date_ = "03-04-2023" # this start date of the option
arg_ = "NPV" # this specifies the type of return results. NPV refers to spot premium.
rapid_key = <your rapidAPI.com> # this is your rapid-API key
############ end of the set of trade and risk request parameters from the user ###############
######## this is a standard set of request.get function that pulls the pricing-analytics #######
####### it does not need to be changed (generally) ###########
url = "https://kiann_options_exotics.p.rapidapi.com/Barrier"
querystring = {"div_":"0.0","strike_": strike_,"fwd_": fwd_,"rf_": rf_,"vol_": vol_,"type_": type_,\
"type_Barrier": type_Barrier_,"H_strike": strike_Barrier_,"digital_": digital_,"sign_": sign_,\
"time_":expiry_,"date_": date_,"arg_":arg_,"ret_":"0"}
headers = {
"X-RapidAPI-Key": rapid_key,
"X-RapidAPI-Host": "kiann_options_exotics.p.rapidapi.com"
}
##################################################
################ this is a loop where you can see using the python request.get(), we are calling the various pricing and risk greek values ############
fwds_ = np.arange(float(0.7 * fwd_), float(1.3 * fwd_), float(0.025 * fwd_))
barrier_npv_ = []
barrier_delta_ = []
barrier_gamma_ = []
barrier_vega_ = []
for fwd_ in fwds_:
querystring = {"div_":"0.0","strike_": strike_,"fwd_": fwd_,"rf_": rf_,"vol_": vol_,"type_": type_,\
"type_Barrier": type_Barrier_,"H_strike": strike_Barrier_,"digital_": digital_,"sign_": sign_,\
"time_":expiry_,"date_": date_,"arg_":"NPV","ret_":"1"}
try:
value_ = requests.request("GET", url, headers=headers, params=querystring).json()
except:
value_ = 0.0 # this is because the barrier touched
barrier_npv_.append(value_)
querystring = {"div_":"0.0","strike_": strike_,"fwd_": fwd_,"rf_": rf_,"vol_": vol_,"type_": type_,\
"type_Barrier": type_Barrier_,"H_strike": strike_Barrier_,"digital_": digital_,"sign_": sign_,\
"time_":expiry_,"date_": date_,"arg_":"delta","ret_":"1"}
try:
value_ = requests.request("GET", url, headers=headers, params=querystring).json()
except:
value_ = 0.0 # this is because the barrier touched
barrier_delta_.append(value_)
querystring = {"div_":"0.0","strike_": strike_,"fwd_": fwd_,"rf_": rf_,"vol_": vol_,"type_": type_,\
"type_Barrier": type_Barrier_,"H_strike": strike_Barrier_,"digital_": digital_,"sign_": sign_,\
"time_":expiry_,"date_": date_,"arg_":"gamma","ret_":"1"}
try:
value_ = requests.request("GET", url, headers=headers, params=querystring).json()
except:
value_ = 0.0 # this is because the barrier touched
barrier_gamma_.append(value_)
querystring = {"div_":"0.0","strike_": strike_,"fwd_": fwd_,"rf_": rf_,"vol_": vol_,"type_": type_,\
"type_Barrier": type_Barrier_,"H_strike": strike_Barrier_,"digital_": digital_,"sign_": sign_,\
"time_":expiry_,"date_": date_,"arg_":"vega","ret_":"1"}
try:
value_ = requests.request("GET", url, headers=headers, params=querystring).json()
except:
value_ = 0.0 # this is because the barrier touched
barrier_vega_.append(value_)
##################################
############# below we plot the graph showing the returned values #####################
plt.show()
plt.plot(fwds_, barrier_npv_)
plt.legend(['npv'])
plt.show()
plt.plot(fwds_, barrier_delta_)
plt.legend(['delta'])
plt.show()
plt.plot(fwds_, barrier_gamma_)
plt.legend(['gamma'])
plt.show()
plt.plot(fwds_, barrier_vega_)
plt.legend(['vega'])