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

« back to all changes in this revision

Viewing changes to SWIG/basketoptions.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:
83
83
  public:
84
84
    %extend {
85
85
        BasketOptionPtr(
86
 
                const boost::shared_ptr<StochasticProcess>& process,
87
86
                const boost::shared_ptr<Payoff>& payoff,
88
 
                const boost::shared_ptr<Exercise>& exercise,
89
 
                const boost::shared_ptr<PricingEngine>& engine
90
 
                   = boost::shared_ptr<PricingEngine>()) {
 
87
                const boost::shared_ptr<Exercise>& exercise) {
91
88
            boost::shared_ptr<BasketPayoff> stPayoff =
92
89
                 boost::dynamic_pointer_cast<BasketPayoff>(payoff);
93
90
            QL_REQUIRE(stPayoff, "wrong payoff given");
94
 
            return new BasketOptionPtr(
95
 
                          new BasketOption(process,stPayoff,exercise,engine));
 
91
            return new BasketOptionPtr(new BasketOption(stPayoff,exercise));
96
92
        }
97
93
    }
98
94
};
108
104
    %feature("kwargs") MCBasketEnginePtr;
109
105
  public:
110
106
    %extend {
111
 
        MCBasketEnginePtr(const std::string& traits,
112
 
                           Size timeStepsPerYear = Null<Size>(),
113
 
                           bool brownianBridge = false,
114
 
                           bool antitheticVariate = false,
115
 
                           bool controlVariate = false,
116
 
                           intOrNull requiredSamples = Null<Size>(),
117
 
                           doubleOrNull requiredTolerance = Null<Real>(),
118
 
                           intOrNull maxSamples = Null<Size>(),
119
 
                           BigInteger seed = 0) {
120
 
//            std::string s = QuantLib::lowercase(traits);
121
 
        std::string s = traits;
 
107
        MCBasketEnginePtr(const StochasticProcessArrayPtr& process,
 
108
                          const std::string& traits,
 
109
                          Size timeStepsPerYear = Null<Size>(),
 
110
                          bool brownianBridge = false,
 
111
                          bool antitheticVariate = false,
 
112
                          bool controlVariate = false,
 
113
                          intOrNull requiredSamples = Null<Size>(),
 
114
                          doubleOrNull requiredTolerance = Null<Real>(),
 
115
                          intOrNull maxSamples = Null<Size>(),
 
116
                          BigInteger seed = 0) {
 
117
            boost::shared_ptr<StochasticProcessArray> processes =
 
118
                 boost::dynamic_pointer_cast<StochasticProcessArray>(process);
 
119
            QL_REQUIRE(processes, "stochastic-process array required");
 
120
            std::string s = boost::algorithm::to_lower_copy(traits);
122
121
            if (s == "pseudorandom" || s == "pr")
123
122
                return new MCBasketEnginePtr(
124
 
                         new MCBasketEngine<PseudoRandom>(timeStepsPerYear,
125
 
                                                           brownianBridge,
126
 
                                                           antitheticVariate,
127
 
                                                           controlVariate,
128
 
                                                           requiredSamples,
129
 
                                                           requiredTolerance,
130
 
                                                           maxSamples,
131
 
                                                           seed));
 
123
                         new MCBasketEngine<PseudoRandom>(processes,
 
124
                                                          timeStepsPerYear,
 
125
                                                          brownianBridge,
 
126
                                                          antitheticVariate,
 
127
                                                          controlVariate,
 
128
                                                          requiredSamples,
 
129
                                                          requiredTolerance,
 
130
                                                          maxSamples,
 
131
                                                          seed));
132
132
            else if (s == "lowdiscrepancy" || s == "ld")
133
133
                return new MCBasketEnginePtr(
134
 
                       new MCBasketEngine<LowDiscrepancy>(timeStepsPerYear,
135
 
                                                           brownianBridge,
136
 
                                                           antitheticVariate,
137
 
                                                           controlVariate,
138
 
                                                           requiredSamples,
139
 
                                                           requiredTolerance,
140
 
                                                           maxSamples,
141
 
                                                           seed));
 
134
                       new MCBasketEngine<LowDiscrepancy>(processes,
 
135
                                                          timeStepsPerYear,
 
136
                                                          brownianBridge,
 
137
                                                          antitheticVariate,
 
138
                                                          controlVariate,
 
139
                                                          requiredSamples,
 
140
                                                          requiredTolerance,
 
141
                                                          maxSamples,
 
142
                                                          seed));
142
143
            else
143
144
                QL_FAIL("unknown Monte Carlo engine type: "+s);
144
145
        }
155
156
    %feature("kwargs") MCAmericanBasketEnginePtr;
156
157
  public:
157
158
    %extend {
158
 
        MCAmericanBasketEnginePtr(const std::string& traits,
159
 
                           Size timeSteps = Null<Size>(),
160
 
                           Size timeStepsPerYear = Null<Size>(),
161
 
                           bool brownianBridge = false,
162
 
                           bool antitheticVariate = false,
163
 
                           bool controlVariate = false,
164
 
                           intOrNull requiredSamples = Null<Size>(),
165
 
                           doubleOrNull requiredTolerance = Null<Real>(),
166
 
                           intOrNull maxSamples = Null<Size>(),
167
 
                           BigInteger seed = 0) {
168
 
//            std::string s = QuantLib::lowercase(traits);
169
 
        std::string s = traits;
 
159
        MCAmericanBasketEnginePtr(const StochasticProcessArrayPtr& process,
 
160
                                  const std::string& traits,
 
161
                                  Size timeSteps = Null<Size>(),
 
162
                                  Size timeStepsPerYear = Null<Size>(),
 
163
                                  bool brownianBridge = false,
 
164
                                  bool antitheticVariate = false,
 
165
                                  bool controlVariate = false,
 
166
                                  intOrNull requiredSamples = Null<Size>(),
 
167
                                  doubleOrNull requiredTolerance = Null<Real>(),
 
168
                                  intOrNull maxSamples = Null<Size>(),
 
169
                                  BigInteger seed = 0) {
 
170
            boost::shared_ptr<StochasticProcessArray> processes =
 
171
                 boost::dynamic_pointer_cast<StochasticProcessArray>(process);
 
172
            QL_REQUIRE(processes, "stochastic-process array required");
 
173
            std::string s = boost::algorithm::to_lower_copy(traits);
170
174
            if (s == "pseudorandom" || s == "pr")
171
175
                  return new MCAmericanBasketEnginePtr(
172
 
                  new MCAmericanBasketEngine<PseudoRandom>(timeSteps,
 
176
                  new MCAmericanBasketEngine<PseudoRandom>(processes,
 
177
                                                           timeSteps,
173
178
                                                           timeStepsPerYear,
174
179
                                                           brownianBridge,
175
180
                                                           antitheticVariate,
180
185
                                                           seed));
181
186
            else if (s == "lowdiscrepancy" || s == "ld")
182
187
                return new MCAmericanBasketEnginePtr(
183
 
                new MCAmericanBasketEngine<LowDiscrepancy>(timeSteps,
 
188
                new MCAmericanBasketEngine<LowDiscrepancy>(processes,
 
189
                                                           timeSteps,
184
190
                                                           timeStepsPerYear,
185
191
                                                           brownianBridge,
186
192
                                                           antitheticVariate,
206
212
    : public boost::shared_ptr<PricingEngine> {
207
213
  public:
208
214
    %extend {
209
 
        StulzEnginePtr() {
210
 
            return new StulzEnginePtr(new StulzEngine);
 
215
        StulzEnginePtr(const GeneralizedBlackScholesProcessPtr& process1,
 
216
                       const GeneralizedBlackScholesProcessPtr& process2,
 
217
                       Real correlation) {
 
218
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess1 =
 
219
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
220
                                                                    process1);
 
221
            QL_REQUIRE(bsProcess1, "Black-Scholes process required");
 
222
            boost::shared_ptr<GeneralizedBlackScholesProcess> bsProcess2 =
 
223
                 boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
 
224
                                                                    process2);
 
225
            QL_REQUIRE(bsProcess2, "Black-Scholes process required");
 
226
            return new StulzEnginePtr(
 
227
                          new StulzEngine(bsProcess1,bsProcess2,correlation));
211
228
        }
212
229
    }
213
230
};
214
231
 
 
232
 
215
233
#endif