Advertisement
Guest User

Untitled

a guest
Jun 12th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # SPDX-License-Identifier: Unlicense
  4. # http://www.h2t.ru/blog/9743.html
  5. from __future__ import division
  6. import numpy as np
  7. import scipy.stats as ss
  8. import datetime as dt
  9. from matplotlib import pyplot as plt
  10.  
  11. def black_price_call(f, strike, sigma, t):
  12.     d1 = (np.log(f / strike) + sigma * sigma * t / 2) / (sigma * np.sqrt(t))
  13.     d2 = d1 - sigma * np.sqrt(t)
  14.     return f * ss.norm.cdf(d1) - strike * ss.norm.cdf(d2)
  15.  
  16. def time_to_exp(now, exp):
  17.     return (exp - now).total_seconds() / (60 * 60 * 24 * 365)
  18.  
  19. now = dt.datetime(2018,6,11,23,59,59)
  20. exp = dt.datetime(2018,7,19,23,59,59)
  21. t = time_to_exp(now, exp)
  22. price = black_price_call(63456, 65000, 0.1536, t)
  23. print price
  24.  
  25. x = []
  26. y = []
  27. d = now
  28. while d < exp:
  29.     price = black_price_call(63456, 65000, 0.1536, time_to_exp(d, exp))
  30.     x.append(d)
  31.     y.append(price)
  32.     d += dt.timedelta(days=1)
  33. fig = plt.figure()
  34. graph = fig.add_subplot(111)
  35. graph.plot(x, y)
  36. plt.grid()
  37. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement