Fx
quantlib 中的外匯遠期匯率協議估值
我正在嘗試使用以下程式碼在 quantlib Python 中評估 FRA:
import QuantLib as ql calendar = ql.UnitedStates() todaysDate = ql.Date(7, ql.May, 2017) # ql.Settings.instance().evaluationDate = todaysDate spotDates = [ql.Date(7, 5, 2017)+ql.Period(i*6, ql.Months) for i in range(0, 10)] spotRates = [4.3291/100]*len(spotDates) interpolation = ql.Linear() compounding = ql.Compounded compoundingFrequency = ql.Annual spotCurve = ql.ZeroCurve(spotDates, spotRates, ql.Actual360(), calendar,interpolation, compounding, compoundingFrequency) spotCurveHandle = ql.YieldTermStructureHandle(spotCurve) indexCurve1 = ql.Euribor6M(spotCurveHandle) indexCurve1.addFixing(ql.Date(7, 5, 2017) -3,0.9,True) forward_rates=[spotCurve.zeroRate(x,ql.Actual360(),compounding,compoundingFrequency).rate()for x in spotDates] fra = ql.ForwardRateAgreement(ql.Date(7, 5, 2017),ql.Date(15,12,2020),ql.Position.Long,0.01,10e6,ql.Euribor6M(spotCurveHandle))
但是,如果我在函式中更改估值日期
fra = ql.ForwardRateAgreement(ql.Date(7, 5, 2018),ql.Date(15,12,2020),ql.Position.Long,0.01,10e6,ql.Euribor6M(spotCurveHandle))
它給了我一個錯誤:RuntimeError: empty Handle cannot be dereferenced
誰能幫我解決這個錯誤?我將由衷感謝。
提前致謝!
您沒有給建構子一個折扣曲線。建構子是:
ql.ForwardRateAgreement(valueDate, maturityDate, position, strikeForward, notional, iborIndex, discountCurve=ql.YieldTermStructureHandle())
所以你應該添加一個 spotCurveHandle 作為最後一個參數:
fra = ql.ForwardRateAgreement(ql.Date(7, 5, 2018), ql.Date(15,12,2020), ql.Position.Long, 0.01, 10e6,ql.Euribor6M(spotCurveHandle), spotCurveHandle)