示例#1
0
    def Fourier_inversion(self):
        """
        Price obtained by inversion of the characteristic function
        """
        k = np.log(self.K / self.S0)  # log moneyness
        w = -np.log(1 - self.theta * self.kappa - self.kappa / 2 *
                    self.sigma**2) / self.kappa  # coefficient w
        cf_VG_b = partial(cf_VG,
                          t=self.T,
                          mu=(self.r - w),
                          theta=self.theta,
                          sigma=self.sigma,
                          kappa=self.kappa)

        right_lim = 5000  # using np.inf may create warnings
        if self.payoff == "call":
            call = self.S0 * Q1(k, cf_VG_b, right_lim) - self.K * np.exp(
                -self.r * self.T) * Q2(k, cf_VG_b,
                                       right_lim)  # pricing function
            return call
        elif self.payoff == "put":
            put = self.K * np.exp(-self.r * self.T) * (
                1 - Q2(k, cf_VG_b, right_lim)) - self.S0 * (
                    1 - Q1(k, cf_VG_b, right_lim))  # pricing function
            return put
        else:
            raise ValueError("invalid type. Set 'call' or 'put'")
示例#2
0
    def Fourier_inversion(self):
        """
        Price obtained by inversion of the characteristic function
        """
        k = np.log(self.K / self.S0)  # log moneyness
        m = self.lam * (np.exp(self.muJ +
                               (self.sigJ**2) / 2) - 1)  # coefficient m
        cf_Mert = partial(cf_mert,
                          t=self.T,
                          mu=(self.r - 0.5 * self.sig**2 - m),
                          sig=self.sig,
                          lam=self.lam,
                          muJ=self.muJ,
                          sigJ=self.sigJ)

        if self.payoff == "call":
            call = self.S0 * Q1(k, cf_Mert, np.inf) - self.K * np.exp(
                -self.r * self.T) * Q2(k, cf_Mert, np.inf)  # pricing function
            return call
        elif self.payoff == "put":
            put = self.K * np.exp(
                -self.r * self.T) * (1 - Q2(k, cf_Mert, np.inf)) - self.S0 * (
                    1 - Q1(k, cf_Mert, np.inf))  # pricing function
            return put
        else:
            raise ValueError("invalid type. Set 'call' or 'put'")
示例#3
0
    def Fourier_inversion(self):
        """
        Price obtained by inversion of the characteristic function
        """
        k = np.log(self.K / self.S0)  # log moneyness
        cf_H_b_good = partial(cf_Heston_good,
                              t=self.T,
                              v0=self.v0,
                              mu=self.r,
                              theta=self.theta,
                              sigma=self.sigma,
                              kappa=self.kappa,
                              rho=self.rho)

        limit_max = 2000  # right limit in the integration

        if self.payoff == "call":
            call = self.S0 * Q1(k, cf_H_b_good, limit_max) \
                                                - self.K * np.exp(-self.r*self.T) * Q2(k, cf_H_b_good, limit_max)
            return call
        elif self.payoff == "put":
            put = self.K * np.exp(-self.r*self.T) * (1 - Q2(k, cf_H_b_good, limit_max)) \
                                                - self.S0 * (1-Q1(k, cf_H_b_good, limit_max))
            return put
        else:
            raise ValueError("invalid type. Set 'call' or 'put'")
    def Fourier_inversion(self):
        """
        Price obtained by inversion of the characteristic function
        """
        k = np.log(self.K / self.S0)
        cf_GBM = partial(cf_normal,
                         mu=(self.r - 0.5 * self.sig**2) * self.T,
                         sig=self.sig * np.sqrt(self.T))  # function binding

        if self.payoff == "call":
            call = self.S0 * Q1(k, cf_GBM, np.inf) - self.K * np.exp(
                -self.r * self.T) * Q2(k, cf_GBM, np.inf)  # pricing function
            return call
        elif self.payoff == "put":
            put = self.K * np.exp(
                -self.r * self.T) * (1 - Q2(k, cf_GBM, np.inf)) - self.S0 * (
                    1 - Q1(k, cf_GBM, np.inf))  # pricing function
            return put
        else:
            raise ValueError("invalid type. Set 'call' or 'put'")
示例#5
0
 def Fourier_inversion(self):
     """
     Price obtained by inversion of the characteristic function
     """
     k = np.log(self.K/self.S0)                # log moneyness
     w = ( 1 - np.sqrt( 1 - 2*self.theta*self.kappa -self.kappa*self.sigma**2) )/self.kappa # martingale correction
     
     cf_NIG_b = partial(cf_NIG, t=self.T, mu=(self.r-w), theta=self.theta, sigma=self.sigma, kappa=self.kappa )
     
     if self.payoff == "call":
         call = self.S0 * Q1(k, cf_NIG_b, np.inf) - self.K * np.exp(-self.r*self.T) * Q2(k, cf_NIG_b, np.inf)   # pricing function
         return call
     elif self.payoff == "put":
         put = self.K * np.exp(-self.r*self.T) * (1 - Q2(k, cf_NIG_b, np.inf)) - self.S0 * (1-Q1(k, cf_NIG_b, np.inf))  # pricing function
         return put
     else:
         raise ValueError("invalid type. Set 'call' or 'put'")