def _option_valuation_(self, K, sigma):
     # Use the binomial Leisen-Reimer tree
     lr_option = BinomialLROption(self.S0, K, self.r, self.T, self.N, {
         "sigma": sigma,
         "is_call": self.is_call,
         "div": self.div
     })
     return lr_option.price()
 def _option_valuation_(self, K, sigma):
     # Use the binomial Leisen-Reimer tree
     lr_option = BinomialLROption(
         self.S0, K, self.r,  self.T, self.N,
         {"sigma": sigma,
          "is_call": self.is_call,
          "div": self.div})
     return lr_option.price()
示例#3
0
              ((self.r-self.div) +
               (self.sigma**2)/2.) *
              self.T) / (self.sigma * math.sqrt(self.T))
        d2 = (math.log(self.S0/self.K) +
              ((self.r-self.div) -
               (self.sigma**2)/2.) *
              self.T) / (self.sigma * math.sqrt(self.T))
        pp_2_inversion = \
            lambda z, n: \
            .5 + math.copysign(1, z) * \
            math.sqrt(.25 - .25 * math.exp(
                -((z/(n+1./3.+.1/(n+1)))**2.)*(n+1./6.)))
        pbar = pp_2_inversion(d1, odd_N)

        self.p = pp_2_inversion(d2, odd_N)
        self.u = 1/self.df * pbar/self.p
        self.d = (1/self.df - self.p*self.u)/(1-self.p)
        self.qu = self.p
        self.qd = 1-self.p

if __name__ == "__main__":
    from BinomialLROption import BinomialLROption
    eu_option = BinomialLROption(
        50, 50, 0.05, 0.5, 3,
        {"sigma": 0.3, "is_call": False})
    print "European put: %s" % eu_option.price()

    am_option = BinomialLROption(
        50, 50, 0.05, 0.5, 3,
        {"sigma": 0.3, "is_call": False, "is_eu": False})
    print "American put: %s" % am_option.price()
        pp_2_inversion = lambda z, n: .5 + math.copysign(1, z) * math.sqrt(
            .25 - .25 * math.exp(-((z / (n + 1. / 3. + .1 / (n + 1)))**2.) *
                                 (n + 1. / 6.)))
        pbar = pp_2_inversion(d1, odd_N)

        self.p = pp_2_inversion(d2, odd_N)
        self.u = 1 / self.df * pbar / self.p
        self.d = (1 / self.df - self.p * self.u) / (1 - self.p)
        self.qu = self.p
        self.qd = 1 - self.p


if __name__ == "__main__":
    from BinomialLROption import BinomialLROption
    eu_option = BinomialLROption(50, 50, 0.05, 0.5, 3, {
        "sigma": 0.3,
        "is_call": False
    })
    print("European put: %s" % eu_option.price())

    am_option = BinomialLROption(50, 50, 0.05, 0.5, 3, {
        "sigma": 0.3,
        "is_call": False,
        "is_eu": False
    })
    print("American put: %s" % am_option.price())

# ## Greeks
#
# ##### In the binomial tree pricing models that we have covered so far, we traversed up and down the tree at each point in time to determine the node values. From the information at each node, we can reuse these computed values easily. One such use is the computation of Greeks. Two particularly useful Greeks for options are delta and gamma. Delta measures the sensitivity of the option price with respect to the underlying asset price. Gamma measures the rate of change in delta with respect to the underlying price.

# In[13]: