Exemple #1
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()
    def _traverse_tree_(self, payoffs):
        for i in reversed(range(self.N)):
            # The payoffs from NOT exercising the option
            payoffs = (payoffs[:-1] * self.qu +
                       payoffs[1:] * self.qd) * self.df

            # Payoffs from exercising, for American options
            if not self.is_european:
                payoffs = self.__check_early_exercise__(payoffs,
                                                        i)

        return payoffs

    def __begin_tree_traversal__(self):
        payoffs = self._initialize_payoffs_tree_()
        return self._traverse_tree_(payoffs)

    def price(self):
        self._setup_parameters_()
        self._initialize_stock_price_tree_()
        payoffs = self.__begin_tree_traversal__()

        return payoffs[0]

if __name__ == "__main__":
    from BinomialTreeOption import BinomialTreeOption
    am_option = BinomialTreeOption(
        50, 50, 0.05, 0.5, 2,
        {"pu": 0.2, "pd": 0.2, "is_call": False, "is_eu": False})
    print (am_option.price())
            payoffs = (payoffs[:-1] * self.qu +
                       payoffs[1:] * self.qd) * self.df

            # Payoffs from exercising, for American options
            if not self.is_european:
                payoffs = self.__check_early_exercise__(payoffs, i)

        return payoffs

    def __begin_tree_traversal__(self):
        payoffs = self._initialize_payoffs_tree_()
        return self._traverse_tree_(payoffs)

    def price(self):
        self._setup_parameters_()
        self._initialize_stock_price_tree_()
        payoffs = self.__begin_tree_traversal__()

        return payoffs[0]


if __name__ == "__main__":
    from BinomialTreeOption import BinomialTreeOption
    am_option = BinomialTreeOption(50, 50, 0.05, 0.5, 2, {
        "pu": 0.2,
        "pd": 0.2,
        "is_call": False,
        "is_eu": False
    })
    print am_option.price()
    def _traverse_tree_(self, payoffs):
        for i in reversed(range(self.N)):
            # The payoffs from NOT exercising the option
            payoffs = (payoffs[:-1] * self.qu +
                       payoffs[1:] * self.qd) * self.df

            # Payoffs from exercising, for American options
            if not self.is_european:
                payoffs = self.__check_early_exercise__(payoffs,
                                                        i)

        return payoffs

    def __begin_tree_traversal__(self):
        payoffs = self._initialize_payoffs_tree_()
        return self._traverse_tree_(payoffs)

    def price(self):
        self._setup_parameters_()
        self._initialize_stock_price_tree_()
        payoffs = self.__begin_tree_traversal__()

        return payoffs[0]

if __name__ == "__main__":
    from BinomialTreeOption import BinomialTreeOption
    am_option = BinomialTreeOption(
        50, 50, 0.05, 0.5, 2,
        {"pu": 0.2, "pd": 0.2, "is_call": False, "is_eu": False})
    print am_option.price()
        payoffs = self._initialize_payoffs_tree_()
        return self._traverse_tree_(payoffs)

    def price(self):
        self._setup_parameters_()
        self._initialize_stock_price_tree_()
        payoffs = self.__begin_tree_traversal__()

        return payoffs[0]


if __name__ == "__main__":
    from BinomialTreeOption import BinomialTreeOption
    am_option = BinomialTreeOption(50, 50, 0.05, 0.5, 2, {
        "pu": 0.2,
        "pd": 0.2,
        "is_call": False,
        "is_eu": False
    })
    print(am_option.price())

# #### The American put option is priced at 5.113. Since American options can be exercised at any time and European options can only be exercised at maturity, this added flexibility of American options increases their value over European options in certain circumstances.
#
# ###  The Cox-Ross-Rubinstein model:
# #### The Cox-Ross-Rubinstein (CRR) model proposes that, over a short period of time in the risk-neutral world, the binomial model matches the mean and variance of the underlying stock. The volatility of the underlying stock, or the standard deviation of returns of the stock.
#
# #### Consider again the two-step binomial tree. The non-dividend paying stock has a current price of 50 and a volatility of 30 percent. Suppose that the risk-free rate is 5 percent per annum and the time to maturity T is 0.5 years.

# In[7]:
""" Price an option by the binomial CRR model """
from BinomialTreeOption import BinomialTreeOption
import math