From b1786123e1b5cf45e192c7c69c9f53236b38b84c Mon Sep 17 00:00:00 2001 From: Jerry Jin Date: Thu, 16 Feb 2017 12:17:18 +0800 Subject: [PATCH] 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