예제 #1
0
 def bsm_geometric_asian_price(self,
                               otype=1,
                               strike=110,
                               marturity=1,
                               num_step=4):
     m = num_step
     n = m + 1
     sigma = self.vol_ratio
     S0 = self.init_state
     T = marturity
     K = strike
     r = self.drift_ratio
     mu = r - 0.5 * sigma**2
     mu_hat = 0.5 * mu
     sigma_hat_s = sigma**2 * (2 * m + 1) / (6 * (m + 1))
     r_hat = mu_hat + 0.5 * sigma_hat_s
     sigma_hat = np.sqrt(sigma_hat_s)
     if otype == 1:
         option = VanillaOption(otype=1,
                                strike=K,
                                maturity=T,
                                market_price=15.)
         return np.exp([
             (r_hat - r) * T
         ]) * Gbm_1d(init_state=S0, drift_ratio=r_hat,
                     vol_ratio=sigma_hat).bsm_price(option)
     else:
         option = VanillaOption(otype=-1,
                                strike=K,
                                maturity=T,
                                market_price=15.)
         return np.exp([
             (r_hat - r) * T
         ]) * Gbm_1d(init_state=S0, drift_ratio=r_hat,
                     vol_ratio=sigma_hat).bsm_price(option)
예제 #2
0
def bsm_geometric_asian_price(
        self,
        otype=1,
        strike=110,
        maturity=1,
        num_step=4  #partition number
):
    s0 = self.init_state
    sigma = self.vol_ratio
    r = self.drift_ratio
    n = num_step

    #NOTE: This price assumes a uniform partition time steps, for ease of coding.

    #Compute mu-hat
    #mu-hat = mu/2 (we are assuming uniform partition as stated above)
    mu = r - 0.5 * (sigma**2)
    mu_hat = (mu / 2)

    #Compute sigma-hat
    #Sigma-hat^2 = (sigma^2 * (2m + 1))/(6*(m+1)) where m is the number of steps.
    #Recall that the vol_ratio is sigma, not sigma^2. Thus we need both.
    sigma_hat_squared = ((sigma**2) * ((2 * n) + 1)) / (6 * (n + 1))
    sigma_hat = sigma_hat_squared**0.5

    #With mu-hat and sigma-hat calculated, we can find r-hat.
    r_hat = mu_hat + (0.5 * sigma_hat_squared)

    #Create a separate GBM variable to store the new sigma and r, for the sake of
    #computing the price.

    gao_internal_gbm = Gbm_1d(init_state=s0,
                              drift_ratio=r_hat,
                              vol_ratio=sigma_hat)

    return np.exp((r_hat - r) * maturity) * gao_internal_gbm.bsm_price(
        VanillaOption(otype, strike, maturity))
예제 #3
0
# In[5]:

if __name__ == '__main__':
    '''============
    test:
        plot Gbm paths
    =============='''
    gbm1 = Gbm_1d(init_state=10., drift_ratio=.03, vol_ratio=.25)
    grid = np.linspace(0, 1, 100)

    plt.figure()
    plt.title('test Gbm_1d.euler')
    plt.xlabel('time')
    plt.ylabel('state')
    for i in range(5):
        xh = gbm1.euler(grid)
        plt.plot(grid, xh)
    '''===============
    Test bsm_price
    ================='''
    gbm1 = Gbm_1d(init_state=100., drift_ratio=.0475, vol_ratio=.2)
    option1 = VanillaOption(otype=1,
                            strike=110.,
                            maturity=1.,
                            market_price=15.)

    print('>>>>>>>>>>call value is ' + str(gbm1.bsm_price(option1)))
    option2 = VanillaOption(otype=-1)
    print('>>>>>>>>>>put value is ' + str(gbm1.bsm_price(option2)))