![]() |
How to graphically represent this function? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: How to graphically represent this function? (/thread-17909.html) |
How to graphically represent this function? - dc996 - Apr-28-2019 Hi everyone, I've tried multiple times to represent this function in Python, but I am still unsuccessful. This is the function: def CON_call_price(spot,strike,tau,sigma,r,q,phi,x): d1 = (log(spot/strike)+(r-q+0.5*sigma**2)*tau)/(sigma*sqrt(tau)) d2 = (d1-sigma*sqrt(tau)) y = x*exp(-r*tau)*norm.cdf(d2) return yAnd this is how I tried to represent it: from math import exp, log, sqrt from scipy.stats import norm import matplotlib.pyplot as plt plt.style.use('ggplot') plt.rcParams['xtick.labelsize'] = 14 plt.rcParams['ytick.labelsize'] = 14 plt.rcParams['figure.titlesize'] = 18 plt.rcParams['figure.titleweight'] = 'medium' plt.rcParams['lines.linewidth'] = 2.5 def CON_call_price(spot,strike,tau,sigma,r,q,phi,x): d1 = (log(spot/strike)+(r-q+0.5*sigma**2)*tau)/(sigma*sqrt(tau)) d2 = (d1-sigma*sqrt(tau)) y = x*exp(-r*tau)*norm.cdf(d2) return y P = list(map(lambda x: x if spot > strike else 0)) return P S = [t/5 for t in range(0,1000)] fig, ax = plt.subplots(nrows=1, ncols=1, sharex=True, sharey=True, figsize = (20,15)) fig.suptitle('Payoff Function for CON CALL', fontsize=20, fontweight='bold') bc_P = CON_call_price(120,100, 1, 0.25, 0.2, 0.03, 1, 50) plt.subplot(222) plt.plot(S, bc_P, 'b') plt.legend(["Binary Call"]) plt.show()This is the result I get: I also get a figure, but no graph in it.I've seen some plot functions, but for some reason I can't get this to work, unfortunately. Thank you in advance. RE: How to graphically represent this function? - scidam - May-03-2019 You need to compute values of your function for all values in S . Just replace line #28 in your code with the following:bc_P = [CON_call_price(120,100, 1, 0.25, 0.2, 0.03, 1, s) for s in S] |