107
110
fixedSchedule = Schedule.new(swapStart, swapEnd,
108
111
fixedLegTenor, calendar,
109
112
fixedLegConvention, fixedLegConvention,
113
DateGeneration::Forward, false)
111
114
floatingSchedule = Schedule.new(swapStart, swapEnd,
112
115
floatingLegTenor, calendar,
113
116
floatingLegConvention, floatingLegConvention,
117
DateGeneration::Forward, false)
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
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
134
142
helpers = SwaptionVols.map { |maturity, length, vol|
135
143
SwaptionHelper.new(maturity, length,
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)
207
atmSwaption.pricingEngine = TreeSwaptionEngine.new(G2model, 50)
208
otmSwaption.pricingEngine = TreeSwaptionEngine.new(G2model, 50)
209
itmSwaption.pricingEngine = TreeSwaptionEngine.new(G2model, 50)
202
211
puts sprintf(format,'G2 analytic', formatPrice(itmSwaption.NPV),
203
212
formatPrice(atmSwaption.NPV), formatPrice(otmSwaption.NPV))