Using QuantLib on the Signaloid Cloud Compute Engine

Quantitative Finance

Quantitative Finance

QuantLib [1] is a popular library for quantitative finance. The Signaloid Cloud Computing Engine (SCCE) provides an execution environment in which organizations can run their QuantLib-based C/C++ models while taking advantage of Signaloid UxHw technology. This technology explainer demonstrates a complete example of implementing a Net Present Value (NPV) calculation using QuantLib, running on the Signaloid Cloud Compute Engine. The example presented achieves a 70-fold speedup when quantifying the uncertainty of the NPV calculation, compared to running on an Intel Xeon platform (AWS r7iz EC2 instance).

Why It Matters

Present value comptuations, often performed for a distribution of possible model parameter values, is an important computation performed regularly by many investment banks and similar financial institutions. The computations, performed across a distribution of possible model parameter values, are conceptually a Monte Carlo simulation over the model parameter space. Signaloid's UxHw technology allows institutions that today perform such Monte Carlo simulations to reduce their operating expenses, energy usage, and runtimes, by deploying an on-premises instance of Signaloid's Cloud Compute Engine that takes advantage of their existing hardware investments.

The Technical Details

The Net Present Value (NPV) is a way of measuring the value of an asset that has cash flows (inflows or credits, outflows or debits) by adding up all the future cash flows the asset will generate. Because it is not always possible to predict future cash flows, it is valuable in computing the NPV to be able to simulate many different possible cash flows and to determine the distribution of possible NPVs; the example below models a scenario where the cash flows are assumed to be each equally likely to be between 250 and 350 currency units. The code example below uses QuantLib's CashFlows::npv method to compute the NPV, for an initial investment of $1000, with a discount factor of 5%, over five years.

In a traditional attempt to estimate the distribution of possible NPVs, one would place the loop seen in the example below inside an outer Monte Carlo loop, with each iteration of the loop using different cash flows for each of the five years. An evaluation would then run that Monte Carlo until the results converged, and would collect the set of NPVs generated. Finally, a traditional implementation could then compute, e.g., summary statistics such as the mean NPV and standard deviation on NPV.

In an implementation running on platform's implementing Signaloid's UxHw technology, the implementation can set the cash flows to be a probability distribution: the value returned by UxHwDoubleUniformDist(250, 350) behaves syntactically like a C++ double but is handled by the compiler, the underlying runtime system, and the execution environment as a combination of both a value and a probability distribution. The code in the example below therefore achieves the same analysis as one that contained an additional outer Monte Carlo loop while running approximately 70-fold faster on the Signaloid Cloud Compute Engine (SCCE), compared to running on an Intel Xeon (AWS r7iz EC2 instance) using similar hardware resources.

Relevant Code Example
#include <quantlib.hpp>
#include <iostream>
#include <ql/time/date.hpp>
#include <ql/time/calendar.hpp>
#include <ql/time/daycounters/actual360.hpp>
#include <uxhw.h>

int
main(int argc, char *  argv[])
{
	Real			netPresentValue;
	Real			initialInvestment = 1000.0;
	Real			discountRate = 0.05;
	int				numberOfYears = 5;
	Leg				cashFlows;
	Date			date = Date::todaysDate();
	DayCounter		dayCounter = ActualActual(ActualActual::ISMA);
	Compounding		compounding = Compounded;
	Frequency		frequency = Annual;

	cashFlows.push_back(boost::shared_ptr<CashFlow>(new SimpleCashFlow( - initialInvestment, date)));

	for (size_t i = 0; i < arguments.numberOfYears; i++)
	{
		Real netCashFlow;

		netCashFlow = UxHwDoubleUniformDist(250, 350);

		cashFlows.push_back(boost::shared_ptr<CashFlow>(new SimpleCashFlow(netCashFlow,
																date + Period(i + 1, QuantLib::Years))));
	}

	/*
	 *      Calculate the Net Present Value (NPV)
	 */
	netPresentValue = CashFlows::npv(cashFlows,
						InterestRate(discountRate,
							dayCounter,
							compounding,
							frequency),
						true);

	printf("netPresentValue = %lf\n", netPresentValue);

	return 0;
}

Figure 1: The Net Present Value output plot generated running on UxHw (Signaloid C0Pro-M core).

Figure 2: A plot generated by the equivalent Monte Carlo sample values (36,401 samples).

Figure 3: The ground truth (1,000,000 Monte Carlo iterations) to which we compare the UxHw and 36k-iteration Monte Carlo.

The Takeaway

Net Present Value (NPV) comptuations, often performed for a distribution of possible model parameter values, are an important computation performed regularly by many investment banks and similar financial institutions. QuantLib [^0] is a popular library for quantitative finance and this technology explainer demonstrated how to run NPV calculations on platforms such as the Signaloid Cloud Compute Engine (SCCE) that implement Signaloid UxHw technology. The example presented demonstrated how implementations targeted for execution on Signaloid's UxHw make it easier to achieve the evaluation of NPV over a distribution of possible future cash flows (single line of code addition needed) and such implementations also run many times faster (70-fold speedup for the example presented) than on a competing execution platform (Intel Xeon / AWS r7iz EC2 instance) with equivalent hardware resources.

References
  1. QuantLib: A free/open-source library for quantitative finance. https://www.quantlib.org

Schedule a Demo Call
Request Whitepaper
Schedule a Demo Call
Request Whitepaper
Schedule a Demo Call
Request Whitepaper