diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cad8d5..31dc831 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,13 +71,13 @@ ENDIF () IF (MSVC_IDE) IF ( CMAKE_CONFIGURATION_TYPES STREQUAL "Debug" ) - TARGET_LINK_LIBRARIES(quantlib QuantLib-vc120-mt-gd.lib) - TARGET_LINK_LIBRARIES(quantlib QuantLibObjects-vc120-mt-gd-1_7_0.lib) - TARGET_LINK_LIBRARIES(quantlib ObjectHandler-vc120-mt-gd-1_7_0.lib) + TARGET_LINK_LIBRARIES(quantlib QuantLib-vc140-mt-gd.lib) + TARGET_LINK_LIBRARIES(quantlib QuantLibObjects-vc140-mt-gd-1_8_0.lib) + TARGET_LINK_LIBRARIES(quantlib ObjectHandler-vc140-mt-gd-1_8_0.lib) ELSE () - TARGET_LINK_LIBRARIES(quantlib QuantLib-vc120-mt-s.lib) - TARGET_LINK_LIBRARIES(quantlib QuantLibObjects-vc120-mt-s-1_7_0.lib) - TARGET_LINK_LIBRARIES(quantlib ObjectHandler-vc120-mt-s-1_7_0.lib) + TARGET_LINK_LIBRARIES(quantlib QuantLib-vc140-mt-s.lib) + TARGET_LINK_LIBRARIES(quantlib QuantLibObjects-vc140-mt-s-1_8_0.lib) + TARGET_LINK_LIBRARIES(quantlib ObjectHandler-vc140-mt-s-1_8_0.lib) ENDIF () ENDIF () diff --git a/LICENSE b/LICENSE index 113256f..23f2727 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2016 Jerry Jin +Copyright (c) 2016 - 2017 Jerry Jin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index f4dda56..b4df4ac 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ -## QuantLib Async Bindings for Node.js [![npm version](https://badge.fury.io/js/quantlib.svg)](http://badge.fury.io/js/quantlib) +## QuantLib Async Bindings for Node.js -This project brings [QuantLib](http://quantlib.org/) to the Node.js community, it's similar to [QuantLibXL](http://quantlib.org/quantlibxl/) project which is for Microsoft Excel. +[![NPM](https://nodei.co/npm/quantlib.png?downloads=true&downloadRank=true)](https://nodei.co/npm/quantlib/) + +[![npm version](https://badge.fury.io/js/quantlib.svg)](http://badge.fury.io/js/quantlib) +[![Twitter Follow](https://img.shields.io/twitter/follow/quantlibnode.svg?style=social&maxAge=3600)](https://twitter.com/quantlibnode) + +This [open source project](https://github.com/quantlibnode/quantlibnode) brings [QuantLib](http://quantlib.org/) to the Node.js community, it's similar to [QuantLibXL](http://quantlib.org/quantlibxl/) project which is for Microsoft Excel. Most functions in QuantLibXL can be used in the similar way in Node on the server side. @@ -13,13 +18,17 @@ All functions in this project are Async, they are exported to [Promise](https:// npm install quantlib ``` -* Windows +* Windows (32-bit & 64-bit) `npm install quantlib` will do everything, including the node package installation and pre-built native addon (no dependency) download, you can start use it right away. +> v0.2.x windows prebuilt on windows 8.1 with VC14 + +> v0.1.x windows prebuilt on windows 7 with VC12, only 32-bit available + * Linux & Mac -Quantlib and QuantLibAddin must be built first, then build QuantLibNode linking to them, pre-built native code is not provided for now +Please refer to [how to build](#building-the-native-addon) below ## QuantLib Documents @@ -33,9 +42,51 @@ Quantlib and QuantLibAddin must be built first, then build QuantLibNode linking | QuantLib | QuantLibAddin | Node.js | quantlib.node | | -------- | ------------- | ------- | ------------- | | 1.7.1 | 1.7.0 | 6.9.1 | 0.1.x | +| 1.8.1 | 1.8.0 | 6.9.5 | 0.2.x | +| 1.9.2 | 1.9.0 | 6.9.5 | 0.3.x | + +## Building the native addon + +#### Prerequisite + +* CMake 2.8 or above, Visual C++ for windows, Xcode for Mac, GCC for Linux +* Node.js according to [version matrix](#version-matrix) +* [nan](https://github.com/nodejs/nan) ^2.2.0 +* [node-gyp](https://github.com/nodejs/node-gyp) ~3.0.3 +* QuantLib, QuantLibAddin, ObjectHandler source code according to [version matrix](#version-matrix), they need to be put in the same directory +* `boost` - which is required to build QuantLib + +> for Mac OS X and Linux, QuantLib projects must be built with `-std=c++11` this flag is required by node + +> for linux, need to add `-fPIC` flag + +#### Set environment variable + +please refer to `cmake/*.cmake` and `CMakeList.txt` files + +* `NAN_DIR` - location of `nan` +* `NODE_GYP_DIR` - location of `.node-gyp` generated by `node-gyp` tool, which is at `~/.node-gyp`, if it doesn't exist, follow the instruction in [node-gyp](https://github.com/nodejs/node-gyp), and build a helloword program, it will generate the `.node-gyp` directory +* `QUANTLIB_ROOT` - location of QuantLib, QuantLibAddin, ObjectHandler source code +* `BOOST_ROOT` - location `boost` installed + +#### Use cmake to build the addon + +1. Build QuantLib and QuantLibAddin, please check `CMakeList.txt` for library name, and make sure generated library names are the same in `CMakeList.txt` +2. from `quantlibnode` root directory `cd build` +3. `cmake ..` for Windows and Linux, `cmake -G Xcode ..` for Mac OS X +4. `cmake --build . --config Release` +5. For Linux, you may need to put `quantlib.node` under `build/Release` manually, ## Example +> This is from QuantLibXL - StandaloneExamples - Math - RankReduction.xlsx - FirstCorrMatrix + +> C2 - formulat: =qlSymmetricSchurDecomposition(,B3:K12) + +> M3:12 - forumula: {=qlSymmetricSchurDecompositionEigenvalues(C2)} + +> the input/output are the same + ```js var ql = require('quantlib'); @@ -53,9 +104,15 @@ var mtx1 = [0.81880, 0.83520, 0.85230, 0.87040, 0.88940, 0.90940, 0.93040, 0.95240, 0.97560, 1.00000] ]; -ql.SymmetricSchurDecomposition('mtx#1',mtx1).then(function(obj){ - - ql.SymmetricSchurDecompositionEigenvalues(obj).then(function(r){ +/* + * call Constructor to create object, objectID needs to be provided as input, this is diffierent with QuantLibXL + * ObjectID, can be generated with Node.js, it needs to be uniquie + * since this is on server side, you may put session# as part of objectID +*/ +ql.SymmetricSchurDecomposition('mtx#1',mtx1).then(function(obj){ //C2 formula: =qlSymmetricSchurDecomposition(,B3:K12) + + // call Method with objectID, this is same as QuantLibXL + ql.SymmetricSchurDecompositionEigenvalues(obj).then(function(r){ // M3:12 formula: {=qlSymmetricSchurDecompositionEigenvalues(C2)} console.log(r); }); @@ -77,4 +134,4 @@ ql.SymmetricSchurDecomposition('mtx#1',mtx1).then(function(obj){ 0.01580103250921176, 0.01377474504269164, 0.012784934140218302 ] -``` +``` \ No newline at end of file diff --git a/cmake/FindNode.cmake b/cmake/FindNode.cmake index 5584f51..6ed2ce8 100644 --- a/cmake/FindNode.cmake +++ b/cmake/FindNode.cmake @@ -4,7 +4,7 @@ # NODE_GYP_FOUND - True if node found. # Read environment variables to find node_gyp include/lib directories -SET(NODE_GYP_VER "6.9.1") +SET(NODE_GYP_VER "6.9.5") MESSAGE( STATUS "NODE_GYP_VER: " ${NODE_GYP_VER} ) SET(NODE_GYP_DIR $ENV{NODE_GYP_DIR}/${NODE_GYP_VER}) MESSAGE( STATUS "NODE_GYP_DIR: " ${NODE_GYP_DIR} ) diff --git a/lib/quantlib.js b/lib/quantlib.js index 730a936..aa55e33 100644 --- a/lib/quantlib.js +++ b/lib/quantlib.js @@ -1,4 +1,7 @@ -// This is a generated file, modify: generate/templates/quantlib.js +/* + Copyright (C) 2016 -2017 Jerry Jin +*/ + var promisify = require("promisify-node"); var rawApi = require("../build/Release/quantlib"); @@ -350,8 +353,8 @@ exports.CreditBasketSetLossModel = promisify(rawApi.CreditBasketSetLossModel); exports.CreditBasketSize = promisify(rawApi.CreditBasketSize); exports.CreditBasketLiveNotional = promisify(rawApi.CreditBasketLiveNotional); exports.CreditBasketLoss = promisify(rawApi.CreditBasketLoss); -exports.CrediBasketAttachLive = promisify(rawApi.CrediBasketAttachLive); -exports.CrediBasketDetachLive = promisify(rawApi.CrediBasketDetachLive); +exports.CreditBasketAttachLive = promisify(rawApi.CreditBasketAttachLive); +exports.CreditBasketDetachLive = promisify(rawApi.CreditBasketDetachLive); exports.ExpectedTrancheLoss = promisify(rawApi.ExpectedTrancheLoss); exports.CreditBasketPercentile = promisify(rawApi.CreditBasketPercentile); exports.CreditBasketESF = promisify(rawApi.CreditBasketESF); @@ -1060,6 +1063,12 @@ exports.PiecewiseConstantVarianceVariance = promisify(rawApi.PiecewiseConstantVa exports.PiecewiseConstantVarianceVolatility = promisify(rawApi.PiecewiseConstantVarianceVolatility); exports.PiecewiseConstantVarianceTotalVariance = promisify(rawApi.PiecewiseConstantVarianceTotalVariance); exports.PiecewiseConstantVarianceTotalVolatility = promisify(rawApi.PiecewiseConstantVarianceTotalVolatility); + +exports.PiecewiseYieldCurveMixedInterpolation = promisify(rawApi.PiecewiseYieldCurveMixedInterpolation); +exports.BachelierCapFloorEngine = promisify(rawApi.BachelierCapFloorEngine); +exports.BachelierCapFloorEngine2 = promisify(rawApi.BachelierCapFloorEngine2); +exports.BachelierBlackFormulaImpliedVol = promisify(rawApi.BachelierBlackFormulaImpliedVol); + exports.ObjectPropertyNames = promisify(rawApi.ObjectPropertyNames); exports.DeleteObject = promisify(rawApi.DeleteObject); exports.DeleteObjects = promisify(rawApi.DeleteObjects); diff --git a/package.json b/package.json index 9491342..fc56982 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,9 @@ { "name": "quantlib", "description": "QuantLib Asyn Bindings for Node.js", - "version": "0.1.5", + "version": "0.3.0", "keywords": [ - "quantlib", - "native", - "addon" + "quantlib" ], "main": "lib/quantlib.js", "repository": { diff --git a/quantlibnode.cpp b/quantlibnode.cpp index 0d4b537..a05608f 100644 --- a/quantlibnode.cpp +++ b/quantlibnode.cpp @@ -1,3 +1,7 @@ +/* + Copyright (C) 2016 -2017 Jerry Jin +*/ + #include #include #include @@ -369,8 +373,8 @@ NAN_MODULE_INIT(init){ Nan::SetMethod(target, "CreditBasketSize", QuantLibNode::CreditBasketSize); Nan::SetMethod(target, "CreditBasketLiveNotional", QuantLibNode::CreditBasketLiveNotional); Nan::SetMethod(target, "CreditBasketLoss", QuantLibNode::CreditBasketLoss); - Nan::SetMethod(target, "CrediBasketAttachLive", QuantLibNode::CrediBasketAttachLive); - Nan::SetMethod(target, "CrediBasketDetachLive", QuantLibNode::CrediBasketDetachLive); + Nan::SetMethod(target, "CreditBasketAttachLive", QuantLibNode::CreditBasketAttachLive); + Nan::SetMethod(target, "CreditBasketDetachLive", QuantLibNode::CreditBasketDetachLive); Nan::SetMethod(target, "ExpectedTrancheLoss", QuantLibNode::ExpectedTrancheLoss); Nan::SetMethod(target, "CreditBasketPercentile", QuantLibNode::CreditBasketPercentile); Nan::SetMethod(target, "CreditBasketESF", QuantLibNode::CreditBasketESF); @@ -1080,6 +1084,11 @@ NAN_MODULE_INIT(init){ Nan::SetMethod(target, "PiecewiseConstantVarianceTotalVariance", QuantLibNode::PiecewiseConstantVarianceTotalVariance); Nan::SetMethod(target, "PiecewiseConstantVarianceTotalVolatility", QuantLibNode::PiecewiseConstantVarianceTotalVolatility); + Nan::SetMethod(target, "PiecewiseYieldCurveMixedInterpolation", QuantLibNode::PiecewiseYieldCurveMixedInterpolation); + Nan::SetMethod(target, "BachelierCapFloorEngine", QuantLibNode::BachelierCapFloorEngine); + Nan::SetMethod(target, "BachelierCapFloorEngine2", QuantLibNode::BachelierCapFloorEngine2); + Nan::SetMethod(target, "BachelierBlackFormulaImpliedVol", QuantLibNode::BachelierBlackFormulaImpliedVol); + Nan::SetMethod(target, "DeleteObject", QuantLibNode::DeleteObject); Nan::SetMethod(target, "DeleteObjects", QuantLibNode::DeleteObjects); Nan::SetMethod(target, "DeleteAllObjects", QuantLibNode::DeleteAllObjects); diff --git a/quantlibnode.hpp b/quantlibnode.hpp index d05eb29..834e625 100644 --- a/quantlibnode.hpp +++ b/quantlibnode.hpp @@ -1,3 +1,8 @@ +/* + Copyright (C) 2016 -2017 Jerry Jin +*/ + + #ifndef quantlibnode_hpp #define quantlibnode_hpp @@ -416,8 +421,8 @@ class QuantLibNode : public Nan::ObjectWrap { static NAN_METHOD(CreditBasketSize); static NAN_METHOD(CreditBasketLiveNotional); static NAN_METHOD(CreditBasketLoss); - static NAN_METHOD(CrediBasketAttachLive); - static NAN_METHOD(CrediBasketDetachLive); + static NAN_METHOD(CreditBasketAttachLive); + static NAN_METHOD(CreditBasketDetachLive); static NAN_METHOD(ExpectedTrancheLoss); static NAN_METHOD(CreditBasketPercentile); static NAN_METHOD(CreditBasketESF); @@ -1127,6 +1132,11 @@ class QuantLibNode : public Nan::ObjectWrap { static NAN_METHOD(PiecewiseConstantVarianceTotalVariance); static NAN_METHOD(PiecewiseConstantVarianceTotalVolatility); + static NAN_METHOD(PiecewiseYieldCurveMixedInterpolation); + static NAN_METHOD(BachelierCapFloorEngine); + static NAN_METHOD(BachelierCapFloorEngine2); + static NAN_METHOD(BachelierBlackFormulaImpliedVol); + static NAN_METHOD(DeleteObject); static NAN_METHOD(DeleteObjects); static NAN_METHOD(DeleteAllObjects); diff --git a/src/abcd.cpp b/src/abcd.cpp index 8e414ea..41d6db1 100644 --- a/src/abcd.cpp +++ b/src/abcd.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/abcd.hpp b/src/abcd.hpp index 2d1e775..965c165 100644 --- a/src/abcd.hpp +++ b/src/abcd.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef abcd_h diff --git a/src/accountingengines.cpp b/src/accountingengines.cpp index ebd8336..5d43860 100644 --- a/src/accountingengines.cpp +++ b/src/accountingengines.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/accountingengines.hpp b/src/accountingengines.hpp index 82015df..4c213c4 100644 --- a/src/accountingengines.hpp +++ b/src/accountingengines.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef accountingengines_h diff --git a/src/alphaform.cpp b/src/alphaform.cpp index 2d4a722..7428831 100644 --- a/src/alphaform.cpp +++ b/src/alphaform.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/alphaform.hpp b/src/alphaform.hpp index 41f32ec..8fdb7f5 100644 --- a/src/alphaform.hpp +++ b/src/alphaform.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef alphaform_h diff --git a/src/assetswap.cpp b/src/assetswap.cpp index 58deed6..60e0005 100644 --- a/src/assetswap.cpp +++ b/src/assetswap.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/assetswap.hpp b/src/assetswap.hpp index d87b633..db12725 100644 --- a/src/assetswap.hpp +++ b/src/assetswap.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef assetswap_h diff --git a/src/basketlossmodels.cpp b/src/basketlossmodels.cpp index 667fd16..4c78283 100644 --- a/src/basketlossmodels.cpp +++ b/src/basketlossmodels.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include @@ -32,7 +32,7 @@ void GaussianLHPLossmodelWorker::Execute(){ new QuantLibAddin::ValueObjects::qlGaussianLHPLossmodel( mObjectID, mCorrelation, - mRecoveyRates, + mRecoveryRates, false )); @@ -41,7 +41,7 @@ void GaussianLHPLossmodelWorker::Execute(){ new QuantLibAddin::GaussianLHPLossModel( valueObject, mCorrelation, - mRecoveyRates, + mRecoveryRates, false )); @@ -78,7 +78,7 @@ NAN_METHOD(QuantLibNode::GaussianLHPLossmodel) { return Nan::ThrowError("Correlation is required."); } if (info.Length() == 2 || !info[2]->IsArray()) { - return Nan::ThrowError("RecoveyRates is required."); + return Nan::ThrowError("RecoveryRates is required."); } // convert js argument to c++ type String::Utf8Value strObjectID(info[0]->ToString()); @@ -88,11 +88,11 @@ NAN_METHOD(QuantLibNode::GaussianLHPLossmodel) { double CorrelationCpp = Nan::To(info[1]).FromJust(); // convert js argument to c++ type - std::vectorRecoveyRatesCpp; + std::vectorRecoveryRatesCpp; - Local RecoveyRatesArray = info[2].As(); - for (unsigned int i = 0; i < RecoveyRatesArray->Length(); i++){ - RecoveyRatesCpp.push_back(Nan::To(Nan::Get(RecoveyRatesArray, i).ToLocalChecked()).FromJust()); + Local RecoveryRatesArray = info[2].As(); + for (unsigned int i = 0; i < RecoveryRatesArray->Length(); i++){ + RecoveryRatesCpp.push_back(Nan::To(Nan::Get(RecoveryRatesArray, i).ToLocalChecked()).FromJust()); } @@ -103,7 +103,7 @@ NAN_METHOD(QuantLibNode::GaussianLHPLossmodel) { callback ,ObjectIDCpp ,CorrelationCpp - ,RecoveyRatesCpp + ,RecoveryRatesCpp )); } @@ -132,7 +132,7 @@ void IHGaussPoolLossModelWorker::Execute(){ new QuantLibAddin::ValueObjects::qlIHGaussPoolLossModel( mObjectID, mCorrelation, - mRecoveyRates, + mRecoveryRates, mNumBuckets, false )); @@ -142,7 +142,7 @@ void IHGaussPoolLossModelWorker::Execute(){ new QuantLibAddin::IHGaussPoolLossModel( valueObject, mCorrelation, - mRecoveyRates, + mRecoveryRates, NumBucketsLib, false )); @@ -180,7 +180,7 @@ NAN_METHOD(QuantLibNode::IHGaussPoolLossModel) { return Nan::ThrowError("Correlation is required."); } if (info.Length() == 2 || !info[2]->IsArray()) { - return Nan::ThrowError("RecoveyRates is required."); + return Nan::ThrowError("RecoveryRates is required."); } if (info.Length() == 3 || !info[3]->IsNumber()) { return Nan::ThrowError("NumBuckets is required."); @@ -193,11 +193,11 @@ NAN_METHOD(QuantLibNode::IHGaussPoolLossModel) { double CorrelationCpp = Nan::To(info[1]).FromJust(); // convert js argument to c++ type - std::vectorRecoveyRatesCpp; + std::vectorRecoveryRatesCpp; - Local RecoveyRatesArray = info[2].As(); - for (unsigned int i = 0; i < RecoveyRatesArray->Length(); i++){ - RecoveyRatesCpp.push_back(Nan::To(Nan::Get(RecoveyRatesArray, i).ToLocalChecked()).FromJust()); + Local RecoveryRatesArray = info[2].As(); + for (unsigned int i = 0; i < RecoveryRatesArray->Length(); i++){ + RecoveryRatesCpp.push_back(Nan::To(Nan::Get(RecoveryRatesArray, i).ToLocalChecked()).FromJust()); } // convert js argument to c++ type @@ -211,7 +211,7 @@ NAN_METHOD(QuantLibNode::IHGaussPoolLossModel) { callback ,ObjectIDCpp ,CorrelationCpp - ,RecoveyRatesCpp + ,RecoveryRatesCpp ,NumBucketsCpp )); @@ -241,7 +241,7 @@ void IHStudentPoolLossModelWorker::Execute(){ new QuantLibAddin::ValueObjects::qlIHStudentPoolLossModel( mObjectID, mCorrelation, - mRecoveyRates, + mRecoveryRates, mTtraits, mNumBuckets, false @@ -252,7 +252,7 @@ void IHStudentPoolLossModelWorker::Execute(){ new QuantLibAddin::IHStudentPoolLossModel( valueObject, mCorrelation, - mRecoveyRates, + mRecoveryRates, mTtraits, NumBucketsLib, false @@ -291,7 +291,7 @@ NAN_METHOD(QuantLibNode::IHStudentPoolLossModel) { return Nan::ThrowError("Correlation is required."); } if (info.Length() == 2 || !info[2]->IsArray()) { - return Nan::ThrowError("RecoveyRates is required."); + return Nan::ThrowError("RecoveryRates is required."); } if (info.Length() == 3 || !info[3]->IsArray()) { return Nan::ThrowError("Ttraits is required."); @@ -307,11 +307,11 @@ NAN_METHOD(QuantLibNode::IHStudentPoolLossModel) { double CorrelationCpp = Nan::To(info[1]).FromJust(); // convert js argument to c++ type - std::vectorRecoveyRatesCpp; + std::vectorRecoveryRatesCpp; - Local RecoveyRatesArray = info[2].As(); - for (unsigned int i = 0; i < RecoveyRatesArray->Length(); i++){ - RecoveyRatesCpp.push_back(Nan::To(Nan::Get(RecoveyRatesArray, i).ToLocalChecked()).FromJust()); + Local RecoveryRatesArray = info[2].As(); + for (unsigned int i = 0; i < RecoveryRatesArray->Length(); i++){ + RecoveryRatesCpp.push_back(Nan::To(Nan::Get(RecoveryRatesArray, i).ToLocalChecked()).FromJust()); } // convert js argument to c++ type @@ -333,7 +333,7 @@ NAN_METHOD(QuantLibNode::IHStudentPoolLossModel) { callback ,ObjectIDCpp ,CorrelationCpp - ,RecoveyRatesCpp + ,RecoveryRatesCpp ,TtraitsCpp ,NumBucketsCpp )); @@ -357,7 +357,7 @@ void GBinomialLossmodelWorker::Execute(){ new QuantLibAddin::ValueObjects::qlGBinomialLossmodel( mObjectID, mFactors, - mRecoveyRates, + mRecoveryRates, false )); @@ -366,7 +366,7 @@ void GBinomialLossmodelWorker::Execute(){ new QuantLibAddin::GaussianBinomialLossModel( valueObject, mFactors, - mRecoveyRates, + mRecoveryRates, false )); @@ -403,7 +403,7 @@ NAN_METHOD(QuantLibNode::GBinomialLossmodel) { return Nan::ThrowError("Factors is required."); } if (info.Length() == 2 || !info[2]->IsArray()) { - return Nan::ThrowError("RecoveyRates is required."); + return Nan::ThrowError("RecoveryRates is required."); } // convert js argument to c++ type String::Utf8Value strObjectID(info[0]->ToString()); @@ -423,11 +423,11 @@ NAN_METHOD(QuantLibNode::GBinomialLossmodel) { } // convert js argument to c++ type - std::vectorRecoveyRatesCpp; + std::vectorRecoveryRatesCpp; - Local RecoveyRatesArray = info[2].As(); - for (unsigned int i = 0; i < RecoveyRatesArray->Length(); i++){ - RecoveyRatesCpp.push_back(Nan::To(Nan::Get(RecoveyRatesArray, i).ToLocalChecked()).FromJust()); + Local RecoveryRatesArray = info[2].As(); + for (unsigned int i = 0; i < RecoveryRatesArray->Length(); i++){ + RecoveryRatesCpp.push_back(Nan::To(Nan::Get(RecoveryRatesArray, i).ToLocalChecked()).FromJust()); } @@ -438,7 +438,7 @@ NAN_METHOD(QuantLibNode::GBinomialLossmodel) { callback ,ObjectIDCpp ,FactorsCpp - ,RecoveyRatesCpp + ,RecoveryRatesCpp )); } @@ -460,7 +460,7 @@ void TBinomialLossmodelWorker::Execute(){ new QuantLibAddin::ValueObjects::qlTBinomialLossmodel( mObjectID, mFactors, - mRecoveyRates, + mRecoveryRates, mTtraits, false )); @@ -470,7 +470,7 @@ void TBinomialLossmodelWorker::Execute(){ new QuantLibAddin::TBinomialLossModel( valueObject, mFactors, - mRecoveyRates, + mRecoveryRates, mTtraits, false )); @@ -508,7 +508,7 @@ NAN_METHOD(QuantLibNode::TBinomialLossmodel) { return Nan::ThrowError("Factors is required."); } if (info.Length() == 2 || !info[2]->IsArray()) { - return Nan::ThrowError("RecoveyRates is required."); + return Nan::ThrowError("RecoveryRates is required."); } if (info.Length() == 3 || !info[3]->IsArray()) { return Nan::ThrowError("Ttraits is required."); @@ -531,11 +531,11 @@ NAN_METHOD(QuantLibNode::TBinomialLossmodel) { } // convert js argument to c++ type - std::vectorRecoveyRatesCpp; + std::vectorRecoveryRatesCpp; - Local RecoveyRatesArray = info[2].As(); - for (unsigned int i = 0; i < RecoveyRatesArray->Length(); i++){ - RecoveyRatesCpp.push_back(Nan::To(Nan::Get(RecoveyRatesArray, i).ToLocalChecked()).FromJust()); + Local RecoveryRatesArray = info[2].As(); + for (unsigned int i = 0; i < RecoveryRatesArray->Length(); i++){ + RecoveryRatesCpp.push_back(Nan::To(Nan::Get(RecoveryRatesArray, i).ToLocalChecked()).FromJust()); } // convert js argument to c++ type @@ -554,7 +554,7 @@ NAN_METHOD(QuantLibNode::TBinomialLossmodel) { callback ,ObjectIDCpp ,FactorsCpp - ,RecoveyRatesCpp + ,RecoveryRatesCpp ,TtraitsCpp )); @@ -715,7 +715,7 @@ void GMCLossModelWorker::Execute(){ new QuantLibAddin::ValueObjects::qlGMCLossModel( mObjectID, mFactors, - mRecoveyRates, + mRecoveryRates, mNumSimulations, false )); @@ -725,7 +725,7 @@ void GMCLossModelWorker::Execute(){ new QuantLibAddin::GaussianRandomDefaultLM( valueObject, mFactors, - mRecoveyRates, + mRecoveryRates, NumSimulationsLib, false )); @@ -763,7 +763,7 @@ NAN_METHOD(QuantLibNode::GMCLossModel) { return Nan::ThrowError("Factors is required."); } if (info.Length() == 2 || !info[2]->IsArray()) { - return Nan::ThrowError("RecoveyRates is required."); + return Nan::ThrowError("RecoveryRates is required."); } if (info.Length() == 3 || !info[3]->IsNumber()) { return Nan::ThrowError("NumSimulations is required."); @@ -786,11 +786,11 @@ NAN_METHOD(QuantLibNode::GMCLossModel) { } // convert js argument to c++ type - std::vectorRecoveyRatesCpp; + std::vectorRecoveryRatesCpp; - Local RecoveyRatesArray = info[2].As(); - for (unsigned int i = 0; i < RecoveyRatesArray->Length(); i++){ - RecoveyRatesCpp.push_back(Nan::To(Nan::Get(RecoveyRatesArray, i).ToLocalChecked()).FromJust()); + Local RecoveryRatesArray = info[2].As(); + for (unsigned int i = 0; i < RecoveryRatesArray->Length(); i++){ + RecoveryRatesCpp.push_back(Nan::To(Nan::Get(RecoveryRatesArray, i).ToLocalChecked()).FromJust()); } // convert js argument to c++ type @@ -804,7 +804,7 @@ NAN_METHOD(QuantLibNode::GMCLossModel) { callback ,ObjectIDCpp ,FactorsCpp - ,RecoveyRatesCpp + ,RecoveryRatesCpp ,NumSimulationsCpp )); @@ -834,7 +834,7 @@ void GRandomRRMCLossModelWorker::Execute(){ new QuantLibAddin::ValueObjects::qlGRandomRRMCLossModel( mObjectID, mFactors, - mRecoveyRates, + mRecoveryRates, mModelA, mNumSimulations, false @@ -845,7 +845,7 @@ void GRandomRRMCLossModelWorker::Execute(){ new QuantLibAddin::GaussianRandomLossLM( valueObject, mFactors, - mRecoveyRates, + mRecoveryRates, mModelA, NumSimulationsLib, false @@ -884,7 +884,7 @@ NAN_METHOD(QuantLibNode::GRandomRRMCLossModel) { return Nan::ThrowError("Factors is required."); } if (info.Length() == 2 || !info[2]->IsArray()) { - return Nan::ThrowError("RecoveyRates is required."); + return Nan::ThrowError("RecoveryRates is required."); } if (info.Length() == 3 || !info[3]->IsNumber()) { return Nan::ThrowError("ModelA is required."); @@ -910,11 +910,11 @@ NAN_METHOD(QuantLibNode::GRandomRRMCLossModel) { } // convert js argument to c++ type - std::vectorRecoveyRatesCpp; + std::vectorRecoveryRatesCpp; - Local RecoveyRatesArray = info[2].As(); - for (unsigned int i = 0; i < RecoveyRatesArray->Length(); i++){ - RecoveyRatesCpp.push_back(Nan::To(Nan::Get(RecoveyRatesArray, i).ToLocalChecked()).FromJust()); + Local RecoveryRatesArray = info[2].As(); + for (unsigned int i = 0; i < RecoveryRatesArray->Length(); i++){ + RecoveryRatesCpp.push_back(Nan::To(Nan::Get(RecoveryRatesArray, i).ToLocalChecked()).FromJust()); } // convert js argument to c++ type @@ -931,7 +931,7 @@ NAN_METHOD(QuantLibNode::GRandomRRMCLossModel) { callback ,ObjectIDCpp ,FactorsCpp - ,RecoveyRatesCpp + ,RecoveryRatesCpp ,ModelACpp ,NumSimulationsCpp )); @@ -960,7 +960,7 @@ void TMCLossModelWorker::Execute(){ new QuantLibAddin::ValueObjects::qlTMCLossModel( mObjectID, mFactors, - mRecoveyRates, + mRecoveryRates, mTtraits, mNumSimulations, false @@ -971,7 +971,7 @@ void TMCLossModelWorker::Execute(){ new QuantLibAddin::TRandomDefaultLM( valueObject, mFactors, - mRecoveyRates, + mRecoveryRates, mTtraits, NumSimulationsLib, false @@ -1010,7 +1010,7 @@ NAN_METHOD(QuantLibNode::TMCLossModel) { return Nan::ThrowError("Factors is required."); } if (info.Length() == 2 || !info[2]->IsArray()) { - return Nan::ThrowError("RecoveyRates is required."); + return Nan::ThrowError("RecoveryRates is required."); } if (info.Length() == 3 || !info[3]->IsArray()) { return Nan::ThrowError("Ttraits is required."); @@ -1036,11 +1036,11 @@ NAN_METHOD(QuantLibNode::TMCLossModel) { } // convert js argument to c++ type - std::vectorRecoveyRatesCpp; + std::vectorRecoveryRatesCpp; - Local RecoveyRatesArray = info[2].As(); - for (unsigned int i = 0; i < RecoveyRatesArray->Length(); i++){ - RecoveyRatesCpp.push_back(Nan::To(Nan::Get(RecoveyRatesArray, i).ToLocalChecked()).FromJust()); + Local RecoveryRatesArray = info[2].As(); + for (unsigned int i = 0; i < RecoveryRatesArray->Length(); i++){ + RecoveryRatesCpp.push_back(Nan::To(Nan::Get(RecoveryRatesArray, i).ToLocalChecked()).FromJust()); } // convert js argument to c++ type @@ -1062,7 +1062,7 @@ NAN_METHOD(QuantLibNode::TMCLossModel) { callback ,ObjectIDCpp ,FactorsCpp - ,RecoveyRatesCpp + ,RecoveryRatesCpp ,TtraitsCpp ,NumSimulationsCpp )); @@ -1093,7 +1093,7 @@ void TRandomRRMCLossModelWorker::Execute(){ new QuantLibAddin::ValueObjects::qlTRandomRRMCLossModel( mObjectID, mFactors, - mRecoveyRates, + mRecoveryRates, mTtraits, mModelA, mNumSimulations, @@ -1105,7 +1105,7 @@ void TRandomRRMCLossModelWorker::Execute(){ new QuantLibAddin::TRandomLossLM( valueObject, mFactors, - mRecoveyRates, + mRecoveryRates, mTtraits, mModelA, NumSimulationsLib, @@ -1145,7 +1145,7 @@ NAN_METHOD(QuantLibNode::TRandomRRMCLossModel) { return Nan::ThrowError("Factors is required."); } if (info.Length() == 2 || !info[2]->IsArray()) { - return Nan::ThrowError("RecoveyRates is required."); + return Nan::ThrowError("RecoveryRates is required."); } if (info.Length() == 3 || !info[3]->IsArray()) { return Nan::ThrowError("Ttraits is required."); @@ -1174,11 +1174,11 @@ NAN_METHOD(QuantLibNode::TRandomRRMCLossModel) { } // convert js argument to c++ type - std::vectorRecoveyRatesCpp; + std::vectorRecoveryRatesCpp; - Local RecoveyRatesArray = info[2].As(); - for (unsigned int i = 0; i < RecoveyRatesArray->Length(); i++){ - RecoveyRatesCpp.push_back(Nan::To(Nan::Get(RecoveyRatesArray, i).ToLocalChecked()).FromJust()); + Local RecoveryRatesArray = info[2].As(); + for (unsigned int i = 0; i < RecoveryRatesArray->Length(); i++){ + RecoveryRatesCpp.push_back(Nan::To(Nan::Get(RecoveryRatesArray, i).ToLocalChecked()).FromJust()); } // convert js argument to c++ type @@ -1203,7 +1203,7 @@ NAN_METHOD(QuantLibNode::TRandomRRMCLossModel) { callback ,ObjectIDCpp ,FactorsCpp - ,RecoveyRatesCpp + ,RecoveryRatesCpp ,TtraitsCpp ,ModelACpp ,NumSimulationsCpp @@ -1228,7 +1228,7 @@ void GSaddlePointLossmodelWorker::Execute(){ new QuantLibAddin::ValueObjects::qlGSaddlePointLossmodel( mObjectID, mFactors, - mRecoveyRates, + mRecoveryRates, false )); @@ -1237,7 +1237,7 @@ void GSaddlePointLossmodelWorker::Execute(){ new QuantLibAddin::SaddlePointLossModel( valueObject, mFactors, - mRecoveyRates, + mRecoveryRates, false )); @@ -1274,7 +1274,7 @@ NAN_METHOD(QuantLibNode::GSaddlePointLossmodel) { return Nan::ThrowError("Factors is required."); } if (info.Length() == 2 || !info[2]->IsArray()) { - return Nan::ThrowError("RecoveyRates is required."); + return Nan::ThrowError("RecoveryRates is required."); } // convert js argument to c++ type String::Utf8Value strObjectID(info[0]->ToString()); @@ -1294,11 +1294,11 @@ NAN_METHOD(QuantLibNode::GSaddlePointLossmodel) { } // convert js argument to c++ type - std::vectorRecoveyRatesCpp; + std::vectorRecoveryRatesCpp; - Local RecoveyRatesArray = info[2].As(); - for (unsigned int i = 0; i < RecoveyRatesArray->Length(); i++){ - RecoveyRatesCpp.push_back(Nan::To(Nan::Get(RecoveyRatesArray, i).ToLocalChecked()).FromJust()); + Local RecoveryRatesArray = info[2].As(); + for (unsigned int i = 0; i < RecoveryRatesArray->Length(); i++){ + RecoveryRatesCpp.push_back(Nan::To(Nan::Get(RecoveryRatesArray, i).ToLocalChecked()).FromJust()); } @@ -1309,7 +1309,7 @@ NAN_METHOD(QuantLibNode::GSaddlePointLossmodel) { callback ,ObjectIDCpp ,FactorsCpp - ,RecoveyRatesCpp + ,RecoveryRatesCpp )); } @@ -1331,7 +1331,7 @@ void TSaddlePointLossmodelWorker::Execute(){ new QuantLibAddin::ValueObjects::qlTSaddlePointLossmodel( mObjectID, mFactors, - mRecoveyRates, + mRecoveryRates, mTtraits, false )); @@ -1341,7 +1341,7 @@ void TSaddlePointLossmodelWorker::Execute(){ new QuantLibAddin::TSaddlePointLossModel( valueObject, mFactors, - mRecoveyRates, + mRecoveryRates, mTtraits, false )); @@ -1379,7 +1379,7 @@ NAN_METHOD(QuantLibNode::TSaddlePointLossmodel) { return Nan::ThrowError("Factors is required."); } if (info.Length() == 2 || !info[2]->IsArray()) { - return Nan::ThrowError("RecoveyRates is required."); + return Nan::ThrowError("RecoveryRates is required."); } if (info.Length() == 3 || !info[3]->IsArray()) { return Nan::ThrowError("Ttraits is required."); @@ -1402,11 +1402,11 @@ NAN_METHOD(QuantLibNode::TSaddlePointLossmodel) { } // convert js argument to c++ type - std::vectorRecoveyRatesCpp; + std::vectorRecoveryRatesCpp; - Local RecoveyRatesArray = info[2].As(); - for (unsigned int i = 0; i < RecoveyRatesArray->Length(); i++){ - RecoveyRatesCpp.push_back(Nan::To(Nan::Get(RecoveyRatesArray, i).ToLocalChecked()).FromJust()); + Local RecoveryRatesArray = info[2].As(); + for (unsigned int i = 0; i < RecoveryRatesArray->Length(); i++){ + RecoveryRatesCpp.push_back(Nan::To(Nan::Get(RecoveryRatesArray, i).ToLocalChecked()).FromJust()); } // convert js argument to c++ type @@ -1425,7 +1425,7 @@ NAN_METHOD(QuantLibNode::TSaddlePointLossmodel) { callback ,ObjectIDCpp ,FactorsCpp - ,RecoveyRatesCpp + ,RecoveryRatesCpp ,TtraitsCpp )); @@ -1448,7 +1448,7 @@ void GRecursiveLossmodelWorker::Execute(){ new QuantLibAddin::ValueObjects::qlGRecursiveLossmodel( mObjectID, mFactors, - mRecoveyRates, + mRecoveryRates, false )); @@ -1457,7 +1457,7 @@ void GRecursiveLossmodelWorker::Execute(){ new QuantLibAddin::RecursiveGaussLossModel( valueObject, mFactors, - mRecoveyRates, + mRecoveryRates, false )); @@ -1494,7 +1494,7 @@ NAN_METHOD(QuantLibNode::GRecursiveLossmodel) { return Nan::ThrowError("Factors is required."); } if (info.Length() == 2 || !info[2]->IsArray()) { - return Nan::ThrowError("RecoveyRates is required."); + return Nan::ThrowError("RecoveryRates is required."); } // convert js argument to c++ type String::Utf8Value strObjectID(info[0]->ToString()); @@ -1514,11 +1514,11 @@ NAN_METHOD(QuantLibNode::GRecursiveLossmodel) { } // convert js argument to c++ type - std::vectorRecoveyRatesCpp; + std::vectorRecoveryRatesCpp; - Local RecoveyRatesArray = info[2].As(); - for (unsigned int i = 0; i < RecoveyRatesArray->Length(); i++){ - RecoveyRatesCpp.push_back(Nan::To(Nan::Get(RecoveyRatesArray, i).ToLocalChecked()).FromJust()); + Local RecoveryRatesArray = info[2].As(); + for (unsigned int i = 0; i < RecoveryRatesArray->Length(); i++){ + RecoveryRatesCpp.push_back(Nan::To(Nan::Get(RecoveryRatesArray, i).ToLocalChecked()).FromJust()); } @@ -1529,7 +1529,7 @@ NAN_METHOD(QuantLibNode::GRecursiveLossmodel) { callback ,ObjectIDCpp ,FactorsCpp - ,RecoveyRatesCpp + ,RecoveryRatesCpp )); } diff --git a/src/basketlossmodels.hpp b/src/basketlossmodels.hpp index c9c3099..5ddccae 100644 --- a/src/basketlossmodels.hpp +++ b/src/basketlossmodels.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef basketlossmodels_h @@ -22,7 +22,7 @@ class GaussianLHPLossmodelWorker : public Nan::AsyncWorker { public: string mObjectID; double mCorrelation; - std::vector mRecoveyRates; + std::vector mRecoveryRates; string mReturnValue; @@ -32,12 +32,12 @@ class GaussianLHPLossmodelWorker : public Nan::AsyncWorker { Nan::Callback *callback ,string ObjectID ,double Correlation - ,std::vector RecoveyRates + ,std::vector RecoveryRates ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) ,mCorrelation(Correlation) - ,mRecoveyRates(RecoveyRates) + ,mRecoveryRates(RecoveryRates) { }; @@ -56,7 +56,7 @@ class IHGaussPoolLossModelWorker : public Nan::AsyncWorker { public: string mObjectID; double mCorrelation; - std::vector mRecoveyRates; + std::vector mRecoveryRates; long mNumBuckets; string mReturnValue; @@ -67,13 +67,13 @@ class IHGaussPoolLossModelWorker : public Nan::AsyncWorker { Nan::Callback *callback ,string ObjectID ,double Correlation - ,std::vector RecoveyRates + ,std::vector RecoveryRates ,long NumBuckets ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) ,mCorrelation(Correlation) - ,mRecoveyRates(RecoveyRates) + ,mRecoveryRates(RecoveryRates) ,mNumBuckets(NumBuckets) { @@ -93,7 +93,7 @@ class IHStudentPoolLossModelWorker : public Nan::AsyncWorker { public: string mObjectID; double mCorrelation; - std::vector mRecoveyRates; + std::vector mRecoveryRates; std::vector mTtraits; long mNumBuckets; @@ -105,14 +105,14 @@ class IHStudentPoolLossModelWorker : public Nan::AsyncWorker { Nan::Callback *callback ,string ObjectID ,double Correlation - ,std::vector RecoveyRates + ,std::vector RecoveryRates ,std::vector Ttraits ,long NumBuckets ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) ,mCorrelation(Correlation) - ,mRecoveyRates(RecoveyRates) + ,mRecoveryRates(RecoveryRates) ,mTtraits(Ttraits) ,mNumBuckets(NumBuckets) { @@ -133,7 +133,7 @@ class GBinomialLossmodelWorker : public Nan::AsyncWorker { public: string mObjectID; std::vector< std::vector > mFactors; - std::vector mRecoveyRates; + std::vector mRecoveryRates; string mReturnValue; @@ -143,12 +143,12 @@ class GBinomialLossmodelWorker : public Nan::AsyncWorker { Nan::Callback *callback ,string ObjectID ,std::vector< std::vector > Factors - ,std::vector RecoveyRates + ,std::vector RecoveryRates ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) ,mFactors(Factors) - ,mRecoveyRates(RecoveyRates) + ,mRecoveryRates(RecoveryRates) { }; @@ -167,7 +167,7 @@ class TBinomialLossmodelWorker : public Nan::AsyncWorker { public: string mObjectID; std::vector< std::vector > mFactors; - std::vector mRecoveyRates; + std::vector mRecoveryRates; std::vector mTtraits; string mReturnValue; @@ -178,13 +178,13 @@ class TBinomialLossmodelWorker : public Nan::AsyncWorker { Nan::Callback *callback ,string ObjectID ,std::vector< std::vector > Factors - ,std::vector RecoveyRates + ,std::vector RecoveryRates ,std::vector Ttraits ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) ,mFactors(Factors) - ,mRecoveyRates(RecoveyRates) + ,mRecoveryRates(RecoveryRates) ,mTtraits(Ttraits) { @@ -244,7 +244,7 @@ class GMCLossModelWorker : public Nan::AsyncWorker { public: string mObjectID; std::vector< std::vector > mFactors; - std::vector mRecoveyRates; + std::vector mRecoveryRates; long mNumSimulations; string mReturnValue; @@ -255,13 +255,13 @@ class GMCLossModelWorker : public Nan::AsyncWorker { Nan::Callback *callback ,string ObjectID ,std::vector< std::vector > Factors - ,std::vector RecoveyRates + ,std::vector RecoveryRates ,long NumSimulations ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) ,mFactors(Factors) - ,mRecoveyRates(RecoveyRates) + ,mRecoveryRates(RecoveryRates) ,mNumSimulations(NumSimulations) { @@ -281,7 +281,7 @@ class GRandomRRMCLossModelWorker : public Nan::AsyncWorker { public: string mObjectID; std::vector< std::vector > mFactors; - std::vector mRecoveyRates; + std::vector mRecoveryRates; double mModelA; long mNumSimulations; @@ -293,14 +293,14 @@ class GRandomRRMCLossModelWorker : public Nan::AsyncWorker { Nan::Callback *callback ,string ObjectID ,std::vector< std::vector > Factors - ,std::vector RecoveyRates + ,std::vector RecoveryRates ,double ModelA ,long NumSimulations ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) ,mFactors(Factors) - ,mRecoveyRates(RecoveyRates) + ,mRecoveryRates(RecoveryRates) ,mModelA(ModelA) ,mNumSimulations(NumSimulations) { @@ -321,7 +321,7 @@ class TMCLossModelWorker : public Nan::AsyncWorker { public: string mObjectID; std::vector< std::vector > mFactors; - std::vector mRecoveyRates; + std::vector mRecoveryRates; std::vector mTtraits; long mNumSimulations; @@ -333,14 +333,14 @@ class TMCLossModelWorker : public Nan::AsyncWorker { Nan::Callback *callback ,string ObjectID ,std::vector< std::vector > Factors - ,std::vector RecoveyRates + ,std::vector RecoveryRates ,std::vector Ttraits ,long NumSimulations ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) ,mFactors(Factors) - ,mRecoveyRates(RecoveyRates) + ,mRecoveryRates(RecoveryRates) ,mTtraits(Ttraits) ,mNumSimulations(NumSimulations) { @@ -361,7 +361,7 @@ class TRandomRRMCLossModelWorker : public Nan::AsyncWorker { public: string mObjectID; std::vector< std::vector > mFactors; - std::vector mRecoveyRates; + std::vector mRecoveryRates; std::vector mTtraits; double mModelA; long mNumSimulations; @@ -374,7 +374,7 @@ class TRandomRRMCLossModelWorker : public Nan::AsyncWorker { Nan::Callback *callback ,string ObjectID ,std::vector< std::vector > Factors - ,std::vector RecoveyRates + ,std::vector RecoveryRates ,std::vector Ttraits ,double ModelA ,long NumSimulations @@ -382,7 +382,7 @@ class TRandomRRMCLossModelWorker : public Nan::AsyncWorker { Nan::AsyncWorker(callback) ,mObjectID(ObjectID) ,mFactors(Factors) - ,mRecoveyRates(RecoveyRates) + ,mRecoveryRates(RecoveryRates) ,mTtraits(Ttraits) ,mModelA(ModelA) ,mNumSimulations(NumSimulations) @@ -404,7 +404,7 @@ class GSaddlePointLossmodelWorker : public Nan::AsyncWorker { public: string mObjectID; std::vector< std::vector > mFactors; - std::vector mRecoveyRates; + std::vector mRecoveryRates; string mReturnValue; @@ -414,12 +414,12 @@ class GSaddlePointLossmodelWorker : public Nan::AsyncWorker { Nan::Callback *callback ,string ObjectID ,std::vector< std::vector > Factors - ,std::vector RecoveyRates + ,std::vector RecoveryRates ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) ,mFactors(Factors) - ,mRecoveyRates(RecoveyRates) + ,mRecoveryRates(RecoveryRates) { }; @@ -438,7 +438,7 @@ class TSaddlePointLossmodelWorker : public Nan::AsyncWorker { public: string mObjectID; std::vector< std::vector > mFactors; - std::vector mRecoveyRates; + std::vector mRecoveryRates; std::vector mTtraits; string mReturnValue; @@ -449,13 +449,13 @@ class TSaddlePointLossmodelWorker : public Nan::AsyncWorker { Nan::Callback *callback ,string ObjectID ,std::vector< std::vector > Factors - ,std::vector RecoveyRates + ,std::vector RecoveryRates ,std::vector Ttraits ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) ,mFactors(Factors) - ,mRecoveyRates(RecoveyRates) + ,mRecoveryRates(RecoveryRates) ,mTtraits(Ttraits) { @@ -475,7 +475,7 @@ class GRecursiveLossmodelWorker : public Nan::AsyncWorker { public: string mObjectID; std::vector< std::vector > mFactors; - std::vector mRecoveyRates; + std::vector mRecoveryRates; string mReturnValue; @@ -485,12 +485,12 @@ class GRecursiveLossmodelWorker : public Nan::AsyncWorker { Nan::Callback *callback ,string ObjectID ,std::vector< std::vector > Factors - ,std::vector RecoveyRates + ,std::vector RecoveryRates ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) ,mFactors(Factors) - ,mRecoveyRates(RecoveyRates) + ,mRecoveryRates(RecoveryRates) { }; diff --git a/src/bonds.cpp b/src/bonds.cpp index 341e43a..0d51e37 100644 --- a/src/bonds.cpp +++ b/src/bonds.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/bonds.hpp b/src/bonds.hpp index 1458622..7d0693b 100644 --- a/src/bonds.hpp +++ b/src/bonds.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef bonds_h diff --git a/src/browniangenerators.cpp b/src/browniangenerators.cpp index 45c1c96..9239c9c 100644 --- a/src/browniangenerators.cpp +++ b/src/browniangenerators.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/browniangenerators.hpp b/src/browniangenerators.hpp index 7220560..5981026 100644 --- a/src/browniangenerators.hpp +++ b/src/browniangenerators.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef browniangenerators_h diff --git a/src/btp.cpp b/src/btp.cpp index 439219b..684f668 100644 --- a/src/btp.cpp +++ b/src/btp.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/btp.hpp b/src/btp.hpp index 39e610d..dc3dfa9 100644 --- a/src/btp.hpp +++ b/src/btp.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef btp_h diff --git a/src/calendar.cpp b/src/calendar.cpp index c14fe3a..504aaa2 100644 --- a/src/calendar.cpp +++ b/src/calendar.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/calendar.hpp b/src/calendar.hpp index d7c3491..cc8104d 100644 --- a/src/calendar.hpp +++ b/src/calendar.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef calendar_h diff --git a/src/calibrationhelpers.cpp b/src/calibrationhelpers.cpp index 6df88c0..7fc4a3a 100644 --- a/src/calibrationhelpers.cpp +++ b/src/calibrationhelpers.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/calibrationhelpers.hpp b/src/calibrationhelpers.hpp index d86ff59..fc49770 100644 --- a/src/calibrationhelpers.hpp +++ b/src/calibrationhelpers.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef calibrationhelpers_h diff --git a/src/capfloor.cpp b/src/capfloor.cpp index a9cd3f8..89d2564 100644 --- a/src/capfloor.cpp +++ b/src/capfloor.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include @@ -718,6 +718,7 @@ void CapFloorImpliedVolatilityWorker::Execute(){ // invoke the member function + std::map strEnum; mReturnValue = ObjectIDLibObjPtr->impliedVolatility( mPrice , @@ -732,6 +733,8 @@ void CapFloorImpliedVolatilityWorker::Execute(){ mMinVol , mMaxVol + , + strEnum[mVolatilityType] , mDisplacement ); @@ -777,7 +780,10 @@ NAN_METHOD(QuantLibNode::CapFloorImpliedVolatility) { if (info.Length() == 7 || !info[7]->IsNumber()) { return Nan::ThrowError("MaxVol is required."); } - if (info.Length() == 8 || !info[8]->IsNumber()) { + if (info.Length() == 8 || !info[8]->IsString()) { + return Nan::ThrowError("VolatilityType is required."); + } + if (info.Length() == 9 || !info[9]->IsNumber()) { return Nan::ThrowError("Displacement is required."); } // convert js argument to c++ type @@ -808,11 +814,15 @@ NAN_METHOD(QuantLibNode::CapFloorImpliedVolatility) { double MaxVolCpp = Nan::To(info[7]).FromJust(); // convert js argument to c++ type - double DisplacementCpp = Nan::To(info[8]).FromJust(); + String::Utf8Value strVolatilityType(info[8]->ToString()); + string VolatilityTypeCpp(strdup(*strVolatilityType)); + + // convert js argument to c++ type + double DisplacementCpp = Nan::To(info[9]).FromJust(); // declare callback - Nan::Callback *callback = new Nan::Callback(info[9].As()); + Nan::Callback *callback = new Nan::Callback(info[10].As()); // launch Async worker Nan::AsyncQueueWorker(new CapFloorImpliedVolatilityWorker( callback @@ -824,6 +834,7 @@ NAN_METHOD(QuantLibNode::CapFloorImpliedVolatility) { ,MaxIterCpp ,MinVolCpp ,MaxVolCpp + ,VolatilityTypeCpp ,DisplacementCpp )); diff --git a/src/capfloor.hpp b/src/capfloor.hpp index f10f9d1..333cba3 100644 --- a/src/capfloor.hpp +++ b/src/capfloor.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef capfloor_h @@ -282,6 +282,7 @@ class CapFloorImpliedVolatilityWorker : public Nan::AsyncWorker { ObjectHandler::property_t mMaxIter; double mMinVol; double mMaxVol; + string mVolatilityType; double mDisplacement; double mReturnValue; @@ -298,6 +299,7 @@ class CapFloorImpliedVolatilityWorker : public Nan::AsyncWorker { ,ObjectHandler::property_t MaxIter ,double MinVol ,double MaxVol + ,string VolatilityType ,double Displacement ): Nan::AsyncWorker(callback) @@ -309,6 +311,7 @@ class CapFloorImpliedVolatilityWorker : public Nan::AsyncWorker { ,mMaxIter(MaxIter) ,mMinVol(MinVol) ,mMaxVol(MaxVol) + ,mVolatilityType(VolatilityType) ,mDisplacement(Displacement) { diff --git a/src/capletvolstructure.cpp b/src/capletvolstructure.cpp index c9f74ed..cfa7ae5 100644 --- a/src/capletvolstructure.cpp +++ b/src/capletvolstructure.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include @@ -136,6 +136,8 @@ void ConstantOptionletVolatilityWorker::Execute(){ QuantLib::DayCounter DayCounterEnum = ObjectHandler::Create()(mDayCounter); + + // convert input datatypes to QuantLib datatypes // Construct the Value Object boost::shared_ptr valueObject( @@ -146,10 +148,13 @@ void ConstantOptionletVolatilityWorker::Execute(){ mBusinessDayConvention, mVolatility, mDayCounter, + mVolatilityType, + mDisplacement, false )); // Construct the Object + std::map strEnum; boost::shared_ptr object( new QuantLibAddin::ConstantOptionletVolatility( valueObject, @@ -158,6 +163,8 @@ void ConstantOptionletVolatilityWorker::Execute(){ BusinessDayConventionEnum, VolatilityLibObj, DayCounterEnum, + strEnum[mVolatilityType], + mDisplacement, false )); @@ -202,6 +209,12 @@ NAN_METHOD(QuantLibNode::ConstantOptionletVolatility) { if (info.Length() == 5 || !info[5]->IsString()) { return Nan::ThrowError("DayCounter is required."); } + if (info.Length() == 6 || !info[6]->IsString()) { + return Nan::ThrowError("VolatilityType is required."); + } + if (info.Length() == 7 || !info[7]->IsNumber()) { + return Nan::ThrowError("Displacement is required."); + } // convert js argument to c++ type String::Utf8Value strObjectID(info[0]->ToString()); string ObjectIDCpp(strdup(*strObjectID)); @@ -225,9 +238,16 @@ NAN_METHOD(QuantLibNode::ConstantOptionletVolatility) { String::Utf8Value strDayCounter(info[5]->ToString()); string DayCounterCpp(strdup(*strDayCounter)); + // convert js argument to c++ type + String::Utf8Value strVolatilityType(info[6]->ToString()); + string VolatilityTypeCpp(strdup(*strVolatilityType)); + + // convert js argument to c++ type + double DisplacementCpp = Nan::To(info[7]).FromJust(); + // declare callback - Nan::Callback *callback = new Nan::Callback(info[6].As()); + Nan::Callback *callback = new Nan::Callback(info[8].As()); // launch Async worker Nan::AsyncQueueWorker(new ConstantOptionletVolatilityWorker( callback @@ -237,6 +257,8 @@ NAN_METHOD(QuantLibNode::ConstantOptionletVolatility) { ,BusinessDayConventionCpp ,VolatilityCpp ,DayCounterCpp + ,VolatilityTypeCpp + ,DisplacementCpp )); } @@ -470,6 +492,8 @@ void StrippedOptionletWorker::Execute(){ QuantLib::DayCounter DayCounterEnum = ObjectHandler::Create()(mDayCounter); + + // convert input datatypes to QuantLib datatypes // Construct the Value Object boost::shared_ptr valueObject( @@ -483,10 +507,13 @@ void StrippedOptionletWorker::Execute(){ mStrikes, mVolatilities, mDayCounter, + mVolatilityType, + mDisplacement, false )); // Construct the Object + std::map strEnum; boost::shared_ptr object( new QuantLibAddin::StrippedOptionlet( valueObject, @@ -498,6 +525,8 @@ void StrippedOptionletWorker::Execute(){ mStrikes, VolatilitiesLibObj, DayCounterEnum, + strEnum[mVolatilityType], + mDisplacement, false )); @@ -554,6 +583,12 @@ NAN_METHOD(QuantLibNode::StrippedOptionlet) { if (info.Length() == 8 || !info[8]->IsString()) { return Nan::ThrowError("DayCounter is required."); } + if (info.Length() == 9 || !info[9]->IsString()) { + return Nan::ThrowError("VolatilityType is required."); + } + if (info.Length() == 10 || !info[10]->IsNumber()) { + return Nan::ThrowError("Displacement is required."); + } // convert js argument to c++ type String::Utf8Value strObjectID(info[0]->ToString()); string ObjectIDCpp(strdup(*strObjectID)); @@ -610,9 +645,16 @@ NAN_METHOD(QuantLibNode::StrippedOptionlet) { String::Utf8Value strDayCounter(info[8]->ToString()); string DayCounterCpp(strdup(*strDayCounter)); + // convert js argument to c++ type + String::Utf8Value strVolatilityType(info[9]->ToString()); + string VolatilityTypeCpp(strdup(*strVolatilityType)); + + // convert js argument to c++ type + double DisplacementCpp = Nan::To(info[10]).FromJust(); + // declare callback - Nan::Callback *callback = new Nan::Callback(info[9].As()); + Nan::Callback *callback = new Nan::Callback(info[11].As()); // launch Async worker Nan::AsyncQueueWorker(new StrippedOptionletWorker( callback @@ -625,6 +667,8 @@ NAN_METHOD(QuantLibNode::StrippedOptionlet) { ,StrikesCpp ,VolatilitiesCpp ,DayCounterCpp + ,VolatilityTypeCpp + ,DisplacementCpp )); } @@ -657,6 +701,8 @@ void OptionletStripper1Worker::Execute(){ QuantLib::Natural MaxIterLib = ObjectHandler::convert2( mMaxIter, "MaxIter", QuantLib::Null()); + + // convert input datatypes to QuantLib datatypes // Construct the Value Object boost::shared_ptr valueObject( @@ -667,10 +713,13 @@ void OptionletStripper1Worker::Execute(){ mSwitchStrike, mAccuracy, mMaxIter, + mVolatilityType, + mDisplacement, false )); // Construct the Object + std::map strEnum; boost::shared_ptr object( new QuantLibAddin::OptionletStripper1( valueObject, @@ -679,6 +728,8 @@ void OptionletStripper1Worker::Execute(){ mSwitchStrike, mAccuracy, MaxIterLib, + strEnum[mVolatilityType], + mDisplacement, false )); @@ -723,6 +774,12 @@ NAN_METHOD(QuantLibNode::OptionletStripper1) { if (info.Length() == 4 || !info[4]->IsNumber()) { return Nan::ThrowError("Accuracy is required."); } + if (info.Length() == 6 || !info[6]->IsString()) { + return Nan::ThrowError("VolatilityType is required."); + } + if (info.Length() == 7 || !info[7]->IsNumber()) { + return Nan::ThrowError("Displacement is required."); + } // convert js argument to c++ type String::Utf8Value strObjectID(info[0]->ToString()); string ObjectIDCpp(strdup(*strObjectID)); @@ -745,9 +802,16 @@ NAN_METHOD(QuantLibNode::OptionletStripper1) { ObjectHandler::property_t MaxIterCpp = ObjectHandler::property_t(static_cast(Nan::To(info[5]).FromJust())); + // convert js argument to c++ type + String::Utf8Value strVolatilityType(info[6]->ToString()); + string VolatilityTypeCpp(strdup(*strVolatilityType)); + + // convert js argument to c++ type + double DisplacementCpp = Nan::To(info[7]).FromJust(); + // declare callback - Nan::Callback *callback = new Nan::Callback(info[6].As()); + Nan::Callback *callback = new Nan::Callback(info[8].As()); // launch Async worker Nan::AsyncQueueWorker(new OptionletStripper1Worker( callback @@ -757,6 +821,8 @@ NAN_METHOD(QuantLibNode::OptionletStripper1) { ,SwitchStrikeCpp ,AccuracyCpp ,MaxIterCpp + ,VolatilityTypeCpp + ,DisplacementCpp )); } diff --git a/src/capletvolstructure.hpp b/src/capletvolstructure.hpp index 8372b57..eb35a5a 100644 --- a/src/capletvolstructure.hpp +++ b/src/capletvolstructure.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef capletvolstructure_h @@ -57,6 +57,8 @@ class ConstantOptionletVolatilityWorker : public Nan::AsyncWorker { string mBusinessDayConvention; ObjectHandler::property_t mVolatility; string mDayCounter; + string mVolatilityType; + double mDisplacement; string mReturnValue; @@ -70,6 +72,8 @@ class ConstantOptionletVolatilityWorker : public Nan::AsyncWorker { ,string BusinessDayConvention ,ObjectHandler::property_t Volatility ,string DayCounter + ,string VolatilityType + ,double Displacement ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) @@ -78,6 +82,8 @@ class ConstantOptionletVolatilityWorker : public Nan::AsyncWorker { ,mBusinessDayConvention(BusinessDayConvention) ,mVolatility(Volatility) ,mDayCounter(DayCounter) + ,mVolatilityType(VolatilityType) + ,mDisplacement(Displacement) { }; @@ -168,6 +174,8 @@ class StrippedOptionletWorker : public Nan::AsyncWorker { std::vector mStrikes; std::vector< std::vector > mVolatilities; string mDayCounter; + string mVolatilityType; + double mDisplacement; string mReturnValue; @@ -184,6 +192,8 @@ class StrippedOptionletWorker : public Nan::AsyncWorker { ,std::vector Strikes ,std::vector< std::vector > Volatilities ,string DayCounter + ,string VolatilityType + ,double Displacement ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) @@ -195,6 +205,8 @@ class StrippedOptionletWorker : public Nan::AsyncWorker { ,mStrikes(Strikes) ,mVolatilities(Volatilities) ,mDayCounter(DayCounter) + ,mVolatilityType(VolatilityType) + ,mDisplacement(Displacement) { }; @@ -217,6 +229,8 @@ class OptionletStripper1Worker : public Nan::AsyncWorker { double mSwitchStrike; double mAccuracy; ObjectHandler::property_t mMaxIter; + string mVolatilityType; + double mDisplacement; string mReturnValue; @@ -230,6 +244,8 @@ class OptionletStripper1Worker : public Nan::AsyncWorker { ,double SwitchStrike ,double Accuracy ,ObjectHandler::property_t MaxIter + ,string VolatilityType + ,double Displacement ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) @@ -238,6 +254,8 @@ class OptionletStripper1Worker : public Nan::AsyncWorker { ,mSwitchStrike(SwitchStrike) ,mAccuracy(Accuracy) ,mMaxIter(MaxIter) + ,mVolatilityType(VolatilityType) + ,mDisplacement(Displacement) { }; diff --git a/src/cmsmarket.cpp b/src/cmsmarket.cpp index 2507397..a459902 100644 --- a/src/cmsmarket.cpp +++ b/src/cmsmarket.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/cmsmarket.hpp b/src/cmsmarket.hpp index a3dfd50..fa586f8 100644 --- a/src/cmsmarket.hpp +++ b/src/cmsmarket.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef cmsmarket_h diff --git a/src/cmsmarketcalibration.cpp b/src/cmsmarketcalibration.cpp index 6a5ee8b..411d48f 100644 --- a/src/cmsmarketcalibration.cpp +++ b/src/cmsmarketcalibration.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/cmsmarketcalibration.hpp b/src/cmsmarketcalibration.hpp index 2c97134..4e888fc 100644 --- a/src/cmsmarketcalibration.hpp +++ b/src/cmsmarketcalibration.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef cmsmarketcalibration_h diff --git a/src/correlation.cpp b/src/correlation.cpp index 236d2ab..53067f0 100644 --- a/src/correlation.cpp +++ b/src/correlation.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/correlation.hpp b/src/correlation.hpp index 79fd159..7545edc 100644 --- a/src/correlation.hpp +++ b/src/correlation.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef correlation_h diff --git a/src/couponvectors.cpp b/src/couponvectors.cpp index 7c35ae4..a334f2d 100644 --- a/src/couponvectors.cpp +++ b/src/couponvectors.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/couponvectors.hpp b/src/couponvectors.hpp index 38333b9..2cba597 100644 --- a/src/couponvectors.hpp +++ b/src/couponvectors.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef couponvectors_h diff --git a/src/credit.cpp b/src/credit.cpp index e6d57a8..0069ed7 100644 --- a/src/credit.cpp +++ b/src/credit.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/credit.hpp b/src/credit.hpp index 5a4c480..b58b749 100644 --- a/src/credit.hpp +++ b/src/credit.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef credit_h diff --git a/src/ctsmmcapletcalibration.cpp b/src/ctsmmcapletcalibration.cpp index 83fe1e5..e3fa58c 100644 --- a/src/ctsmmcapletcalibration.cpp +++ b/src/ctsmmcapletcalibration.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/ctsmmcapletcalibration.hpp b/src/ctsmmcapletcalibration.hpp index f7a4bb5..be6d22d 100644 --- a/src/ctsmmcapletcalibration.hpp +++ b/src/ctsmmcapletcalibration.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef ctsmmcapletcalibration_h diff --git a/src/curvestate.cpp b/src/curvestate.cpp index 5870a11..85d45d9 100644 --- a/src/curvestate.cpp +++ b/src/curvestate.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/curvestate.hpp b/src/curvestate.hpp index 3f9fc95..f7dc600 100644 --- a/src/curvestate.hpp +++ b/src/curvestate.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef curvestate_h diff --git a/src/date.cpp b/src/date.cpp index 58ab416..5eb0674 100644 --- a/src/date.cpp +++ b/src/date.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/date.hpp b/src/date.hpp index 62517d0..551d2a0 100644 --- a/src/date.hpp +++ b/src/date.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef date_h diff --git a/src/daycounter.cpp b/src/daycounter.cpp index 095edf7..c6aa2e9 100644 --- a/src/daycounter.cpp +++ b/src/daycounter.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/daycounter.hpp b/src/daycounter.hpp index eca86be..fff0f8f 100644 --- a/src/daycounter.hpp +++ b/src/daycounter.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef daycounter_h diff --git a/src/defaultbasket.cpp b/src/defaultbasket.cpp index 1f3855e..9bba061 100644 --- a/src/defaultbasket.cpp +++ b/src/defaultbasket.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include @@ -444,7 +444,7 @@ NAN_METHOD(QuantLibNode::CreditBasketLoss) { // //} -void CrediBasketAttachLiveWorker::Execute(){ +void CreditBasketAttachLiveWorker::Execute(){ try{ // convert object IDs into library objects @@ -467,7 +467,7 @@ void CrediBasketAttachLiveWorker::Execute(){ } -void CrediBasketAttachLiveWorker::HandleOKCallback(){ +void CreditBasketAttachLiveWorker::HandleOKCallback(){ Nan::HandleScope scope; @@ -479,7 +479,7 @@ void CrediBasketAttachLiveWorker::HandleOKCallback(){ callback->Call(2, argv); } -NAN_METHOD(QuantLibNode::CrediBasketAttachLive) { +NAN_METHOD(QuantLibNode::CreditBasketAttachLive) { // validate js arguments if (info.Length() == 0 || !info[0]->IsString()) { @@ -493,22 +493,22 @@ NAN_METHOD(QuantLibNode::CrediBasketAttachLive) { // declare callback Nan::Callback *callback = new Nan::Callback(info[1].As()); // launch Async worker - Nan::AsyncQueueWorker(new CrediBasketAttachLiveWorker( + Nan::AsyncQueueWorker(new CreditBasketAttachLiveWorker( callback ,ObjectIDCpp )); } -//CrediBasketAttachLiveWorker::~CrediBasketAttachLiveWorker(){ +//CreditBasketAttachLiveWorker::~CreditBasketAttachLiveWorker(){ // //} -//void CrediBasketAttachLiveWorker::Destroy(){ +//void CreditBasketAttachLiveWorker::Destroy(){ // //} -void CrediBasketDetachLiveWorker::Execute(){ +void CreditBasketDetachLiveWorker::Execute(){ try{ // convert object IDs into library objects @@ -531,7 +531,7 @@ void CrediBasketDetachLiveWorker::Execute(){ } -void CrediBasketDetachLiveWorker::HandleOKCallback(){ +void CreditBasketDetachLiveWorker::HandleOKCallback(){ Nan::HandleScope scope; @@ -543,7 +543,7 @@ void CrediBasketDetachLiveWorker::HandleOKCallback(){ callback->Call(2, argv); } -NAN_METHOD(QuantLibNode::CrediBasketDetachLive) { +NAN_METHOD(QuantLibNode::CreditBasketDetachLive) { // validate js arguments if (info.Length() == 0 || !info[0]->IsString()) { @@ -557,18 +557,18 @@ NAN_METHOD(QuantLibNode::CrediBasketDetachLive) { // declare callback Nan::Callback *callback = new Nan::Callback(info[1].As()); // launch Async worker - Nan::AsyncQueueWorker(new CrediBasketDetachLiveWorker( + Nan::AsyncQueueWorker(new CreditBasketDetachLiveWorker( callback ,ObjectIDCpp )); } -//CrediBasketDetachLiveWorker::~CrediBasketDetachLiveWorker(){ +//CreditBasketDetachLiveWorker::~CreditBasketDetachLiveWorker(){ // //} -//void CrediBasketDetachLiveWorker::Destroy(){ +//void CreditBasketDetachLiveWorker::Destroy(){ // //} diff --git a/src/defaultbasket.hpp b/src/defaultbasket.hpp index 667488c..f852ae7 100644 --- a/src/defaultbasket.hpp +++ b/src/defaultbasket.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef defaultbasket_h @@ -180,7 +180,7 @@ class CreditBasketLossWorker : public Nan::AsyncWorker { }; -class CrediBasketAttachLiveWorker : public Nan::AsyncWorker { +class CreditBasketAttachLiveWorker : public Nan::AsyncWorker { public: string mObjectID; @@ -188,7 +188,7 @@ class CrediBasketAttachLiveWorker : public Nan::AsyncWorker { string mError; - CrediBasketAttachLiveWorker( + CreditBasketAttachLiveWorker( Nan::Callback *callback ,string ObjectID ): @@ -198,7 +198,7 @@ class CrediBasketAttachLiveWorker : public Nan::AsyncWorker { }; - //~CrediBasketAttachLiveWorker(); + //~CreditBasketAttachLiveWorker(); //void Destroy(); @@ -208,7 +208,7 @@ class CrediBasketAttachLiveWorker : public Nan::AsyncWorker { }; -class CrediBasketDetachLiveWorker : public Nan::AsyncWorker { +class CreditBasketDetachLiveWorker : public Nan::AsyncWorker { public: string mObjectID; @@ -216,7 +216,7 @@ class CrediBasketDetachLiveWorker : public Nan::AsyncWorker { string mError; - CrediBasketDetachLiveWorker( + CreditBasketDetachLiveWorker( Nan::Callback *callback ,string ObjectID ): @@ -226,7 +226,7 @@ class CrediBasketDetachLiveWorker : public Nan::AsyncWorker { }; - //~CrediBasketDetachLiveWorker(); + //~CreditBasketDetachLiveWorker(); //void Destroy(); diff --git a/src/defaulttermstructures.cpp b/src/defaulttermstructures.cpp index c54e3b5..0e154b5 100644 --- a/src/defaulttermstructures.cpp +++ b/src/defaulttermstructures.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/defaulttermstructures.hpp b/src/defaulttermstructures.hpp index 9cbc7cd..a27c324 100644 --- a/src/defaulttermstructures.hpp +++ b/src/defaulttermstructures.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef defaulttermstructures_h diff --git a/src/driftcalculators.cpp b/src/driftcalculators.cpp index 2f1b4c7..981cfa3 100644 --- a/src/driftcalculators.cpp +++ b/src/driftcalculators.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/driftcalculators.hpp b/src/driftcalculators.hpp index 2600c47..f46cd6d 100644 --- a/src/driftcalculators.hpp +++ b/src/driftcalculators.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef driftcalculators_h diff --git a/src/evolutiondescription.cpp b/src/evolutiondescription.cpp index f28f740..e27ae69 100644 --- a/src/evolutiondescription.cpp +++ b/src/evolutiondescription.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/evolutiondescription.hpp b/src/evolutiondescription.hpp index 3e94827..c1824eb 100644 --- a/src/evolutiondescription.hpp +++ b/src/evolutiondescription.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef evolutiondescription_h diff --git a/src/exercise.cpp b/src/exercise.cpp index 8784a58..7622e9e 100644 --- a/src/exercise.cpp +++ b/src/exercise.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/exercise.hpp b/src/exercise.hpp index 3dc3469..4a6613a 100644 --- a/src/exercise.hpp +++ b/src/exercise.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef exercise_h diff --git a/src/forwardrateagreement.cpp b/src/forwardrateagreement.cpp index e1f6988..b6d0e48 100644 --- a/src/forwardrateagreement.cpp +++ b/src/forwardrateagreement.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/forwardrateagreement.hpp b/src/forwardrateagreement.hpp index 7ab7dd1..c951b2a 100644 --- a/src/forwardrateagreement.hpp +++ b/src/forwardrateagreement.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef forwardrateagreement_h diff --git a/src/handles.cpp b/src/handles.cpp index fc13254..843e26c 100644 --- a/src/handles.cpp +++ b/src/handles.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/handles.hpp b/src/handles.hpp index 1febb1d..7d7c87a 100644 --- a/src/handles.hpp +++ b/src/handles.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef handles_h diff --git a/src/index.cpp b/src/index.cpp index 977d62f..ed73bd3 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/index.hpp b/src/index.hpp index f20abfb..ce86313 100644 --- a/src/index.hpp +++ b/src/index.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef index_h diff --git a/src/instruments.cpp b/src/instruments.cpp index ebede54..8a5b806 100644 --- a/src/instruments.cpp +++ b/src/instruments.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/instruments.hpp b/src/instruments.hpp index ac7ec8b..e7dcbb3 100644 --- a/src/instruments.hpp +++ b/src/instruments.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef instruments_h diff --git a/src/interpolation.cpp b/src/interpolation.cpp index 2f96cf9..f286bb7 100644 --- a/src/interpolation.cpp +++ b/src/interpolation.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/interpolation.hpp b/src/interpolation.hpp index 1a317c9..ebcd1c6 100644 --- a/src/interpolation.hpp +++ b/src/interpolation.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef interpolation_h diff --git a/src/latentmodels.cpp b/src/latentmodels.cpp index 303f26e..1d5cd7d 100644 --- a/src/latentmodels.cpp +++ b/src/latentmodels.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/latentmodels.hpp b/src/latentmodels.hpp index a0250ce..3826a62 100644 --- a/src/latentmodels.hpp +++ b/src/latentmodels.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef latentmodels_h diff --git a/src/leg.cpp b/src/leg.cpp index b0d12cd..649fbe7 100644 --- a/src/leg.cpp +++ b/src/leg.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/leg.hpp b/src/leg.hpp index 29deb00..87e3fd0 100644 --- a/src/leg.hpp +++ b/src/leg.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef leg_h diff --git a/src/marketmodelevolvers.cpp b/src/marketmodelevolvers.cpp index 9c557a4..b51d9c6 100644 --- a/src/marketmodelevolvers.cpp +++ b/src/marketmodelevolvers.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/marketmodelevolvers.hpp b/src/marketmodelevolvers.hpp index ff2b23b..7d81950 100644 --- a/src/marketmodelevolvers.hpp +++ b/src/marketmodelevolvers.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef marketmodelevolvers_h diff --git a/src/marketmodels.cpp b/src/marketmodels.cpp index 219bd99..45d6e61 100644 --- a/src/marketmodels.cpp +++ b/src/marketmodels.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/marketmodels.hpp b/src/marketmodels.hpp index 5b0bd28..e118102 100644 --- a/src/marketmodels.hpp +++ b/src/marketmodels.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef marketmodels_h diff --git a/src/mathf.cpp b/src/mathf.cpp index b97eaa7..37d4d75 100644 --- a/src/mathf.cpp +++ b/src/mathf.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/mathf.hpp b/src/mathf.hpp index a34f1d8..b911892 100644 --- a/src/mathf.hpp +++ b/src/mathf.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef mathf_h diff --git a/src/optimization.cpp b/src/optimization.cpp index 304d618..0cf81c4 100644 --- a/src/optimization.cpp +++ b/src/optimization.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/optimization.hpp b/src/optimization.hpp index 7948e1a..e8297ee 100644 --- a/src/optimization.hpp +++ b/src/optimization.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef optimization_h diff --git a/src/options.cpp b/src/options.cpp index 95d3c8a..d5ddb6d 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/options.hpp b/src/options.hpp index fe6e554..57ec4fb 100644 --- a/src/options.hpp +++ b/src/options.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef options_h diff --git a/src/overnightindexedswap.cpp b/src/overnightindexedswap.cpp index 193f8d1..202d642 100644 --- a/src/overnightindexedswap.cpp +++ b/src/overnightindexedswap.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/overnightindexedswap.hpp b/src/overnightindexedswap.hpp index fa21c7e..01707fe 100644 --- a/src/overnightindexedswap.hpp +++ b/src/overnightindexedswap.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef overnightindexedswap_h diff --git a/src/payoffs.cpp b/src/payoffs.cpp index 31d6b3a..817afc6 100644 --- a/src/payoffs.cpp +++ b/src/payoffs.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/payoffs.hpp b/src/payoffs.hpp index b83dd88..999258c 100644 --- a/src/payoffs.hpp +++ b/src/payoffs.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef payoffs_h diff --git a/src/piecewiseyieldcurve.cpp b/src/piecewiseyieldcurve.cpp index 2338dc6..b8450e9 100644 --- a/src/piecewiseyieldcurve.cpp +++ b/src/piecewiseyieldcurve.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include @@ -225,6 +225,236 @@ NAN_METHOD(QuantLibNode::PiecewiseYieldCurve) { // //} +void PiecewiseYieldCurveMixedInterpolationWorker::Execute(){ + + try{ + + // convert input datatypes to QuantLib datatypes + QuantLib::Natural NDaysLib = ObjectHandler::convert2( + mNDays, "NDays", QuantLib::Null()); + + + // convert input datatypes to QuantLib enumerated datatypes + QuantLib::Calendar CalendarEnum = + ObjectHandler::Create()(mCalendar); + + + // convert object IDs into library objects + std::vector< boost::shared_ptr > RateHelpersLibObjPtr = + ObjectHandler::getLibraryObjectVector(mRateHelpers); + + + // convert input datatypes to QuantLib enumerated datatypes + QuantLib::DayCounter DayCounterEnum = + ObjectHandler::Create()(mDayCounter); + + + // convert object IDs into library objects + std::vector< QuantLib::Handle > JumpsLibObj = + ObjectHandler::vector::convert2< QuantLib::Handle >(mJumps, "Jumps"); + + + // convert input datatypes to QuantLib datatypes + std::vector JumpDatesLib = ObjectHandler::vector::convert2( + mJumpDates, "JumpDates"); + + + // convert input datatypes to QuantLib datatypes + + // convert input datatypes to QuantLib datatypes + QuantLib::Size PillarsBeforeChangeLib; + QuantLibAddin::cppToLibrary(mPillarsBeforeChange, PillarsBeforeChangeLib); + + + // Construct the Value Object + boost::shared_ptr valueObject( + new QuantLibAddin::ValueObjects::qlPiecewiseYieldCurveMixedInterpolation( + mObjectID, + mNDays, + mCalendar, + mRateHelpers, + mDayCounter, + mJumps, + mJumpDates, + mAccuracy, + mTraitsID, + mInterpolatorID, + mMixedInterpolationBehavior, + mPillarsBeforeChange, + false + )); + + // Construct the Object + std::map strEnum; + boost::shared_ptr object( + new QuantLibAddin::PiecewiseYieldCurve( + valueObject, + NDaysLib, + CalendarEnum, + RateHelpersLibObjPtr, + DayCounterEnum, + JumpsLibObj, + JumpDatesLib, + mAccuracy, + mTraitsID, + mInterpolatorID, + strEnum[mMixedInterpolationBehavior], + PillarsBeforeChangeLib, + false + )); + + // Store the Object in the Repository + mReturnValue = ObjectHandler::Repository::instance().storeObject(mObjectID, object, false, valueObject); + + }catch(const std::exception &e){ + mError = e.what(); + }catch (...){ + mError = "unkown error"; + } + +} + +void PiecewiseYieldCurveMixedInterpolationWorker::HandleOKCallback(){ + Nan::HandleScope scope; + + + Local argv[2] = { + Nan::New(mError).ToLocalChecked(), + Nan::New(mReturnValue).ToLocalChecked() + }; + + callback->Call(2, argv); +} + +NAN_METHOD(QuantLibNode::PiecewiseYieldCurveMixedInterpolation) { + + // validate js arguments + if (info.Length() == 0 || !info[0]->IsString()) { + return Nan::ThrowError("ObjectID is required."); + } + if (info.Length() == 2 || !info[2]->IsString()) { + return Nan::ThrowError("Calendar is required."); + } + if (info.Length() == 3 || !info[3]->IsArray()) { + return Nan::ThrowError("RateHelpers is required."); + } + if (info.Length() == 4 || !info[4]->IsString()) { + return Nan::ThrowError("DayCounter is required."); + } + if (info.Length() == 5 || !info[5]->IsArray()) { + return Nan::ThrowError("Jumps is required."); + } + if (info.Length() == 6 || !info[6]->IsArray()) { + return Nan::ThrowError("JumpDates is required."); + } + if (info.Length() == 7 || !info[7]->IsNumber()) { + return Nan::ThrowError("Accuracy is required."); + } + if (info.Length() == 8 || !info[8]->IsString()) { + return Nan::ThrowError("TraitsID is required."); + } + if (info.Length() == 9 || !info[9]->IsString()) { + return Nan::ThrowError("InterpolatorID is required."); + } + if (info.Length() == 10 || !info[10]->IsString()) { + return Nan::ThrowError("MixedInterpolationBehavior is required."); + } + if (info.Length() == 11 || !info[11]->IsNumber()) { + return Nan::ThrowError("PillarsBeforeChange is required."); + } + // convert js argument to c++ type + String::Utf8Value strObjectID(info[0]->ToString()); + string ObjectIDCpp(strdup(*strObjectID)); + + // convert js argument to c++ type + ObjectHandler::property_t NDaysCpp = + ObjectHandler::property_t(static_cast(Nan::To(info[1]).FromJust())); + + // convert js argument to c++ type + String::Utf8Value strCalendar(info[2]->ToString()); + string CalendarCpp(strdup(*strCalendar)); + + // convert js argument to c++ type + std::vectorRateHelpersCpp; + + Local RateHelpersArray = info[3].As(); + for (unsigned int i = 0; i < RateHelpersArray->Length(); i++){ + String::Utf8Value strRateHelpers(Nan::Get(RateHelpersArray, i).ToLocalChecked()->ToString()); + RateHelpersCpp.push_back(strdup(*strRateHelpers)); + } + + // convert js argument to c++ type + String::Utf8Value strDayCounter(info[4]->ToString()); + string DayCounterCpp(strdup(*strDayCounter)); + + // convert js argument to c++ type + std::vectorJumpsCpp; + + Local JumpsArray = info[5].As(); + for (unsigned int i = 0; i < JumpsArray->Length(); i++){ + ObjectHandler::property_t tmp = + ObjectHandler::property_t(static_cast(Nan::To(Nan::Get(JumpsArray, i).ToLocalChecked()).FromJust())); + JumpsCpp.push_back(tmp); + } + + // convert js argument to c++ type + std::vectorJumpDatesCpp; + + Local JumpDatesArray = info[6].As(); + for (unsigned int i = 0; i < JumpDatesArray->Length(); i++){ + ObjectHandler::property_t tmp = + ObjectHandler::property_t(static_cast(Nan::To(Nan::Get(JumpDatesArray, i).ToLocalChecked()).FromJust())); + JumpDatesCpp.push_back(tmp); + } + + // convert js argument to c++ type + double AccuracyCpp = Nan::To(info[7]).FromJust(); + + // convert js argument to c++ type + String::Utf8Value strTraitsID(info[8]->ToString()); + string TraitsIDCpp(strdup(*strTraitsID)); + + // convert js argument to c++ type + String::Utf8Value strInterpolatorID(info[9]->ToString()); + string InterpolatorIDCpp(strdup(*strInterpolatorID)); + + // convert js argument to c++ type + String::Utf8Value strMixedInterpolationBehavior(info[10]->ToString()); + string MixedInterpolationBehaviorCpp(strdup(*strMixedInterpolationBehavior)); + + // convert js argument to c++ type + long PillarsBeforeChangeCpp = Nan::To(info[11]).FromJust(); + + + // declare callback + Nan::Callback *callback = new Nan::Callback(info[12].As()); + // launch Async worker + Nan::AsyncQueueWorker(new PiecewiseYieldCurveMixedInterpolationWorker( + callback + ,ObjectIDCpp + ,NDaysCpp + ,CalendarCpp + ,RateHelpersCpp + ,DayCounterCpp + ,JumpsCpp + ,JumpDatesCpp + ,AccuracyCpp + ,TraitsIDCpp + ,InterpolatorIDCpp + ,MixedInterpolationBehaviorCpp + ,PillarsBeforeChangeCpp + )); + +} + +//PiecewiseYieldCurveMixedInterpolationWorker::~PiecewiseYieldCurveMixedInterpolationWorker(){ +// +//} + +//void PiecewiseYieldCurveMixedInterpolationWorker::Destroy(){ +// +//} + void PiecewiseYieldCurveTimesWorker::Execute(){ try{ diff --git a/src/piecewiseyieldcurve.hpp b/src/piecewiseyieldcurve.hpp index 5abbdfb..33da822 100644 --- a/src/piecewiseyieldcurve.hpp +++ b/src/piecewiseyieldcurve.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef piecewiseyieldcurve_h @@ -73,6 +73,67 @@ class PiecewiseYieldCurveWorker : public Nan::AsyncWorker { }; +class PiecewiseYieldCurveMixedInterpolationWorker : public Nan::AsyncWorker { + public: + string mObjectID; + ObjectHandler::property_t mNDays; + string mCalendar; + std::vector mRateHelpers; + string mDayCounter; + std::vector mJumps; + std::vector mJumpDates; + double mAccuracy; + string mTraitsID; + string mInterpolatorID; + string mMixedInterpolationBehavior; + long mPillarsBeforeChange; + + string mReturnValue; + + string mError; + + PiecewiseYieldCurveMixedInterpolationWorker( + Nan::Callback *callback + ,string ObjectID + ,ObjectHandler::property_t NDays + ,string Calendar + ,std::vector RateHelpers + ,string DayCounter + ,std::vector Jumps + ,std::vector JumpDates + ,double Accuracy + ,string TraitsID + ,string InterpolatorID + ,string MixedInterpolationBehavior + ,long PillarsBeforeChange + ): + Nan::AsyncWorker(callback) + ,mObjectID(ObjectID) + ,mNDays(NDays) + ,mCalendar(Calendar) + ,mRateHelpers(RateHelpers) + ,mDayCounter(DayCounter) + ,mJumps(Jumps) + ,mJumpDates(JumpDates) + ,mAccuracy(Accuracy) + ,mTraitsID(TraitsID) + ,mInterpolatorID(InterpolatorID) + ,mMixedInterpolationBehavior(MixedInterpolationBehavior) + ,mPillarsBeforeChange(PillarsBeforeChange) + { + + }; + + //~PiecewiseYieldCurveMixedInterpolationWorker(); + + //void Destroy(); + + void Execute(); + + void HandleOKCallback(); + +}; + class PiecewiseYieldCurveTimesWorker : public Nan::AsyncWorker { public: string mObjectID; diff --git a/src/prices.cpp b/src/prices.cpp index 66bd80a..145b147 100644 --- a/src/prices.cpp +++ b/src/prices.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/prices.hpp b/src/prices.hpp index 3cdda7c..e3fcc2c 100644 --- a/src/prices.hpp +++ b/src/prices.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef prices_h diff --git a/src/pricingengines.cpp b/src/pricingengines.cpp index 1017ae2..e9ed98d 100644 --- a/src/pricingengines.cpp +++ b/src/pricingengines.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include @@ -1331,6 +1331,221 @@ NAN_METHOD(QuantLibNode::BlackCapFloorEngine2) { // //} +void BachelierCapFloorEngineWorker::Execute(){ + + try{ + + // convert object IDs into library objects + OH_GET_OBJECT(YieldCurveCoerce, mYieldCurve, ObjectHandler::Object) + QuantLib::Handle YieldCurveLibObj = + QuantLibAddin::CoerceHandle< + QuantLibAddin::YieldTermStructure, + QuantLib::YieldTermStructure>()( + YieldCurveCoerce); + + + // convert object IDs into library objects + OH_GET_OBJECT(VolTSCoerce, mVolTS, ObjectHandler::Object) + QuantLib::Handle VolTSLibObj = + QuantLibAddin::CoerceHandle< + QuantLibAddin::OptionletVolatilityStructure, + QuantLib::OptionletVolatilityStructure>()( + VolTSCoerce); + + + // Construct the Value Object + boost::shared_ptr valueObject( + new QuantLibAddin::ValueObjects::qlBachelierCapFloorEngine( + mObjectID, + mYieldCurve, + mVolTS, + false + )); + + // Construct the Object + boost::shared_ptr object( + new QuantLibAddin::BachelierCapFloorEngine( + valueObject, + YieldCurveLibObj, + VolTSLibObj, + false + )); + + // Store the Object in the Repository + mReturnValue = ObjectHandler::Repository::instance().storeObject(mObjectID, object, false, valueObject); + + }catch(const std::exception &e){ + mError = e.what(); + }catch (...){ + mError = "unkown error"; + } + +} + +void BachelierCapFloorEngineWorker::HandleOKCallback(){ + Nan::HandleScope scope; + + + Local argv[2] = { + Nan::New(mError).ToLocalChecked(), + Nan::New(mReturnValue).ToLocalChecked() + }; + + callback->Call(2, argv); +} + +NAN_METHOD(QuantLibNode::BachelierCapFloorEngine) { + + // validate js arguments + if (info.Length() == 0 || !info[0]->IsString()) { + return Nan::ThrowError("ObjectID is required."); + } + // convert js argument to c++ type + String::Utf8Value strObjectID(info[0]->ToString()); + string ObjectIDCpp(strdup(*strObjectID)); + + // convert js argument to c++ type + ObjectHandler::property_t YieldCurveCpp = + ObjectHandler::property_t(static_cast(Nan::To(info[1]).FromJust())); + + // convert js argument to c++ type + ObjectHandler::property_t VolTSCpp = + ObjectHandler::property_t(static_cast(Nan::To(info[2]).FromJust())); + + + // declare callback + Nan::Callback *callback = new Nan::Callback(info[3].As()); + // launch Async worker + Nan::AsyncQueueWorker(new BachelierCapFloorEngineWorker( + callback + ,ObjectIDCpp + ,YieldCurveCpp + ,VolTSCpp + )); + +} + +//BachelierCapFloorEngineWorker::~BachelierCapFloorEngineWorker(){ +// +//} + +//void BachelierCapFloorEngineWorker::Destroy(){ +// +//} + +void BachelierCapFloorEngine2Worker::Execute(){ + + try{ + + // convert object IDs into library objects + OH_GET_OBJECT(YieldCurveCoerce, mYieldCurve, ObjectHandler::Object) + QuantLib::Handle YieldCurveLibObj = + QuantLibAddin::CoerceHandle< + QuantLibAddin::YieldTermStructure, + QuantLib::YieldTermStructure>()( + YieldCurveCoerce); + + + // convert object IDs into library objects + QuantLib::Handle VolLibObj = + ObjectHandler::convert2< QuantLib::Handle >(mVol, "Vol"); + + + // convert input datatypes to QuantLib enumerated datatypes + QuantLib::DayCounter DayCounterEnum = + ObjectHandler::Create()(mDayCounter); + + + // Construct the Value Object + boost::shared_ptr valueObject( + new QuantLibAddin::ValueObjects::qlBachelierCapFloorEngine2( + mObjectID, + mYieldCurve, + mVol, + mDayCounter, + false + )); + + // Construct the Object + boost::shared_ptr object( + new QuantLibAddin::BachelierCapFloorEngine( + valueObject, + YieldCurveLibObj, + VolLibObj, + DayCounterEnum, + false + )); + + // Store the Object in the Repository + mReturnValue = ObjectHandler::Repository::instance().storeObject(mObjectID, object, false, valueObject); + + }catch(const std::exception &e){ + mError = e.what(); + }catch (...){ + mError = "unkown error"; + } + +} + +void BachelierCapFloorEngine2Worker::HandleOKCallback(){ + Nan::HandleScope scope; + + + Local argv[2] = { + Nan::New(mError).ToLocalChecked(), + Nan::New(mReturnValue).ToLocalChecked() + }; + + callback->Call(2, argv); +} + +NAN_METHOD(QuantLibNode::BachelierCapFloorEngine2) { + + // validate js arguments + if (info.Length() == 0 || !info[0]->IsString()) { + return Nan::ThrowError("ObjectID is required."); + } + if (info.Length() == 3 || !info[3]->IsString()) { + return Nan::ThrowError("DayCounter is required."); + } + // convert js argument to c++ type + String::Utf8Value strObjectID(info[0]->ToString()); + string ObjectIDCpp(strdup(*strObjectID)); + + // convert js argument to c++ type + ObjectHandler::property_t YieldCurveCpp = + ObjectHandler::property_t(static_cast(Nan::To(info[1]).FromJust())); + + // convert js argument to c++ type + ObjectHandler::property_t VolCpp = + ObjectHandler::property_t(static_cast(Nan::To(info[2]).FromJust())); + + // convert js argument to c++ type + String::Utf8Value strDayCounter(info[3]->ToString()); + string DayCounterCpp(strdup(*strDayCounter)); + + + // declare callback + Nan::Callback *callback = new Nan::Callback(info[4].As()); + // launch Async worker + Nan::AsyncQueueWorker(new BachelierCapFloorEngine2Worker( + callback + ,ObjectIDCpp + ,YieldCurveCpp + ,VolCpp + ,DayCounterCpp + )); + +} + +//BachelierCapFloorEngine2Worker::~BachelierCapFloorEngine2Worker(){ +// +//} + +//void BachelierCapFloorEngine2Worker::Destroy(){ +// +//} + void AnalyticCapFloorEngineWorker::Execute(){ try{ @@ -3989,6 +4204,125 @@ NAN_METHOD(QuantLibNode::BachelierBlackFormula) { // //} +void BachelierBlackFormulaImpliedVolWorker::Execute(){ + + try{ + + // convert input datatypes to QuantLib enumerated datatypes + QuantLib::Option::Type OptionTypeEnum = + ObjectHandler::Create()(mOptionType); + + + // convert input datatypes to QuantLib datatypes + + // convert input datatypes to QuantLib datatypes + + // convert input datatypes to QuantLib datatypes + + // convert input datatypes to QuantLib datatypes + + // convert input datatypes to QuantLib datatypes + // invoke the utility function + QuantLib::Real returnValue = QuantLib::bachelierBlackFormulaImpliedVol( + OptionTypeEnum + , + mStrike + , + mAtmForwardValue + , + mTimeToExpiry + , + mOptionPrice + , + mDeflator + ); + + mReturnValue = returnValue; + + }catch(const std::exception &e){ + mError = e.what(); + }catch (...){ + mError = "unkown error"; + } + +} + +void BachelierBlackFormulaImpliedVolWorker::HandleOKCallback(){ + Nan::HandleScope scope; + + + Local argv[2] = { + Nan::New(mError).ToLocalChecked(), + Nan::New(mReturnValue) + }; + + callback->Call(2, argv); +} + +NAN_METHOD(QuantLibNode::BachelierBlackFormulaImpliedVol) { + + // validate js arguments + if (info.Length() == 0 || !info[0]->IsString()) { + return Nan::ThrowError("OptionType is required."); + } + if (info.Length() == 1 || !info[1]->IsNumber()) { + return Nan::ThrowError("Strike is required."); + } + if (info.Length() == 2 || !info[2]->IsNumber()) { + return Nan::ThrowError("AtmForwardValue is required."); + } + if (info.Length() == 3 || !info[3]->IsNumber()) { + return Nan::ThrowError("TimeToExpiry is required."); + } + if (info.Length() == 4 || !info[4]->IsNumber()) { + return Nan::ThrowError("OptionPrice is required."); + } + if (info.Length() == 5 || !info[5]->IsNumber()) { + return Nan::ThrowError("Deflator is required."); + } + // convert js argument to c++ type + String::Utf8Value strOptionType(info[0]->ToString()); + string OptionTypeCpp(strdup(*strOptionType)); + + // convert js argument to c++ type + double StrikeCpp = Nan::To(info[1]).FromJust(); + + // convert js argument to c++ type + double AtmForwardValueCpp = Nan::To(info[2]).FromJust(); + + // convert js argument to c++ type + double TimeToExpiryCpp = Nan::To(info[3]).FromJust(); + + // convert js argument to c++ type + double OptionPriceCpp = Nan::To(info[4]).FromJust(); + + // convert js argument to c++ type + double DeflatorCpp = Nan::To(info[5]).FromJust(); + + + // declare callback + Nan::Callback *callback = new Nan::Callback(info[6].As()); + // launch Async worker + Nan::AsyncQueueWorker(new BachelierBlackFormulaImpliedVolWorker( + callback + ,OptionTypeCpp + ,StrikeCpp + ,AtmForwardValueCpp + ,TimeToExpiryCpp + ,OptionPriceCpp + ,DeflatorCpp + )); + +} + +//BachelierBlackFormulaImpliedVolWorker::~BachelierBlackFormulaImpliedVolWorker(){ +// +//} + +//void BachelierBlackFormulaImpliedVolWorker::Destroy(){ +// +//} + void BlackFormula2Worker::Execute(){ try{ diff --git a/src/pricingengines.hpp b/src/pricingengines.hpp index 0b52224..c815fc8 100644 --- a/src/pricingengines.hpp +++ b/src/pricingengines.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef pricingengines_h @@ -455,6 +455,77 @@ class BlackCapFloorEngine2Worker : public Nan::AsyncWorker { }; +class BachelierCapFloorEngineWorker : public Nan::AsyncWorker { + public: + string mObjectID; + ObjectHandler::property_t mYieldCurve; + ObjectHandler::property_t mVolTS; + + string mReturnValue; + + string mError; + + BachelierCapFloorEngineWorker( + Nan::Callback *callback + ,string ObjectID + ,ObjectHandler::property_t YieldCurve + ,ObjectHandler::property_t VolTS + ): + Nan::AsyncWorker(callback) + ,mObjectID(ObjectID) + ,mYieldCurve(YieldCurve) + ,mVolTS(VolTS) + { + + }; + + //~BachelierCapFloorEngineWorker(); + + //void Destroy(); + + void Execute(); + + void HandleOKCallback(); + +}; + +class BachelierCapFloorEngine2Worker : public Nan::AsyncWorker { + public: + string mObjectID; + ObjectHandler::property_t mYieldCurve; + ObjectHandler::property_t mVol; + string mDayCounter; + + string mReturnValue; + + string mError; + + BachelierCapFloorEngine2Worker( + Nan::Callback *callback + ,string ObjectID + ,ObjectHandler::property_t YieldCurve + ,ObjectHandler::property_t Vol + ,string DayCounter + ): + Nan::AsyncWorker(callback) + ,mObjectID(ObjectID) + ,mYieldCurve(YieldCurve) + ,mVol(Vol) + ,mDayCounter(DayCounter) + { + + }; + + //~BachelierCapFloorEngine2Worker(); + + //void Destroy(); + + void Execute(); + + void HandleOKCallback(); + +}; + class AnalyticCapFloorEngineWorker : public Nan::AsyncWorker { public: string mObjectID; @@ -1535,6 +1606,49 @@ class BachelierBlackFormulaWorker : public Nan::AsyncWorker { }; +class BachelierBlackFormulaImpliedVolWorker : public Nan::AsyncWorker { + public: + string mOptionType; + double mStrike; + double mAtmForwardValue; + double mTimeToExpiry; + double mOptionPrice; + double mDeflator; + + double mReturnValue; + + string mError; + + BachelierBlackFormulaImpliedVolWorker( + Nan::Callback *callback + ,string OptionType + ,double Strike + ,double AtmForwardValue + ,double TimeToExpiry + ,double OptionPrice + ,double Deflator + ): + Nan::AsyncWorker(callback) + ,mOptionType(OptionType) + ,mStrike(Strike) + ,mAtmForwardValue(AtmForwardValue) + ,mTimeToExpiry(TimeToExpiry) + ,mOptionPrice(OptionPrice) + ,mDeflator(Deflator) + { + + }; + + //~BachelierBlackFormulaImpliedVolWorker(); + + //void Destroy(); + + void Execute(); + + void HandleOKCallback(); + +}; + class BlackFormula2Worker : public Nan::AsyncWorker { public: string mPayoff; diff --git a/src/processes.cpp b/src/processes.cpp index e93b1e6..eaf7c94 100644 --- a/src/processes.cpp +++ b/src/processes.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/processes.hpp b/src/processes.hpp index 1223548..0f7bf79 100644 --- a/src/processes.hpp +++ b/src/processes.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef processes_h diff --git a/src/products.cpp b/src/products.cpp index d24ffcf..c2c16a4 100644 --- a/src/products.cpp +++ b/src/products.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/products.hpp b/src/products.hpp index 47d1e18..b63d24a 100644 --- a/src/products.hpp +++ b/src/products.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef products_h diff --git a/src/quotes.cpp b/src/quotes.cpp index 6add7e2..a397a5c 100644 --- a/src/quotes.cpp +++ b/src/quotes.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/quotes.hpp b/src/quotes.hpp index 7c64b15..0ca50e4 100644 --- a/src/quotes.hpp +++ b/src/quotes.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef quotes_h diff --git a/src/randomsequencegenerator.cpp b/src/randomsequencegenerator.cpp index ef665a1..d54a7a0 100644 --- a/src/randomsequencegenerator.cpp +++ b/src/randomsequencegenerator.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/randomsequencegenerator.hpp b/src/randomsequencegenerator.hpp index 82db544..47bcb0d 100644 --- a/src/randomsequencegenerator.hpp +++ b/src/randomsequencegenerator.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef randomsequencegenerator_h diff --git a/src/rangeaccrual.cpp b/src/rangeaccrual.cpp index add5a61..0aa49c7 100644 --- a/src/rangeaccrual.cpp +++ b/src/rangeaccrual.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/rangeaccrual.hpp b/src/rangeaccrual.hpp index cc828b7..1de995e 100644 --- a/src/rangeaccrual.hpp +++ b/src/rangeaccrual.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef rangeaccrual_h diff --git a/src/ratehelpers.cpp b/src/ratehelpers.cpp index 332f07b..105d5e3 100644 --- a/src/ratehelpers.cpp +++ b/src/ratehelpers.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/ratehelpers.hpp b/src/ratehelpers.hpp index e2640b4..8ed88b1 100644 --- a/src/ratehelpers.hpp +++ b/src/ratehelpers.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef ratehelpers_h diff --git a/src/repository.cpp b/src/repository.cpp index 11c5aed..1e45d38 100644 --- a/src/repository.cpp +++ b/src/repository.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/repository.hpp b/src/repository.hpp index c5e2cd3..ae35e26 100644 --- a/src/repository.hpp +++ b/src/repository.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef repository_h diff --git a/src/schedule.cpp b/src/schedule.cpp index aa6464c..6827932 100644 --- a/src/schedule.cpp +++ b/src/schedule.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/schedule.hpp b/src/schedule.hpp index 26c05b4..87e3c9e 100644 --- a/src/schedule.hpp +++ b/src/schedule.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef schedule_h diff --git a/src/sequencestatistics.cpp b/src/sequencestatistics.cpp index b965d23..f7a0f31 100644 --- a/src/sequencestatistics.cpp +++ b/src/sequencestatistics.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/sequencestatistics.hpp b/src/sequencestatistics.hpp index b46e727..0167142 100644 --- a/src/sequencestatistics.hpp +++ b/src/sequencestatistics.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef sequencestatistics_h diff --git a/src/settings.cpp b/src/settings.cpp index 777831d..2cb015b 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/settings.hpp b/src/settings.hpp index e4ae3e1..5fe1d68 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef settings_h diff --git a/src/shortratemodels.cpp b/src/shortratemodels.cpp index e76cfbe..7c06824 100644 --- a/src/shortratemodels.cpp +++ b/src/shortratemodels.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/shortratemodels.hpp b/src/shortratemodels.hpp index 9be7157..4000082 100644 --- a/src/shortratemodels.hpp +++ b/src/shortratemodels.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef shortratemodels_h diff --git a/src/smilesection.cpp b/src/smilesection.cpp index 79d9dd0..d93f50f 100644 --- a/src/smilesection.cpp +++ b/src/smilesection.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include @@ -41,6 +41,8 @@ void FlatSmileSectionWorker::Execute(){ mRefDate, "RefDate"); + // convert input datatypes to QuantLib datatypes + // convert input datatypes to QuantLib datatypes // Construct the Value Object @@ -52,10 +54,13 @@ void FlatSmileSectionWorker::Execute(){ mDayCounter, mRefDate, mAtmValue, + mVolatilityType, + mDisplacement, false )); // Construct the Object + std::map strEnum; boost::shared_ptr object( new QuantLibAddin::FlatSmileSection( valueObject, @@ -64,6 +69,8 @@ void FlatSmileSectionWorker::Execute(){ DayCounterEnum, RefDateLib, mAtmValue, + strEnum[mVolatilityType], + mDisplacement, false )); @@ -105,6 +112,12 @@ NAN_METHOD(QuantLibNode::FlatSmileSection) { if (info.Length() == 5 || !info[5]->IsNumber()) { return Nan::ThrowError("AtmValue is required."); } + if (info.Length() == 6 || !info[6]->IsString()) { + return Nan::ThrowError("VolatilityType is required."); + } + if (info.Length() == 7 || !info[7]->IsNumber()) { + return Nan::ThrowError("Displacement is required."); + } // convert js argument to c++ type String::Utf8Value strObjectID(info[0]->ToString()); string ObjectIDCpp(strdup(*strObjectID)); @@ -127,9 +140,16 @@ NAN_METHOD(QuantLibNode::FlatSmileSection) { // convert js argument to c++ type double AtmValueCpp = Nan::To(info[5]).FromJust(); + // convert js argument to c++ type + String::Utf8Value strVolatilityType(info[6]->ToString()); + string VolatilityTypeCpp(strdup(*strVolatilityType)); + + // convert js argument to c++ type + double DisplacementCpp = Nan::To(info[7]).FromJust(); + // declare callback - Nan::Callback *callback = new Nan::Callback(info[6].As()); + Nan::Callback *callback = new Nan::Callback(info[8].As()); // launch Async worker Nan::AsyncQueueWorker(new FlatSmileSectionWorker( callback @@ -139,6 +159,8 @@ NAN_METHOD(QuantLibNode::FlatSmileSection) { ,DayCounterCpp ,RefDateCpp ,AtmValueCpp + ,VolatilityTypeCpp + ,DisplacementCpp )); } @@ -950,6 +972,8 @@ void InterpolatedSmileSectionWorker::Execute(){ QuantLib::DayCounter DayCounterEnum = ObjectHandler::Create()(mDayCounter); + + // convert input datatypes to QuantLib datatypes // Construct the Value Object boost::shared_ptr valueObject( @@ -960,10 +984,13 @@ void InterpolatedSmileSectionWorker::Execute(){ mStdDevs, mAtmLevel, mDayCounter, + mVolatilityType, + mDisplacement, false )); // Construct the Object + std::map strEnum; boost::shared_ptr object( new QuantLibAddin::InterpolatedSmileSection( valueObject, @@ -972,6 +999,8 @@ void InterpolatedSmileSectionWorker::Execute(){ StdDevsLibObj, AtmLevelLibObj, DayCounterEnum, + strEnum[mVolatilityType], + mDisplacement, false )); @@ -1013,6 +1042,12 @@ NAN_METHOD(QuantLibNode::InterpolatedSmileSection) { if (info.Length() == 5 || !info[5]->IsString()) { return Nan::ThrowError("DayCounter is required."); } + if (info.Length() == 6 || !info[6]->IsString()) { + return Nan::ThrowError("VolatilityType is required."); + } + if (info.Length() == 7 || !info[7]->IsNumber()) { + return Nan::ThrowError("Displacement is required."); + } // convert js argument to c++ type String::Utf8Value strObjectID(info[0]->ToString()); string ObjectIDCpp(strdup(*strObjectID)); @@ -1047,9 +1082,16 @@ NAN_METHOD(QuantLibNode::InterpolatedSmileSection) { String::Utf8Value strDayCounter(info[5]->ToString()); string DayCounterCpp(strdup(*strDayCounter)); + // convert js argument to c++ type + String::Utf8Value strVolatilityType(info[6]->ToString()); + string VolatilityTypeCpp(strdup(*strVolatilityType)); + + // convert js argument to c++ type + double DisplacementCpp = Nan::To(info[7]).FromJust(); + // declare callback - Nan::Callback *callback = new Nan::Callback(info[6].As()); + Nan::Callback *callback = new Nan::Callback(info[8].As()); // launch Async worker Nan::AsyncQueueWorker(new InterpolatedSmileSectionWorker( callback @@ -1059,6 +1101,8 @@ NAN_METHOD(QuantLibNode::InterpolatedSmileSection) { ,StdDevsCpp ,AtmLevelCpp ,DayCounterCpp + ,VolatilityTypeCpp + ,DisplacementCpp )); } diff --git a/src/smilesection.hpp b/src/smilesection.hpp index 11462a2..cc0d28d 100644 --- a/src/smilesection.hpp +++ b/src/smilesection.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef smilesection_h @@ -26,6 +26,8 @@ class FlatSmileSectionWorker : public Nan::AsyncWorker { string mDayCounter; ObjectHandler::property_t mRefDate; double mAtmValue; + string mVolatilityType; + double mDisplacement; string mReturnValue; @@ -39,6 +41,8 @@ class FlatSmileSectionWorker : public Nan::AsyncWorker { ,string DayCounter ,ObjectHandler::property_t RefDate ,double AtmValue + ,string VolatilityType + ,double Displacement ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) @@ -47,6 +51,8 @@ class FlatSmileSectionWorker : public Nan::AsyncWorker { ,mDayCounter(DayCounter) ,mRefDate(RefDate) ,mAtmValue(AtmValue) + ,mVolatilityType(VolatilityType) + ,mDisplacement(Displacement) { }; @@ -306,6 +312,8 @@ class InterpolatedSmileSectionWorker : public Nan::AsyncWorker { std::vector mStdDevs; ObjectHandler::property_t mAtmLevel; string mDayCounter; + string mVolatilityType; + double mDisplacement; string mReturnValue; @@ -319,6 +327,8 @@ class InterpolatedSmileSectionWorker : public Nan::AsyncWorker { ,std::vector StdDevs ,ObjectHandler::property_t AtmLevel ,string DayCounter + ,string VolatilityType + ,double Displacement ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) @@ -327,6 +337,8 @@ class InterpolatedSmileSectionWorker : public Nan::AsyncWorker { ,mStdDevs(StdDevs) ,mAtmLevel(AtmLevel) ,mDayCounter(DayCounter) + ,mVolatilityType(VolatilityType) + ,mDisplacement(Displacement) { }; diff --git a/src/statistics.cpp b/src/statistics.cpp index 3a969c5..d68503e 100644 --- a/src/statistics.cpp +++ b/src/statistics.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/statistics.hpp b/src/statistics.hpp index f004182..584c249 100644 --- a/src/statistics.hpp +++ b/src/statistics.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef statistics_h diff --git a/src/swap.cpp b/src/swap.cpp index 6d7e743..3762a30 100644 --- a/src/swap.cpp +++ b/src/swap.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/swap.hpp b/src/swap.hpp index 8229cdf..257c734 100644 --- a/src/swap.hpp +++ b/src/swap.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef swap_h diff --git a/src/swaption.cpp b/src/swaption.cpp index e5435c3..7e06657 100644 --- a/src/swaption.cpp +++ b/src/swaption.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/swaption.hpp b/src/swaption.hpp index 7aa8ade..653b58b 100644 --- a/src/swaption.hpp +++ b/src/swaption.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef swaption_h diff --git a/src/swaptionvolstructure.cpp b/src/swaptionvolstructure.cpp index 2a285e9..be92037 100644 --- a/src/swaptionvolstructure.cpp +++ b/src/swaptionvolstructure.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/swaptionvolstructure.hpp b/src/swaptionvolstructure.hpp index b30c354..da64882 100644 --- a/src/swaptionvolstructure.hpp +++ b/src/swaptionvolstructure.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef swaptionvolstructure_h diff --git a/src/termstructures.cpp b/src/termstructures.cpp index 359bb3f..83d395a 100644 --- a/src/termstructures.cpp +++ b/src/termstructures.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include @@ -844,6 +844,11 @@ void InterpolatedYieldCurveWorker::Execute(){ std::vector JumpDatesLib = ObjectHandler::vector::convert2( mJumpDates, "JumpDates"); + + // convert input datatypes to QuantLib datatypes + QuantLib::Size NRateHelperLib; + QuantLibAddin::cppToLibrary(mNRateHelper, NRateHelperLib); + // Construct the Value Object boost::shared_ptr valueObject( @@ -857,10 +862,13 @@ void InterpolatedYieldCurveWorker::Execute(){ mJumpDates, mTraitsID, mInterpolatorID, + mMixedInterpolationBehavior, + mNRateHelper, false )); // Construct the Object + std::map strEnum; boost::shared_ptr object( new QuantLibAddin::InterpolatedYieldCurve( valueObject, @@ -872,6 +880,8 @@ void InterpolatedYieldCurveWorker::Execute(){ JumpDatesLib, mTraitsID, mInterpolatorID, + strEnum[mMixedInterpolationBehavior], + NRateHelperLib, false )); @@ -928,6 +938,12 @@ NAN_METHOD(QuantLibNode::InterpolatedYieldCurve) { if (info.Length() == 8 || !info[8]->IsString()) { return Nan::ThrowError("InterpolatorID is required."); } + if (info.Length() == 9 || !info[9]->IsString()) { + return Nan::ThrowError("MixedInterpolationBehavior is required."); + } + if (info.Length() == 10 || !info[10]->IsNumber()) { + return Nan::ThrowError("NRateHelper is required."); + } // convert js argument to c++ type String::Utf8Value strObjectID(info[0]->ToString()); string ObjectIDCpp(strdup(*strObjectID)); @@ -986,9 +1002,16 @@ NAN_METHOD(QuantLibNode::InterpolatedYieldCurve) { String::Utf8Value strInterpolatorID(info[8]->ToString()); string InterpolatorIDCpp(strdup(*strInterpolatorID)); + // convert js argument to c++ type + String::Utf8Value strMixedInterpolationBehavior(info[9]->ToString()); + string MixedInterpolationBehaviorCpp(strdup(*strMixedInterpolationBehavior)); + + // convert js argument to c++ type + long NRateHelperCpp = Nan::To(info[10]).FromJust(); + // declare callback - Nan::Callback *callback = new Nan::Callback(info[9].As()); + Nan::Callback *callback = new Nan::Callback(info[11].As()); // launch Async worker Nan::AsyncQueueWorker(new InterpolatedYieldCurveWorker( callback @@ -1001,6 +1024,8 @@ NAN_METHOD(QuantLibNode::InterpolatedYieldCurve) { ,JumpDatesCpp ,TraitsIDCpp ,InterpolatorIDCpp + ,MixedInterpolationBehaviorCpp + ,NRateHelperCpp )); } diff --git a/src/termstructures.hpp b/src/termstructures.hpp index 90e92fe..f7c3e34 100644 --- a/src/termstructures.hpp +++ b/src/termstructures.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef termstructures_h @@ -285,6 +285,8 @@ class InterpolatedYieldCurveWorker : public Nan::AsyncWorker { std::vector mJumpDates; string mTraitsID; string mInterpolatorID; + string mMixedInterpolationBehavior; + long mNRateHelper; string mReturnValue; @@ -301,6 +303,8 @@ class InterpolatedYieldCurveWorker : public Nan::AsyncWorker { ,std::vector JumpDates ,string TraitsID ,string InterpolatorID + ,string MixedInterpolationBehavior + ,long NRateHelper ): Nan::AsyncWorker(callback) ,mObjectID(ObjectID) @@ -312,6 +316,8 @@ class InterpolatedYieldCurveWorker : public Nan::AsyncWorker { ,mJumpDates(JumpDates) ,mTraitsID(TraitsID) ,mInterpolatorID(InterpolatorID) + ,mMixedInterpolationBehavior(MixedInterpolationBehavior) + ,mNRateHelper(NRateHelper) { }; diff --git a/src/timeseries.cpp b/src/timeseries.cpp index a6a8a21..3a174e0 100644 --- a/src/timeseries.cpp +++ b/src/timeseries.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/timeseries.hpp b/src/timeseries.hpp index a45217b..5648a6f 100644 --- a/src/timeseries.hpp +++ b/src/timeseries.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef timeseries_h diff --git a/src/utilities.cpp b/src/utilities.cpp index 0558aaf..e92cb7c 100644 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/utilities.hpp b/src/utilities.hpp index fec8030..5b72de4 100644 --- a/src/utilities.hpp +++ b/src/utilities.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef utilities_h diff --git a/src/vanillaswap.cpp b/src/vanillaswap.cpp index 36f1144..b5cfd81 100644 --- a/src/vanillaswap.cpp +++ b/src/vanillaswap.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/vanillaswap.hpp b/src/vanillaswap.hpp index e5d9260..9a0df3b 100644 --- a/src/vanillaswap.hpp +++ b/src/vanillaswap.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef vanillaswap_h diff --git a/src/volatilities.cpp b/src/volatilities.cpp index c64f4ca..99da1cc 100644 --- a/src/volatilities.cpp +++ b/src/volatilities.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/volatilities.hpp b/src/volatilities.hpp index d19f8ac..41359f7 100644 --- a/src/volatilities.hpp +++ b/src/volatilities.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef volatilities_h diff --git a/src/volatility.cpp b/src/volatility.cpp index 5314f1f..b29ee32 100644 --- a/src/volatility.cpp +++ b/src/volatility.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #include diff --git a/src/volatility.hpp b/src/volatility.hpp index ff742b8..f579064 100644 --- a/src/volatility.hpp +++ b/src/volatility.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Jerry Jin + Copyright (C) 2016 -2017 Jerry Jin */ #ifndef volatility_h