
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)

[((362, 391), 'options.pricing.binomial_trees.BinomialTreePricer', 'BinomialTreePricer', ([], {'steps': '(100)'}), '(steps=100)\n', (380, 391), False, 'from options.pricing.binomial_trees import BinomialTreePricer\n'), ((409, 453), 'options.option.Option', 'Option', (['OptionType.PUT', '(50)', '(52)', '(0.05)', '(2)', '(0.3)'], {}), '(OptionType.PUT, 50, 52, 0.05, 2, 0.3)\n', (415, 453), False, 'from options.option import OptionType, Option\n')]