Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # SPDX-License-Identifier: Unlicense
- # http://www.h2t.ru/blog/9743.html
- from __future__ import division
- import numpy as np
- import scipy.stats as ss
- import datetime as dt
- from matplotlib import pyplot as plt
- def black_price_call(f, strike, sigma, t):
- d1 = (np.log(f / strike) + sigma * sigma * t / 2) / (sigma * np.sqrt(t))
- d2 = d1 - sigma * np.sqrt(t)
- return f * ss.norm.cdf(d1) - strike * ss.norm.cdf(d2)
- def time_to_exp(now, exp):
- return (exp - now).total_seconds() / (60 * 60 * 24 * 365)
- now = dt.datetime(2018,6,11,23,59,59)
- exp = dt.datetime(2018,7,19,23,59,59)
- t = time_to_exp(now, exp)
- price = black_price_call(63456, 65000, 0.1536, t)
- print price
- x = []
- y = []
- d = now
- while d < exp:
- price = black_price_call(63456, 65000, 0.1536, time_to_exp(d, exp))
- x.append(d)
- y.append(price)
- d += dt.timedelta(days=1)
- fig = plt.figure()
- graph = fig.add_subplot(111)
- graph.plot(x, y)
- plt.grid()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement