XLL_DEC OPER *qlMoneyMarketPlusMeasure( char *EvolutionDescription, OPER *Offset, OPER *Trigger) { // declare a shared pointer to the Function Call object boost::shared_ptr<ObjectHandler::FunctionCall> functionCall; try { // instantiate the Function Call object functionCall = boost::shared_ptr<ObjectHandler::FunctionCall>( new ObjectHandler::FunctionCall("qlMoneyMarketPlusMeasure")); ObjectHandler::validateRange(Trigger, "Trigger"); // initialize the session ID (if enabled) SET_SESSION_ID // convert input datatypes to C++ datatypes long OffsetCpp = ObjectHandler::convert2<long>( ObjectHandler::ConvertOper(*Offset), "Offset", 1); // convert input datatypes to QuantLib datatypes QuantLib::Size OffsetLib = ObjectHandler::convert2<QuantLib::Size>( ObjectHandler::ConvertOper(*Offset), "Offset", 1); // convert object IDs into library objects OH_GET_UNDERLYING(EvolutionDescriptionLibObj, EvolutionDescription, QuantLibAddin::EvolutionDescription, QuantLib::EvolutionDescription) // invoke the utility function std::vector<QuantLib::Size> returnValue = QuantLib::moneyMarketPlusMeasure( EvolutionDescriptionLibObj, OffsetLib); // convert and return the return value std::vector<long> returnValVec = QuantLibAddin::convertVector<QuantLib::Size, long>(returnValue); static OPER xRet; ObjectHandler::vectorToOper(returnValVec, xRet); return &xRet; } catch (const std::exception &e) { ObjectHandler::RepositoryXL::instance().logError(e.what(), functionCall); return 0; } catch (...) { ObjectHandler::RepositoryXL::instance().logError("unkown error type", functionCall); return 0; } }
std::string CALCapFloor( const std::string &ObjectId, const std::string &OptionType, const std::string &LegID, const std::vector<double>& Strikes, const ObjectHandler::property_t &Permanent, const ObjectHandler::property_t &Trigger, const bool &Overwrite) { try { // convert input datatypes to C++ datatypes bool PermanentCpp = ObjectHandler::convert2<bool>( Permanent, "Permanent", false); // convert input datatypes to QuantLib enumerated datatypes QuantLib::CapFloor::Type OptionTypeEnum = ObjectHandler::Create<QuantLib::CapFloor::Type>()(OptionType); // convert object IDs into library objects OH_GET_UNDERLYING(LegIDLibObj, LegID, QuantLibAddin::Leg, QuantLib::Leg) // Construct the Value Object boost::shared_ptr<ObjectHandler::ValueObject> valueObject( new QuantLibAddin::ValueObjects::CALCapFloor( ObjectId, OptionType, LegID, Strikes, PermanentCpp)); // Construct the Object boost::shared_ptr<ObjectHandler::Object> object( new QuantLibAddin::CapFloor( valueObject, OptionTypeEnum, LegIDLibObj, Strikes, PermanentCpp)); // Store the Object in the Repository std::string returnValue = ObjectHandler::Repository::instance().storeObject(ObjectId, object, Overwrite); // Convert and return the return value return returnValue; } catch (const std::exception &e) { OH_FAIL("Error in function CALCapFloor : " << e.what()); } }
boost::shared_ptr<ObjectHandler::Object> create_qlFlatVol( const boost::shared_ptr<ObjectHandler::ValueObject> &valueObject) { // convert input datatypes to C++ datatypes std::vector<double> Volatilities = ObjectHandler::vector::convert2<double>(valueObject->getProperty("Volatilities"), "Volatilities"); std::string Correlations = ObjectHandler::convert2<std::string>(valueObject->getProperty("Correlations")); std::string EvolutionDescription = ObjectHandler::convert2<std::string>(valueObject->getProperty("EvolutionDescription")); long Factors = ObjectHandler::convert2<long>(valueObject->getProperty("Factors")); std::vector<double> InitialRates = ObjectHandler::vector::convert2<double>(valueObject->getProperty("InitialRates"), "InitialRates"); std::vector<double> Displacements = ObjectHandler::vector::convert2<double>(valueObject->getProperty("Displacements"), "Displacements"); bool Permanent = ObjectHandler::convert2<bool>(valueObject->getProperty("Permanent")); // convert object IDs into library objects OH_GET_REFERENCE(CorrelationsLibObjPtr, Correlations, QuantLibAddin::PiecewiseConstantCorrelation, QuantLib::PiecewiseConstantCorrelation) OH_GET_UNDERLYING(EvolutionDescriptionLibObj, EvolutionDescription, QuantLibAddin::EvolutionDescription, QuantLib::EvolutionDescription) // update value object precedent IDs (if any) valueObject->processPrecedentID(Correlations); valueObject->processPrecedentID(EvolutionDescription); // construct and return the object boost::shared_ptr<ObjectHandler::Object> object( new QuantLibAddin::FlatVol( valueObject, Volatilities, CorrelationsLibObjPtr, EvolutionDescriptionLibObj, Factors, InitialRates, Displacements, Permanent)); return object; }
XLL_DEC OPER *qlSMMDriftCalculatorCompute( char *ObjectId, char *CurveState, OPER *Trigger) { // declare a shared pointer to the Function Call object boost::shared_ptr<ObjectHandler::FunctionCall> functionCall; try { // instantiate the Function Call object functionCall = boost::shared_ptr<ObjectHandler::FunctionCall>( new ObjectHandler::FunctionCall("qlSMMDriftCalculatorCompute")); ObjectHandler::validateRange(Trigger, "Trigger"); // initialize the session ID (if enabled) SET_SESSION_ID // convert input datatypes to Object references OH_GET_OBJECT(ObjectIdObjPtr, ObjectId, QuantLibAddin::SMMDriftCalculator) // convert object IDs into library objects OH_GET_UNDERLYING(CurveStateLibObj, CurveState, QuantLibAddin::CoterminalSwapCurveState, QuantLib::CoterminalSwapCurveState) // invoke the member function std::vector<double> returnValue = ObjectIdObjPtr->compute( CurveStateLibObj); // convert and return the return value static OPER xRet; ObjectHandler::vectorToOper(returnValue, xRet); return &xRet; } catch (const std::exception &e) { ObjectHandler::RepositoryXL::instance().logError(e.what(), functionCall); return 0; } catch (...) { ObjectHandler::RepositoryXL::instance().logError("unkown error type", functionCall); return 0; } }
std::string qlEvolutionDescriptionFromProduct( const std::string &ObjectId, const std::string &Product, const ObjectHandler::property_t &Permanent, const ObjectHandler::property_t &Trigger, const bool &Overwrite) { try { // convert input datatypes to C++ datatypes bool PermanentCpp = ObjectHandler::convert2<bool>( Permanent, "Permanent", false); // convert object IDs into library objects OH_GET_UNDERLYING(ProductLibObj, Product, QuantLibAddin::MarketModelMultiProduct, QuantLib::MarketModelMultiProduct) // Construct the Value Object boost::shared_ptr<ObjectHandler::ValueObject> valueObject( new QuantLibAddin::ValueObjects::qlEvolutionDescriptionFromProduct( ObjectId, Product, PermanentCpp)); // Construct the Object boost::shared_ptr<ObjectHandler::Object> object( new QuantLibAddin::EvolutionDescription( valueObject, ProductLibObj, PermanentCpp)); // Store the Object in the Repository std::string returnValue = ObjectHandler::Repository::instance().storeObject(ObjectId, object, Overwrite, valueObject); // Convert and return the return value return returnValue; } catch (const std::exception &e) { OH_FAIL("Error in function qlEvolutionDescriptionFromProduct : " << e.what()); } }
boost::shared_ptr<ObjectHandler::Object> create_qlAccountingEngine( const boost::shared_ptr<ObjectHandler::ValueObject> &valueObject) { // convert input datatypes to C++ datatypes std::string MarketModelEvolver = ObjectHandler::convert2<std::string>(valueObject->getProperty("MarketModelEvolver")); std::string Product = ObjectHandler::convert2<std::string>(valueObject->getProperty("Product")); double InitialNumeraireValue = ObjectHandler::convert2<double>(valueObject->getProperty("InitialNumeraireValue")); bool Permanent = ObjectHandler::convert2<bool>(valueObject->getProperty("Permanent")); // convert object IDs into library objects OH_GET_REFERENCE(MarketModelEvolverLibObjPtr, MarketModelEvolver, QuantLibAddin::MarketModelEvolver, QuantLib::MarketModelEvolver) OH_GET_UNDERLYING(ProductLibObj, Product, QuantLibAddin::MarketModelMultiProduct, QuantLib::MarketModelMultiProduct) // update value object precedent IDs (if any) valueObject->processPrecedentID(MarketModelEvolver); valueObject->processPrecedentID(Product); // construct and return the object boost::shared_ptr<ObjectHandler::Object> object( new QuantLibAddin::AccountingEngine( valueObject, MarketModelEvolverLibObjPtr, ProductLibObj, InitialNumeraireValue, Permanent)); return object; }
/* Fonction de calcul du carry d'un bond */ DLLEXPORT xloper * xlInstrumentCarry (const char * instrumentId_, const double * startAccruedDate_, const double * endAccruedDate_, const double * instrumentYield_, const char * conventionId_, xloper * trigger_) { boost::shared_ptr<ObjectHandler::FunctionCall> functionCall( new ObjectHandler::FunctionCall("xlInstrumentCarry")) ; try { QL_ENSURE(! functionCall->calledByFunctionWizard(), "") ; double returnValue ; // trigger pour provoquer le recalcul ObjectHandler::validateRange(trigger_, "trigger") ; // on récupère la convention OH_GET_REFERENCE(conventionPtr, conventionId_, QuantLibAddin::interestRateConventionObject, QuantLib::InterestRate) // on récupère l'instrument OH_GET_UNDERLYING(myBond, instrumentId_, QuantLibAddin::Bond, QuantLib::Bond) returnValue = myBond.cleanPrice(* instrumentYield_, conventionPtr->dayCounter(), conventionPtr->compounding(), conventionPtr->frequency(), conventionPtr->businessDayConvention(), myBond.settlementDate( QuantLib::Date(static_cast<QuantLib::BigInteger>(* endAccruedDate_)))) ; returnValue -= myBond.cleanPrice(* instrumentYield_, conventionPtr->dayCounter(), conventionPtr->compounding(), conventionPtr->frequency(), conventionPtr->businessDayConvention(), myBond.settlementDate( QuantLib::Date(static_cast<QuantLib::BigInteger>(* startAccruedDate_)))) ; // variable de retour static XLOPER returnOper ; ObjectHandler::scalarToOper(returnValue, returnOper) ; return & returnOper ; } catch (std::exception & e) { ObjectHandler::RepositoryXL::instance().logError(e.what(), functionCall); static XLOPER returnOper; returnOper.xltype = xltypeErr; returnOper.val.err = xlerrValue; return & returnOper; } }
/* Fonction de calcul du nombre de flux restant */ DLLEXPORT xloper * xlInstrumentFlowCount (const char * instrumentId_, xloper * settlementDate_, xloper * trigger_) { boost::shared_ptr<ObjectHandler::FunctionCall> functionCall( new ObjectHandler::FunctionCall("xlInstrumentFlowCount")) ; try { QL_ENSURE(! functionCall->calledByFunctionWizard(), "") ; /* recherche de code erreur */ ObjectHandler::validateRange(trigger_, "trigger") ; ObjectHandler::validateRange(settlementDate_, "settlement Date") ; /* on récupère l'instrument */ OH_GET_UNDERLYING(myBond, instrumentId_, QuantLibAddin::Bond, QuantLib::Bond) /* les XLOPER des date */ ObjectHandler::ConvertOper myOper(* settlementDate_) ; QuantLib::Date settlementDate( myOper.missing() ? QuantLib::Date() : QuantLib::Date(static_cast<QuantLib::BigInteger>(myOper))) ; QuantLib::Natural returnValue = 0; // increments for (std::vector<boost::shared_ptr<QuantLib::CashFlow> >::const_reverse_iterator It = myBond.cashflows().crbegin(); It != myBond.cashflows().crend(); It++) It->get()->date() > settlementDate ? returnValue++ : 0; static XLOPER returnOper ; ObjectHandler::scalarToOper(static_cast<double>(returnValue), returnOper) ; return & returnOper ; } catch (std::exception & e) { #ifdef _DEBUG OutputDebugString(e.what()) ; #endif ObjectHandler::RepositoryXL::instance().logError(e.what(), functionCall) ; static XLOPER returnOper ; returnOper.xltype = xltypeErr ; returnOper.val.err = xlerrValue ; return & returnOper ; } } ;
std::string CALForwardRateIpc( const std::string &ObjectId, const std::string &MarketModel, const std::string &BrownianGeneratorFactory, const std::vector<long>& Numeraires, const ObjectHandler::property_t &Permanent, const ObjectHandler::property_t &Trigger, const bool &Overwrite) { try { // convert input datatypes to C++ datatypes bool PermanentCpp = ObjectHandler::convert2<bool>( Permanent, "Permanent", false); // convert input datatypes to QuantLib datatypes std::vector<QuantLib::Size> NumerairesLib = QuantLibAddin::convertVector<long, QuantLib::Size>(Numeraires); // convert object IDs into library objects OH_GET_REFERENCE(MarketModelLibObjPtr, MarketModel, QuantLibAddin::MarketModel, QuantLib::MarketModel) OH_GET_UNDERLYING(BrownianGeneratorFactoryLibObj, BrownianGeneratorFactory, QuantLibAddin::BrownianGeneratorFactory, QuantLib::BrownianGeneratorFactory) // Construct the Value Object boost::shared_ptr<ObjectHandler::ValueObject> valueObject( new QuantLibAddin::ValueObjects::CALForwardRateIpc( ObjectId, MarketModel, BrownianGeneratorFactory, Numeraires, PermanentCpp)); // Construct the Object boost::shared_ptr<ObjectHandler::Object> object( new QuantLibAddin::LogNormalFwdRateIpc( valueObject, MarketModelLibObjPtr, BrownianGeneratorFactoryLibObj, NumerairesLib, PermanentCpp)); // Store the Object in the Repository std::string returnValue = ObjectHandler::Repository::instance().storeObject(ObjectId, object, Overwrite); // Convert and return the return value return returnValue; } catch (const std::exception &e) { OH_FAIL("Error in function CALForwardRateIpc : " << e.what()); } }
XLL_DEC char *qlRangeAccrualFloatersCouponFromLeg( char *ObjectId, char *RangeAccrualLeg, long *Position, OPER *Permanent, OPER *Trigger, bool *Overwrite) { // declare a shared pointer to the Function Call object boost::shared_ptr<ObjectHandler::FunctionCall> functionCall; try { // instantiate the Function Call object functionCall = boost::shared_ptr<ObjectHandler::FunctionCall>( new ObjectHandler::FunctionCall("qlRangeAccrualFloatersCouponFromLeg")); ObjectHandler::validateRange(Trigger, "Trigger"); // initialize the session ID (if enabled) SET_SESSION_ID // convert input datatypes to C++ datatypes bool PermanentCpp = ObjectHandler::convert2<bool>( ObjectHandler::ConvertOper(*Permanent), "Permanent", false); // convert input datatypes to QuantLib datatypes QuantLib::Size PositionLib; QuantLibAddin::cppToLibrary(*Position, PositionLib); // convert object IDs into library objects OH_GET_UNDERLYING(RangeAccrualLegLibObj, RangeAccrualLeg, QuantLibAddin::Leg, QuantLib::Leg) // Strip the Excel cell update counter suffix from Object IDs std::string ObjectIdStrip = ObjectHandler::CallingRange::getStub(ObjectId); std::string RangeAccrualLegStrip = ObjectHandler::CallingRange::getStub(RangeAccrualLeg); // Construct the Value Object boost::shared_ptr<ObjectHandler::ValueObject> valueObject( new QuantLibAddin::ValueObjects::qlRangeAccrualFloatersCouponFromLeg( ObjectIdStrip, RangeAccrualLegStrip, *Position, PermanentCpp)); // Construct the Object boost::shared_ptr<ObjectHandler::Object> object( new QuantLibAddin::RangeAccrualFloatersCoupon( valueObject, RangeAccrualLegLibObj, PositionLib, PermanentCpp)); // Store the Object in the Repository std::string returnValue = ObjectHandler::RepositoryXL::instance().storeObject(ObjectIdStrip, object, *Overwrite, valueObject); // Convert and return the return value static char ret[XL_MAX_STR_LEN]; ObjectHandler::stringToChar(returnValue, ret); return ret; } catch (const std::exception &e) { ObjectHandler::RepositoryXL::instance().logError(e.what(), functionCall); return 0; } catch (...) { ObjectHandler::RepositoryXL::instance().logError("unkown error type", functionCall); return 0; } }
std::string qlBond( const std::string &ObjectId, const ObjectHandler::property_t &Description, const ObjectHandler::property_t &Currency, const ObjectHandler::property_t &SettlementDays, const ObjectHandler::property_t &Calendar, const ObjectHandler::property_t &FaceAmount, const ObjectHandler::property_t &MaturityDate, const ObjectHandler::property_t &IssueDate, const std::string &LegID, const ObjectHandler::property_t &Permanent, const ObjectHandler::property_t &Trigger, const bool &Overwrite) { try { // convert input datatypes to C++ datatypes std::string DescriptionCpp = ObjectHandler::convert2<std::string>( Description, "Description", std::string()); std::string CurrencyCpp = ObjectHandler::convert2<std::string>( Currency, "Currency", "NullCurrency"); long SettlementDaysCpp = ObjectHandler::convert2<long>( SettlementDays, "SettlementDays", 3); std::string CalendarCpp = ObjectHandler::convert2<std::string>( Calendar, "Calendar", "NullCalendar"); double FaceAmountCpp = ObjectHandler::convert2<double>( FaceAmount, "FaceAmount", 100.0); bool PermanentCpp = ObjectHandler::convert2<bool>( Permanent, "Permanent", false); // convert input datatypes to QuantLib datatypes QuantLib::Size SettlementDaysLib = ObjectHandler::convert2<QuantLib::Size>( SettlementDays, "SettlementDays", 3); QuantLib::Real FaceAmountLib = ObjectHandler::convert2<QuantLib::Real>( FaceAmount, "FaceAmount", 100.0); QuantLib::Date MaturityDateLib = ObjectHandler::convert2<QuantLib::Date>( MaturityDate, "MaturityDate", QuantLib::Date()); QuantLib::Date IssueDateLib = ObjectHandler::convert2<QuantLib::Date>( IssueDate, "IssueDate", QuantLib::Date()); // convert input datatypes to QuantLib enumerated datatypes QuantLib::Currency CurrencyEnum = ObjectHandler::Create<QuantLib::Currency>()(CurrencyCpp); QuantLib::Calendar CalendarEnum = ObjectHandler::Create<QuantLib::Calendar>()(CalendarCpp); // convert object IDs into library objects OH_GET_UNDERLYING(LegIDLibObj, LegID, QuantLibAddin::Leg, QuantLib::Leg) // Construct the Value Object boost::shared_ptr<ObjectHandler::ValueObject> valueObject( new QuantLibAddin::ValueObjects::qlBond( ObjectId, DescriptionCpp, CurrencyCpp, SettlementDaysCpp, CalendarCpp, FaceAmountCpp, MaturityDate, IssueDate, LegID, PermanentCpp)); // Construct the Object boost::shared_ptr<ObjectHandler::Object> object( new QuantLibAddin::Bond( valueObject, DescriptionCpp, CurrencyEnum, SettlementDaysLib, CalendarEnum, FaceAmountLib, MaturityDateLib, IssueDateLib, LegIDLibObj, PermanentCpp)); // Store the Object in the Repository std::string returnValue = ObjectHandler::Repository::instance().storeObject(ObjectId, object, Overwrite, valueObject); // Convert and return the return value return returnValue; } catch (const std::exception &e) { OH_FAIL("Error in function qlBond : " << e.what()); } }
SEQSEQ(ANY) SAL_CALL CalcAddins_impl::qlRangeAccrualFloatersCouponFromLeg( const ANY &ObjectId, const ANY &RangeAccrualLeg, const ANY &Position, const sal_Int32 Permanent, const ANY &Trigger, const sal_Int32 Overwrite) throw(RuntimeException) { try { // convert input datatypes to C++ datatypes std::string ObjectIdCpp; calcToScalar(ObjectIdCpp, ObjectId); std::string RangeAccrualLegCpp; calcToScalar(RangeAccrualLegCpp, RangeAccrualLeg); long PositionCpp; calcToScalar(PositionCpp, Position); bool PermanentCpp; calcToScalar(PermanentCpp, Permanent); // convert input datatypes to QuantLib datatypes QuantLib::Size PositionLib; calcToScalar(PositionLib, Position); // convert object IDs into library objects OH_GET_UNDERLYING(RangeAccrualLegLibObj, RangeAccrualLegCpp, QuantLibAddin::Leg, QuantLib::Leg) // Construct the Value Object boost::shared_ptr<ObjectHandler::ValueObject> valueObject( new QuantLibAddin::ValueObjects::qlRangeAccrualFloatersCouponFromLeg( ObjectIdCpp, RangeAccrualLegCpp, PositionCpp, PermanentCpp)); // Construct the Object boost::shared_ptr<ObjectHandler::Object> object( new QuantLibAddin::RangeAccrualFloatersCoupon( valueObject, RangeAccrualLegLibObj, PositionLib, PermanentCpp)); // Store the Object in the Repository std::string returnValue = ObjectHandler::Repository::instance().storeObject(ObjectIdCpp, object, Overwrite, valueObject); // Convert and return the return value ANY returnValueCalc; scalarToCalc(returnValueCalc, returnValue); SEQSEQ(ANY) retAnyArray; retAnyArray.realloc(1); SEQ(ANY) retAnyVector(1); retAnyVector[0] = returnValueCalc; retAnyArray[0] = retAnyVector; return retAnyArray; } catch (const std::exception &e) { do { std::ostringstream errorMsg; errorMsg << "ERROR: qlRangeAccrualFloatersCouponFromLeg: " << e.what(); OH_LOG_MESSAGE(errorMsg.str()); SEQSEQ(ANY) retAnyArray; retAnyArray.realloc(1); SEQ(ANY) retAnyVector(1); STRING s = STRFROMASCII( errorMsg.str().c_str() ); retAnyVector[0] = CSS::uno::makeAny( s ); retAnyArray[0] = retAnyVector; return retAnyArray; } while (false); } }