Exemple #1
0
    def test_vol_values(self):
        """Test values of implied volatility."""
        premium = .024
        price = 1
        strike = 1
        riskfree = .02
        maturity = 30/365
        call = True
        moneyness = lfmoneyness(price, strike, riskfree, maturity)
        vol = imp_vol(moneyness, maturity, premium, call)

        self.assertAlmostEqual(float(vol), .2, 2)

        strike = [1, .95]
        premium = [.024, .057]
        moneyness = lfmoneyness(price, strike, riskfree, maturity)
        vol = imp_vol(moneyness, maturity, premium, call)

        np.testing.assert_array_almost_equal(vol, [.2, .2], 2)
Exemple #2
0
    def test_moneyness(self):
        """Test conversion to moneyness."""

        price, strike, riskfree, time = 1, 1, 0, .5
        moneyness = lfmoneyness(price, strike, riskfree, time)

        self.assertEqual(moneyness, 0)

        price, riskfree, time = 1, 0, .5
        strike = [1, np.e]
        moneyness = lfmoneyness(price, strike, riskfree, time)

        np.testing.assert_array_equal(moneyness, np.array([0, 1]))

        strike, riskfree, time = 1, 0, .5
        price = [1, np.e]
        moneyness = lfmoneyness(price, strike, riskfree, time)

        np.testing.assert_array_equal(moneyness, np.array([0, -1]))