
from unittest import TestCase

from options.pricing.binomial_trees import BinomialTreePricer
from options.option import OptionType, Option


class BinomialTreeTestCase(TestCase):

    def test_basic(self):
        """European option, spot price 50, strike price 52, risk free interest rate 5%
        expiry 2 years, volatility 30%
        """
        pricer = BinomialTreePricer(steps=100)
        option = Option(OptionType.PUT, 50, 52, 0.05, 2, 0.3)
        result = pricer.price_option(option)
        self.assertEqual(6.7781, result)

[((14, 17, 14, 46), 'options.pricing.binomial_trees.BinomialTreePricer', 'BinomialTreePricer', (), '', False, 'from options.pricing.binomial_trees import BinomialTreePricer\n'), ((15, 17, 15, 61), 'options.option.Option', 'Option', ({(15, 24, 15, 38): 'OptionType.PUT', (15, 40, 15, 42): '50', (15, 44, 15, 46): '52', (15, 48, 15, 52): '0.05', (15, 54, 15, 55): '2', (15, 57, 15, 60): '0.3'}, {}), '(OptionType.PUT, 50, 52, 0.05, 2, 0.3)', False, 'from options.option import OptionType, Option\n')]