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

« back to all changes in this revision

Viewing changes to SWIG/shortratemodels.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:
1
1
 
2
2
/*
3
3
 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
4
 
 Copyright (C) 2003 StatPro Italia srl
5
 
 Copyright (c) 2005 Dominic Thuillier
 
4
 Copyright (C) 2003, 2007 StatPro Italia srl
 
5
 Copyright (C) 2005 Dominic Thuillier
 
6
 Copyright (C) 2007 Luis Cota
6
7
 
7
8
 This file is part of QuantLib, a free-software/open-source library
8
9
 for financial quantitative analysts and developers - http://quantlib.org/
161
162
%template(ShortRateModel) boost::shared_ptr<ShortRateModel>;
162
163
IsObservable(boost::shared_ptr<ShortRateModel>);
163
164
 
 
165
%template(ShortRateModelHandle) Handle<ShortRateModel>;
 
166
IsObservable(Handle<ShortRateModel>);
 
167
%template(RelinkableShortRateModelHandle)
 
168
RelinkableHandle<ShortRateModel>;
 
169
 
164
170
// actual models
165
171
 
166
172
%{
167
 
using QuantLib::HullWhite;
168
 
using QuantLib::BlackKarasinski;
169
 
using QuantLib::G2;
170
 
typedef boost::shared_ptr<ShortRateModel> HullWhitePtr;
171
 
typedef boost::shared_ptr<ShortRateModel> BlackKarasinskiPtr;
172
 
typedef boost::shared_ptr<ShortRateModel> G2Ptr;
 
173
    using QuantLib::Vasicek;
 
174
    using QuantLib::HullWhite;
 
175
    using QuantLib::BlackKarasinski;
 
176
    using QuantLib::G2;
 
177
    typedef boost::shared_ptr<ShortRateModel> VasicekPtr;
 
178
    typedef boost::shared_ptr<ShortRateModel> HullWhitePtr;
 
179
    typedef boost::shared_ptr<ShortRateModel> BlackKarasinskiPtr;
 
180
    typedef boost::shared_ptr<ShortRateModel> G2Ptr;
173
181
%}
174
182
 
 
183
%rename(Vasicek) VasicekPtr;
 
184
class VasicekPtr : public boost::shared_ptr<ShortRateModel> {
 
185
  public:
 
186
    %extend {
 
187
        VasicekPtr(Rate r0 = 0.05,
 
188
                   Real a = 0.1,
 
189
                   Real b = 0.05,
 
190
                   Real sigma = 0.01,
 
191
                   Real lambda = 0.0) {
 
192
            return new VasicekPtr(new Vasicek(r0, a, b, sigma, lambda));
 
193
        }
 
194
        DiscountFactor discount(Time t) const {
 
195
            return boost::dynamic_pointer_cast<Vasicek>(*self)->discount(t);
 
196
        }
 
197
    }
 
198
};
 
199
 
 
200
 
175
201
%rename(HullWhite) HullWhitePtr;
176
202
class HullWhitePtr : public boost::shared_ptr<ShortRateModel> {
177
203
  public:
181
207
            return new HullWhitePtr(
182
208
                new HullWhite(termStructure, a, sigma));
183
209
        }
 
210
        DiscountFactor discount(Time t) const {
 
211
            return boost::dynamic_pointer_cast<HullWhite>(*self)->discount(t);
 
212
        }
184
213
    }
185
214
};
186
215
 
205
234
              Real eta = 0.01, Real rho = -0.75) {
206
235
            return new G2Ptr(new G2(termStructure, a, sigma, b, eta, rho));
207
236
        }
 
237
        DiscountFactor discount(Time t) const {
 
238
            return boost::dynamic_pointer_cast<G2>(*self)->discount(t);
 
239
        }
208
240
    }
209
241
};
210
242
 
228
260
  public:
229
261
    %extend {
230
262
        JamshidianSwaptionEnginePtr(
231
 
                             const boost::shared_ptr<ShortRateModel>& model) {
 
263
                         const boost::shared_ptr<ShortRateModel>& model,
 
264
                         const Handle<YieldTermStructure>& termStructure =
 
265
                                                Handle<YieldTermStructure>()) {
232
266
            using QuantLib::OneFactorAffineModel;
233
267
            boost::shared_ptr<OneFactorAffineModel> m =
234
268
                 boost::dynamic_pointer_cast<OneFactorAffineModel>(model);
235
269
            QL_REQUIRE(model, "affine model required");
236
270
            return new JamshidianSwaptionEnginePtr(
237
 
                                             new JamshidianSwaptionEngine(m));
 
271
                               new JamshidianSwaptionEngine(m,termStructure));
238
272
        }
239
273
    }
240
274
};
243
277
class TreeSwaptionEnginePtr : public boost::shared_ptr<PricingEngine> {
244
278
  public:
245
279
    %extend {
246
 
        TreeSwaptionEnginePtr(const boost::shared_ptr<ShortRateModel>& model,
247
 
                              Size timeSteps) {
 
280
        TreeSwaptionEnginePtr(
 
281
                         const boost::shared_ptr<ShortRateModel>& model,
 
282
                         Size timeSteps,
 
283
                         const Handle<YieldTermStructure>& termStructure =
 
284
                                                Handle<YieldTermStructure>()) {
248
285
            return new TreeSwaptionEnginePtr(
249
 
                                     new TreeSwaptionEngine(model,timeSteps));
 
286
                       new TreeSwaptionEngine(model,timeSteps,termStructure));
250
287
        }
251
 
        TreeSwaptionEnginePtr(const boost::shared_ptr<ShortRateModel>& model,
252
 
                              const TimeGrid& grid) {
 
288
        TreeSwaptionEnginePtr(
 
289
                         const boost::shared_ptr<ShortRateModel>& model,
 
290
                         const TimeGrid& grid,
 
291
                         const Handle<YieldTermStructure>& termStructure =
 
292
                                                Handle<YieldTermStructure>()) {
253
293
            return new TreeSwaptionEnginePtr(
254
 
                                     new TreeSwaptionEngine(model,grid));
 
294
                            new TreeSwaptionEngine(model,grid,termStructure));
255
295
        }
256
296
    }
257
297
};
261
301
  public:
262
302
    %extend {
263
303
        AnalyticCapFloorEnginePtr(
264
 
                             const boost::shared_ptr<ShortRateModel>& model) {
 
304
                         const boost::shared_ptr<ShortRateModel>& model,
 
305
                         const Handle<YieldTermStructure>& termStructure =
 
306
                                                Handle<YieldTermStructure>()) {
265
307
            using QuantLib::OneFactorAffineModel;
266
308
            boost::shared_ptr<OneFactorAffineModel> m =
267
309
                 boost::dynamic_pointer_cast<OneFactorAffineModel>(model);
268
310
            QL_REQUIRE(model, "affine model required");
269
311
            return new AnalyticCapFloorEnginePtr(
270
 
                                           new AnalyticCapFloorEngine(m));
 
312
                                 new AnalyticCapFloorEngine(m,termStructure));
271
313
        }
272
314
    }
273
315
};
276
318
class TreeCapFloorEnginePtr : public boost::shared_ptr<PricingEngine> {
277
319
  public:
278
320
    %extend {
279
 
        TreeCapFloorEnginePtr(const boost::shared_ptr<ShortRateModel>& model,
280
 
                              Size timeSteps) {
 
321
        TreeCapFloorEnginePtr(
 
322
                         const boost::shared_ptr<ShortRateModel>& model,
 
323
                         Size timeSteps,
 
324
                         const Handle<YieldTermStructure>& termStructure =
 
325
                                                Handle<YieldTermStructure>()) {
281
326
            return new TreeCapFloorEnginePtr(
282
 
                                     new TreeCapFloorEngine(model,timeSteps));
 
327
                       new TreeCapFloorEngine(model,timeSteps,termStructure));
283
328
        }
284
 
        TreeCapFloorEnginePtr(const boost::shared_ptr<ShortRateModel>& model,
285
 
                              const TimeGrid& grid) {
 
329
        TreeCapFloorEnginePtr(
 
330
                         const boost::shared_ptr<ShortRateModel>& model,
 
331
                         const TimeGrid& grid,
 
332
                         const Handle<YieldTermStructure>& termStructure =
 
333
                                                Handle<YieldTermStructure>()) {
286
334
            return new TreeCapFloorEnginePtr(
287
 
                                     new TreeCapFloorEngine(model,grid));
 
335
                            new TreeCapFloorEngine(model,grid,termStructure));
288
336
        }
289
337
    }
290
338
};