title: Error when trying to price instrument when using Quantlib
body: <p>I am receiving the following error when trying to price a 20x10 swap from a bootstrapped curve. The error get thrown on the last line of the <code>ImpliedRate</code> function</p>
  
  <blockquote>
    <p>SwapRatesServiceTests.ImpliedRate_ForTwenty_x_TenYearSwap_ReturnsRate: 
    System.ApplicationException : 2nd leg: empty Handle cannot be dereferenced</p>
  </blockquote>
  
  <p>I don't have the faintest idea where to start to debug this issue. Any assistance will be highly appreciated.</p>
  
  <p>IMPORTANT: I am using the C# Swig version of Quantlib, so my actual prod code is as follows based on the swapvaluation.cpp example:</p>
  
  <p>The test method:</p>
  
  <pre><code>    [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 =&gt; r.Read(It.IsAny&lt;string&gt;())).Returns(LoadSwapPoints()); // LoadSwapPoints returns IEnumerable&lt;RateHelpers&gt;
  
          //Act
          service.ConstructSwapPoints(SettlementDate);
          var instrumentRate = service.ImpliedRate(startingDate, length);
  
          //Assert
          Assert.That(instrumentRate, Is.Not.Null); // this must change to a value test
  
      }
  </code></pre>
  
  <p>This is part of the larger ConstructSwapPoints method</p>
  
  <pre><code>        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           
  </code></pre>
  
  <p>With the ImpliedRate method as follows (i have snipped some parts out due to IP restrictions);</p>
  
  <pre><code>    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(); // &lt;---exception thrown here
      }
  </code></pre>
  
  <p>I hope my terminology is correct as the finance jargon is still new to me.</p>
  
  <p>Edit: I have added the C++ tag, since I figure is actually related to some underlying C++ code. Hoping that this exposure may reveal some insights into what may be happening here.</p>