////////////////////////////////////////////////////////////////////////////////////////// // Fonction que vous allez modifier afin de dessiner ///////////////////////////////////////////////////////////////////////////////////////// void render_scene() { //Définition de la couleur glColor3f(1.0, 1.0, 1.0); // Nous créons ici un polygone. Nous pourrions aussi créer un triangle ou des lignes. Voir ci-dessous les parties // en commentaires (il faut commenter le bloc qui ne vous intéresse pas et décommenter celui que vous voulez tester. // Création de deux lignes /* glBegin(GL_LINES); glVertex3f(-1, -1, 0); glVertex3f(1, 1, 0); glVertex3f(1, -1, 0); glVertex3f(-1, 1, 0); glEnd();*/ // création d'un polygone /*glBegin(GL_POLYGON); glVertex3f(-1, -1, 0); glVertex3f(1, -1, 0); glVertex3f(1, 1, 0); glVertex3f(-1, 1, 0); glEnd();*/ //glutSolidCube(2); /* // création d'un triangle glBegin(GL_TRIANGLES); glVertex3f(-1, -1, 0); glVertex3f(1, -1, 0); glVertex3f(1, 1, 0); glEnd(); */ /* Point A(-3.0, -3.0, 0.0); Point B(3.0, 3.0, 0.0); Point C(-3.0, 3.0, 0.0); Point Cp = C.ProjectOnLine(A, B); glPointSize (5.0); glBegin(GL_POINTS); myGlVertex(A); myGlVertex(B); glEnd(); glBegin(GL_LINES); myGlVertex(A); myGlVertex(B); glEnd(); glBegin(GL_POINTS); myGlVertex(C); glEnd(); glBegin(GL_POINTS); myGlVertex(Cp); glEnd(); */ Point A(-0.0, -0.0, 0.0); Point B(2.0, 0.0, 0.0); Vector v1(1.0, 1.0, 0.0); Vector v2(1.0, -1.0, 0.0); glPointSize (4.0); glBegin(GL_POINTS); myGlVertex(A); myGlVertex(B); glEnd(); displayLine(A, v1); displayLine(B, v2); Hermite myCurve(A, v1, B, v2); Point curve[10]; myCurve.HermiteCubicCurve(curve ,10); drawCurve(curve, 10); }
// register an interpolated curve object DLLEXPORT char * xlInitiateInterpolatedCurve(const char * objectID_ , xloper * calculationDate_, const char * curveCalendarId_, xloper * helperId_ , xloper * trigger_ ) { boost::shared_ptr<ObjectHandler::FunctionCall> functionCall( new ObjectHandler::FunctionCall("xlInitiateInterpolatedCurve")) ; try { QL_ENSURE(! functionCall->calledByFunctionWizard(), "") ; // range validation ObjectHandler::validateRange(trigger_ , "trigger" ); ObjectHandler::validateRange(helperId_ , "helper Id" ); ObjectHandler::validateRange(calculationDate_, "calculation Date"); ObjectHandler::ConvertOper myOper1(* calculationDate_) ; // xlopers std::vector<std::string> helperId = ObjectHandler::operToVector<std::string>( * helperId_, "helper Id") ; QuantLib::Date currentDate( // initiate pricing date myOper1.missing() ? QuantLib::Date() : QuantLib::Date(static_cast<QuantLib::BigInteger>(myOper1))); std::vector<boost::shared_ptr<QuantLib::BootstrapHelper< // the helpers QuantLib::YieldTermStructure> > > helpers; for (std::vector<std::string>::const_iterator It = helperId.begin(); It != helperId.end(); ++It) { OH_GET_REFERENCE(helperPtr, * It, // get helper references QuantLibAddin::RateHelper, QuantLib::RateHelper); helpers.push_back(helperPtr); } // Construction du value object boost::shared_ptr<QuantLibAddin::ValueObjects::interpolatedCurveValueObject> curveValueObject( new QuantLibAddin::ValueObjects::interpolatedCurveValueObject( objectID_, currentDate.serialNumber(), true)) ; // creates the curve boost::shared_ptr<ObjectHandler::Object> myCurve( new QuantLibAddin::interpolatedCurveObject( curveValueObject, currentDate, helpers, true, std::vector<QuantLib::Handle<QuantLib::Quote> >(), // empty jump date std::vector<QuantLib::Date>(), CURVE_DEFAULT_ACCURACY)); // object storage std::string returnValue = ObjectHandler::RepositoryXL::instance().storeObject(objectID_, myCurve, true); static char ret[XL_MAX_STR_LEN] ; ObjectHandler::stringToChar(returnValue, ret); return ret; } catch (std::exception & e) { static char ret[XL_MAX_STR_LEN]; ObjectHandler::RepositoryXL::instance().logError(e.what(), functionCall); ObjectHandler::stringToChar(e.what(), ret); return ret; } } ;
// parametric fitted curve DLLEXPORT char * xlInitiateFittedBondDiscountCurve (const char * objectID_ , const xloper * evaluationDate_ , const xloper * settlementDate_ , const xloper * instruments_ , const xloper * quote_ , const char * calendarID_ , const char * fittingMethodID_ , const xloper * bondSelectionRule_, const xloper * trigger_) { boost::shared_ptr<ObjectHandler::FunctionCall> functionCall( new ObjectHandler::FunctionCall("xlInitiateFittedBondDiscountCurve")); try { QL_ENSURE(! functionCall->calledByFunctionWizard(), ""); // called by wizard ? ObjectHandler::validateRange(trigger_, "trigger" ); // validate range ObjectHandler::validateRange(settlementDate_, "settlement Date" ); ObjectHandler::validateRange(instruments_, "instruments" ); ObjectHandler::validateRange(quote_, "quotes" ); ObjectHandler::validateRange(bondSelectionRule_, "bond selection rule"); ObjectHandler::ConvertOper myOper1(* bondSelectionRule_); // bond selection rule oper QuantLib::bondSelectionRule myRule = // the rule (myOper1.missing() ? QuantLib::activeRule() : ObjectHandler::bondSelectionRuleFactory()( static_cast<std::string>(myOper1))); QuantLib::Calendar curveCalendar // calendar = ObjectHandler::calendarFactory()(calendarID_); ObjectHandler::ConvertOper oper1(* evaluationDate_); // evaluation date QuantLib::Date evaluationDate(oper1.missing() ? QuantLib::Date() : static_cast<QuantLib::Date>(oper1)); std::vector<std::string> instruments = // instrument ids ObjectHandler::operToVector<std::string>( * instruments_, "instruments"); std::vector<QuantLib::Real> quote = // quotes ObjectHandler::operToVector<double>( * quote_, "quote"); std::vector<boost::shared_ptr<QuantLib::BondHelper> > instrumentsObject; // helpers for (unsigned int i = 0 ; i < instruments.size() ; i++) { // capture individual bonds try { OH_GET_REFERENCE(instrumentPtr, // get a reference instruments[i], QuantLibAddin::Bond, QuantLib::Bond) if (quote[i] != 0.0 && instrumentPtr->isTradable()) { // valid quote ? QuantLib::RelinkableHandle<QuantLib::Quote> quoteHandle; // the handler quoteHandle.linkTo(boost::shared_ptr<QuantLib::Quote>( // link to the quote new QuantLib::SimpleQuote(quote[i]))); boost::shared_ptr<QuantLib::BondHelper> noteHelper( // the helper new QuantLib::BondHelper(quoteHandle, instrumentPtr)); instrumentsObject.push_back(noteHelper); // helper storage } } catch (...) {} // nothing on exception } ObjectHandler::ConvertOper oper2(* settlementDate_); // settlement date QuantLib::Date settlementDate(oper2.missing() ? instrumentsObject[0]->bond()->settlementDate(evaluationDate) : static_cast<QuantLib::Date>(oper2)); OH_GET_OBJECT(fittingMethodTemp, // fitting method selection fittingMethodID_, ObjectHandler::Object) std::string returnValue; if (fittingMethodTemp->properties()->className() // svensson ? == "stochasticFittingValueObject") { OH_GET_REFERENCE(fittingMethodPtr, fittingMethodID_, QuantLibAddin::stochasticFittingObject, QuantLib::stochasticFittingHelper) // build the value object boost::shared_ptr<QuantLibAddin::ValueObjects::fittedBondDiscountCurveValueObject> curveValueObject( new QuantLibAddin::ValueObjects::fittedBondDiscountCurveValueObject( objectID_, settlementDate.serialNumber(), true)); boost::shared_ptr<ObjectHandler::Object> myCurve( // instanciating the curve new QuantLibAddin::fittedBondDiscountCurveObject( curveValueObject, settlementDate, myRule.select(instrumentsObject, settlementDate), * fittingMethodPtr->fittingMethod(), fittingMethodPtr->initialVector(), fittingMethodPtr->randomMatrix(), fittingMethodPtr->accuracy(), fittingMethodPtr->maxEvaluationPercycle(), fittingMethodPtr->cyclesPerThread(), fittingMethodPtr->cycles(), 1.000, // simplex lambda true)) ; returnValue = // the value to return ObjectHandler::RepositoryXL::instance().storeObject(objectID_, myCurve , true ); } static char ret[XL_MAX_STR_LEN]; ObjectHandler::stringToChar(returnValue, ret); return ret; } catch (std::exception & e) { static char ret[XL_MAX_STR_LEN]; ObjectHandler::RepositoryXL::instance().logError(e.what(), functionCall); ObjectHandler::stringToChar(std::string(e.what()), ret); return ret; } };