From df00fef262f36a697cf0e72a5f86035d770e55e8 Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Fri, 17 Feb 2017 10:45:01 +0800 Subject: [PATCH 01/11] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f61d077..6302d2a 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,13 @@ 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 Please refer to [how to build](#building-the-native-addon) below @@ -46,6 +49,8 @@ Please refer to [how to build](#building-the-native-addon) below * 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 + #### Set environment variable please refer to `cmake/*.cmake` and `CMakeList.txt` files From de0cfcb118243d78f071c69f465dafcad2179df8 Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Fri, 17 Feb 2017 10:53:24 +0800 Subject: [PATCH 02/11] Update README.md --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6302d2a..b895ec7 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ npm install quantlib `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 @@ -115,8 +116,14 @@ var mtx1 = [0.81880, 0.83520, 0.85230, 0.87040, 0.88940, 0.90940, 0.93040, 0.95240, 0.97560, 1.00000] ]; +/* + * 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){ - + + // call Method with objectID, this is same as QuantLibXL ql.SymmetricSchurDecompositionEigenvalues(obj).then(function(r){ console.log(r); }); From 46024a92d1f4e665c4f964ab0791212729303284 Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Fri, 17 Feb 2017 13:18:39 +0800 Subject: [PATCH 03/11] minor fix to quantlib.js --- lib/quantlib.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/quantlib.js b/lib/quantlib.js index f6e0923..145e2c5 100644 --- a/lib/quantlib.js +++ b/lib/quantlib.js @@ -1064,10 +1064,10 @@ exports.PiecewiseConstantVarianceVolatility = promisify(rawApi.PiecewiseConstant exports.PiecewiseConstantVarianceTotalVariance = promisify(rawApi.PiecewiseConstantVarianceTotalVariance); exports.PiecewiseConstantVarianceTotalVolatility = promisify(rawApi.PiecewiseConstantVarianceTotalVolatility); -exports.PiecewiseYieldCurveMixedInterpolation = promisify(PiecewiseYieldCurveMixedInterpolation); -exports.BachelierCapFloorEngine = promisify(BachelierCapFloorEngine); -exports.BachelierCapFloorEngine2 = promisify(BachelierCapFloorEngine2); -exports.BachelierBlackFormulaImpliedVol = promisify(BachelierBlackFormulaImpliedVol); +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); From 8a28e0e0234f1a363f402353aa5934a0d47c9bab Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Fri, 17 Feb 2017 13:19:12 +0800 Subject: [PATCH 04/11] bump version to 0.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index be2fe52..997f48a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "quantlib", "description": "QuantLib Asyn Bindings for Node.js", - "version": "0.2.0", + "version": "0.2.1", "keywords": [ "quantlib" ], From 7e8df0e402cbbcae9b9c6835476e985fb2daa06e Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Fri, 17 Feb 2017 14:45:46 +0800 Subject: [PATCH 05/11] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b895ec7..31a7b54 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ -## QuantLib Async Bindings for Node.js [![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) +## QuantLib Async Bindings for Node.js + +[![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. From 75e25c768d473c92f447be98c405e84f13520be0 Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Mon, 20 Feb 2017 15:53:23 +0800 Subject: [PATCH 06/11] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 31a7b54..973c2fb 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ Please refer to [how to build](#building-the-native-addon) below > 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 @@ -104,6 +106,10 @@ please refer to `cmake/*.cmake` and `CMakeList.txt` files ## Example +> This is from QuantLibXL - StandaloneExamples - Math - RankReduction.xlsx - FirstCorrMatrix - M3:12 - forumula: {=qlSymmetricSchurDecompositionEigenvalues(C2)} + +> the input/output are the same + ```js var ql = require('quantlib'); From 34edd5f9993404e0d2d0f6a13f2ad18a879d923a Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Mon, 20 Feb 2017 16:02:10 +0800 Subject: [PATCH 07/11] Update README.md --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 973c2fb..bd6177d 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,11 @@ please refer to `cmake/*.cmake` and `CMakeList.txt` files ## Example -> This is from QuantLibXL - StandaloneExamples - Math - RankReduction.xlsx - FirstCorrMatrix - M3:12 - forumula: {=qlSymmetricSchurDecompositionEigenvalues(C2)} +> 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 @@ -132,10 +136,10 @@ var mtx1 = * 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){ +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){ + ql.SymmetricSchurDecompositionEigenvalues(obj).then(function(r){ // M3:12 formula: {=qlSymmetricSchurDecompositionEigenvalues(C2)} console.log(r); }); From 6cb92c71f9b09b2f0e5486ce2298feb655ae431e Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Mon, 27 Feb 2017 21:07:17 +0800 Subject: [PATCH 08/11] Update README.md --- README.md | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/README.md b/README.md index bd6177d..693fcff 100644 --- a/README.md +++ b/README.md @@ -76,34 +76,6 @@ please refer to `cmake/*.cmake` and `CMakeList.txt` files 4. `cmake --build . --config Release` 5. For Linux, you may need to put `quantlib.node` under `build/Release` manually, -## 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 - -#### 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 From ab492c09821b21602dcda5fe29623fd77e93b65f Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Tue, 16 May 2017 17:42:41 +0800 Subject: [PATCH 09/11] update src for 1.9 --- src/basketlossmodels.cpp | 192 ++++++++++++++++++------------------ src/basketlossmodels.hpp | 72 +++++++------- src/capfloor.cpp | 16 ++- src/capfloor.hpp | 3 + src/capletvolstructure.cpp | 9 +- src/defaultbasket.cpp | 24 ++--- src/defaultbasket.hpp | 12 +-- src/piecewiseyieldcurve.cpp | 4 +- src/smilesection.cpp | 6 +- src/termstructures.cpp | 3 +- 10 files changed, 173 insertions(+), 168 deletions(-) diff --git a/src/basketlossmodels.cpp b/src/basketlossmodels.cpp index bc7c56b..4c78283 100644 --- a/src/basketlossmodels.cpp +++ b/src/basketlossmodels.cpp @@ -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 eb83799..5ddccae 100644 --- a/src/basketlossmodels.hpp +++ b/src/basketlossmodels.hpp @@ -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/capfloor.cpp b/src/capfloor.cpp index 2b981fe..cca98ee 100644 --- a/src/capfloor.cpp +++ b/src/capfloor.cpp @@ -732,6 +732,8 @@ void CapFloorImpliedVolatilityWorker::Execute(){ mMinVol , mMaxVol + , + mVolatilityType , mDisplacement ); @@ -777,7 +779,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 +813,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 +833,7 @@ NAN_METHOD(QuantLibNode::CapFloorImpliedVolatility) { ,MaxIterCpp ,MinVolCpp ,MaxVolCpp + ,VolatilityTypeCpp ,DisplacementCpp )); diff --git a/src/capfloor.hpp b/src/capfloor.hpp index 48ddd02..333cba3 100644 --- a/src/capfloor.hpp +++ b/src/capfloor.hpp @@ -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 cfa7ae5..7913f0f 100644 --- a/src/capletvolstructure.cpp +++ b/src/capletvolstructure.cpp @@ -154,7 +154,6 @@ void ConstantOptionletVolatilityWorker::Execute(){ )); // Construct the Object - std::map strEnum; boost::shared_ptr object( new QuantLibAddin::ConstantOptionletVolatility( valueObject, @@ -163,7 +162,7 @@ void ConstantOptionletVolatilityWorker::Execute(){ BusinessDayConventionEnum, VolatilityLibObj, DayCounterEnum, - strEnum[mVolatilityType], + mVolatilityType, mDisplacement, false )); @@ -513,7 +512,6 @@ void StrippedOptionletWorker::Execute(){ )); // Construct the Object - std::map strEnum; boost::shared_ptr object( new QuantLibAddin::StrippedOptionlet( valueObject, @@ -525,7 +523,7 @@ void StrippedOptionletWorker::Execute(){ mStrikes, VolatilitiesLibObj, DayCounterEnum, - strEnum[mVolatilityType], + mVolatilityType, mDisplacement, false )); @@ -719,7 +717,6 @@ void OptionletStripper1Worker::Execute(){ )); // Construct the Object - std::map strEnum; boost::shared_ptr object( new QuantLibAddin::OptionletStripper1( valueObject, @@ -728,7 +725,7 @@ void OptionletStripper1Worker::Execute(){ mSwitchStrike, mAccuracy, MaxIterLib, - strEnum[mVolatilityType], + mVolatilityType, mDisplacement, false )); diff --git a/src/defaultbasket.cpp b/src/defaultbasket.cpp index e132105..9bba061 100644 --- a/src/defaultbasket.cpp +++ b/src/defaultbasket.cpp @@ -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 0a1f4ec..f852ae7 100644 --- a/src/defaultbasket.hpp +++ b/src/defaultbasket.hpp @@ -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/piecewiseyieldcurve.cpp b/src/piecewiseyieldcurve.cpp index 365dcfc..3610d84 100644 --- a/src/piecewiseyieldcurve.cpp +++ b/src/piecewiseyieldcurve.cpp @@ -285,8 +285,6 @@ void PiecewiseYieldCurveMixedInterpolationWorker::Execute(){ )); // Construct the Object - - std::map strEnum; boost::shared_ptr object( new QuantLibAddin::PiecewiseYieldCurve( valueObject, @@ -299,7 +297,7 @@ void PiecewiseYieldCurveMixedInterpolationWorker::Execute(){ mAccuracy, mTraitsID, mInterpolatorID, - strEnum[mMixedInterpolationBehavior], + mMixedInterpolationBehavior, PillarsBeforeChangeLib, false )); diff --git a/src/smilesection.cpp b/src/smilesection.cpp index d93f50f..e268b0c 100644 --- a/src/smilesection.cpp +++ b/src/smilesection.cpp @@ -60,7 +60,6 @@ void FlatSmileSectionWorker::Execute(){ )); // Construct the Object - std::map strEnum; boost::shared_ptr object( new QuantLibAddin::FlatSmileSection( valueObject, @@ -69,7 +68,7 @@ void FlatSmileSectionWorker::Execute(){ DayCounterEnum, RefDateLib, mAtmValue, - strEnum[mVolatilityType], + mVolatilityType, mDisplacement, false )); @@ -990,7 +989,6 @@ void InterpolatedSmileSectionWorker::Execute(){ )); // Construct the Object - std::map strEnum; boost::shared_ptr object( new QuantLibAddin::InterpolatedSmileSection( valueObject, @@ -999,7 +997,7 @@ void InterpolatedSmileSectionWorker::Execute(){ StdDevsLibObj, AtmLevelLibObj, DayCounterEnum, - strEnum[mVolatilityType], + mVolatilityType, mDisplacement, false )); diff --git a/src/termstructures.cpp b/src/termstructures.cpp index 83d395a..92470a9 100644 --- a/src/termstructures.cpp +++ b/src/termstructures.cpp @@ -868,7 +868,6 @@ void InterpolatedYieldCurveWorker::Execute(){ )); // Construct the Object - std::map strEnum; boost::shared_ptr object( new QuantLibAddin::InterpolatedYieldCurve( valueObject, @@ -880,7 +879,7 @@ void InterpolatedYieldCurveWorker::Execute(){ JumpDatesLib, mTraitsID, mInterpolatorID, - strEnum[mMixedInterpolationBehavior], + mMixedInterpolationBehavior, NRateHelperLib, false )); From f6398d56679c4e23805f14caaf7da0cc3452cce2 Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Tue, 16 May 2017 17:49:33 +0800 Subject: [PATCH 10/11] update CreditBasketAttachLive CreditBasketDetachLive --- lib/quantlib.js | 4 ++-- quantlibnode.cpp | 4 ++-- quantlibnode.hpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/quantlib.js b/lib/quantlib.js index f6e0923..bbbfbcf 100644 --- a/lib/quantlib.js +++ b/lib/quantlib.js @@ -353,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); diff --git a/quantlibnode.cpp b/quantlibnode.cpp index c9d223c..a05608f 100644 --- a/quantlibnode.cpp +++ b/quantlibnode.cpp @@ -373,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); diff --git a/quantlibnode.hpp b/quantlibnode.hpp index f6c0c32..834e625 100644 --- a/quantlibnode.hpp +++ b/quantlibnode.hpp @@ -421,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); From fc2577ab397e8ada06690111988b19db0ae991ea Mon Sep 17 00:00:00 2001 From: Jin <46172@global.ul.com> Date: Wed, 17 May 2017 12:15:57 +0800 Subject: [PATCH 11/11] build for 1.9 --- README.md | 40 +++++++++++++++++++++++++++++++------ package.json | 2 +- src/capfloor.cpp | 3 ++- src/capletvolstructure.cpp | 9 ++++++--- src/piecewiseyieldcurve.cpp | 3 ++- src/smilesection.cpp | 6 ++++-- src/termstructures.cpp | 3 ++- 7 files changed, 51 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 906bd29..b4df4ac 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ -## QuantLib Async Bindings for Node.js [![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) +## QuantLib Async Bindings for Node.js + +[![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. @@ -13,10 +18,14 @@ 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 Please refer to [how to build](#building-the-native-addon) below @@ -34,6 +43,7 @@ Please refer to [how to build](#building-the-native-addon) below | -------- | ------------- | ------- | ------------- | | 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 @@ -46,6 +56,10 @@ Please refer to [how to build](#building-the-native-addon) below * 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 @@ -65,6 +79,14 @@ please refer to `cmake/*.cmake` and `CMakeList.txt` files ## 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'); @@ -82,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); }); @@ -106,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/package.json b/package.json index be2fe52..fc56982 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "quantlib", "description": "QuantLib Asyn Bindings for Node.js", - "version": "0.2.0", + "version": "0.3.0", "keywords": [ "quantlib" ], diff --git a/src/capfloor.cpp b/src/capfloor.cpp index cca98ee..89d2564 100644 --- a/src/capfloor.cpp +++ b/src/capfloor.cpp @@ -718,6 +718,7 @@ void CapFloorImpliedVolatilityWorker::Execute(){ // invoke the member function + std::map strEnum; mReturnValue = ObjectIDLibObjPtr->impliedVolatility( mPrice , @@ -733,7 +734,7 @@ void CapFloorImpliedVolatilityWorker::Execute(){ , mMaxVol , - mVolatilityType + strEnum[mVolatilityType] , mDisplacement ); diff --git a/src/capletvolstructure.cpp b/src/capletvolstructure.cpp index 7913f0f..cfa7ae5 100644 --- a/src/capletvolstructure.cpp +++ b/src/capletvolstructure.cpp @@ -154,6 +154,7 @@ void ConstantOptionletVolatilityWorker::Execute(){ )); // Construct the Object + std::map strEnum; boost::shared_ptr object( new QuantLibAddin::ConstantOptionletVolatility( valueObject, @@ -162,7 +163,7 @@ void ConstantOptionletVolatilityWorker::Execute(){ BusinessDayConventionEnum, VolatilityLibObj, DayCounterEnum, - mVolatilityType, + strEnum[mVolatilityType], mDisplacement, false )); @@ -512,6 +513,7 @@ void StrippedOptionletWorker::Execute(){ )); // Construct the Object + std::map strEnum; boost::shared_ptr object( new QuantLibAddin::StrippedOptionlet( valueObject, @@ -523,7 +525,7 @@ void StrippedOptionletWorker::Execute(){ mStrikes, VolatilitiesLibObj, DayCounterEnum, - mVolatilityType, + strEnum[mVolatilityType], mDisplacement, false )); @@ -717,6 +719,7 @@ void OptionletStripper1Worker::Execute(){ )); // Construct the Object + std::map strEnum; boost::shared_ptr object( new QuantLibAddin::OptionletStripper1( valueObject, @@ -725,7 +728,7 @@ void OptionletStripper1Worker::Execute(){ mSwitchStrike, mAccuracy, MaxIterLib, - mVolatilityType, + strEnum[mVolatilityType], mDisplacement, false )); diff --git a/src/piecewiseyieldcurve.cpp b/src/piecewiseyieldcurve.cpp index 3610d84..b8450e9 100644 --- a/src/piecewiseyieldcurve.cpp +++ b/src/piecewiseyieldcurve.cpp @@ -285,6 +285,7 @@ void PiecewiseYieldCurveMixedInterpolationWorker::Execute(){ )); // Construct the Object + std::map strEnum; boost::shared_ptr object( new QuantLibAddin::PiecewiseYieldCurve( valueObject, @@ -297,7 +298,7 @@ void PiecewiseYieldCurveMixedInterpolationWorker::Execute(){ mAccuracy, mTraitsID, mInterpolatorID, - mMixedInterpolationBehavior, + strEnum[mMixedInterpolationBehavior], PillarsBeforeChangeLib, false )); diff --git a/src/smilesection.cpp b/src/smilesection.cpp index e268b0c..d93f50f 100644 --- a/src/smilesection.cpp +++ b/src/smilesection.cpp @@ -60,6 +60,7 @@ void FlatSmileSectionWorker::Execute(){ )); // Construct the Object + std::map strEnum; boost::shared_ptr object( new QuantLibAddin::FlatSmileSection( valueObject, @@ -68,7 +69,7 @@ void FlatSmileSectionWorker::Execute(){ DayCounterEnum, RefDateLib, mAtmValue, - mVolatilityType, + strEnum[mVolatilityType], mDisplacement, false )); @@ -989,6 +990,7 @@ void InterpolatedSmileSectionWorker::Execute(){ )); // Construct the Object + std::map strEnum; boost::shared_ptr object( new QuantLibAddin::InterpolatedSmileSection( valueObject, @@ -997,7 +999,7 @@ void InterpolatedSmileSectionWorker::Execute(){ StdDevsLibObj, AtmLevelLibObj, DayCounterEnum, - mVolatilityType, + strEnum[mVolatilityType], mDisplacement, false )); diff --git a/src/termstructures.cpp b/src/termstructures.cpp index 92470a9..83d395a 100644 --- a/src/termstructures.cpp +++ b/src/termstructures.cpp @@ -868,6 +868,7 @@ void InterpolatedYieldCurveWorker::Execute(){ )); // Construct the Object + std::map strEnum; boost::shared_ptr object( new QuantLibAddin::InterpolatedYieldCurve( valueObject, @@ -879,7 +880,7 @@ void InterpolatedYieldCurveWorker::Execute(){ JumpDatesLib, mTraitsID, mInterpolatorID, - mMixedInterpolationBehavior, + strEnum[mMixedInterpolationBehavior], NRateHelperLib, false ));