Ejemplo n.º 1
0
    def prtfCalc(self):
        calc = {}
        calc["FairValue"], calc["Delta"], calc["Gamma"], calc["Vega"], calc[
            "Rho"], calc["Theta"] = 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
        calc["Vanna"], calc["Volga"], calc["Veta"], calc[
            "Charm"] = 0.0, 0.0, 0.0, 0.0

        for tr in self.tradeRecord:
            if tr:
                opt = EuropeanOption(tr["CallOrPut"] == "Call", tr["Strike"],
                                     tr["DayToExpiry"], tr["DvdYield"] / 100.0)
                opt.setLevel(self.spot, tr["ImplVol"] / 100.0,
                             tr["RiskFree"] / 100.0)
                calc["FairValue"] += opt.fairValue() * tr["Notional"]
                calc["Delta"] += opt.delta() * tr["Notional"]
                calc["Gamma"] += opt.gamma() * tr["Notional"]
                calc["Vega"] += opt.vega() * tr["Notional"]
                calc["Rho"] += opt.rho() * tr["Notional"]
                calc["Theta"] += opt.theta(
                ) * tr["Notional"] / self.DaysPerYear
                calc["Vanna"] += opt.vanna() * tr["Notional"]
                calc["Volga"] += opt.volga() * tr["Notional"]
                calc["Veta"] += opt.veta() * tr["Notional"]
                calc["Charm"] += opt.charm() * tr["Notional"]

        return calc
Ejemplo n.º 2
0
 def test_f_vanna(self):
     #vanna = d2V/ dS dv = dDelta/dv
     dvol = 0.001
     
     opt1 = EuropeanOption(False, 204.0, 91.0, 0.02) #isCall, strike, dayToExpiry, dvdYield
     opt1.setLevel(200.0, 0.300, 0.03) #spot, ivol, riskFree
     d1 = opt1.delta()
     
     opt2 = EuropeanOption(False, 204.0, 91.0, 0.02) #isCall, strike, dayToExpiry, dvdYield
     opt2.setLevel(200.0, 0.300+dvol, 0.03) #spot, ivol, riskFree
     d2 = opt2.delta()        
     
     approx = (d2-d1)/dvol
     
     optMid = EuropeanOption(False, 204.0, 91.0, 0.02) #isCall, strike, dayToExpiry, dvdYield
     optMid.setLevel(200.0, 0.300+dvol*0.5, 0.03) #spot, ivol, riskFree
     print(approx)
     print(optMid.vanna())
     assert self._isFloatNear( approx/ optMid.vanna(), 1.0, 1e-3)