-
Notifications
You must be signed in to change notification settings - Fork 300
Expand file tree
/
Copy pathscriptlibrary.xml
More file actions
411 lines (371 loc) · 15.8 KB
/
Copy pathscriptlibrary.xml
File metadata and controls
411 lines (371 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<?xml version="1.0"?>
<ScriptLibrary>
<!-- Cash settled European EQ, FX, COM Option
Inputs:
Expiry option expiry date
Settlement option payoff settlement date
Strike option strike
PutCall 1 for call, -1 for put
LongShort 1 for a long, -1 for a short position
Quantity number of option contracts
Underlying underlying index
PayCcy payment currency
Results:
NPV npv of the option
ExerciseProbability exercise probability of the option
-->
<Script>
<Name>EuropeanOption</Name>
<Script>
<Code>
<![CDATA[
NUMBER Payoff, currentNotional;
Payoff = PutCall * (Underlying(Expiry) - Strike);
Option = LOGPAY( LongShort * Quantity * max( Payoff, 0 ), Expiry, Settlement, PayCcy, 1, OptionFlow);
currentNotional = Strike * Quantity;
]]></Code>
<NPV>Option</NPV>
<Results>
<Result>currentNotional</Result>
<Result rename="notionalCurrency">PayCcy</Result>
</Results>
<CalibrationSpec>
<Calibration>
<Index>Underlying</Index>
<Strikes>
<Strike>Strike</Strike>
</Strikes>
</Calibration>
</CalibrationSpec>
</Script>
<Script purpose = "FD">
<Code>
<![CDATA[
NUMBER Payoff, currentNotional;
Payoff = PutCall * (Underlying(Expiry) - Strike);
Option = LOGPAY( LongShort * Quantity * max( Payoff, 0 ), Expiry, Settlement, PayCcy, 1, OptionFlow);
currentNotional = Strike * Quantity;
]]></Code>
<NPV>Option</NPV>
<Results>
<Result>currentNotional</Result>
<Result rename="notionalCurrency">PayCcy</Result>
</Results>
<CalibrationSpec>
<Calibration>
<Index>Underlying</Index>
<Strikes>
<Strike>Strike</Strike>
</Strikes>
</Calibration>
</CalibrationSpec>
</Script>
</Script>
<!-- Single Barrier Option
Inputs:
PayoffType 0 = Vanilla max(0, S-K), 1 = Cash or Nothing
LongShort long / short indicator, +1 for long, -1 for short position
PutCall put / call indicator, +1 for call, -1 for put
Quantity quantity for PayoffType = 0 (Vanilla)
Strike the strike for PayoffType = 0 (Vanilla)
Amount amount for PayoffType = 1 (Cash or Nothing)
PayCcy payment currency
Expiry option expiry date
Settlement option settlement date
Underlying the underlying index
BarrierType 1 = DonwIn, 2 = UpIn, 3 = DownOut, 4 = UpOut
BarrierLevel barrier level
BarrierRebate barrier rebate (only for out)
BarrierRebateCurrency barrier rebate currency
BarrierRebatePayTime 0 = atHit, 1 = atExpiry (only for out)
BarrierMonitoringDates list of barrier monitoring dates
Results:
Value NPV of the barrier option
currentNotional current notional
notionalCurrency current notional currency
-->
<Script>
<Name>SingleBarrierOption</Name>
<!--<ProductTag>SingleAssetOptionBwd({AssetClass})</ProductTag>-->
<Script>
<Code><![CDATA[
REQUIRE PayoffType == 0 OR PayoffType == 1;
NUMBER KnockedIn, KnockedOut, Active, Rebate;
NUMBER U, i, d, currentNotional;
FOR d IN (1, SIZE(BarrierMonitoringDates), 1) DO
U = Underlying(BarrierMonitoringDates[d]);
IF {BarrierType == 1 AND U <= BarrierLevel} OR
{BarrierType == 2 AND U >= BarrierLevel} THEN
IF KnockedOut == 0 THEN
KnockedIn = 1;
END;
END;
IF {BarrierType == 3 AND U < BarrierLevel} OR
{BarrierType == 4 AND U > BarrierLevel} THEN
IF KnockedOut == 0 THEN
IF BarrierRebatePayTime == 0 THEN
Rebate = PAY( LongShort * BarrierRebate, BarrierMonitoringDates[d], BarrierMonitoringDates[d], BarrierRebateCurrency );
ELSE
Rebate = PAY( LongShort * BarrierRebate, BarrierMonitoringDates[d], Settlement, BarrierRebateCurrency );
END;
END;
KnockedOut = 1;
END;
END;
Active = 1;
IF BarrierType == 1 OR BarrierType == 2 THEN
Active = 0;
END;
Active = max(Active, KnockedIn) * (1 - KnockedOut);
IF BarrierRebate != 0 THEN
Rebate = (1 - Active) * PAY( LongShort * BarrierRebate, Settlement, Settlement, BarrierRebateCurrency );
END;
IF PayoffType == 0 THEN
value = Active * PAY( LongShort * Quantity * max(0, PutCall * (Underlying(Expiry) - Strike)), Expiry, Settlement, PayCcy ) +
Rebate;
ELSE
value = Active * PAY( LongShort * Amount, Expiry, Settlement, PayCcy ) +
Rebate;
END;
IF PayoffType == 0 THEN
currentNotional = Quantity * Strike;
ELSE
currentNotional = Amount;
END;
]]></Code>
<NPV>value</NPV>
<Results>
<Result>currentNotional</Result>
<Result rename="notionalCurrency">PayCcy</Result>
<Result>Active</Result>
</Results>
<CalibrationSpec>
<Calibration>
<Index>Underlying</Index>
<Strikes>
<Strike>Strike</Strike>
<Strike>BarrierLevel</Strike>
</Strikes>
</Calibration>
</CalibrationSpec>
</Script>
</Script>
<Script>
<Name>SingleContinuousBarrierOption</Name>
<!--<ProductTag>SingleAssetOptionBwd({AssetClass})</ProductTag>-->
<Script>
<Code><![CDATA[
REQUIRE PayoffType == 0 OR PayoffType == 1;
NUMBER KnockedIn, KnockedOut, Active, Rebate;
NUMBER U, i, d, currentNotional, Alive;
Alive = 1;
FOR d IN (1, SIZE(BarrierMonitoringDates), 1) DO
U = Underlying(BarrierMonitoringDates[d]);
IF {BarrierType == 1 AND U <= BarrierLevel} OR
{BarrierType == 2 AND U >= BarrierLevel} THEN
IF KnockedOut == 0 THEN
KnockedIn = 1;
END;
END;
IF {BarrierType == 3 AND U < BarrierLevel} OR
{BarrierType == 4 AND U > BarrierLevel} THEN
IF KnockedOut == 0 THEN
IF BarrierRebatePayTime == 0 THEN
Rebate = PAY( LongShort * BarrierRebate, BarrierMonitoringDates[d], BarrierMonitoringDates[d], BarrierRebateCurrency );
ELSE
Rebate = PAY( LongShort * BarrierRebate, BarrierMonitoringDates[d], Settlement, BarrierRebateCurrency );
END;
END;
KnockedOut = 1;
END;
IF BarrierType == 4 THEN
IF d == 1 OR BarrierMonitoringDates[d-1] <= StartDate THEN
Alive = Alive * (1 - ABOVEPROB(Underlying, StartDate, BarrierMonitoringDates[d], BarrierLevel));
ELSE
Alive = Alive * (1 - ABOVEPROB(Underlying, BarrierMonitoringDates[d-1], BarrierMonitoringDates[d], BarrierLevel));
END;
END;
IF BarrierType == 3 THEN
IF d == 1 OR BarrierMonitoringDates[d-1] <= StartDate THEN
Alive = Alive * (1 - BELOWPROB(Underlying, StartDate, BarrierMonitoringDates[d], BarrierLevel));
ELSE
Alive = Alive * (1 - BELOWPROB(Underlying, BarrierMonitoringDates[d-1], BarrierMonitoringDates[d], BarrierLevel));
END;
END;
END;
Active = 1;
IF BarrierType == 1 OR BarrierType == 2 THEN
Active = 0;
END;
Active = max(Active, KnockedIn) * (1 - KnockedOut);
IF BarrierRebate != 0 THEN
Rebate = (1 - Active) * PAY( LongShort * BarrierRebate, Settlement, Settlement, BarrierRebateCurrency );
END;
IF PayoffType == 0 THEN
value = Active * Alive * PAY( LongShort * Quantity * max(0, PutCall * (Underlying(Expiry) - Strike)), Expiry, Settlement, PayCcy ) +
Rebate;
ELSE
value = Active * Alive * PAY( LongShort * Amount, Expiry, Settlement, PayCcy ) +
Rebate;
END;
IF PayoffType == 0 THEN
currentNotional = Quantity * Strike;
ELSE
currentNotional = Amount;
END;
]]></Code>
<NPV>value</NPV>
<Results>
<Result>currentNotional</Result>
<Result rename="notionalCurrency">PayCcy</Result>
<Result>Active</Result>
</Results>
<CalibrationSpec>
<Calibration>
<Index>Underlying</Index>
<Strikes>
<Strike>Strike</Strike>
<Strike>BarrierLevel</Strike>
</Strikes>
</Calibration>
</CalibrationSpec>
</Script>
</Script>
<!-- Accumulator
Inputs:
Strike option strike
FixingAmount unleveraged amount paid on each fixing date
LongShort 1 for a long, -1 for a short position
Underlying underlying index
PayCcy payment currency
StartDate start date (only needed if AmericanKO = 1)
FixingDates fixing valuation dates
SettlementDates settlement dates
RangeUpperBounds upper bounds of fixing ranges
RangeLowerBounds lower bounds of fixing ranges
RangeLeverages leverage amounts of fixing ranges
KnockOutLevel knock out level
KnockOutType barrier type 3=DownOut, 4=UpOut
AmericanKO 1 for American KO style, -1 for European KO style
GuaranteedFixings the number of fixings guaranteed regardless of knockout level
Results:
value npv of the option
CurrentNotional current notional
notionalCurrency notional currency
-->
<Script>
<Name>Accumulator</Name>
<!--<ProductTag>SingleAssetOption({AssetClass})</ProductTag>-->
<Script>
<Code><![CDATA[
REQUIRE KnockOutType == 3 OR KnockOutType == 4;
NUMBER Payoff, fix, d, r, Alive, currentNotional, Factor, ThisPayout, Fixing[SIZE(FixingDates)];
Alive = 1;
FOR d IN (1, SIZE(FixingDates), 1) DO
fix = Underlying(FixingDates[d]);
Fixing[d] = fix;
IF AmericanKO == 1 THEN
IF KnockOutType == 4 THEN
IF FixingDates[d] >= StartDate THEN
IF d == 1 OR FixingDates[d-1] <= StartDate THEN
Alive = Alive * (1 - ABOVEPROB(Underlying, StartDate, FixingDates[d], KnockOutLevel));
ELSE
Alive = Alive * (1 - ABOVEPROB(Underlying, FixingDates[d-1], FixingDates[d], KnockOutLevel));
END;
END;
ELSE
IF FixingDates[d] >= StartDate THEN
IF d == 1 OR FixingDates[d-1] <= StartDate THEN
Alive = Alive * (1 - BELOWPROB(Underlying, StartDate, FixingDates[d], KnockOutLevel));
ELSE
Alive = Alive * (1 - BELOWPROB(Underlying, FixingDates[d-1], FixingDates[d], KnockOutLevel));
END;
END;
END;
ELSE
IF {KnockOutType == 4 AND fix >= KnockOutLevel} OR
{KnockOutType == 3 AND fix <= KnockOutLevel} THEN
Alive = 0;
END;
END;
IF d <= GuaranteedFixings THEN
Factor = 1;
ELSE
Factor = Alive;
END;
FOR r IN (1, SIZE(RangeUpperBounds), 1) DO
IF fix > RangeLowerBounds[r] AND fix <= RangeUpperBounds[r] THEN
ThisPayout = RangeLeverages[r] * FixingAmount * (fix - Strike) * Factor;
IF d > GuaranteedFixings OR ThisPayout >= 0 THEN
Payoff = Payoff + LOGPAY(RangeLeverages[r] * FixingAmount * (fix - Strike) * Factor,
FixingDates[d], SettlementDates[d], PayCcy);
END;
END;
END;
END;
value = LongShort * Payoff;
currentNotional = FixingAmount * Strike;
]]></Code>
<NPV>value</NPV>
<Results>
<Result>currentNotional</Result>
<Result rename="notionalCurrency">PayCcy</Result>
<Result>Alive</Result>
<Result>Fixing</Result>
</Results>
<CalibrationSpec>
<Calibration>
<Index>Underlying</Index>
<Strikes>
<Strike>Strike</Strike>
<Strike>KnockOutLevel</Strike>
</Strikes>
</Calibration>
</CalibrationSpec>
</Script>
</Script>
<!-- Rainbow Option: Worst of Asset or Cash Option, EQ, FX, COM
Inputs:
Expiry option expiry date
Settlement option payoff settlement date
LongShort 1 for a long, -1 for a short position
Notional multiplier, number of option contracts, etc.
Strike option strike
Underlyings vector of underlying indices
Weights vector of underlying weights
PayCcy payment currency
Results:
Option npv of the option
currentNotional current notional
notionalCurrency notional currency
expectedUnderlyingValue vector of expected values of the underlyings at expiry
-->
<Script>
<Name>RainbowOption</Name>
<ProductTag>MultiAssetOption({AssetClass})</ProductTag>
<Script>
<Code><![CDATA[
REQUIRE SIZE(Underlyings) == SIZE(Weights);
NUMBER u, thisPrice, worstPrice, Payoff, currentNotional;
NUMBER expUnderValue[SIZE(Underlyings)];
worstPrice = Strike;
FOR u IN (1, SIZE(Underlyings), 1) DO
expUnderValue[u] = Underlyings[u](Expiry);
thisPrice = Underlyings[u](Expiry) * Weights[u];
IF thisPrice < worstPrice THEN
worstPrice = thisPrice;
END;
END;
Option = LongShort * Notional * PAY(worstPrice, Expiry, Settlement, PayCcy);
currentNotional = Notional * Strike;
]]>
</Code>
<NPV>Option</NPV>
<Results>
<Result>currentNotional</Result>
<Result rename="notionalCurrency">PayCcy</Result>
<Result rename="expectedUnderlyingValue">expUnderValue</Result>
</Results>
</Script>
</Script>
</ScriptLibrary>