// Test that uniform_int<> can be used with std::random_shuffle // Author: Jos Hickson void test_random_shuffle() { typedef boost::uniform_int<> distribution_type; typedef boost::variate_generator<boost::mt19937 &, distribution_type> generator_type; boost::mt19937 engine1(1234); boost::mt19937 engine2(1234); rand_for_random_shuffle<boost::mt19937> referenceRand(engine1); distribution_type dist(0,10); generator_type testRand(engine2, dist); std::vector<int> referenceVec; for (int i = 0; i < 200; ++i) { referenceVec.push_back(i); } std::vector<int> testVec(referenceVec); std::random_shuffle(referenceVec.begin(), referenceVec.end(), referenceRand); std::random_shuffle(testVec.begin(), testVec.end(), testRand); typedef std::vector<int>::iterator iter_type; iter_type theEnd(referenceVec.end()); for (iter_type referenceIter(referenceVec.begin()), testIter(testVec.begin()); referenceIter != theEnd; ++referenceIter, ++testIter) { BOOST_CHECK_EQUAL(*referenceIter, *testIter); } }
int main() { boost::mt19937 engine1(1234); boost::mt19937 engine2(1234); boost::uniform_int<> dist(100,200); for (int i=0; i<20; i++) { std::cout << dist(engine1) << " is equal to " << dist(engine2) << std::endl; } }
double caplet_lmm(const Date& todaysDate_, const Date& settlementDate_, const Date& maturity_, Rate spot_, Rate strike, Rate Numeraire, //zero-coupon bond //Volatility volatility double correl, double a, double b, double c, double d ) { //SavedSettings backup; const Size size = 10; #if defined(QL_USE_INDEXED_COUPON) const Real tolerance = 1e-5; #else const Real tolerance = 1e-12; #endif boost::shared_ptr<IborIndex> index = makeIndex(); boost::shared_ptr<LiborForwardModelProcess> process(new LiborForwardModelProcess(size, index)); // set-up pricing engine const boost::shared_ptr<OptionletVolatilityStructure> capVolCurve = makeCapVolCurve(Settings::instance().evaluationDate()); Array variances = LfmHullWhiteParameterization(process, capVolCurve).covariance(0.0).diagonal(); boost::shared_ptr<LmVolatilityModel> volaModel(new LmFixedVolatilityModel(Sqrt(variances),process->fixingTimes())); boost::shared_ptr<LmCorrelationModel> corrModel(new LmExponentialCorrelationModel(size, correl)); boost::shared_ptr<AffineModel> model(new LiborForwardModel(process, volaModel, corrModel)); const Handle<YieldTermStructure> termStructure = process->index()->forwardingTermStructure(); boost::shared_ptr<AnalyticCapFloorEngine> engine1(new AnalyticCapFloorEngine(model, termStructure)); boost::shared_ptr<Cap> cap1(new Cap(process->cashFlows(),std::vector<Rate>(size, strike))); cap1->setPricingEngine(engine1); return cap1->NPV(); }