A JSON / JavaScript financial risk and pricing library
Here are three reasons for using a financial risk and pricing library in JavaScript.
- As one of the key technologies of the web, JavaScript is ubiquitous and heavily supported by the leading tech companies and by a large open source community.
- Web applications required to have access to financial math logic both on the client and on the server side are largely bound to use JavaScript, as JavaScript is the only programming language natively supported in all major web browsers.
- With JSON being a native subset of JavaScript, data interchange in JavaScript applications is almost as easy as calling the Javascript
JSON.parseandJSON.stringifyfunctions, making any parsing and serialization logic obsolete for most applications.
const JsonRisk=require('path/to/json_risk.js');
<script src="path/to/json_risk.min.js"></script>
const bond = new JsonRisk.Bond({
maturity: new Date(2028,0,1), //final maturity of the bond
notional: 100.0, //notional
fixed_rate: 0.05, //interest rate 5%
tenor: 12, //yearly interest payments
bdc: "following", //business day convention
dcc: "act/act", //day count convention
calendar: "TARGET", //holiday calendar
disc_curve: "DISCOUNT" //name reference to the discount curve
});
const discount_curve={
labels: ["1Y", "2Y", "3Y", "10Y"], //times encoded as labels
zcs: [0.01, 0.02, 0.025, 0.1] //zero-coupon rates act/365 annual compounding
};
const params=new JsonRisk.Params({
valuation_date: "2019/12/31", //one of the supported date string formats
curves: {
"DISCOUNT": discount_curve //the discount curve defined above
}
});
const present_value=bond.value(params);
See the documentation for details and examples.
JSON Risk supports the instrument types below:
- Fixed income instruments
- Fixed rate bonds
- Floating rate bonds
- Interest rate swaps
- Bespoke leg instruments
- FX instruments
- FX spot
- FX forward
- Cross-Currency Swap
- Callable fixed income instruments
- Plain vanilla swaptions
- Single callable and multicallable bond
- Equities
- Stock
- Stock/Index Future
- Stock/Index Forward
- European Options
- American Options
- Credit
- Credit default swaps
Fixed income, FX and Credit instruments support cash flow generation from terms and conditions as well as pre-defined leg structures.
Pricing of complex interest rate derivatives is implemented with a Linear Gauss Markov (or, equivalently, Hull-White) model in the spirit of Hagan, Patrick; EVALUATING AND HEDGING EXOTIC SWAP INSTRUMENTS VIA LGM (2019).
- bullet repayment upon maturity
- step-down amortization (regular repayments)
- interest capitalization (allowing to define annuity-type profiles)
- long and short implicit stubs (e.g., forward and backward roll out)
- explicit initial and final stubs
- completely independent generation of
- interest rate schedule
- fixing schedule for floating rate instruments
- repayment schedule for amortizing instruments
JSON Risk supports the day count conventions
- act/act (ISDA) according to the ISDA 2006 rules in section 4.16 (b), also recognized by JSON Risk as act/act
- act/act (ICMA) according to the ISDA 2006 rules in section 4.16 (c), also recognized by JSON Risk as act/act (ISMA) or act/nAct
- act/365 according to the ISDA 2006 rules in section 4.16 (d), also recognized by JSON Risk as act/365 (fixed)
- act/360 according to the ISDA 2006 rules in section 4.16 (e), also recognized by JSON Risk as french
- 30u/360 according to the ISDA 2006 rules in section 4.16 (f), also recognized by JSON Risk as 30/360, bond basis, or bond
- 30e/360 according to the ISDA 2006 rules in section 4.16 (g), also recognized by JSON Risk as eurobond basis or eurobond
- 30g/360 according to the ISDA 2006 rules in section 4.16 (h), also recognized by JSON Risk as 30e/360 (ISDA) or 30/360 German
- act/act (AFB) as described in a 1999 ISDA memo, originally defined by the french banking association
JSON Risk is case insensitive when parsing day count conventions on instrument data. Instead of "act", is is ok to specify "actual" or just "a". Specific sub-conventions above may be specified with or without brackets, e.g., act/act ICMA and act/act (ICMA) refer to the same convention.
JSON Risk supports the business day conventions
- unadjusted,
- following,
- modified following,
- preceding.
JSON Risk supports one built-in calendar (TARGET) as of now.
Adding custom calendars is as simple as
const holidays = [
new Date(2018,11,1), //javascript date object
"2018/12/12", //valid YYYY/MM/DD date string
"2019-12-01", //valid YYYY/MM/DD date string
"01.12.2020" //valid DD.MM.YYYY date string
];
JsonRisk.add_calendar("CUSTOM", holidays);
Saturdays and Sundays are considered holidays in all custom calendars.
- The Instruments guide summarizes supported instruments and features
- The Fields guide contains a complete list of JSON fields for describing instrument terms and conditions
- The Data types guide explains the data types used in the JSON fields
- The Parameters guide explains how to represent parameters for valuation, e.g., yield curves and surfaces.
- The Schedule generation guide explains how JSON risk generates schedules for interest rate instruments.