Пример #1
0
 def pricer(self, S0, K, r, T, N, sigma,
            is_call=True, div=0., is_eu=False):
     model = BinomialCRROption(S0, K, r, T, N,
                               {"sigma": sigma,
                                "div": div,
                                "is_call": is_call,
                                "is_eu": is_eu})
     return model.price()
Пример #2
0
 def _option_valuation_( self, K, sigma, model ):
     """ Do valuation based on given model:
             Binomial, CRR...
     """
     if model.upper() == "CRR":
         option = BinomialCRROption(
                         self.S0, K, self.r, self.T, self.N,
                         { "sigma":sigma, 
                           "is_call":self.is_call,
                           "div": self.div } )
     else:
         option = BinomialTreeOption(
                         self.S0, K, self.r, self.T, self.N,
                         { "sigma":sigma, 
                           "is_call":self.is_call,
                           "div": self.div } )
     return option.price()
Пример #3
0
======
This file contains Python codes.
======
"""

""" Price an option by the binomial CRR model """
from BinomialTreeOption import BinomialTreeOption
import math


class BinomialCRROption(BinomialTreeOption):

    def _setup_parameters_(self):
        self.u = math.exp(self.sigma * math.sqrt(self.dt))
        self.d = 1./self.u
        self.qu = (math.exp((self.r-self.div)*self.dt) -
                   self.d)/(self.u-self.d)
        self.qd = 1-self.qu

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

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


class BinomialCRROption(BinomialTreeOption):
    def _setup_parameters_(self):
        self.u = math.exp(self.sigma * math.sqrt(self.dt))
        self.d = 1. / self.u
        self.qu = (math.exp(
            (self.r - self.div) * self.dt) - self.d) / (self.u - self.d)
        self.qd = 1 - self.qu


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

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

# ### Leisen-Reimer tree:
# #### Dr. Dietmar Leisen and Matthias Reimer proposed a binomial tree model with the purpose of approximating to the Black-Scholes solution as the number of steps increases. It is known as the Leisen-Reimer (LR) tree, and the nodes do not recombine at every alternate step. It uses an inversion formula to achieve better accuracy during tree transversal. A detailed explanation of the formulas is given in the paper Binomial Models For Option Valuation - Examining And Improving Convergence, March 1995, which is available at http://papers.ssrn.com/sol3/papers.cfm?abstract_id=5976.

# In[8]:
""" Price an option by the Leisen-Reimer tree """