Exemple #1
0
 def test_options_on_futures(self):
     ''' 
     Q:  (Options on Futures)
         A European option on futures, 9 month to expiry, future price is 19, the strike
         price is 19, risk free interest rate is 10% per year, volatility is 28% per year
     A:
         c = p = 1.7011
     '''
     bsm = BlackScholes('futures_option', 19, 19, 0.1, 0.75, 0.28, 0.1)
     self.assertEqual(1.7011, bsm.get_option_price(OptionType.CALL))
     self.assertEqual(1.7011, bsm.get_option_price(OptionType.PUT))
 def test_options_on_futures(self):
     ''' 
     Q:  (Options on Futures)
         A European option on futures, 9 month to expiry, future price is 19, the strike
         price is 19, risk free interest rate is 10% per year, volatility is 28% per year
     A:
         c = p = 1.7011
     '''
     bsm = BlackScholes('futures_option', 19, 19, 0.1, 0.75, 0.28, 0.1)
     self.assertEqual(1.7011,
                      bsm.get_option_price(OptionType.CALL))
     self.assertEqual(1.7011,
                      bsm.get_option_price(OptionType.PUT))
Exemple #3
0
 def test_options_on_FX(self):
     ''' 
     Q:  (Options on FX)
         A European USD-call/EUR-put option, 6 month to expiry, USD/EUR exchange rate is 1.56, 
         the strike strike rate is 1.6, the domestic risk free interest rate in EUR is 8% per year, 
         the foreign risk-free interest rate in USD is 6%, volatility is 12% per year
     A:
         c = 0.0291
     '''
     bsm1 = BlackScholes('currency_option', 1.56, 1.6, 0.06, 0.5, 0.12,
                         0.08)
     self.assertEqual(0.0291, bsm1.get_option_price(OptionType.CALL))
     bsm2 = BlackScholes('currency_option', 1 / 1.56, 1 / 1.6, 0.08, 0.5,
                         0.12, 0.06)
     self.assertEqual(0.0117, bsm2.get_option_price(OptionType.PUT))
 def test_options_on_FX(self):
     ''' 
     Q:  (Options on FX)
         A European USD-call/EUR-put option, 6 month to expiry, USD/EUR exchange rate is 1.56, 
         the strike strike rate is 1.6, the domestic risk free interest rate in EUR is 8% per year, 
         the foreign risk-free interest rate in USD is 6%, volatility is 12% per year
     A:
         c = 0.0291
     '''
     bsm1 = BlackScholes('currency_option', 1.56, 1.6, 0.06, 0.5, 0.12, 0.08)
     self.assertEqual(0.0291,
                      bsm1.get_option_price(OptionType.CALL))
     bsm2 = BlackScholes('currency_option', 1/1.56, 1/1.6, 0.08, 0.5, 0.12, 0.06)
     self.assertEqual(0.0117,
                      bsm2.get_option_price(OptionType.PUT))
Exemple #5
0
 def test_vanilla_call_option(self):
     '''
     Q:  (Vanilla option)
         A European call option, 3 month to expiry, stock price is 60, the strike
         price is 65, risk free interest rate is 8% per year, volatility is 30% per year
     A:
         2.1334
     '''
     bsm = BlackScholes('stock_option', 60, 65, 0.08, 0.25, 0.3)
     self.assertEqual(2.1334, bsm.get_option_price(OptionType.CALL))
 def get_price(self, otype=OptionType.CALL, product='stock_option', 
               spot=60, strike=65, rate=0.08, expiry=0.25, vol=0.3):
     '''
     Q:  (Vanilla option)
         A European call option, 3 month to expiry, stock price is 60, the strike
         price is 65, risk free interest rate is 8% per year, volatility is 30% per year
     A:
         2.1334
     '''
     bsm = BlackScholes(product, spot, strike, rate, expiry, vol)
     return bsm.get_option_price(otype)
Exemple #7
0
 def test_compare_binomial_tree(self):
     '''
     European put option, 2 years to expiry, spot price 50, strike price 52, risk free rate 5%,
     volatility 30%
     
     The result from binomial trees with steps == 10 : 6.747
                                                  100: 6.7781
                                                  500: 6.7569
     '''
     bsm = BlackScholes('stock_option', 50, 52, 0.05, 2, 0.3)
     self.assertEqual(6.7601, bsm.get_option_price(OptionType.PUT))
 def test_vanilla_call_option(self):
     '''
     Q:  (Vanilla option)
         A European call option, 3 month to expiry, stock price is 60, the strike
         price is 65, risk free interest rate is 8% per year, volatility is 30% per year
     A:
         2.1334
     '''
     bsm = BlackScholes('stock_option', 60, 65, 0.08, 0.25, 0.3)
     self.assertEqual(2.1334,
                      bsm.get_option_price(OptionType.CALL))
Exemple #9
0
 def test_vanilla_option_with_dividend(self):
     '''
     Q:  (Vanilla option with yield)
         A European put option, 6 month to expiry, stock price is 100, the strike
         price is 95, risk free interest rate is 10% per year, 
         the dividend is 5% per year, volatility is 20% per year
     A:
         2.4648
     '''
     bsm = BlackScholes('stock_option_with_dividend', 100, 95, 0.1, 0.5,
                        0.2, 0.05)
     self.assertEqual(2.4648, bsm.get_option_price(OptionType.PUT))
 def test_compare_binomial_tree(self):
     '''
     European put option, 2 years to expiry, spot price 50, strike price 52, risk free rate 5%,
     volatility 30%
     
     The result from binomial trees with steps == 10 : 6.747
                                                  100: 6.7781
                                                  500: 6.7569
     '''
     bsm = BlackScholes('stock_option', 50, 52, 0.05, 2, 0.3)
     self.assertEqual(6.7601,
                      bsm.get_option_price(OptionType.PUT))
 def test_vanilla_option_with_dividend(self):
     '''
     Q:  (Vanilla option with yield)
         A European put option, 6 month to expiry, stock price is 100, the strike
         price is 95, risk free interest rate is 10% per year, 
         the dividend is 5% per year, volatility is 20% per year
     A:
         2.4648
     '''
     bsm = BlackScholes('stock_option_with_dividend', 100, 95, 0.1, 0.5, 0.2, 0.05)
     self.assertEqual(2.4648,
                      bsm.get_option_price(OptionType.PUT))
Exemple #12
0
 def get_price(self,
               otype=OptionType.CALL,
               product='stock_option',
               spot=60,
               strike=65,
               rate=0.08,
               expiry=0.25,
               vol=0.3):
     '''
     Q:  (Vanilla option)
         A European call option, 3 month to expiry, stock price is 60, the strike
         price is 65, risk free interest rate is 8% per year, volatility is 30% per year
     A:
         2.1334
     '''
     bsm = BlackScholes(product, spot, strike, rate, expiry, vol)
     return bsm.get_option_price(otype)