~ubuntu-branches/ubuntu/vivid/quantlib-swig/vivid

« back to all changes in this revision

Viewing changes to SWIG/options.i

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2007-12-26 08:10:08 UTC
  • mfrom: (1.1.6 upstream) (2.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20071226081008-cjq979mvtxydli4r
New upstream release 0.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
  public:
111
111
    %extend {
112
112
        VanillaOptionPtr(
113
 
                const boost::shared_ptr<StochasticProcess>& process,
114
113
                const boost::shared_ptr<Payoff>& payoff,
115
 
                const boost::shared_ptr<Exercise>& exercise,
116
 
                const boost::shared_ptr<PricingEngine>& engine
117
 
                   = boost::shared_ptr<PricingEngine>()) {
 
114
                const boost::shared_ptr<Exercise>& exercise) {
118
115
            boost::shared_ptr<StrikedTypePayoff> stPayoff =
119
116
                 boost::dynamic_pointer_cast<StrikedTypePayoff>(payoff);
120
117
            QL_REQUIRE(stPayoff, "wrong payoff given");
121
 
            return new VanillaOptionPtr(
122
 
                         new VanillaOption(process,stPayoff,exercise,engine));
 
118
            return new VanillaOptionPtr(new VanillaOption(stPayoff,exercise));
123
119
        }
124
120
        Real delta() {
125
121
            return boost::dynamic_pointer_cast<VanillaOption>(*self)->delta();
152
148
            return boost::dynamic_pointer_cast<VanillaOption>(*self)
153
149
                ->result<SampledCurve>("priceCurve");
154
150
        }
155
 
        Volatility impliedVolatility(Real targetValue,
156
 
                                     Real accuracy = 1.0e-4,
157
 
                                     Size maxEvaluations = 100,
158
 
                                     Volatility minVol = 1.0e-4,
159
 
                                     Volatility maxVol = 4.0) {
 
151
        Volatility impliedVolatility(
 
152
                             Real targetValue,
 
153
                             const GeneralizedBlackScholesProcessPtr& process,
 
154
                             Real accuracy = 1.0e-4,
 
155
                             Size maxEvaluations = 100,
 
156
                             Volatility minVol = 1.0e-4,
 
157
                             Volatility maxVol = 4.0) {
 
158
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
159
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
160
                                                                     process);
 
161
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
160
162
            return boost::dynamic_pointer_cast<VanillaOption>(*self)
161
 
                 ->impliedVolatility(targetValue,accuracy,maxEvaluations,
162
 
                                     minVol,maxVol);
 
163
                ->impliedVolatility(targetValue, bsProcess, accuracy,
 
164
                                    maxEvaluations, minVol, maxVol);
163
165
        }
164
166
    }
165
167
};
176
178
  public:
177
179
    %extend {
178
180
        EuropeanOptionPtr(
179
 
                const boost::shared_ptr<StochasticProcess>& process,
180
181
                const boost::shared_ptr<Payoff>& payoff,
181
 
                const boost::shared_ptr<Exercise>& exercise,
182
 
                const boost::shared_ptr<PricingEngine>& engine
183
 
                   = boost::shared_ptr<PricingEngine>()) {
 
182
                const boost::shared_ptr<Exercise>& exercise) {
184
183
            boost::shared_ptr<StrikedTypePayoff> stPayoff =
185
184
                 boost::dynamic_pointer_cast<StrikedTypePayoff>(payoff);
186
185
            QL_REQUIRE(stPayoff, "wrong payoff given");
187
 
            return new EuropeanOptionPtr(
188
 
                        new EuropeanOption(process,stPayoff,exercise,engine));
 
186
            return new EuropeanOptionPtr(new EuropeanOption(stPayoff,exercise));
189
187
        }
190
188
    }
191
189
};
204
202
        ForwardVanillaOptionPtr(
205
203
                Real moneyness,
206
204
                Date resetDate,
207
 
                const boost::shared_ptr<StochasticProcess>& process,
208
205
                const boost::shared_ptr<Payoff>& payoff,
209
 
                const boost::shared_ptr<Exercise>& exercise,
210
 
                const boost::shared_ptr<PricingEngine>& engine
211
 
                                       = boost::shared_ptr<PricingEngine>()) {
 
206
                const boost::shared_ptr<Exercise>& exercise) {
212
207
            boost::shared_ptr<StrikedTypePayoff> stPayoff =
213
208
                 boost::dynamic_pointer_cast<StrikedTypePayoff>(payoff);
214
209
            QL_REQUIRE(stPayoff, "wrong payoff given");
215
210
            return new ForwardVanillaOptionPtr(
216
 
                       new ForwardVanillaOption(moneyness, resetDate, process,
217
 
                                                stPayoff, exercise, engine));
 
211
                                new ForwardVanillaOption(moneyness, resetDate,
 
212
                                                         stPayoff, exercise));
218
213
        }
219
214
    }
220
215
};
231
226
  public:
232
227
    %extend {
233
228
        QuantoVanillaOptionPtr(
234
 
                const Handle<YieldTermStructure>& foreignRiskFreeTS,
235
 
                const Handle<BlackVolTermStructure>& exchRateVolTS,
236
 
                const Handle<Quote>& correlation,
237
 
                const boost::shared_ptr<StochasticProcess>& process,
238
229
                const boost::shared_ptr<Payoff>& payoff,
239
 
                const boost::shared_ptr<Exercise>& exercise,
240
 
                const boost::shared_ptr<PricingEngine>& engine
241
 
                                       = boost::shared_ptr<PricingEngine>()) {
 
230
                const boost::shared_ptr<Exercise>& exercise) {
242
231
            boost::shared_ptr<StrikedTypePayoff> stPayoff =
243
232
                 boost::dynamic_pointer_cast<StrikedTypePayoff>(payoff);
244
233
            QL_REQUIRE(stPayoff, "wrong payoff given");
245
234
            return new QuantoVanillaOptionPtr(
246
 
                                    new QuantoVanillaOption(foreignRiskFreeTS,
247
 
                                                            exchRateVolTS,
248
 
                                                            correlation,
249
 
                                                            process,
250
 
                                                            stPayoff,
251
 
                                                            exercise,
252
 
                                                            engine));
 
235
                                 new QuantoVanillaOption(stPayoff, exercise));
253
236
        }
254
237
        Real qvega() {
255
238
            return boost::dynamic_pointer_cast<QuantoVanillaOption>(*self)
276
259
  public:
277
260
    %extend {
278
261
        QuantoForwardVanillaOptionPtr(
279
 
                const Handle<YieldTermStructure>& foreignRiskFreeTS,
280
 
                const Handle<BlackVolTermStructure>& exchRateVolTS,
281
 
                const Handle<Quote>& correlation,
282
262
                Real moneyness,
283
263
                Date resetDate,
284
 
                const boost::shared_ptr<StochasticProcess>& process,
285
264
                const boost::shared_ptr<Payoff>& payoff,
286
 
                const boost::shared_ptr<Exercise>& exercise,
287
 
                const boost::shared_ptr<PricingEngine>& engine
288
 
                                       = boost::shared_ptr<PricingEngine>()) {
 
265
                const boost::shared_ptr<Exercise>& exercise) {
289
266
            boost::shared_ptr<StrikedTypePayoff> stPayoff =
290
267
                 boost::dynamic_pointer_cast<StrikedTypePayoff>(payoff);
291
268
            QL_REQUIRE(stPayoff, "wrong payoff given");
292
269
            return new QuantoForwardVanillaOptionPtr(
293
 
                             new QuantoForwardVanillaOption(foreignRiskFreeTS,
294
 
                                                            exchRateVolTS,
295
 
                                                            correlation,
296
 
                                                            moneyness,
297
 
                                                            resetDate,
298
 
                                                            process,
299
 
                                                            stPayoff,
300
 
                                                            exercise,
301
 
                                                            engine));
 
270
                          new QuantoForwardVanillaOption(moneyness, resetDate,
 
271
                                                         stPayoff, exercise));
302
272
        }
303
273
    }
304
274
};
346
316
class AnalyticEuropeanEnginePtr : public boost::shared_ptr<PricingEngine> {
347
317
  public:
348
318
    %extend {
349
 
        AnalyticEuropeanEnginePtr() {
350
 
            return new AnalyticEuropeanEnginePtr(new AnalyticEuropeanEngine);
 
319
        AnalyticEuropeanEnginePtr(
 
320
                           const GeneralizedBlackScholesProcessPtr& process) {
 
321
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
322
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
323
                                                                     process);
 
324
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
 
325
            return new AnalyticEuropeanEnginePtr(
 
326
                                       new AnalyticEuropeanEngine(bsProcess));
351
327
        }
352
328
    }
353
329
};
362
338
class IntegralEnginePtr : public boost::shared_ptr<PricingEngine> {
363
339
  public:
364
340
    %extend {
365
 
        IntegralEnginePtr() {
366
 
            return new IntegralEnginePtr(new IntegralEngine);
367
 
        }
368
 
    }
369
 
};
370
 
 
 
341
        IntegralEnginePtr(const GeneralizedBlackScholesProcessPtr& process) {
 
342
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
343
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
344
                                                                     process);
 
345
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
 
346
            return new IntegralEnginePtr(new IntegralEngine(bsProcess));
 
347
        }
 
348
    }
 
349
};
 
350
 
 
351
 
 
352
%{
 
353
using QuantLib::FDBermudanEngine;
 
354
typedef boost::shared_ptr<PricingEngine> FDBermudanEnginePtr;
 
355
%}
 
356
 
 
357
%rename(FDBermudanEngine) FDBermudanEnginePtr;
 
358
class FDBermudanEnginePtr : public boost::shared_ptr<PricingEngine> {
 
359
  public:
 
360
    %extend {
 
361
        FDBermudanEnginePtr(const GeneralizedBlackScholesProcessPtr& process,
 
362
                            Size timeSteps = 100, Size gridPoints = 100,
 
363
                            bool timeDependent = false) {
 
364
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
365
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
366
                                                                     process);
 
367
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
 
368
            return new FDBermudanEnginePtr(
 
369
                              new FDBermudanEngine(bsProcess,timeSteps,
 
370
                                                   gridPoints,timeDependent));
 
371
        }
 
372
    }
 
373
};
371
374
 
372
375
%{
373
376
using QuantLib::FDEuropeanEngine;
378
381
class FDEuropeanEnginePtr : public boost::shared_ptr<PricingEngine> {
379
382
  public:
380
383
    %extend {
381
 
        FDEuropeanEnginePtr(Size timeSteps = 100, Size gridPoints = 100,
 
384
        FDEuropeanEnginePtr(const GeneralizedBlackScholesProcessPtr& process,
 
385
                            Size timeSteps = 100, Size gridPoints = 100,
382
386
                            bool timeDependent = false) {
 
387
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
388
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
389
                                                                     process);
 
390
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
383
391
            return new FDEuropeanEnginePtr(
384
 
                    new FDEuropeanEngine(timeSteps,gridPoints,timeDependent));
 
392
                              new FDEuropeanEngine(bsProcess,timeSteps,
 
393
                                                   gridPoints,timeDependent));
385
394
        }
386
395
    }
387
396
};
394
403
using QuantLib::Trigeorgis;
395
404
using QuantLib::Tian;
396
405
using QuantLib::LeisenReimer;
 
406
using QuantLib::Joshi4;
397
407
typedef boost::shared_ptr<PricingEngine> BinomialVanillaEnginePtr;
398
408
%}
399
409
 
401
411
class BinomialVanillaEnginePtr : public boost::shared_ptr<PricingEngine> {
402
412
  public:
403
413
    %extend {
404
 
        BinomialVanillaEnginePtr(const std::string& type,
405
 
                                 Size steps) {
406
 
//            std::string s = QuantLib::lowercase(type);
407
 
        std::string s = type;
 
414
        BinomialVanillaEnginePtr(
 
415
                             const GeneralizedBlackScholesProcessPtr& process,
 
416
                             const std::string& type,
 
417
                             Size steps) {
 
418
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
419
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
420
                                                                     process);
 
421
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
 
422
            std::string s = boost::algorithm::to_lower_copy(type);
408
423
            if (s == "crr" || s == "coxrossrubinstein")
409
424
                return new BinomialVanillaEnginePtr(
410
 
                    new BinomialVanillaEngine<CoxRossRubinstein>(steps));
 
425
                    new BinomialVanillaEngine<CoxRossRubinstein>(
 
426
                                                            bsProcess,steps));
411
427
            else if (s == "jr" || s == "jarrowrudd")
412
428
                return new BinomialVanillaEnginePtr(
413
 
                    new BinomialVanillaEngine<JarrowRudd>(steps));
414
 
            else if (s == "eqp")
 
429
                    new BinomialVanillaEngine<JarrowRudd>(bsProcess,steps));
 
430
            else if (s == "eqp" || s == "additiveeqpbinomialtree")
415
431
                return new BinomialVanillaEnginePtr(
416
 
                    new BinomialVanillaEngine<AdditiveEQPBinomialTree>(steps));
 
432
                    new BinomialVanillaEngine<AdditiveEQPBinomialTree>(
 
433
                                                            bsProcess,steps));
417
434
            else if (s == "trigeorgis")
418
435
                return new BinomialVanillaEnginePtr(
419
 
                    new BinomialVanillaEngine<Trigeorgis>(steps));
 
436
                    new BinomialVanillaEngine<Trigeorgis>(bsProcess,steps));
420
437
            else if (s == "tian")
421
438
                return new BinomialVanillaEnginePtr(
422
 
                    new BinomialVanillaEngine<Tian>(steps));
 
439
                    new BinomialVanillaEngine<Tian>(bsProcess,steps));
423
440
            else if (s == "lr" || s == "leisenreimer")
424
441
                return new BinomialVanillaEnginePtr(
425
 
                    new BinomialVanillaEngine<LeisenReimer>(steps));
 
442
                    new BinomialVanillaEngine<LeisenReimer>(bsProcess,steps));
 
443
            else if (s == "j4" || s == "joshi4")
 
444
                return new BinomialVanillaEnginePtr(
 
445
                    new BinomialVanillaEngine<Joshi4>(bsProcess,steps));
426
446
            else
427
447
                QL_FAIL("unknown binomial engine type: "+s);
428
448
        }
442
462
    %feature("kwargs") MCEuropeanEnginePtr;
443
463
  public:
444
464
    %extend {
445
 
        MCEuropeanEnginePtr(const std::string& traits,
 
465
        MCEuropeanEnginePtr(const GeneralizedBlackScholesProcessPtr& process,
 
466
                            const std::string& traits,
446
467
                            intOrNull timeSteps = Null<Size>(),
447
468
                            intOrNull timeStepsPerYear = Null<Size>(),
448
469
                            bool brownianBridge = false,
452
473
                            doubleOrNull requiredTolerance = Null<Real>(),
453
474
                            intOrNull maxSamples = Null<Size>(),
454
475
                            BigInteger seed = 0) {
455
 
//            std::string s = QuantLib::lowercase(traits);
456
 
        std::string s = traits;
 
476
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
477
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
478
                                                                     process);
 
479
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
 
480
            std::string s = boost::algorithm::to_lower_copy(traits);
457
481
            QL_REQUIRE(Size(timeSteps) != Null<Size>() ||
458
482
                       Size(timeStepsPerYear) != Null<Size>(),
459
483
                       "number of steps not specified");
460
484
            if (s == "pseudorandom" || s == "pr")
461
485
                return new MCEuropeanEnginePtr(
462
 
                         new MCEuropeanEngine<PseudoRandom>(timeSteps,
 
486
                         new MCEuropeanEngine<PseudoRandom>(bsProcess,
 
487
                                                            timeSteps,
463
488
                                                            timeStepsPerYear,
464
489
                                                            brownianBridge,
465
490
                                                            antitheticVariate,
470
495
                                                            seed));
471
496
            else if (s == "lowdiscrepancy" || s == "ld")
472
497
                return new MCEuropeanEnginePtr(
473
 
                       new MCEuropeanEngine<LowDiscrepancy>(timeSteps,
 
498
                       new MCEuropeanEngine<LowDiscrepancy>(bsProcess,
 
499
                                                            timeSteps,
474
500
                                                            timeStepsPerYear,
475
501
                                                            brownianBridge,
476
502
                                                            antitheticVariate,
499
525
class FDAmericanEnginePtr : public boost::shared_ptr<PricingEngine> {
500
526
  public:
501
527
    %extend {
502
 
        FDAmericanEnginePtr(Size timeSteps = 100, Size gridPoints = 100,
 
528
        FDAmericanEnginePtr(const GeneralizedBlackScholesProcessPtr& process,
 
529
                            Size timeSteps = 100, Size gridPoints = 100,
503
530
                            bool timeDependent = false) {
 
531
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
532
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
533
                                                                     process);
 
534
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
504
535
            return new FDAmericanEnginePtr(
505
 
                    new FDAmericanEngine(timeSteps,gridPoints,timeDependent));
 
536
                              new FDAmericanEngine(bsProcess,timeSteps,
 
537
                                                   gridPoints,timeDependent));
506
538
        }
507
539
    }
508
540
};
511
543
class FDShoutEnginePtr : public boost::shared_ptr<PricingEngine> {
512
544
  public:
513
545
    %extend {
514
 
        FDShoutEnginePtr(Size timeSteps = 100, Size gridPoints = 100,
 
546
        FDShoutEnginePtr(const GeneralizedBlackScholesProcessPtr& process,
 
547
                         Size timeSteps = 100, Size gridPoints = 100,
515
548
                         bool timeDependent = false) {
 
549
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
550
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
551
                                                                     process);
 
552
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
516
553
            return new FDShoutEnginePtr(
517
 
                       new FDShoutEngine(timeSteps,gridPoints,timeDependent));
 
554
                                 new FDShoutEngine(bsProcess,timeSteps,
 
555
                                                   gridPoints,timeDependent));
518
556
        }
519
557
    }
520
558
};
531
569
    : public boost::shared_ptr<PricingEngine> {
532
570
  public:
533
571
    %extend {
534
 
        BaroneAdesiWhaleyApproximationEnginePtr() {
 
572
        BaroneAdesiWhaleyApproximationEnginePtr(
 
573
                           const GeneralizedBlackScholesProcessPtr& process) {
 
574
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
575
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
576
                                                                     process);
 
577
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
535
578
            return new BaroneAdesiWhaleyApproximationEnginePtr(
536
 
                new BaroneAdesiWhaleyApproximationEngine);
 
579
                         new BaroneAdesiWhaleyApproximationEngine(bsProcess));
537
580
        }
538
581
    }
539
582
};
550
593
    : public boost::shared_ptr<PricingEngine> {
551
594
  public:
552
595
    %extend {
553
 
        BjerksundStenslandApproximationEnginePtr() {
 
596
        BjerksundStenslandApproximationEnginePtr(
 
597
                           const GeneralizedBlackScholesProcessPtr& process) {
 
598
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
599
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
600
                                                                     process);
 
601
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
554
602
            return new BjerksundStenslandApproximationEnginePtr(
555
 
                new BjerksundStenslandApproximationEngine);
 
603
                        new BjerksundStenslandApproximationEngine(bsProcess));
556
604
        }
557
605
    }
558
606
};
567
615
    : public boost::shared_ptr<PricingEngine> {
568
616
  public:
569
617
    %extend {
570
 
        AnalyticDigitalAmericanEnginePtr() {
 
618
        AnalyticDigitalAmericanEnginePtr(
 
619
                           const GeneralizedBlackScholesProcessPtr& process) {
 
620
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
621
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
622
                                                                     process);
 
623
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
571
624
            return new AnalyticDigitalAmericanEnginePtr(
572
 
                new AnalyticDigitalAmericanEngine);
 
625
                                new AnalyticDigitalAmericanEngine(bsProcess));
573
626
        }
574
627
    }
575
628
};
592
645
  public:
593
646
    %extend {
594
647
        DividendVanillaOptionPtr(
595
 
                const boost::shared_ptr<StochasticProcess>& process,
596
648
                const boost::shared_ptr<Payoff>& payoff,
597
649
                const boost::shared_ptr<Exercise>& exercise,
598
650
                const std::vector<Date>& dividendDates,
599
 
                const std::vector<Real>& dividends,
600
 
                const boost::shared_ptr<PricingEngine>& engine
601
 
                   = boost::shared_ptr<PricingEngine>()) {
 
651
                const std::vector<Real>& dividends) {
602
652
            boost::shared_ptr<StrikedTypePayoff> stPayoff =
603
653
                 boost::dynamic_pointer_cast<StrikedTypePayoff>(payoff);
604
654
            QL_REQUIRE(stPayoff, "wrong payoff given");
605
655
            return new DividendVanillaOptionPtr(
606
 
                   new DividendVanillaOption(process,stPayoff,exercise,
607
 
                                             dividendDates,dividends,engine));
 
656
                          new DividendVanillaOption(stPayoff,exercise,
 
657
                                                    dividendDates,dividends));
608
658
        }
609
659
        Real delta() {
610
660
            return boost::dynamic_pointer_cast<DividendVanillaOption>(*self)
638
688
            return boost::dynamic_pointer_cast<DividendVanillaOption>(*self)
639
689
                ->result<SampledCurve>("priceCurve");
640
690
        }
641
 
        Volatility impliedVolatility(Real targetValue,
642
 
                                     Real accuracy = 1.0e-4,
643
 
                                     Size maxEvaluations = 100,
644
 
                                     Volatility minVol = 1.0e-4,
645
 
                                     Volatility maxVol = 4.0) {
 
691
        Volatility impliedVolatility(
 
692
                             Real targetValue,
 
693
                             const GeneralizedBlackScholesProcessPtr& process,
 
694
                             Real accuracy = 1.0e-4,
 
695
                             Size maxEvaluations = 100,
 
696
                             Volatility minVol = 1.0e-4,
 
697
                             Volatility maxVol = 4.0) {
 
698
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
699
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
700
                                                                     process);
 
701
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
646
702
            return boost::dynamic_pointer_cast<DividendVanillaOption>(*self)
647
 
                 ->impliedVolatility(targetValue,accuracy,maxEvaluations,
648
 
                                     minVol,maxVol);
 
703
                ->impliedVolatility(targetValue, bsProcess, accuracy,
 
704
                                    maxEvaluations, minVol, maxVol);
649
705
        }
650
706
    }
651
707
};
660
716
    : public boost::shared_ptr<PricingEngine> {
661
717
  public:
662
718
    %extend {
663
 
        AnalyticDividendEuropeanEnginePtr() {
 
719
        AnalyticDividendEuropeanEnginePtr(
 
720
                           const GeneralizedBlackScholesProcessPtr& process) {
 
721
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
722
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
723
                                                                     process);
 
724
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
664
725
            return new AnalyticDividendEuropeanEnginePtr(
665
 
                new AnalyticDividendEuropeanEngine);
 
726
                               new AnalyticDividendEuropeanEngine(bsProcess));
666
727
        }
667
728
    }
668
729
};
679
740
    : public boost::shared_ptr<PricingEngine> {
680
741
  public:
681
742
    %extend {
682
 
        FDDividendEuropeanEnginePtr(Size timeSteps = 100,
683
 
                                    Size gridPoints = 100,
684
 
                                    bool timeDependent = false) {
 
743
        FDDividendEuropeanEnginePtr(
 
744
                             const GeneralizedBlackScholesProcessPtr& process,
 
745
                             Size timeSteps = 100,
 
746
                             Size gridPoints = 100,
 
747
                             bool timeDependent = false) {
 
748
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
749
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
750
                                                                     process);
 
751
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
685
752
            return new FDDividendEuropeanEnginePtr(
686
 
                new FDDividendEuropeanEngine(timeSteps,gridPoints,
687
 
                                             timeDependent));
 
753
                     new FDDividendEuropeanEngine(bsProcess,timeSteps,
 
754
                                                  gridPoints, timeDependent));
688
755
        }
689
756
    }
690
757
};
694
761
    : public boost::shared_ptr<PricingEngine> {
695
762
  public:
696
763
    %extend {
697
 
        FDDividendAmericanEnginePtr(Size timeSteps = 100,
698
 
                                    Size gridPoints = 100,
699
 
                                    bool timeDependent = false) {
 
764
        FDDividendAmericanEnginePtr(
 
765
                             const GeneralizedBlackScholesProcessPtr& process,
 
766
                             Size timeSteps = 100,
 
767
                             Size gridPoints = 100,
 
768
                             bool timeDependent = false) {
 
769
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
770
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
771
                                                                     process);
 
772
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
700
773
            return new FDDividendAmericanEnginePtr(
701
 
                new FDDividendAmericanEngine(timeSteps,gridPoints,
702
 
                                             timeDependent));
 
774
                     new FDDividendAmericanEngine(bsProcess,timeSteps,
 
775
                                                  gridPoints, timeDependent));
703
776
        }
704
777
    }
705
778
};
724
797
                   Barrier::Type barrierType,
725
798
                   Real barrier,
726
799
                   Real rebate,
727
 
                   const boost::shared_ptr<StochasticProcess>& process,
728
800
                   const boost::shared_ptr<Payoff>& payoff,
729
 
                   const boost::shared_ptr<Exercise>& exercise,
730
 
                   const boost::shared_ptr<PricingEngine>& engine
731
 
                                     = boost::shared_ptr<PricingEngine>()) {
 
801
                   const boost::shared_ptr<Exercise>& exercise) {
732
802
            boost::shared_ptr<StrikedTypePayoff> stPayoff =
733
803
                 boost::dynamic_pointer_cast<StrikedTypePayoff>(payoff);
734
804
            QL_REQUIRE(stPayoff, "wrong payoff given");
735
805
            return new BarrierOptionPtr(
736
 
                         new BarrierOption(barrierType, barrier, rebate,
737
 
                                           process,stPayoff,exercise,engine));
 
806
                               new BarrierOption(barrierType, barrier, rebate,
 
807
                                                 stPayoff,exercise));
738
808
        }
739
809
        Real delta() {
740
810
            return boost::dynamic_pointer_cast<BarrierOption>(*self)->delta();
763
833
            return boost::dynamic_pointer_cast<BarrierOption>(*self)
764
834
                ->result<SampledCurve>("priceCurve");
765
835
        }
766
 
        Volatility impliedVolatility(Real targetValue,
767
 
                                     Real accuracy = 1.0e-4,
768
 
                                     Size maxEvaluations = 100,
769
 
                                     Volatility minVol = 1.0e-4,
770
 
                                     Volatility maxVol = 4.0) {
 
836
        Volatility impliedVolatility(
 
837
                             Real targetValue,
 
838
                             const GeneralizedBlackScholesProcessPtr& process,
 
839
                             Real accuracy = 1.0e-4,
 
840
                             Size maxEvaluations = 100,
 
841
                             Volatility minVol = 1.0e-4,
 
842
                             Volatility maxVol = 4.0) {
 
843
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
844
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
845
                                                                     process);
 
846
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
771
847
            return boost::dynamic_pointer_cast<BarrierOption>(*self)
772
 
                 ->impliedVolatility(targetValue,accuracy,maxEvaluations,
773
 
                                     minVol,maxVol);
 
848
                 ->impliedVolatility(targetValue, bsProcess, accuracy,
 
849
                                     maxEvaluations, minVol, maxVol);
774
850
        }
775
851
    }
776
852
};
787
863
    : public boost::shared_ptr<PricingEngine> {
788
864
  public:
789
865
    %extend {
790
 
        AnalyticBarrierEnginePtr() {
791
 
            return new AnalyticBarrierEnginePtr(new AnalyticBarrierEngine);
 
866
        AnalyticBarrierEnginePtr(
 
867
                           const GeneralizedBlackScholesProcessPtr& process) {
 
868
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
869
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
870
                                                                     process);
 
871
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
 
872
            return new AnalyticBarrierEnginePtr(
 
873
                                        new AnalyticBarrierEngine(bsProcess));
792
874
        }
793
875
    }
794
876
};
803
885
    %feature("kwargs") MCBarrierEnginePtr;
804
886
  public:
805
887
    %extend {
806
 
        MCBarrierEnginePtr(const std::string& traits,
 
888
        MCBarrierEnginePtr(const GeneralizedBlackScholesProcessPtr& process,
 
889
                           const std::string& traits,
807
890
                           Size timeStepsPerYear = Null<Size>(),
808
891
                           bool brownianBridge = false,
809
892
                           bool antitheticVariate = false,
813
896
                           intOrNull maxSamples = Null<Size>(),
814
897
                           bool isBiased = false,
815
898
                           BigInteger seed = 0) {
816
 
//            std::string s = QuantLib::lowercase(traits);
817
 
        std::string s = traits;
 
899
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
900
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
901
                                                                     process);
 
902
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
 
903
            std::string s = boost::algorithm::to_lower_copy(traits);
818
904
            if (s == "pseudorandom" || s == "pr")
819
905
                return new MCBarrierEnginePtr(
820
 
                         new MCBarrierEngine<PseudoRandom>(timeStepsPerYear,
 
906
                         new MCBarrierEngine<PseudoRandom>(bsProcess,
 
907
                                                           timeStepsPerYear,
821
908
                                                           brownianBridge,
822
909
                                                           antitheticVariate,
823
910
                                                           controlVariate,
828
915
                                                           seed));
829
916
            else if (s == "lowdiscrepancy" || s == "ld")
830
917
                return new MCBarrierEnginePtr(
831
 
                       new MCBarrierEngine<LowDiscrepancy>(timeStepsPerYear,
 
918
                       new MCBarrierEngine<LowDiscrepancy>(bsProcess,
 
919
                                                           timeStepsPerYear,
832
920
                                                           brownianBridge,
833
921
                                                           antitheticVariate,
834
922
                                                           controlVariate,
845
933
 
846
934
%{
847
935
using QuantLib::QuantoEngine;
848
 
using QuantLib::ForwardEngine;
849
 
typedef boost::shared_ptr<PricingEngine> ForwardVanillaEnginePtr;
850
 
typedef boost::shared_ptr<PricingEngine> QuantoVanillaEnginePtr;
851
 
typedef boost::shared_ptr<PricingEngine> QuantoForwardVanillaEnginePtr;
 
936
using QuantLib::ForwardVanillaEngine;
 
937
typedef boost::shared_ptr<PricingEngine> ForwardEuropeanEnginePtr;
 
938
typedef boost::shared_ptr<PricingEngine> QuantoEuropeanEnginePtr;
 
939
typedef boost::shared_ptr<PricingEngine> QuantoForwardEuropeanEnginePtr;
852
940
%}
853
941
 
854
942
 
855
 
%rename(ForwardVanillaEngine) ForwardVanillaEnginePtr;
856
 
class ForwardVanillaEnginePtr: public boost::shared_ptr<PricingEngine> {
857
 
  public:
858
 
    %extend {
859
 
        ForwardVanillaEnginePtr(boost::shared_ptr<PricingEngine> engine) {
860
 
            boost::shared_ptr<VanillaOption::engine> uengine =
861
 
                boost::dynamic_pointer_cast<VanillaOption::engine>(engine);
862
 
            return new ForwardVanillaEnginePtr(
863
 
                                   new ForwardVanillaOption::engine(uengine));
864
 
        }
865
 
    }
866
 
};
867
 
 
868
 
 
869
 
%rename(QuantoVanillaEngine) QuantoVanillaEnginePtr;
870
 
class QuantoVanillaEnginePtr: public boost::shared_ptr<PricingEngine> {
871
 
  public:
872
 
    %extend {
873
 
        QuantoVanillaEnginePtr(boost::shared_ptr<PricingEngine> engine) {
874
 
            boost::shared_ptr<VanillaOption::engine> uengine =
875
 
                boost::dynamic_pointer_cast<VanillaOption::engine>(engine);
876
 
            return new QuantoVanillaEnginePtr(
877
 
                                    new QuantoVanillaOption::engine(uengine));
878
 
        }
879
 
    }
880
 
};
881
 
 
882
 
%rename(QuantoForwardVanillaEngine) QuantoForwardVanillaEnginePtr;
883
 
class QuantoForwardVanillaEnginePtr: public boost::shared_ptr<PricingEngine> {
 
943
%rename(ForwardEuropeanEngine) ForwardEuropeanEnginePtr;
 
944
class ForwardEuropeanEnginePtr: public boost::shared_ptr<PricingEngine> {
 
945
  public:
 
946
    %extend {
 
947
        ForwardEuropeanEnginePtr(
 
948
                           const GeneralizedBlackScholesProcessPtr& process) {
 
949
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
950
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
951
                                                                     process);
 
952
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
 
953
            return new ForwardEuropeanEnginePtr(
 
954
                 new ForwardVanillaEngine<AnalyticEuropeanEngine>(bsProcess));
 
955
        }
 
956
    }
 
957
};
 
958
 
 
959
 
 
960
%rename(QuantoEuropeanEngine) QuantoEuropeanEnginePtr;
 
961
class QuantoEuropeanEnginePtr: public boost::shared_ptr<PricingEngine> {
 
962
  public:
 
963
    %extend {
 
964
        QuantoEuropeanEnginePtr(
 
965
                  const GeneralizedBlackScholesProcessPtr& process,
 
966
                  const Handle<YieldTermStructure>& foreignRiskFreeRate,
 
967
                  const Handle<BlackVolTermStructure>& exchangeRateVolatility,
 
968
                  const Handle<Quote>& correlation) {
 
969
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
970
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
971
                                                                     process);
 
972
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
 
973
            return new QuantoEuropeanEnginePtr(
 
974
                new QuantoEngine<VanillaOption,AnalyticEuropeanEngine>(
 
975
                                                       bsProcess,
 
976
                                                       foreignRiskFreeRate,
 
977
                                                       exchangeRateVolatility,
 
978
                                                       correlation));
 
979
        }
 
980
    }
 
981
};
 
982
 
 
983
%rename(QuantoForwardEuropeanEngine) QuantoForwardEuropeanEnginePtr;
 
984
class QuantoForwardEuropeanEnginePtr: public boost::shared_ptr<PricingEngine> {
884
985
public:
885
986
    %extend {
886
 
        QuantoForwardVanillaEnginePtr(boost::shared_ptr<PricingEngine> engine) {
887
 
            boost::shared_ptr<VanillaOption::engine> vengine =
888
 
                boost::dynamic_pointer_cast<VanillaOption::engine>(vengine);
889
 
            boost::shared_ptr<ForwardVanillaOption::engine>
890
 
                fengine(new ForwardVanillaOption::engine(vengine));
891
 
            return new QuantoForwardVanillaEnginePtr(
892
 
                             new QuantoForwardVanillaOption::engine(fengine));
 
987
        QuantoForwardEuropeanEnginePtr(
 
988
                  const GeneralizedBlackScholesProcessPtr& process,
 
989
                  const Handle<YieldTermStructure>& foreignRiskFreeRate,
 
990
                  const Handle<BlackVolTermStructure>& exchangeRateVolatility,
 
991
                  const Handle<Quote>& correlation) {
 
992
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess =
 
993
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
994
                                                                     process);
 
995
            QL_REQUIRE(bsProcess, "Black-Scholes process required");
 
996
            return new QuantoForwardEuropeanEnginePtr(
 
997
                new QuantoEngine<ForwardVanillaOption,AnalyticEuropeanEngine>(
 
998
                                                       bsProcess,
 
999
                                                       foreignRiskFreeRate,
 
1000
                                                       exchangeRateVolatility,
 
1001
                                                       correlation));
893
1002
        }
894
1003
    }
895
1004
};