def test_BDTExampleOne(): # HULL BOOK NOTES # http://www-2.rotman.utoronto.ca/~hull/technicalnotes/TechnicalNote23.pdf valuationDate = FinDate(1, 1, 2020) years = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0] zeroDates = valuationDate.addYears(years) zeroRates = [0.00, 0.10, 0.11, 0.12, 0.125, 0.13] testCases.header("DATES") testCases.print(zeroDates) testCases.header("RATES") testCases.print(zeroRates) curve = FinDiscountCurveZeros(valuationDate, zeroDates, zeroRates, FinFrequencyTypes.ANNUAL) yieldVol = 0.16 numTimeSteps = 5 tmat = years[-1] dfs = curve.df(zeroDates) testCases.print("DFS") testCases.print(dfs) years = np.array(years) dfs = np.array(dfs) model = FinModelRatesBDT(yieldVol, numTimeSteps) model.buildTree(tmat, years, dfs)
def test_FinBondOptionAmericanConvergenceONE(): # Build discount curve settlementDate = FinDate(1, 12, 2019) discountCurve = FinDiscountCurveFlat(settlementDate, 0.05) # Bond details issueDate = FinDate(1, 9, 2010) maturityDate = FinDate(1, 9, 2025) coupon = 0.05 freqType = FinFrequencyTypes.SEMI_ANNUAL accrualType = FinDayCountTypes.ACT_ACT_ICMA bond = FinBond(issueDate, maturityDate, coupon, freqType, accrualType) # Option Details expiryDate = FinDate(1, 12, 2020) strikePrice = 100.0 face = 100.0 testCases.header("TIME", "N", "PUT_AMER", "PUT_EUR", "CALL_AME", "CALL_EUR") timeSteps = range(30, 100, 1) for numTimeSteps in timeSteps: sigma = 0.20 start = time.time() optionType = FinOptionTypes.AMERICAN_PUT bondOption1 = FinBondOption(bond, expiryDate, strikePrice, face, optionType) model = FinModelRatesBDT(sigma, numTimeSteps) v1put = bondOption1.value(settlementDate, discountCurve, model) optionType = FinOptionTypes.EUROPEAN_PUT bondOption2 = FinBondOption(bond, expiryDate, strikePrice, face, optionType) model = FinModelRatesBDT(sigma, numTimeSteps) v2put = bondOption2.value(settlementDate, discountCurve, model) optionType = FinOptionTypes.AMERICAN_CALL bondOption1 = FinBondOption(bond, expiryDate, strikePrice, face, optionType) model = FinModelRatesBDT(sigma, numTimeSteps) v1call = bondOption1.value(settlementDate, discountCurve, model) optionType = FinOptionTypes.EUROPEAN_CALL bondOption2 = FinBondOption(bond, expiryDate, strikePrice, face, optionType) model = FinModelRatesBDT(sigma, numTimeSteps) v2call = bondOption2.value(settlementDate, discountCurve, model) end = time.time() period = end - start testCases.print(period, numTimeSteps, v1put, v2put, v1call, v2call)
def test_BDTExampleThree(): # Valuation of a swaption as in Leif Andersen's paper - see Table 1 on # SSRN-id155208.pdf testCases.banner("===================== ANDERSEN PAPER ==============") # This is a sanity check testBlackModelCheck() settlementDate = FinDate(1, 1, 2020) times = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) dates = settlementDate.addYears(times) rate = 0.06 dfs = 1.0 / (1.0 + rate / 2.0)**(2.0 * times) curve = FinDiscountCurve(settlementDate, dates, dfs) coupon = 0.06 freqType = FinFrequencyTypes.SEMI_ANNUAL accrualType = FinDayCountTypes.ACT_ACT_ICMA strikePrice = 100.0 face = 100.0 # Andersen paper numTimeSteps = 200 testCases.header("ExerciseType", "Sigma", "NumSteps", "Texp", "Tmat", "V_Fixed", "V_pay", "V_rec") for exerciseType in [FinExerciseTypes.EUROPEAN, FinExerciseTypes.BERMUDAN]: for maturityYears in [4.0, 5.0, 10.0, 20.0]: maturityDate = settlementDate.addYears(maturityYears) issueDate = FinDate(maturityDate._d, maturityDate._m, 2000) if maturityYears == 4.0 or maturityYears == 5.0: sigma = 0.2012 elif maturityYears == 10.0: sigma = 0.1522 elif maturityYears == 20.0: sigma = 0.1035 for expiryYears in range( int(maturityYears / 2) - 1, int(maturityYears)): expiryDate = settlementDate.addYears(expiryYears) tmat = (maturityDate - settlementDate) / gDaysInYear texp = (expiryDate - settlementDate) / gDaysInYear bond = FinBond(issueDate, maturityDate, coupon, freqType, accrualType) couponTimes = [] couponFlows = [] cpn = bond._coupon / bond._frequency for flowDate in bond._flowDates: if flowDate > expiryDate: flowTime = (flowDate - settlementDate) / gDaysInYear couponTimes.append(flowTime) couponFlows.append(cpn) couponTimes = np.array(couponTimes) couponFlows = np.array(couponFlows) price = bond.cleanPriceFromDiscountCurve(settlementDate, curve) model = FinModelRatesBDT(sigma, numTimeSteps) model.buildTree(tmat, times, dfs) v = model.bermudanSwaption(texp, tmat, strikePrice, face, couponTimes, couponFlows, exerciseType) testCases.print("%s" % exerciseType, "%9.5f" % sigma, "%9.5f" % numTimeSteps, "%9.5f" % expiryYears, "%9.5f" % maturityYears, "%9.5f" % price, "%9.2f" % (v['pay'] * 100.0), "%9.2f" % (v['rec'] * 100.0))
def test_BDTExampleTwo(): # Valuation of a European option on a coupon bearing bond # This follows example in Fig 28.11 of John Hull's book (6th Edition) # but does not have the exact same dt so there are some differences testCases.banner("===================== FIG 28.11 HULL BOOK =============") settlementDate = FinDate(1, 12, 2019) issueDate = FinDate(1, 12, 2015) expiryDate = settlementDate.addTenor("18m") maturityDate = settlementDate.addTenor("10Y") coupon = 0.05 freqType = FinFrequencyTypes.SEMI_ANNUAL accrualType = FinDayCountTypes.ACT_ACT_ICMA bond = FinBond(issueDate, maturityDate, coupon, freqType, accrualType) couponTimes = [] couponFlows = [] cpn = bond._coupon / bond._frequency numFlows = len(bond._flowDates) for i in range(1, numFlows): pcd = bond._flowDates[i - 1] ncd = bond._flowDates[i] if pcd < settlementDate and ncd > settlementDate: flowTime = (pcd - settlementDate) / gDaysInYear couponTimes.append(flowTime) couponFlows.append(cpn) for flowDate in bond._flowDates: if flowDate > settlementDate: flowTime = (flowDate - settlementDate) / gDaysInYear couponTimes.append(flowTime) couponFlows.append(cpn) couponTimes = np.array(couponTimes) couponFlows = np.array(couponFlows) strikePrice = 105.0 face = 100.0 tmat = (maturityDate - settlementDate) / gDaysInYear texp = (expiryDate - settlementDate) / gDaysInYear times = np.linspace(0, tmat, 11) dates = settlementDate.addYears(times) dfs = np.exp(-0.05 * times) testCases.header("LABEL", "VALUES") testCases.print("TIMES:", times) curve = FinDiscountCurve(settlementDate, dates, dfs) price = bond.cleanPriceFromDiscountCurve(settlementDate, curve) testCases.print("Fixed Income Price:", price) sigma = 0.20 # Test convergence numStepsList = [5] #[100, 200, 300, 400, 500, 600, 700, 800, 900, 1000] exerciseType = FinExerciseTypes.AMERICAN testCases.header("Values") treeVector = [] for numTimeSteps in numStepsList: model = FinModelRatesBDT(sigma, numTimeSteps) model.buildTree(tmat, times, dfs) v = model.bondOption(texp, strikePrice, face, couponTimes, couponFlows, exerciseType) testCases.print(v) treeVector.append(v['call']) if PLOT_GRAPHS: plt.plot(numStepsList, treeVector) # The value in Hull converges to 0.699 with 100 time steps while I get 0.70 if 1 == 0: print("RT") printTree(model._rt, 5) print("Q") printTree(model._Q, 5)
def test_FinBondOptionZEROVOLConvergence(): # Build discount curve settlementDate = FinDate(1, 12, 2019) # CHANGED rate = 0.05 discountCurve = FinDiscountCurveFlat(settlementDate, rate, FinFrequencyTypes.ANNUAL) # Bond details issueDate = FinDate(1, 9, 2015) maturityDate = FinDate(1, 9, 2025) coupon = 0.06 freqType = FinFrequencyTypes.ANNUAL accrualType = FinDayCountTypes.ACT_ACT_ICMA bond = FinBond(issueDate, maturityDate, coupon, freqType, accrualType) # Option Details expiryDate = settlementDate.addTenor("18m") # FinDate(1, 12, 2021) # print("EXPIRY:", expiryDate) face = 100.0 dfExpiry = discountCurve.df(expiryDate) spotCleanValue = bond.cleanPriceFromDiscountCurve(settlementDate, discountCurve) fwdCleanValue = bond.cleanPriceFromDiscountCurve(expiryDate, discountCurve) # print("BOND SpotCleanBondPx", spotCleanValue) # print("BOND FwdCleanBondPx", fwdCleanValue) # print("BOND Accrued:", bond._accruedInterest) spotCleanValue = bond.cleanPriceFromDiscountCurve(settlementDate, discountCurve) testCases.header("STRIKE", "STEPS", "CALL_INT", "CALL_INT_PV", "CALL_EUR", "CALL_AMER", "PUT_INT", "PUT_INT_PV", "PUT_EUR", "PUT_AMER") numTimeSteps = range(100, 1000, 200) strikePrices = [90, 100, 110, 120] for strikePrice in strikePrices: callIntrinsic = max(spotCleanValue - strikePrice, 0) putIntrinsic = max(strikePrice - spotCleanValue, 0) callIntrinsicPV = max(fwdCleanValue - strikePrice, 0) * dfExpiry putIntrinsicPV = max(strikePrice - fwdCleanValue, 0) * dfExpiry for numSteps in numTimeSteps: sigma = 0.0000001 model = FinModelRatesBDT(sigma, numSteps) optionType = FinOptionTypes.EUROPEAN_CALL bondOption1 = FinBondOption(bond, expiryDate, strikePrice, face, optionType) v1 = bondOption1.value(settlementDate, discountCurve, model) optionType = FinOptionTypes.AMERICAN_CALL bondOption2 = FinBondOption(bond, expiryDate, strikePrice, face, optionType) v2 = bondOption2.value(settlementDate, discountCurve, model) optionType = FinOptionTypes.EUROPEAN_PUT bondOption3 = FinBondOption(bond, expiryDate, strikePrice, face, optionType) v3 = bondOption3.value(settlementDate, discountCurve, model) optionType = FinOptionTypes.AMERICAN_PUT bondOption4 = FinBondOption(bond, expiryDate, strikePrice, face, optionType) v4 = bondOption4.value(settlementDate, discountCurve, model) testCases.print(strikePrice, numSteps, callIntrinsic, callIntrinsicPV, v1, v2, putIntrinsic, putIntrinsicPV, v3, v4)
def test_FinBondOption(): settlementDate = FinDate(1, 12, 2019) issueDate = FinDate(1, 12, 2018) maturityDate = settlementDate.addTenor("10Y") coupon = 0.05 freqType = FinFrequencyTypes.SEMI_ANNUAL accrualType = FinDayCountTypes.ACT_ACT_ICMA bond = FinBond(issueDate, maturityDate, coupon, freqType, accrualType) tmat = (maturityDate - settlementDate) / gDaysInYear times = np.linspace(0, tmat, 20) dates = settlementDate.addYears(times) dfs = np.exp(-0.05 * times) discountCurve = FinDiscountCurve(settlementDate, dates, dfs) expiryDate = settlementDate.addTenor("18m") strikePrice = 105.0 face = 100.0 ########################################################################### strikes = [80, 90, 100, 110, 120] optionType = FinOptionTypes.EUROPEAN_CALL testCases.header("LABEL", "VALUE") price = bond.fullPriceFromDiscountCurve(settlementDate, discountCurve) testCases.print("Fixed Income Price:", price) numTimeSteps = 100 testCases.header("OPTION TYPE AND MODEL", "STRIKE", "VALUE") for strikePrice in strikes: sigma = 0.20 bondOption = FinBondOption(bond, expiryDate, strikePrice, face, optionType) model = FinModelRatesBDT(sigma, numTimeSteps) v = bondOption.value(settlementDate, discountCurve, model) testCases.print("EUROPEAN CALL - BK", strikePrice, v) for strikePrice in strikes: sigma = 0.20 bondOption = FinBondOption(bond, expiryDate, strikePrice, face, optionType) model = FinModelRatesBDT(sigma, numTimeSteps) v = bondOption.value(settlementDate, discountCurve, model) testCases.print("EUROPEAN CALL - BK", strikePrice, v) ########################################################################### optionType = FinOptionTypes.AMERICAN_CALL price = bond.fullPriceFromDiscountCurve(settlementDate, discountCurve) testCases.header("LABEL", "VALUE") testCases.print("Fixed Income Price:", price) testCases.header("OPTION TYPE AND MODEL", "STRIKE", "VALUE") for strikePrice in strikes: sigma = 0.20 bondOption = FinBondOption(bond, expiryDate, strikePrice, face, optionType) model = FinModelRatesBDT(sigma, numTimeSteps) v = bondOption.value(settlementDate, discountCurve, model) testCases.print("AMERICAN CALL - BK", strikePrice, v) for strikePrice in strikes: sigma = 0.20 bondOption = FinBondOption(bond, expiryDate, strikePrice, face, optionType) model = FinModelRatesBDT(sigma, numTimeSteps) v = bondOption.value(settlementDate, discountCurve, model) testCases.print("AMERICAN CALL - BK", strikePrice, v) ########################################################################### optionType = FinOptionTypes.EUROPEAN_PUT price = bond.fullPriceFromDiscountCurve(settlementDate, discountCurve) for strikePrice in strikes: sigma = 0.01 bondOption = FinBondOption(bond, expiryDate, strikePrice, face, optionType) model = FinModelRatesBDT(sigma, numTimeSteps) v = bondOption.value(settlementDate, discountCurve, model) testCases.print("EUROPEAN PUT - BK", strikePrice, v) for strikePrice in strikes: sigma = 0.20 bondOption = FinBondOption(bond, expiryDate, strikePrice, face, optionType) model = FinModelRatesBDT(sigma, numTimeSteps) v = bondOption.value(settlementDate, discountCurve, model) testCases.print("EUROPEAN PUT - BK", strikePrice, v) ########################################################################### optionType = FinOptionTypes.AMERICAN_PUT price = bond.fullPriceFromDiscountCurve(settlementDate, discountCurve) for strikePrice in strikes: sigma = 0.02 bondOption = FinBondOption(bond, expiryDate, strikePrice, face, optionType) model = FinModelRatesBDT(sigma, numTimeSteps) v = bondOption.value(settlementDate, discountCurve, model) testCases.print("AMERICAN PUT - BK", strikePrice, v) for strikePrice in strikes: sigma = 0.20 bondOption = FinBondOption(bond, expiryDate, strikePrice, face, optionType) model = FinModelRatesBDT(sigma, numTimeSteps) v = bondOption.value(settlementDate, discountCurve, model) testCases.print("AMERICAN PUT - BK", strikePrice, v)
def test_FinBondOptionAmericanConvergenceTWO(): # Build discount curve settlementDate = FinDate(1, 12, 2019) discountCurve = FinDiscountCurveFlat(settlementDate, 0.05, FinFrequencyTypes.CONTINUOUS) # Bond details issueDate = FinDate(1, 9, 2014) maturityDate = FinDate(1, 9, 2025) coupon = 0.05 freqType = FinFrequencyTypes.ANNUAL accrualType = FinDayCountTypes.ACT_ACT_ICMA bond = FinBond(issueDate, maturityDate, coupon, freqType, accrualType) expiryDate = settlementDate.addTenor("18m") face = 100.0 spotValue = bond.fullPriceFromDiscountCurve(settlementDate, discountCurve) testCases.header("LABEL", "VALUE") testCases.print("BOND PRICE", spotValue) testCases.header("TIME", "N", "EUR_CALL", "AMER_CALL", "EUR_PUT", "AMER_PUT") sigma = 0.2 model = FinModelRatesBDT(sigma) K = 101.0 vec_ec = [] vec_ac = [] vec_ep = [] vec_ap = [] if 1 == 1: K = 100.0 bkModel = FinModelRatesBDT(sigma, 100) europeanCallBondOption = FinBondOption(bond, expiryDate, K, face, FinOptionTypes.EUROPEAN_CALL) v_ec = europeanCallBondOption.value(settlementDate, discountCurve, model) testCases.header("LABEL", "VALUE") testCases.print("OPTION", v_ec) numStepsVector = range(100, 100, 1) # should be 100-400 for numSteps in numStepsVector: bkModel = FinModelRatesBDT(sigma, numSteps) start = time.time() europeanCallBondOption = FinBondOption(bond, expiryDate, K, face, FinOptionTypes.EUROPEAN_CALL) v_ec = europeanCallBondOption.value(settlementDate, discountCurve, bkModel) americanCallBondOption = FinBondOption(bond, expiryDate, K, face, FinOptionTypes.AMERICAN_CALL) v_ac = americanCallBondOption.value(settlementDate, discountCurve, bkModel) europeanPutBondOption = FinBondOption(bond, expiryDate, K, face, FinOptionTypes.EUROPEAN_PUT) v_ep = europeanPutBondOption.value(settlementDate, discountCurve, bkModel) americanPutBondOption = FinBondOption(bond, expiryDate, K, face, FinOptionTypes.AMERICAN_PUT) v_ap = americanPutBondOption.value(settlementDate, discountCurve, bkModel) end = time.time() period = end - start testCases.print(period, numSteps, v_ec, v_ac, v_ep, v_ap) vec_ec.append(v_ec) vec_ac.append(v_ac) vec_ep.append(v_ep) vec_ap.append(v_ap) if plotGraphs: plt.figure() plt.plot(numStepsVector, vec_ec, label="European Call") plt.legend() plt.figure() plt.plot(numStepsVector, vec_ac, label="American Call") plt.legend() plt.figure() plt.plot(numStepsVector, vec_ep, label="European Put") plt.legend() plt.figure() plt.plot(numStepsVector, vec_ap, label="American Put") plt.legend()
def test_FinIborBermudanSwaptionBKModel(): ''' Replicate examples in paper by Leif Andersen which can be found at file:///C:/Users/Dominic/Downloads/SSRN-id155208.pdf ''' valuationDate = FinDate(1, 1, 2011) settlementDate = valuationDate exerciseDate = settlementDate.addYears(1) swapMaturityDate = settlementDate.addYears(4) swapFixedCoupon = 0.060 swapFixedFrequencyType = FinFrequencyTypes.SEMI_ANNUAL swapFixedDayCountType = FinDayCountTypes.ACT_365F liborCurve = FinDiscountCurveFlat(valuationDate, 0.0625, FinFrequencyTypes.SEMI_ANNUAL) fwdPAYSwap = FinIborSwap(exerciseDate, swapMaturityDate, FinSwapTypes.PAY, swapFixedCoupon, swapFixedFrequencyType, swapFixedDayCountType) fwdSwapValue = fwdPAYSwap.value(settlementDate, liborCurve, liborCurve) testCases.header("LABEL", "VALUE") testCases.print("FWD SWAP VALUE", fwdSwapValue) # fwdPAYSwap.printFixedLegPV() # Now we create the European swaptions fixedLegType = FinSwapTypes.PAY europeanSwaptionPay = FinIborSwaption(settlementDate, exerciseDate, swapMaturityDate, fixedLegType, swapFixedCoupon, swapFixedFrequencyType, swapFixedDayCountType) fixedLegType = FinSwapTypes.RECEIVE europeanSwaptionRec = FinIborSwaption(settlementDate, exerciseDate, swapMaturityDate, fixedLegType, swapFixedCoupon, swapFixedFrequencyType, swapFixedDayCountType) ########################################################################### ########################################################################### ########################################################################### # BLACK'S MODEL ########################################################################### ########################################################################### ########################################################################### testCases.banner("======= ZERO VOLATILITY ========") model = FinModelBlack(0.0000001) testCases.print("Black Model", model._volatility) valuePay = europeanSwaptionPay.value(settlementDate, liborCurve, model) testCases.print("EUROPEAN BLACK PAY VALUE ZERO VOL:", valuePay) valueRec = europeanSwaptionRec.value(settlementDate, liborCurve, model) testCases.print("EUROPEAN BLACK REC VALUE ZERO VOL:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) testCases.banner("======= 20%% BLACK VOLATILITY ========") model = FinModelBlack(0.20) testCases.print("Black Model", model._volatility) valuePay = europeanSwaptionPay.value(settlementDate, liborCurve, model) testCases.print("EUROPEAN BLACK PAY VALUE:", valuePay) valueRec = europeanSwaptionRec.value(settlementDate, liborCurve, model) testCases.print("EUROPEAN BLACK REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) ########################################################################### ########################################################################### ########################################################################### # BK MODEL ########################################################################### ########################################################################### ########################################################################### testCases.banner("=======================================================") testCases.banner("=======================================================") testCases.banner("==================== BK MODEL =========================") testCases.banner("=======================================================") testCases.banner("=======================================================") testCases.banner("======= 0% VOLATILITY EUROPEAN SWAPTION BK MODEL ======") # Used BK with constant short-rate volatility sigma = 0.00001 a = 0.01 numTimeSteps = 200 model = FinModelRatesBK(sigma, a, numTimeSteps) valuePay = europeanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("EUROPEAN BK PAY VALUE:", valuePay) valueRec = europeanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("EUROPEAN BK REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) testCases.banner("======= 20% VOLATILITY EUROPEAN SWAPTION BK MODEL ========") # Used BK with constant short-rate volatility sigma = 0.20 a = 0.01 model = FinModelRatesBK(sigma, a, numTimeSteps) testCases.banner("BK MODEL SWAPTION CLASS EUROPEAN EXERCISE") valuePay = europeanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("EUROPEAN BK PAY VALUE:", valuePay) valueRec = europeanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("EUROPEAN BK REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) ########################################################################### # Now we create the Bermudan swaptions but only allow European exercise fixedLegType = FinSwapTypes.PAY exerciseType = FinExerciseTypes.EUROPEAN bermudanSwaptionPay = FinIborBermudanSwaption(settlementDate, exerciseDate, swapMaturityDate, fixedLegType, exerciseType, swapFixedCoupon, swapFixedFrequencyType, swapFixedDayCountType) fixedLegType = FinSwapTypes.RECEIVE exerciseType = FinExerciseTypes.EUROPEAN bermudanSwaptionRec = FinIborBermudanSwaption(settlementDate, exerciseDate, swapMaturityDate, fixedLegType, exerciseType, swapFixedCoupon, swapFixedFrequencyType, swapFixedDayCountType) testCases.banner("======= 0% VOLATILITY BERMUDAN SWAPTION EUROPEAN EXERCISE BK MODEL ========") # Used BK with constant short-rate volatility sigma = 0.000001 a = 0.01 model = FinModelRatesBK(sigma, a, numTimeSteps) testCases.banner("BK MODEL BERMUDAN SWAPTION CLASS EUROPEAN EXERCISE") valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BK PAY VALUE:", valuePay) valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BK REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) testCases.banner("======= 20% VOLATILITY BERMUDAN SWAPTION EUROPEAN EXERCISE BK MODEL ========") # Used BK with constant short-rate volatility sigma = 0.2 a = 0.01 model = FinModelRatesBK(sigma, a, numTimeSteps) testCases.banner("BK MODEL BERMUDAN SWAPTION CLASS EUROPEAN EXERCISE") valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BK PAY VALUE:", valuePay) valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BK REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) ########################################################################### # Now we create the Bermudan swaptions but allow Bermudan exercise ########################################################################### fixedLegType = FinSwapTypes.PAY exerciseType = FinExerciseTypes.BERMUDAN bermudanSwaptionPay = FinIborBermudanSwaption(settlementDate, exerciseDate, swapMaturityDate, fixedLegType, exerciseType, swapFixedCoupon, swapFixedFrequencyType, swapFixedDayCountType) fixedLegType = FinSwapTypes.RECEIVE exerciseType = FinExerciseTypes.BERMUDAN bermudanSwaptionRec = FinIborBermudanSwaption(settlementDate, exerciseDate, swapMaturityDate, fixedLegType, exerciseType, swapFixedCoupon, swapFixedFrequencyType, swapFixedDayCountType) testCases.banner("======= ZERO VOLATILITY BERMUDAN SWAPTION BERMUDAN EXERCISE BK MODEL ========") # Used BK with constant short-rate volatility sigma = 0.000001 a = 0.01 model = FinModelRatesBK(sigma, a, numTimeSteps) testCases.banner("BK MODEL BERMUDAN SWAPTION CLASS BERMUDAN EXERCISE") valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BK PAY VALUE:", valuePay) valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BK REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) testCases.banner("======= 20% VOLATILITY BERMUDAN SWAPTION BERMUDAN EXERCISE BK MODEL ========") # Used BK with constant short-rate volatility sigma = 0.20 a = 0.01 model = FinModelRatesBK(sigma, a, numTimeSteps) testCases.banner("BK MODEL BERMUDAN SWAPTION CLASS BERMUDAN EXERCISE") valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BK PAY VALUE:", valuePay) valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BK REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) ########################################################################### ########################################################################### ########################################################################### # BDT MODEL ########################################################################### ########################################################################### ########################################################################### testCases.banner("=======================================================") testCases.banner("=======================================================") testCases.banner("======================= BDT MODEL =====================") testCases.banner("=======================================================") testCases.banner("=======================================================") testCases.banner("====== 0% VOLATILITY EUROPEAN SWAPTION BDT MODEL ======") # Used BK with constant short-rate volatility sigma = 0.00001 numTimeSteps = 200 model = FinModelRatesBDT(sigma, numTimeSteps) valuePay = europeanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("EUROPEAN BDT PAY VALUE:", valuePay) valueRec = europeanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("EUROPEAN BDT REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) testCases.banner("===== 20% VOLATILITY EUROPEAN SWAPTION BDT MODEL ======") # Used BK with constant short-rate volatility sigma = 0.20 a = 0.01 model = FinModelRatesBDT(sigma, numTimeSteps) testCases.banner("BDT MODEL SWAPTION CLASS EUROPEAN EXERCISE") valuePay = europeanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("EUROPEAN BDT PAY VALUE:", valuePay) valueRec = europeanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("EUROPEAN BDT REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) ########################################################################### # Now we create the Bermudan swaptions but only allow European exercise fixedLegType = FinSwapTypes.PAY exerciseType = FinExerciseTypes.EUROPEAN bermudanSwaptionPay = FinIborBermudanSwaption(settlementDate, exerciseDate, swapMaturityDate, fixedLegType, exerciseType, swapFixedCoupon, swapFixedFrequencyType, swapFixedDayCountType) fixedLegType = FinSwapTypes.RECEIVE bermudanSwaptionRec = FinIborBermudanSwaption(settlementDate, exerciseDate, swapMaturityDate, fixedLegType, exerciseType, swapFixedCoupon, swapFixedFrequencyType, swapFixedDayCountType) testCases.banner("======= 0% VOLATILITY BERMUDAN SWAPTION EUROPEAN EXERCISE BDT MODEL ========") # Used BK with constant short-rate volatility sigma = 0.000001 model = FinModelRatesBDT(sigma, numTimeSteps) testCases.banner("BK MODEL BERMUDAN SWAPTION CLASS EUROPEAN EXERCISE") valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BDT PAY VALUE:", valuePay) valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BDT REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) testCases.banner("======= 20% VOLATILITY BERMUDAN SWAPTION EUROPEAN EXERCISE BDT MODEL ========") # Used BK with constant short-rate volatility sigma = 0.2 model = FinModelRatesBDT(sigma, numTimeSteps) testCases.banner("BDT MODEL BERMUDAN SWAPTION CLASS EUROPEAN EXERCISE") valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BDT PAY VALUE:", valuePay) valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BDT REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) ########################################################################### # Now we create the Bermudan swaptions but allow Bermudan exercise ########################################################################### fixedLegType = FinSwapTypes.PAY exerciseType = FinExerciseTypes.BERMUDAN bermudanSwaptionPay = FinIborBermudanSwaption(settlementDate, exerciseDate, swapMaturityDate, fixedLegType, exerciseType, swapFixedCoupon, swapFixedFrequencyType, swapFixedDayCountType) fixedLegType = FinSwapTypes.RECEIVE bermudanSwaptionRec = FinIborBermudanSwaption(settlementDate, exerciseDate, swapMaturityDate, fixedLegType, exerciseType, swapFixedCoupon, swapFixedFrequencyType, swapFixedDayCountType) testCases.banner("======= ZERO VOLATILITY BERMUDAN SWAPTION BERMUDAN EXERCISE BDT MODEL ========") # Used BK with constant short-rate volatility sigma = 0.000001 a = 0.01 model = FinModelRatesBDT(sigma, numTimeSteps) testCases.banner("BK MODEL BERMUDAN SWAPTION CLASS BERMUDAN EXERCISE") valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BDT PAY VALUE:", valuePay) valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BDT REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) testCases.banner("======= 20% VOLATILITY BERMUDAN SWAPTION BERMUDAN EXERCISE BDT MODEL ========") # Used BK with constant short-rate volatility sigma = 0.20 a = 0.01 model = FinModelRatesBDT(sigma, numTimeSteps) # print("BDT MODEL BERMUDAN SWAPTION CLASS BERMUDAN EXERCISE") valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BDT PAY VALUE:", valuePay) valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BDT REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) ########################################################################### ########################################################################### ########################################################################### # BDT MODEL ########################################################################### ########################################################################### ########################################################################### testCases.banner("=======================================================") testCases.banner("=======================================================") testCases.banner("======================= HW MODEL ======================") testCases.banner("=======================================================") testCases.banner("=======================================================") testCases.banner("====== 0% VOLATILITY EUROPEAN SWAPTION HW MODEL ======") sigma = 0.0000001 a = 0.1 numTimeSteps = 200 model = FinModelRatesHW(sigma, a, numTimeSteps) valuePay = europeanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("EUROPEAN HW PAY VALUE:", valuePay) valueRec = europeanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("EUROPEAN HW REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) testCases.banner("===== 20% VOLATILITY EUROPEAN SWAPTION BDT MODEL ======") # Used BK with constant short-rate volatility sigma = 0.01 a = 0.01 model = FinModelRatesHW(sigma, a, numTimeSteps) testCases.banner("HW MODEL SWAPTION CLASS EUROPEAN EXERCISE") valuePay = europeanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("EUROPEAN HW PAY VALUE:", valuePay) valueRec = europeanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("EUROPEAN HW REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) ########################################################################### # Now we create the Bermudan swaptions but only allow European exercise fixedLegType = FinSwapTypes.PAY exerciseType = FinExerciseTypes.EUROPEAN bermudanSwaptionPay = FinIborBermudanSwaption(settlementDate, exerciseDate, swapMaturityDate, fixedLegType, exerciseType, swapFixedCoupon, swapFixedFrequencyType, swapFixedDayCountType) fixedLegType = FinSwapTypes.RECEIVE bermudanSwaptionRec = FinIborBermudanSwaption(settlementDate, exerciseDate, swapMaturityDate, fixedLegType, exerciseType, swapFixedCoupon, swapFixedFrequencyType, swapFixedDayCountType) testCases.banner("======= 0% VOLATILITY BERMUDAN SWAPTION EUROPEAN EXERCISE HW MODEL ========") sigma = 0.000001 model = FinModelRatesHW(sigma, a, numTimeSteps) testCases.banner("BK MODEL BERMUDAN SWAPTION CLASS EUROPEAN EXERCISE") valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BDT PAY VALUE:", valuePay) valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BDT REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) testCases.banner("======= 100bp VOLATILITY BERMUDAN SWAPTION EUROPEAN EXERCISE HW MODEL ========") # Used BK with constant short-rate volatility sigma = 0.01 model = FinModelRatesHW(sigma, a, numTimeSteps) testCases.banner("BDT MODEL BERMUDAN SWAPTION CLASS EUROPEAN EXERCISE") valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BDT PAY VALUE:", valuePay) valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN BDT REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) ########################################################################### # Now we create the Bermudan swaptions but allow Bermudan exercise ########################################################################### fixedLegType = FinSwapTypes.PAY exerciseType = FinExerciseTypes.BERMUDAN bermudanSwaptionPay = FinIborBermudanSwaption(settlementDate, exerciseDate, swapMaturityDate, fixedLegType, exerciseType, swapFixedCoupon, swapFixedFrequencyType, swapFixedDayCountType) fixedLegType = FinSwapTypes.RECEIVE bermudanSwaptionRec = FinIborBermudanSwaption(settlementDate, exerciseDate, swapMaturityDate, fixedLegType, exerciseType, swapFixedCoupon, swapFixedFrequencyType, swapFixedDayCountType) testCases.banner("======= ZERO VOLATILITY BERMUDAN SWAPTION BERMUDAN EXERCISE HW MODEL ========") # Used BK with constant short-rate volatility sigma = 0.000001 a = 0.01 model = FinModelRatesHW(sigma, a, numTimeSteps) testCases.banner("HW MODEL BERMUDAN SWAPTION CLASS BERMUDAN EXERCISE") valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN HW PAY VALUE:", valuePay) valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN HW REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec) testCases.banner("======= 100bps VOLATILITY BERMUDAN SWAPTION BERMUDAN EXERCISE HW MODEL ========") # Used BK with constant short-rate volatility sigma = 0.01 a = 0.01 model = FinModelRatesHW(sigma, a, numTimeSteps) testCases.banner("HW MODEL BERMUDAN SWAPTION CLASS BERMUDAN EXERCISE") valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN HW PAY VALUE:", valuePay) valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model) testCases.print("BERMUDAN HW REC VALUE:", valueRec) payRec = valuePay - valueRec testCases.print("PAY MINUS RECEIVER :", payRec)
def testFinLiborSwaptionMatlabExamples(): # We value a European swaption using Black's model and try to replicate a # ML example at https://fr.mathworks.com/help/fininst/swaptionbyblk.html testCases.header("=======================================") testCases.header("MATLAB EXAMPLE WITH FLAT TERM STRUCTURE") testCases.header("=======================================") valuationDate = FinDate(1, 1, 2010) liborCurve = FinDiscountCurveFlat(valuationDate, 0.06, FinFrequencyTypes.CONTINUOUS, FinDayCountTypes.THIRTY_E_360) settlementDate = FinDate(1, 1, 2011) exerciseDate = FinDate(1, 1, 2016) maturityDate = FinDate(1, 1, 2019) fixedCoupon = 0.062 fixedFrequencyType = FinFrequencyTypes.SEMI_ANNUAL fixedDayCountType = FinDayCountTypes.THIRTY_E_360_ISDA notional = 100.0 # Pricing a PAYER swaptionType = FinLiborSwapTypes.PAYER swaption = FinLiborSwaption(settlementDate, exerciseDate, maturityDate, swaptionType, fixedCoupon, fixedFrequencyType, fixedDayCountType, notional) model = FinModelBlack(0.20) v_finpy = swaption.value(valuationDate, liborCurve, model) v_matlab = 2.071 testCases.header("LABEL", "VALUE") testCases.print("FP Price:", v_finpy) testCases.print("MATLAB Prix:", v_matlab) testCases.print("DIFF:", v_finpy - v_matlab) ############################################################################### testCases.header("===================================") testCases.header("MATLAB EXAMPLE WITH TERM STRUCTURE") testCases.header("===================================") valuationDate = FinDate(1, 1, 2010) dates = [ FinDate(1, 1, 2011), FinDate(1, 1, 2012), FinDate(1, 1, 2013), FinDate(1, 1, 2014), FinDate(1, 1, 2015) ] zeroRates = [0.03, 0.034, 0.037, 0.039, 0.040] contFreq = FinFrequencyTypes.CONTINUOUS interpType = FinInterpTypes.LINEAR_ZERO_RATES dayCountType = FinDayCountTypes.THIRTY_E_360 liborCurve = FinDiscountCurveZeros(valuationDate, dates, zeroRates, contFreq, dayCountType, interpType) settlementDate = FinDate(1, 1, 2011) exerciseDate = FinDate(1, 1, 2012) maturityDate = FinDate(1, 1, 2017) fixedCoupon = 0.03 fixedFrequencyType = FinFrequencyTypes.SEMI_ANNUAL fixedDayCountType = FinDayCountTypes.THIRTY_E_360 floatFrequencyType = FinFrequencyTypes.SEMI_ANNUAL floatDayCountType = FinDayCountTypes.THIRTY_E_360 notional = 1000.0 # Pricing a put swaptionType = FinLiborSwapTypes.RECEIVER swaption = FinLiborSwaption(settlementDate, exerciseDate, maturityDate, swaptionType, fixedCoupon, fixedFrequencyType, fixedDayCountType, notional, floatFrequencyType, floatDayCountType) model = FinModelBlack(0.21) v_finpy = swaption.value(valuationDate, liborCurve, model) v_matlab = 0.5771 testCases.header("LABEL", "VALUE") testCases.print("FP Price:", v_finpy) testCases.print("MATLAB Prix:", v_matlab) testCases.print("DIFF:", v_finpy - v_matlab) ############################################################################### testCases.header("===================================") testCases.header("MATLAB EXAMPLE WITH SHIFTED BLACK") testCases.header("===================================") valuationDate = FinDate(1, 1, 2016) dates = [ FinDate(1, 1, 2017), FinDate(1, 1, 2018), FinDate(1, 1, 2019), FinDate(1, 1, 2020), FinDate(1, 1, 2021) ] zeroRates = np.array([-0.02, 0.024, 0.047, 0.090, 0.12]) / 100.0 contFreq = FinFrequencyTypes.ANNUAL interpType = FinInterpTypes.LINEAR_ZERO_RATES dayCountType = FinDayCountTypes.THIRTY_E_360 liborCurve = FinDiscountCurveZeros(valuationDate, dates, zeroRates, contFreq, dayCountType, interpType) settlementDate = FinDate(1, 1, 2016) exerciseDate = FinDate(1, 1, 2017) maturityDate = FinDate(1, 1, 2020) fixedCoupon = -0.003 fixedFrequencyType = FinFrequencyTypes.SEMI_ANNUAL fixedDayCountType = FinDayCountTypes.THIRTY_E_360_ISDA floatFrequencyType = FinFrequencyTypes.SEMI_ANNUAL floatDayCountType = FinDayCountTypes.THIRTY_E_360_ISDA notional = 1000.0 # Pricing a PAYER swaptionType = FinLiborSwapTypes.PAYER swaption = FinLiborSwaption(settlementDate, exerciseDate, maturityDate, swaptionType, fixedCoupon, fixedFrequencyType, fixedDayCountType, notional, floatFrequencyType, floatDayCountType) model = FinModelBlackShifted(0.31, 0.008) v_finpy = swaption.value(valuationDate, liborCurve, model) v_matlab = 12.8301 testCases.header("LABEL", "VALUE") testCases.print("FP Price:", v_finpy) testCases.print("MATLAB Prix:", v_matlab) testCases.print("DIFF:", v_finpy - v_matlab) ############################################################################### testCases.header("===================================") testCases.header("MATLAB EXAMPLE WITH HULL WHITE") testCases.header("===================================") # https://fr.mathworks.com/help/fininst/swaptionbyhw.html valuationDate = FinDate(1, 1, 2007) dates = [ FinDate(1, 1, 2007), FinDate(1, 7, 2007), FinDate(1, 1, 2008), FinDate(1, 7, 2008), FinDate(1, 1, 2009), FinDate(1, 7, 2009), FinDate(1, 1, 2010), FinDate(1, 7, 2010), FinDate(1, 1, 2011), FinDate(1, 7, 2011), FinDate(1, 1, 2012) ] zeroRates = np.array([0.075] * 11) interpType = FinInterpTypes.FLAT_FORWARDS dayCountType = FinDayCountTypes.THIRTY_E_360_ISDA contFreq = FinFrequencyTypes.SEMI_ANNUAL liborCurve = FinDiscountCurveZeros(valuationDate, dates, zeroRates, contFreq, dayCountType, interpType) settlementDate = valuationDate exerciseDate = FinDate(1, 1, 2010) maturityDate = FinDate(1, 1, 2012) fixedCoupon = 0.04 fixedFrequencyType = FinFrequencyTypes.SEMI_ANNUAL fixedDayCountType = FinDayCountTypes.THIRTY_E_360_ISDA notional = 100.0 swaptionType = FinLiborSwapTypes.RECEIVER swaption = FinLiborSwaption(settlementDate, exerciseDate, maturityDate, swaptionType, fixedCoupon, fixedFrequencyType, fixedDayCountType, notional) model = FinModelRatesHW(0.05, 0.01) v_finpy = swaption.value(valuationDate, liborCurve, model) v_matlab = 2.9201 testCases.header("LABEL", "VALUE") testCases.print("FP Price:", v_finpy) testCases.print("MATLAB Prix:", v_matlab) testCases.print("DIFF:", v_finpy - v_matlab) ############################################################################### testCases.header("====================================") testCases.header("MATLAB EXAMPLE WITH BLACK KARASINSKI") testCases.header("====================================") # https://fr.mathworks.com/help/fininst/swaptionbybk.html valuationDate = FinDate(1, 1, 2007) dates = [ FinDate(1, 1, 2007), FinDate(1, 7, 2007), FinDate(1, 1, 2008), FinDate(1, 7, 2008), FinDate(1, 1, 2009), FinDate(1, 7, 2009), FinDate(1, 1, 2010), FinDate(1, 7, 2010), FinDate(1, 1, 2011), FinDate(1, 7, 2011), FinDate(1, 1, 2012) ] zeroRates = np.array([0.07] * 11) interpType = FinInterpTypes.FLAT_FORWARDS dayCountType = FinDayCountTypes.THIRTY_E_360_ISDA contFreq = FinFrequencyTypes.SEMI_ANNUAL liborCurve = FinDiscountCurveZeros(valuationDate, dates, zeroRates, contFreq, dayCountType, interpType) settlementDate = valuationDate exerciseDate = FinDate(1, 1, 2011) maturityDate = FinDate(1, 1, 2012) fixedFrequencyType = FinFrequencyTypes.SEMI_ANNUAL fixedDayCountType = FinDayCountTypes.THIRTY_E_360_ISDA notional = 100.0 model = FinModelRatesBK(0.1, 0.05, 200) fixedCoupon = 0.07 swaptionType = FinLiborSwapTypes.PAYER swaption = FinLiborSwaption(settlementDate, exerciseDate, maturityDate, swaptionType, fixedCoupon, fixedFrequencyType, fixedDayCountType, notional) v_finpy = swaption.value(valuationDate, liborCurve, model) v_matlab = 0.3634 testCases.header("LABEL", "VALUE") testCases.print("FP Price:", v_finpy) testCases.print("MATLAB Prix:", v_matlab) testCases.print("DIFF:", v_finpy - v_matlab) fixedCoupon = 0.0725 swaptionType = FinLiborSwapTypes.RECEIVER swaption = FinLiborSwaption(settlementDate, exerciseDate, maturityDate, swaptionType, fixedCoupon, fixedFrequencyType, fixedDayCountType, notional) v_finpy = swaption.value(valuationDate, liborCurve, model) v_matlab = 0.4798 testCases.header("LABEL", "VALUE") testCases.print("FP Price:", v_finpy) testCases.print("MATLAB Prix:", v_matlab) testCases.print("DIFF:", v_finpy - v_matlab) ############################################################################### testCases.header("====================================") testCases.header("MATLAB EXAMPLE WITH BLACK-DERMAN-TOY") testCases.header("====================================") # https://fr.mathworks.com/help/fininst/swaptionbybdt.html valuationDate = FinDate(1, 1, 2007) dates = [ FinDate(1, 1, 2007), FinDate(1, 7, 2007), FinDate(1, 1, 2008), FinDate(1, 7, 2008), FinDate(1, 1, 2009), FinDate(1, 7, 2009), FinDate(1, 1, 2010), FinDate(1, 7, 2010), FinDate(1, 1, 2011), FinDate(1, 7, 2011), FinDate(1, 1, 2012) ] zeroRates = np.array([0.06] * 11) interpType = FinInterpTypes.FLAT_FORWARDS dayCountType = FinDayCountTypes.THIRTY_E_360_ISDA contFreq = FinFrequencyTypes.ANNUAL liborCurve = FinDiscountCurveZeros(valuationDate, dates, zeroRates, contFreq, dayCountType, interpType) settlementDate = valuationDate exerciseDate = FinDate(1, 1, 2012) maturityDate = FinDate(1, 1, 2015) fixedFrequencyType = FinFrequencyTypes.ANNUAL fixedDayCountType = FinDayCountTypes.THIRTY_E_360_ISDA notional = 100.0 fixedCoupon = 0.062 swaptionType = FinLiborSwapTypes.PAYER swaption = FinLiborSwaption(settlementDate, exerciseDate, maturityDate, swaptionType, fixedCoupon, fixedFrequencyType, fixedDayCountType, notional) model = FinModelRatesBDT(0.20, 200) v_finpy = swaption.value(valuationDate, liborCurve, model) v_matlab = 2.0592 testCases.header("LABEL", "VALUE") testCases.print("FP Price:", v_finpy) testCases.print("MATLAB Prix:", v_matlab) testCases.print("DIFF:", v_finpy - v_matlab)