我在尝试从引导曲线为20x10交换定价时收到以下错误。在
ImpliedRate
功能
swapratesServiceTests.impliedrate_fortwenty_x_tenyearswap_returns日期:
System.ApplicationException:第2段:不能取消引用空句柄
我不知道从哪里开始调试这个问题。如有任何帮助,我们将不胜感激。
重要提示:我使用的是Quantlib的C_Swig版本,因此基于swapValue.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
}
这是更大的构造交换点方法的一部分
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++代码有关。希望这次曝光能揭示一些对这里可能发生的事情的见解。