Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()