ブートストラップされたカーブから20x10スワップの価格を設定しようとすると、次のエラーが発生します。ImpliedRate関数の最後の行にエラーがスローされます
SwapRatesServiceTests.ImpliedRate_ForTwenty_x_TenYearSwap_ReturnsRate:System.ApplicationException:2番目のレッグ:空のハンドルは逆参照できません
この問題のデバッグをどこから始めればよいのか、私にはわかりません。どんな援助も大歓迎です。
重要:私はQuantlibのC#Swigバージョンを使用しているので、実際の製品コードは、swapvaluation.cppの例に基づいて次のようになります。
試験方法:
[Test]
public void ImpliedRate_ForTwenty_x_TenYearSwap_ReturnsRate()
{
//Arrange
var startingDate = new Date(10,Month.October,2030); // starting date of 20x10yr swap
var length= 10;
repo.Setup(r => r.Read(It.IsAny<string>())).Returns(LoadSwapPoints()); // LoadSwapPoints returns IEnumerable<RateHelpers>
//Act
service.ConstructSwapPoints(SettlementDate);
var instrumentRate = service.ImpliedRate(startingDate, length);
//Assert
Assert.That(instrumentRate, Is.Not.Null); // this must change to a value test
}
これは、より大きなConstructSwapPointsメソッドの一部です
var depoFRASwapInstruments = PointVector; // RateHelperVector populated with RateHelpers
DayCounter termStructureDayCounter = new ActualActual(ActualActual.Convention.Actual365);
QuoteHandleVector quotes = new QuoteHandleVector();
DateVector quoteDates = new DateVector();
py = CreatePiecewiseLinearCurve(settlementDate, depoFRASwapInstruments, termStructureDayCounter, quotes, quoteDates);
DiscountingTermStructure = new RelinkableYieldTermStructureHandle(py); //RelinkableYieldTermStructureHandle
//DiscountingTermStructure.linkTo(py); // alternate way
PricingEngine = new DiscountingSwapEngine(DiscountingTermStructure); // DiscountingSwapEngine
ImpliedRateメソッドを次のように使用します(IP制限のために一部のパーツを削除しました)。
public double ImpliedRate(Date startingDate, int length)
{
var swapMaturityDate = startingDate.Add(new Period(length, TimeUnit.Years));
var curveMaturityDate = py.maxDate();
Schedule fixedSchedule = new Schedule(startingDate, swapMaturityDate, new Period(Frequency.Quarterly), SouthAfricanCalender, Convention, Convention, DateGeneration.Rule.Forward, false);
Schedule floatSchedule = new Schedule(startingDate, swapMaturityDate, new Period(Frequency.Quarterly), SouthAfricanCalender, Convention, Convention, DateGeneration.Rule.Forward, false);
VanillaSwap impliedSwap = new VanillaSwap(
_VanillaSwap.Type.Payer,
10000000.0,
fixedSchedule,
0.1,
Actual365FixedDayCounter,
floatSchedule,
new Jibar(new Period(Frequency.Quarterly)),
0,
Actual365FixedDayCounter);
impliedSwap.setPricingEngine(PricingEngine);
return impliedSwap.fairRate(); // <---exception thrown here
}
金融用語はまだ私には新しいので、私の用語が正しいことを願っています。
編集:私はC ++タグを追加しました。これは、実際にはいくつかの基礎となるC++コードに関連していると考えているためです。この露出がここで何が起こっているのかについての洞察を明らかにするかもしれないことを願っています。