Building a OIS yield curve in QuantLib Java

Simple OIS curve build

This example illustrates building an Overnight Index Swap based curve. With the phase-out of the use of survey-base rate benchmarks such as Libor these swaps are now the primary means of building the interest rates curves.

package demo;
/*

  Copyright (C) 2024 BN Algorithms Ltd

  QuantLib is free software: you can redistribute it and/or modify it
  under the terms of the QuantLib license.  You should have received a
  copy of the license along with this program; if not, please email
  <quantlib-dev@lists.sf.net>. The license is also available online at
  <http://quantlib.org/license.shtml>.
  
  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

import java.util.ArrayList;

import org.quantlib.*;

public class IRSwap {

    public static ArrayList<RateHelper> mkOISHelpers(double rates[],
                             int times[],
                             TimeUnit units[])
    {
    var res = new ArrayList<RateHelper>();
    var index = new Sofr();

    for (int i=0; i<rates.length; ++i) {
        var h =  new OISRateHelper(2,
                       new Period(times[i], units[i]),
                       new QuoteHandle(new SimpleQuote(rates[i])),
                       index);
        res.add(h);
        }   
    return res;
    }

    static public final Date today = new Date(5, Month.June, 2020);
    
    public void main() throws Exception {

    Settings.instance().setEvaluationDate(today);   


    double ycrate[] = {0.01, 0.01, 0.01, 0.01};
    int ycInt[]    =  { 2, 4, 6, 8};
    TimeUnit ycUnit[]   = { TimeUnit.Years, TimeUnit.Years, TimeUnit.Years, TimeUnit.Years};

    var rh = mkOISHelpers(ycrate, ycInt, ycUnit);
    var yy = new PiecewiseFlatForward(new Date(1, Month.June, 2020),
                      new RateHelperVector(rh),
                      new Actual360());
    
    yy.forwardRate(0.0, 0.01, Compounding.Continuous).rate();
    }

}

Contact

Copyright and published by: BN Algorihtms Ltd 2024. For general information only. Not to be relied for any purpose. Not advice about investment. No warranty of any kind. No liability for any use of this information accepted. Contact: webs@bnikolic.co.uk