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

« back to all changes in this revision

Viewing changes to Ruby/examples/bermudan-swaption.rb

  • 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:
88
88
                      FlatForward.new(settlementDate,rate,Actual365Fixed.new))
89
89
 
90
90
# define the ATM/OTM/ITM swaps
 
91
 
 
92
swapEngine = DiscountingSwapEngine.new(termStructure)
 
93
 
91
94
fixedLegFrequency = Annual
92
95
fixedLegTenor = Period.new(1,Years)
93
96
fixedLegConvention = Unadjusted
107
110
fixedSchedule = Schedule.new(swapStart, swapEnd,
108
111
                             fixedLegTenor, calendar,
109
112
                             fixedLegConvention, fixedLegConvention,
110
 
                             false, false)
 
113
                             DateGeneration::Forward, false)
111
114
floatingSchedule = Schedule.new(swapStart, swapEnd,
112
115
                                floatingLegTenor, calendar,
113
116
                                floatingLegConvention, floatingLegConvention,
114
 
                                false, false)
 
117
                                DateGeneration::Forward, false)
115
118
 
116
 
atmRate = VanillaSwap.new(payFixed, 100.0,
117
 
                          fixedSchedule, 0.0, fixedLegDayCounter,
118
 
                          floatingSchedule, index, 0.0,
119
 
                          floatingLegDayCounter, termStructure).fairRate
 
119
dummy = VanillaSwap.new(payFixed, 100.0,
 
120
                        fixedSchedule, 0.0, fixedLegDayCounter,
 
121
                        floatingSchedule, index, 0.0,
 
122
                        floatingLegDayCounter)
 
123
dummy.pricingEngine = swapEngine
 
124
atmRate = dummy.fairRate
120
125
 
121
126
atmSwap = VanillaSwap.new(payFixed, 1000.0,
122
127
                          fixedSchedule, atmRate, fixedLegDayCounter,
123
128
                          floatingSchedule, index, 0.0,
124
 
                          floatingLegDayCounter, termStructure)
 
129
                          floatingLegDayCounter)
125
130
otmSwap = VanillaSwap.new(payFixed, 1000.0,
126
131
                          fixedSchedule, atmRate*1.2, fixedLegDayCounter,
127
132
                          floatingSchedule, index, 0.0,
128
 
                          floatingLegDayCounter, termStructure)
 
133
                          floatingLegDayCounter)
129
134
itmSwap = VanillaSwap.new(payFixed, 1000.0,
130
135
                          fixedSchedule, atmRate*0.8, fixedLegDayCounter,
131
136
                          floatingSchedule, index, 0.0,
132
 
                          floatingLegDayCounter, termStructure)
 
137
                          floatingLegDayCounter)
 
138
atmSwap.pricingEngine = swapEngine
 
139
itmSwap.pricingEngine = swapEngine
 
140
otmSwap.pricingEngine = swapEngine
133
141
 
134
142
helpers = SwaptionVols.map { |maturity, length, vol|
135
143
  SwaptionHelper.new(maturity, length,
192
200
puts header
193
201
puts rule
194
202
 
195
 
atmSwaption = Swaption.new(atmSwap, exercise, termStructure,
196
 
                           TreeSwaptionEngine.new(G2model, 50))
197
 
otmSwaption = Swaption.new(otmSwap, exercise, termStructure,
198
 
                           TreeSwaptionEngine.new(G2model, 50))
199
 
itmSwaption = Swaption.new(itmSwap, exercise, termStructure,
200
 
                           TreeSwaptionEngine.new(G2model, 50))
 
203
atmSwaption = Swaption.new(atmSwap, exercise)
 
204
otmSwaption = Swaption.new(otmSwap, exercise)
 
205
itmSwaption = Swaption.new(itmSwap, exercise)
 
206
 
 
207
atmSwaption.pricingEngine = TreeSwaptionEngine.new(G2model, 50)
 
208
otmSwaption.pricingEngine = TreeSwaptionEngine.new(G2model, 50)
 
209
itmSwaption.pricingEngine = TreeSwaptionEngine.new(G2model, 50)
201
210
 
202
211
puts sprintf(format,'G2 analytic', formatPrice(itmSwaption.NPV),
203
212
             formatPrice(atmSwaption.NPV), formatPrice(otmSwaption.NPV))