With such a web service, you can of course do multiple calls to calculate multiple option
values quite easily:
In [ 96 ]: %%time
urlpara = ‘http://localhost:4000/application?V0=25&kappa=2.0’
urlpara += ‘&theta=25&sigma=1.0&zeta=0.0&T=1&r=0.02&K=%s’
strikes = np.linspace( 20 , 30 , 50 )
results = []
for K in strikes:
results.append(float(urllib.urlopen(urlpara % K).read()))
results = np.array(results)
Out[96]: CPU times: user 64 ms, sys: 20 ms, total: 84 ms
Wall time: 196 ms
In [ 97 ]: results
Out[97]: array([ 4.91296701, 4.71661296, 4.52120153, 4.32692516, 4.1339945 ,
3.94264561, 3.75313813, 3.56575972, 3.38079846, 3.19858765,
3.01946028, 2.8437621 , 2.67184576, 2.50406508, 2.34078693,
2.18230495, 2.02898213, 1.88111287, 1.738968 , 1.60280064,
1.47281111, 1.34917004, 1.23204859, 1.12141092, 1.01739405,
0.9199686 , 0.82907686, 0.74462353, 0.66647327, 0.59445387,
0.52843174, 0.46798166, 0.41300694, 0.36319553, 0.31824647,
0.27785656, 0.24171678, 0.20951651, 0.18094732, 0.1557064 ,
0.1334996 , 0.11414975, 0.09710449, 0.08234678, 0.06958767,
0.05859317, 0.04915788, 0.04109348, 0.03422854, 0.02840802])
One advantage of this approach is that you do not use your local resources to get the
results, but rather the resources of a web server — which might also use, for example,
parallelization techniques. Of course, in our example all is local and the web service uses
the local computing resources. Figure 14-13 shows the valuation results graphically,
concluding this section:
In [ 98 ]: import matplotlib.pyplot as plt
%matplotlib inline
plt.plot(strikes, results, ‘b’)
plt.plot(strikes, results, ‘ro’)
plt.grid(True)
plt.xlabel(‘strike’)
plt.ylabel(‘European call option value’)
Figure 14-13. Value of European volatility call option for different strikes
WEB SERVICES ARCHITECTURE
The web services architecture is often a powerful and efficient alternative to the provision of Python-based
analytical functionality, or even whole applications. This holds true for the Internet as well as for models where
private networks are used. This architecture also simplifies updates and maintenance, since such services are
generally provided in a centralized fashion.