Beispiel #1
0
def BSM_put_value(St, K, t, T, r, sigma):
    ''' Calculates Black-Scholes-Merton European put option value.
    
    Parameters
    ==========
    St : float
        stock/index level at time t
    K : float
        strike price
    t : float
        valuation date
    T : float
        date of maturity/time-to-maturity if t = 0; T > t
    r : float
        constant, risk-less short rate
    sigma : float
        volatility
        
    Returns
    =======
    put_value : float
        European put present value at t
    '''


    put_value = BSM_call_value(St, K, t, T, r, sigma) \
        - St + math.exp(-r * (T - t)) * K
    return put_value
Beispiel #2
0
def BSM_error_function(p0):
    ''' Error Function for parameter calibration in BSM Model via
    
    Parameters
    ==========
    sigma: float
        volatility factor in diffusion term

    Returns
    =======
    RMSE: float
        root mean squared error
    '''
    global i, min_RMSE
    sigma = p0
    if sigma < 0.0:
        return 500.0
    se = []
    for row, option in options.iterrows():
        T = (option['Maturity'] - option['Date']).days / 365.
        model_value = BSM_call_value(S0, option['Strike'], 0, T, r, sigma)
        se.append((model_value - option['Call']) ** 2)
    RMSE = math.sqrt(sum(se) / len(se))
    min_RMSE = min(min_RMSE, RMSE)
    if i % 5 == 0:
        print('%4d |' % i, np.array(p0), '| %7.3f | %7.3f' % (RMSE, min_RMSE))
    i += 1
    return RMSE
Beispiel #3
0
def plot_convergence(mmin, mmax, step_size):
    ''' Plots the CRR option values for increasing number of time
    intervals M against the Black-Scholes-Merton benchmark value.'''
    BSM_benchmark = BSM_call_value(S0, K, 0, T, r, sigma)
    m = range(mmin, mmax, step_size)
    CRR_values = [CRR_option_value(S0, K, T, r, sigma, 'call', M) for M in m]
    plt.figure(figsize=(9, 5))
    plt.plot(m, CRR_values, label='CRR values')
    plt.axhline(BSM_benchmark, color='r', ls='dashed', lw=1.5,
                label='BSM benchmark')
    plt.xlabel('# of binomial steps $M$')
    plt.ylabel('European call option value')
    plt.legend(loc=4)
    plt.xlim(0, mmax)
Beispiel #4
0
def IVolBsm(S0, K, T, r, P0):
    """
    Inputs:
        S0: spot price
        K: strike
        T: time to maturity in year
        r: rate
        P0: market price
    Outputs:
        Implied volatility
    """
    InitVol = .3
    error = lambda sigma: (BSM_call_value(S0, K, 0, T, r, sigma) - P0)**2
    opt = optimize.fmin(error, InitVol);
    return opt[0]
Beispiel #5
0
def generate_plot(opt, options):
    #
    # Calculating Model Prices
    #
    sigma = opt
    options['Model'] = 0.0
    for row, option in options.iterrows():
        T = (option['Maturity'] - option['Date']).days / 365.
        options.loc[row, 'Model'] = BSM_call_value(S0, option['Strike'], 0, T, r, sigma)

    #
    # Plotting
    #
    mats = sorted(set(options['Maturity']))
    options = options.set_index('Strike')
    for i, mat in enumerate(mats):
        options[options['Maturity'] == mat][['Call', 'Model']].\
            plot(style=['b-', 'ro'], title='%s' % str(mat)[:10],
                 grid=True)
        plt.ylabel('option value')
        plt.savefig('BSM_calibration_3_%s.pdf' % i)
Beispiel #6
0
mpl.rcParams['font.family'] = 'serif'

#import the defined function

import sys
sys.path.append('05_com')
from BSM_option_valuation import BSM_call_value

#Model and option Parameters
K = 8000
T = 1.0
r = 0.025
vol = 0.2

#sample generation
S = np.linspace(4000, 12000, 150)
h = np.maximum(S - K, 0)
C = [BSM_call_value(S0, K, 0, T, r, vol) for S0 in S]

plt.figure()
plt.plot(S, h, 'b-.', lw=2.5, label='inner value')
#plot inner value at maturity
plt.plot(S, C, 'r', lw=2.5, label='present value')
#plot option present value
plt.grid(True)
plt.legend(loc=0)
plt.xlabel('index level $S_0$ ')
plt.ylabel('present value $C(t=0)$')
plt.show()