From 733557a72177b1de0b1537a024f04b562872198a Mon Sep 17 00:00:00 2001 From: Jerry Yang Jin Date: Thu, 29 Dec 2016 10:22:35 +0800 Subject: [PATCH 01/17] update README.md --- README.md | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f4dda56..a7891ff 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -## 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 [![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 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. +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 +13,17 @@ All functions in this project are Async, they are exported to [Promise](https:// npm install quantlib ``` -* Windows +* Windows - 32-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. +* Windows - 64-Bit + +I will try to build and upload the pre-built addon, before that, Please refer to [how to build](#building_the_native_addon) below + * 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 @@ -34,6 +38,34 @@ Quantlib and QuantLibAddin must be built first, then build QuantLibNode linking | -------- | ------------- | ------- | ------------- | | 1.7.1 | 1.7.0 | 6.9.1 | 0.1.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 + +#### 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 ```js From d1eb11cfc680256770bb898d4c06190b0ffae351 Mon Sep 17 00:00:00 2001 From: Jerry Yang Jin Date: Thu, 29 Dec 2016 10:25:40 +0800 Subject: [PATCH 02/17] update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a7891ff..698e6d0 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,11 @@ npm install quantlib * Windows - 64-Bit -I will try to build and upload the pre-built addon, before that, Please refer to [how to build](#building_the_native_addon) below +I will try to build and upload the pre-built addon, before that, Please refer to [how to build](#building-the-native-addon) below * Linux & Mac -Please refer to [how to build](#building_the_native_addon) below +Please refer to [how to build](#building-the-native-addon) below ## QuantLib Documents From b1786123e1b5cf45e192c7c69c9f53236b38b84c Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Thu, 16 Feb 2017 12:17:18 +0800 Subject: [PATCH 03/17] prepare for 1.8 --- src/abcd.cpp | 2 +- src/abcd.hpp | 2 +- src/accountingengines.cpp | 2 +- src/accountingengines.hpp | 2 +- src/alphaform.cpp | 2 +- src/alphaform.hpp | 2 +- src/assetswap.cpp | 2 +- src/assetswap.hpp | 2 +- src/basketlossmodels.cpp | 2 +- src/basketlossmodels.hpp | 2 +- src/bonds.cpp | 2 +- src/bonds.hpp | 2 +- src/browniangenerators.cpp | 2 +- src/browniangenerators.hpp | 2 +- src/btp.cpp | 2 +- src/btp.hpp | 2 +- src/calendar.cpp | 2 +- src/calendar.hpp | 2 +- src/calibrationhelpers.cpp | 2 +- src/calibrationhelpers.hpp | 2 +- src/capfloor.cpp | 2 +- src/capfloor.hpp | 2 +- src/capletvolstructure.cpp | 71 ++++++- src/capletvolstructure.hpp | 20 +- src/cmsmarket.cpp | 2 +- src/cmsmarket.hpp | 2 +- src/cmsmarketcalibration.cpp | 2 +- src/cmsmarketcalibration.hpp | 2 +- src/correlation.cpp | 2 +- src/correlation.hpp | 2 +- src/couponvectors.cpp | 2 +- src/couponvectors.hpp | 2 +- src/credit.cpp | 2 +- src/credit.hpp | 2 +- src/ctsmmcapletcalibration.cpp | 2 +- src/ctsmmcapletcalibration.hpp | 2 +- src/curvestate.cpp | 2 +- src/curvestate.hpp | 2 +- src/date.cpp | 2 +- src/date.hpp | 2 +- src/daycounter.cpp | 2 +- src/daycounter.hpp | 2 +- src/defaultbasket.cpp | 2 +- src/defaultbasket.hpp | 2 +- src/defaulttermstructures.cpp | 2 +- src/defaulttermstructures.hpp | 2 +- src/driftcalculators.cpp | 2 +- src/driftcalculators.hpp | 2 +- src/evolutiondescription.cpp | 2 +- src/evolutiondescription.hpp | 2 +- src/exercise.cpp | 2 +- src/exercise.hpp | 2 +- src/forwardrateagreement.cpp | 2 +- src/forwardrateagreement.hpp | 2 +- src/handles.cpp | 2 +- src/handles.hpp | 2 +- src/index.cpp | 2 +- src/index.hpp | 2 +- src/instruments.cpp | 2 +- src/instruments.hpp | 2 +- src/interpolation.cpp | 2 +- src/interpolation.hpp | 2 +- src/latentmodels.cpp | 2 +- src/latentmodels.hpp | 2 +- src/leg.cpp | 2 +- src/leg.hpp | 2 +- src/marketmodelevolvers.cpp | 2 +- src/marketmodelevolvers.hpp | 2 +- src/marketmodels.cpp | 2 +- src/marketmodels.hpp | 2 +- src/mathf.cpp | 2 +- src/mathf.hpp | 2 +- src/optimization.cpp | 2 +- src/optimization.hpp | 2 +- src/options.cpp | 2 +- src/options.hpp | 2 +- src/overnightindexedswap.cpp | 2 +- src/overnightindexedswap.hpp | 2 +- src/payoffs.cpp | 2 +- src/payoffs.hpp | 2 +- src/piecewiseyieldcurve.cpp | 231 +++++++++++++++++++++- src/piecewiseyieldcurve.hpp | 63 +++++- src/prices.cpp | 2 +- src/prices.hpp | 2 +- src/pricingengines.cpp | 336 +++++++++++++++++++++++++++++++- src/pricingengines.hpp | 116 ++++++++++- src/processes.cpp | 2 +- src/processes.hpp | 2 +- src/products.cpp | 2 +- src/products.hpp | 2 +- src/quotes.cpp | 2 +- src/quotes.hpp | 2 +- src/randomsequencegenerator.cpp | 2 +- src/randomsequencegenerator.hpp | 2 +- src/rangeaccrual.cpp | 2 +- src/rangeaccrual.hpp | 2 +- src/ratehelpers.cpp | 2 +- src/ratehelpers.hpp | 2 +- src/repository.cpp | 2 +- src/repository.hpp | 2 +- src/schedule.cpp | 2 +- src/schedule.hpp | 2 +- src/sequencestatistics.cpp | 2 +- src/sequencestatistics.hpp | 2 +- src/settings.cpp | 2 +- src/settings.hpp | 2 +- src/shortratemodels.cpp | 2 +- src/shortratemodels.hpp | 2 +- src/smilesection.cpp | 48 ++++- src/smilesection.hpp | 14 +- src/statistics.cpp | 2 +- src/statistics.hpp | 2 +- src/swap.cpp | 2 +- src/swap.hpp | 2 +- src/swaption.cpp | 2 +- src/swaption.hpp | 2 +- src/swaptionvolstructure.cpp | 2 +- src/swaptionvolstructure.hpp | 2 +- src/termstructures.cpp | 28 ++- src/termstructures.hpp | 8 +- src/timeseries.cpp | 2 +- src/timeseries.hpp | 2 +- src/utilities.cpp | 2 +- src/utilities.hpp | 2 +- src/vanillaswap.cpp | 2 +- src/vanillaswap.hpp | 2 +- src/volatilities.cpp | 2 +- src/volatilities.hpp | 2 +- src/volatility.cpp | 2 +- src/volatility.hpp | 2 +- 130 files changed, 1039 insertions(+), 136 deletions(-) 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..bc7c56b 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 diff --git a/src/basketlossmodels.hpp b/src/basketlossmodels.hpp index c9c3099..eb83799 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 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..2b981fe 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 diff --git a/src/capfloor.hpp b/src/capfloor.hpp index f10f9d1..48ddd02 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 diff --git a/src/capletvolstructure.cpp b/src/capletvolstructure.cpp index c9f74ed..7913f0f 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,6 +148,8 @@ void ConstantOptionletVolatilityWorker::Execute(){ mBusinessDayConvention, mVolatility, mDayCounter, + mVolatilityType, + mDisplacement, false )); @@ -158,6 +162,8 @@ void ConstantOptionletVolatilityWorker::Execute(){ BusinessDayConventionEnum, VolatilityLibObj, DayCounterEnum, + mVolatilityType, + mDisplacement, false )); @@ -202,6 +208,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 +237,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 +256,8 @@ NAN_METHOD(QuantLibNode::ConstantOptionletVolatility) { ,BusinessDayConventionCpp ,VolatilityCpp ,DayCounterCpp + ,VolatilityTypeCpp + ,DisplacementCpp )); } @@ -470,6 +491,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,6 +506,8 @@ void StrippedOptionletWorker::Execute(){ mStrikes, mVolatilities, mDayCounter, + mVolatilityType, + mDisplacement, false )); @@ -498,6 +523,8 @@ void StrippedOptionletWorker::Execute(){ mStrikes, VolatilitiesLibObj, DayCounterEnum, + mVolatilityType, + mDisplacement, false )); @@ -554,6 +581,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 +643,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 +665,8 @@ NAN_METHOD(QuantLibNode::StrippedOptionlet) { ,StrikesCpp ,VolatilitiesCpp ,DayCounterCpp + ,VolatilityTypeCpp + ,DisplacementCpp )); } @@ -657,6 +699,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,6 +711,8 @@ void OptionletStripper1Worker::Execute(){ mSwitchStrike, mAccuracy, mMaxIter, + mVolatilityType, + mDisplacement, false )); @@ -679,6 +725,8 @@ void OptionletStripper1Worker::Execute(){ mSwitchStrike, mAccuracy, MaxIterLib, + mVolatilityType, + mDisplacement, false )); @@ -723,6 +771,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 +799,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 +818,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..e132105 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 diff --git a/src/defaultbasket.hpp b/src/defaultbasket.hpp index 667488c..0a1f4ec 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 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..3610d84 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,235 @@ 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 + boost::shared_ptr object( + new QuantLibAddin::PiecewiseYieldCurve( + valueObject, + NDaysLib, + CalendarEnum, + RateHelpersLibObjPtr, + DayCounterEnum, + JumpsLibObj, + JumpDatesLib, + mAccuracy, + mTraitsID, + mInterpolatorID, + 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..e268b0c 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,6 +54,8 @@ void FlatSmileSectionWorker::Execute(){ mDayCounter, mRefDate, mAtmValue, + mVolatilityType, + mDisplacement, false )); @@ -64,6 +68,8 @@ void FlatSmileSectionWorker::Execute(){ DayCounterEnum, RefDateLib, mAtmValue, + mVolatilityType, + mDisplacement, false )); @@ -105,6 +111,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 +139,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 +158,8 @@ NAN_METHOD(QuantLibNode::FlatSmileSection) { ,DayCounterCpp ,RefDateCpp ,AtmValueCpp + ,VolatilityTypeCpp + ,DisplacementCpp )); } @@ -950,6 +971,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,6 +983,8 @@ void InterpolatedSmileSectionWorker::Execute(){ mStdDevs, mAtmLevel, mDayCounter, + mVolatilityType, + mDisplacement, false )); @@ -972,6 +997,8 @@ void InterpolatedSmileSectionWorker::Execute(){ StdDevsLibObj, AtmLevelLibObj, DayCounterEnum, + mVolatilityType, + mDisplacement, false )); @@ -1013,6 +1040,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 +1080,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 +1099,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..92470a9 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,6 +862,8 @@ void InterpolatedYieldCurveWorker::Execute(){ mJumpDates, mTraitsID, mInterpolatorID, + mMixedInterpolationBehavior, + mNRateHelper, false )); @@ -872,6 +879,8 @@ void InterpolatedYieldCurveWorker::Execute(){ JumpDatesLib, mTraitsID, mInterpolatorID, + mMixedInterpolationBehavior, + NRateHelperLib, false )); @@ -928,6 +937,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 +1001,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 +1023,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 From f88ac4c3e168b9d140fa1d0146756cc1964190aa Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Thu, 16 Feb 2017 12:32:58 +0800 Subject: [PATCH 04/17] add new functions from 1.8 --- README.md | 2 +- package.json | 2 +- quantlibnode.cpp | 5 +++++ quantlibnode.hpp | 5 +++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f4dda56..1c94d56 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ 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.4 | 0.2.x | ## Example diff --git a/package.json b/package.json index 9491342..5e6a589 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "quantlib", "description": "QuantLib Asyn Bindings for Node.js", - "version": "0.1.5", + "version": "0.2.0", "keywords": [ "quantlib", "native", diff --git a/quantlibnode.cpp b/quantlibnode.cpp index 0d4b537..c4b5d03 100644 --- a/quantlibnode.cpp +++ b/quantlibnode.cpp @@ -1080,6 +1080,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..bc97eb2 100644 --- a/quantlibnode.hpp +++ b/quantlibnode.hpp @@ -1127,6 +1127,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); From a14befc83143627767d5ad909ab09f8b41f7ccfb Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Thu, 16 Feb 2017 17:26:16 +0800 Subject: [PATCH 05/17] update version info --- CMakeLists.txt | 12 ++++++------ LICENSE | 2 +- README.md | 43 ++++++++++++++++++++++++++++++++++++++----- cmake/FindNode.cmake | 2 +- lib/quantlib.js | 11 ++++++++++- package.json | 4 +--- quantlibnode.cpp | 4 ++++ quantlibnode.hpp | 5 +++++ 8 files changed, 66 insertions(+), 17 deletions(-) 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 1c94d56..aae0e55 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -## 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 [![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 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. +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 +13,17 @@ All functions in this project are Async, they are exported to [Promise](https:// npm install quantlib ``` -* Windows +* Windows - 32-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. +* Windows - 64-Bit + +I will try to build and upload the pre-built addon, before that, Please refer to [how to build](#building-the-native-addon) below + * 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 @@ -32,7 +36,36 @@ Quantlib and QuantLibAddin must be built first, then build QuantLibNode linking | QuantLib | QuantLibAddin | Node.js | quantlib.node | | -------- | ------------- | ------- | ------------- | -| 1.8.1 | 1.8.0 | 6.9.4 | 0.2.x | +| 1.7.1 | 1.7.0 | 6.9.1 | 0.1.x | +| 1.8.1 | 1.8.0 | 6.9.5 | 0.2.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 + +#### 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 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..f6e0923 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"); @@ -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(PiecewiseYieldCurveMixedInterpolation); +exports.BachelierCapFloorEngine = promisify(BachelierCapFloorEngine); +exports.BachelierCapFloorEngine2 = promisify(BachelierCapFloorEngine2); +exports.BachelierBlackFormulaImpliedVol = promisify(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 5e6a589..be2fe52 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,7 @@ "description": "QuantLib Asyn Bindings for Node.js", "version": "0.2.0", "keywords": [ - "quantlib", - "native", - "addon" + "quantlib" ], "main": "lib/quantlib.js", "repository": { diff --git a/quantlibnode.cpp b/quantlibnode.cpp index c4b5d03..c9d223c 100644 --- a/quantlibnode.cpp +++ b/quantlibnode.cpp @@ -1,3 +1,7 @@ +/* + Copyright (C) 2016 -2017 Jerry Jin +*/ + #include #include #include diff --git a/quantlibnode.hpp b/quantlibnode.hpp index bc97eb2..f6c0c32 100644 --- a/quantlibnode.hpp +++ b/quantlibnode.hpp @@ -1,3 +1,8 @@ +/* + Copyright (C) 2016 -2017 Jerry Jin +*/ + + #ifndef quantlibnode_hpp #define quantlibnode_hpp From daf50943115ba23e0a2839123a89d93a21d09ca2 Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Thu, 16 Feb 2017 19:35:38 +0800 Subject: [PATCH 06/17] convert enum --- README.md | 6 +----- src/capletvolstructure.cpp | 9 ++++++--- src/piecewiseyieldcurve.cpp | 4 +++- src/smilesection.cpp | 6 ++++-- src/termstructures.cpp | 3 ++- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index aae0e55..906bd29 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,10 @@ All functions in this project are Async, they are exported to [Promise](https:// npm install quantlib ``` -* Windows - 32-Bit +* Windows `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. -* Windows - 64-Bit - -I will try to build and upload the pre-built addon, before that, Please refer to [how to build](#building-the-native-addon) below - * Linux & Mac Please refer to [how to build](#building-the-native-addon) below 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..365dcfc 100644 --- a/src/piecewiseyieldcurve.cpp +++ b/src/piecewiseyieldcurve.cpp @@ -285,6 +285,8 @@ void PiecewiseYieldCurveMixedInterpolationWorker::Execute(){ )); // Construct the Object + + std::map strEnum; boost::shared_ptr object( new QuantLibAddin::PiecewiseYieldCurve( valueObject, @@ -297,7 +299,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 )); From df00fef262f36a697cf0e72a5f86035d770e55e8 Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Fri, 17 Feb 2017 10:45:01 +0800 Subject: [PATCH 07/17] 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 08/17] 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 09/17] 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 10/17] 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 11/17] 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 12/17] 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 13/17] 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 14/17] 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 15/17] 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 16/17] 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 17/17] 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 ));