Exemplo n.º 1
0
    def testBlackBasic(self):
        strike = 1.0
        forward = 1.2
        stdDev = 0.2
        discount = 0.95

        expected = discount * (forward - strike)
        calculated = blackFormula(OptionType.Call, strike, forward, 0.0, discount)
        self.assertAlmostEqual(expected, calculated, 15)

        expected = discount * forward
        calculated = blackFormula(OptionType.Call, 0.0, forward, stdDev, discount)
        self.assertAlmostEqual(expected, calculated, 15)
Exemplo n.º 2
0
    def testBlackBasic(self):
        strike = 1.0
        forward = 1.2
        stdDev = 0.2
        discount = 0.95

        expected = discount * (forward - strike)
        calculated = blackFormula(OptionType.Call, strike, forward, 0.0,
                                  discount)
        self.assertAlmostEqual(expected, calculated, 15)

        expected = discount * forward
        calculated = blackFormula(OptionType.Call, 0.0, forward, stdDev,
                                  discount)
        self.assertAlmostEqual(expected, calculated, 15)
Exemplo n.º 3
0
    def testBlackImpliedVol(self):
        forward = 1.0
        bpvol = 0.25
        tte = 10.0
        stdDev = bpvol * math.sqrt(tte)
        discount = 0.95

        dList = [-3.0, -2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0, 3.0]

        for d in dList:
            strike = forward * math.exp(d * bpvol * math.sqrt(tte))
            callPrem = blackFormula(OptionType.Call, strike, forward, stdDev, discount)
            impliedStdDev = blackFormulaImpliedStdDev(OptionType.Call, strike, forward, callPrem, discount)
            self.assertAlmostEqual(impliedStdDev, stdDev, 10)

            putPrem = blackFormula(OptionType.Put, strike, forward, stdDev, discount)
            impliedStdDev = blackFormulaImpliedStdDev(OptionType.Put, strike, forward, putPrem, discount)
            self.assertAlmostEqual(impliedStdDev, stdDev, 10)
Exemplo n.º 4
0
    def testBlackImpliedVol(self):
        forward = 1.0
        bpvol = 0.25
        tte = 10.0
        stdDev = bpvol * math.sqrt(tte)
        discount = 0.95

        dList = [-3.0, -2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0, 3.0]

        for d in dList:
            strike = forward * math.exp(d * bpvol * math.sqrt(tte))
            callPrem = blackFormula(OptionType.Call, strike, forward, stdDev,
                                    discount)
            impliedStdDev = blackFormulaImpliedStdDev(OptionType.Call, strike,
                                                      forward, callPrem,
                                                      discount)
            self.assertAlmostEqual(impliedStdDev, stdDev, 10)

            putPrem = blackFormula(OptionType.Put, strike, forward, stdDev,
                                   discount)
            impliedStdDev = blackFormulaImpliedStdDev(OptionType.Put, strike,
                                                      forward, putPrem,
                                                      discount)
            self.assertAlmostEqual(impliedStdDev, stdDev, 10)