示例#1
0
    def payoffProfile(self, sArr, spotMVAsZero=True, dayFromNow=0):
        if spotMVAsZero:
            mvNow = 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)
                    mvNow += opt.fairValue() * tr["Notional"]
        payoff = [0.0] * len(sArr)

        for tr in self.tradeRecord:
            if tr:
                opt = EuropeanOption(tr["CallOrPut"] == "Call", tr["Strike"],
                                     max(0.0, tr["DayToExpiry"] - dayFromNow),
                                     tr["DvdYield"] / 100.0)
                for i, s in enumerate(sArr):
                    opt.setLevel(s, tr["ImplVol"] / 100.0,
                                 tr["RiskFree"] / 100.0)
                    payoff[i] += opt.fairValue() * tr["Notional"]

        for i in range(len(sArr)):
            payoff[i] -= mvNow
        return payoff
示例#2
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
示例#3
0
 def perTradeCalc(self):
     tradeCalc = [{} for i in range(self.NTradeInput)]
     for i, tr in enumerate(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)
             tradeCalc[i]["FairValue"] = opt.fairValue()
             tradeCalc[i]["Delta"] = opt.delta()
             tradeCalc[i]["Gamma"] = opt.gamma()
             tradeCalc[i]["Vega"] = opt.vega()
             tradeCalc[i]["Rho"] = opt.rho()
             tradeCalc[i]["Theta"] = opt.theta() / self.DaysPerYear
     return tradeCalc
示例#4
0
 def perScenCalc(self, scen):
     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
     for tr in self.tradeRecord:
         if tr:
             vol = scen[f"k={tr['Strike']:.2f}"] / 100.0
             opt = EuropeanOption(
                 tr["CallOrPut"] == "Call", tr["Strike"],
                 tr["DayToExpiry"] - abs(scen["DayToExpiry"]),
                 tr["DvdYield"] / 100.0)
             opt.setLevel(self.spot + scen["Spot"], vol,
                          (tr["RiskFree"] + scen["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
     return calc
 def test_expired_put_2(self):
     opt = EuropeanOption(False, 51.0, 0.0, 0.02) #isCall, strike, dayToExpiry, dvdYield
     opt.setLevel(50.0, 0.3, 0.03) #spot, ivol, riskFree
     assert self._isFloatNear(opt.fairValue(), 1.0, 1e-16)