SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_market_risk_funs_def_2.sas
1%macro irmst_market_risk_funs_def_2;
2
3
4
5
6 function RSK_BINARY_ASSET_OPTION_PF(CallPutType $, Price, Strike, RiskFreeRate, YieldParam, TimeToExpiration, Volatility)
7 label="European binary asset or nothing option pricing by Reiner and Rubinstein (1991)";
8 /***************************************************/
9 /* Error and special case checking */
10 /***************************************************/
11 /* Past maturity, option is worthless */
12 if TimeToExpiration < 0 then return(0);
13 /* Initialize the return missing flag to zero (state: no error found)
14 If we find an error in one of the inputs, we will return missing */
15 /* Set the function name for error reporting */
16 ReturnMissingFlg = 0;
17 Fname = 'rsk_binary_asset_option_pf';
18 /* Check that nonoptional inputs are nonmissing */
19 ReturnMissingFlg = rsk_check_num_missing_pf( RiskFreeRate, Fname, '4', 'RiskFreeRate', ReturnMissingFlg );
20 ReturnMissingFlg = rsk_check_num_missing_pf( YieldParam, Fname, '5', 'YieldParam', ReturnMissingFlg );
21 /* Make sure some input values are positive */
22 /* Nonpositive or missing values for these variables may cause problems
23 if input into another function (e.g. the logarithm function) */
24 ReturnMissingFlg = rsk_check_nonpositive_pf( Price, Fname, '2', 'Price', ReturnMissingFlg );
25 ReturnMissingFlg = rsk_check_nonpositive_pf( Strike, Fname, '3', 'Strike', ReturnMissingFlg );
26 ReturnMissingFlg = rsk_check_nonpositive_pf( Volatility, Fname, '7', 'Volatility', ReturnMissingFlg );
27 /* Return missing, if errors are found */
28 if ReturnMissingFlg eq 1 then return(.);
29 /* At maturity, return payoff */
30 if abs(TimeToExpiration) le constant('SQRTMACEPS') then do;
31 if upcase(CallPutType) eq 'CALL' and Price > Strike then return(Price);
32 if upcase(CallPutType) ne'CALL' and Price < Strike then return(Price);
33 return(0);
34 end;
35 /************************************************************/
36 /* RESUME STANDARD PRICING */
37 /************************************************************/
38 /* Calculate constants used in pricing */
39 CostofCarry=RiskFreeRate - YieldParam;
40 g = Volatility*sqrt(TimeToExpiration);
41 d = (log(Price / Strike) + CostofCarry * TimeToExpiration )/g + 0.5 * g;
42 /* Price the option, whether put or call */
43 IF upcase(CallPutType) eq 'CALL' THEN DO;
44 OptionPrice = Price * exp((CostofCarry - RiskFreeRate )* TimeToExpiration) * probnorm(d);
45 END;
46 ELSE
47 DO;
48 OptionPrice = Price * exp((CostofCarry - RiskFreeRate )* TimeToExpiration) * probnorm(-d);
49 END;
50 return(OptionPrice);
51
52 endsub;
53
54
55 function RSK_BINARY_BARRIEROPTION_PF(CallPutType $, BarrierType $, SettlementType $, PayAtHitFlg, Price, Price_Chk_Barrier_Up, Price_Chk_Barrier_Down, Strike, Barrier, Cash_Amt, RiskFreeRate, YieldParam, TimeToExpiration, Volatility)
56 label="European binary barrier option pricing by Reiner and Rubinstein (1991)";
57 /***************************************************/
58 /* Error and special case checking */
59 /***************************************************/
60 /* If past expiration, option is worthless */
61 if TimeToExpiration < 0 then return(0);
62 /* Initialize the return missing flag to zero (state: no error found)
63 If we find an error in one of the inputs, we will return missing */
64 /* Set the function name for error reporting */
65 ReturnMissingFlg = 0;
66 Fname = 'rsk_binary_barrieroption_pf';
67 /* Check that nonoptional inputs are nonmissing */
68 ReturnMissingFlg = rsk_check_num_missing_pf( RiskFreeRate, Fname, '11', 'RiskFreeRate', ReturnMissingFlg );
69 ReturnMissingFlg = rsk_check_num_missing_pf( YieldParam, Fname, '12', 'YieldParam', ReturnMissingFlg );
70 /* Make sure some input values are positive */
71 /* Nonpositive or missing values for these variables may cause problems
72 if input into another function (e.g. the logarithm function) */
73 ReturnMissingFlg = rsk_check_nonpositive_pf( Price, Fname, '5', 'Price', ReturnMissingFlg );
74 ReturnMissingFlg = rsk_check_nonpositive_pf( Barrier, Fname, '9', 'Barrier', ReturnMissingFlg );
75 ReturnMissingFlg = rsk_check_nonpositive_pf( Volatility, Fname, '14', 'Volatility', ReturnMissingFlg );
76 /* Return missing, if errors are found */
77 if ReturnMissingFlg eq 1 then return(.);
78 /* Adjusting casing for character inputs */
79 BarrType = lowcase(BarrierType);
80 SettleType = upcase(SettlementType);
81 /* Return payoff at maturity */
82 if TimeToexpiration eq 0 then do;
83 /* Set the payoff */
84 if ( upcase(CallPutType) eq 'CALL' and Price > Strike ) or ( upcase(CallPutType) eq 'PUT' and Price < Strike ) or ( upcase(CallPutType) not in ( 'CALL', 'PUT' ) ) then
85 do;
86 if SettleType eq 'CASH' then Payoff = Cash_Amt;
87 else
88 Payoff = Price;
89 end;
90 else
91 return(0);
92 if min(Price,Price_Chk_Barrier_Down) < Barrier then do;
93 if BarrType eq 'ui' then return(0);
94 if BarrType eq 'uo' then return(Payoff);
95 if BarrType eq 'di' then return(Payoff);
96 if BarrType eq 'do' then return(0);
97 end;
98 else
99 if max(Price,Price_Chk_Barrier_Up) > Barrier then do;
100 if BarrType eq 'ui' then return(Payoff);
101 if BarrType eq 'uo' then return(0);
102 if BarrType eq 'di' then return(0);
103 if BarrType eq 'do' then return(Payoff);
104 end;
105 else
106 do;
107 if BarrType eq 'ui' then return(Payoff);
108 if BarrType eq 'uo' then return(0);
109 if BarrType eq 'di' then return(Payoff);
110 if BarrType eq 'do' then return(0);
111 end;
112 end;
113 /************************************************************/
114 /* RESUME STANDARD PRICING */
115 /************************************************************/
116 /* BINARY_BARRIERTYPE CODES (not used anymore, but here for reference):
117 1: DOWN AND IN cash at hit or nothing
118 2: UP AND IN cash at hit or nothing
119 3: DOWN AND IN asset at hit or nothing
120 4: UP AND IN asset at hit or nothing
121 5: DOWN AND IN cash at expiration or nothing
122 6: UP AND IN cash at expiration or nothing
123 7: DOWN AND IN asset at expiration or nothing
124 8: UP AND IN asset at expiration or nothing
125 9: DOWN AND OUT cash or nothing
126 10: UP AND OUT cash or nothing
127 11: DOWN AND OUT asset ot nothing
128 12: UP AND OUT asset or nothing
129 13: DOWN AND IN cash or nothing call
130 14: UP AND IN cash or nothing call
131 15: DOWN AND IN asset or nothing call
132 16: UP AND IN asset or nothing call
133 17: DOWN AND IN cash or nothing put
134 18: UP AND IN cash or nothing put
135 19: DOWN AND IN asset or nothing put
136 20: UP AND IN asset or nothing put
137 21: DOWN AND OUT cash ornothing call
138 22: UP AND OUT cash or nothing call
139 23: DOWN AND OUT asset or nothing call
140 24: UP AND OUT asset or nothing call
141 25: DOWN AND OUT cash or nothing put
142 26: UP AND OUT cash or nothing put
143 27: DOWN AND OUT asset or nothing put
144 28: UP AND OUT asset or nothing put
145 */
146 /* Set cost of carry, phi and eta */
147 CostofCarry=RiskFreeRate - YieldParam;
148 if upcase(CallPutType) not in ( 'CALL', 'PUT' ) then do;
149 IF BarrType eq 'di' and SettleType eq 'CASH' and PayAtHitFlg eq 1 THEN DO;
150/*1 */
151 _fi_=1;
152 _eta_=1;
153 END;
154 ELSE
155 IF BarrType eq 'ui' and SettleType eq 'CASH' and PayAtHitFlg eq 1 THEN DO;
156/*2 */
157 _fi_=1;
158 _eta_=-1;
159 END;
160 ELSE
161 IF BarrType eq 'di' and SettleType ne 'CASH' and PayAtHitFlg eq 1 THEN DO;
162/*3 */
163 _fi_=1;
164 _eta_=1;
165 END;
166 ELSE
167 IF BarrType eq 'ui' and SettleType ne 'CASH' and PayAtHitFlg eq 1 THEN DO;
168/*4 */
169 _fi_=1;
170 _eta_=-1;
171 END;
172 ELSE
173 IF BarrType eq 'di' and SettleType eq 'CASH' and PayAtHitFlg ne 1 THEN DO;
174/*5 */
175 _fi_=-1;
176 _eta_=1;
177 END;
178 ELSE
179 IF BarrType eq 'ui' and SettleType eq 'CASH' and PayAtHitFlg ne 1 THEN DO;
180/*6 */
181 _fi_=1;
182 _eta_=-1;
183 END;
184 ELSE
185 IF BarrType eq 'di' and SettleType ne 'CASH' and PayAtHitFlg ne 1 THEN DO;
186/*7 */
187 _fi_=-1;
188 _eta_=1;
189 END;
190 ELSE
191 IF BarrType eq 'ui' and SettleType ne 'CASH' and PayAtHitFlg ne 1 THEN DO;
192/*8 */
193 _fi_=1;
194 _eta_=-1;
195 END;
196 ELSE
197 IF BarrType eq 'do' and SettleType eq 'CASH' THEN DO;
198 /* 9 */
199 _fi_=1;
200 _eta_=1;
201 END;
202 ELSE
203 IF BarrType eq 'uo' and SettleType eq 'CASH' THEN DO;
204 /* 10 */
205 _fi_=-1;
206 _eta_=-1;
207 END;
208 ELSE
209 IF BarrType eq 'do' and SettleType ne 'CASH' THEN DO;
210 /* 11 */
211 _fi_=1;
212 _eta_=1;
213 END;
214 ELSE
215 IF BarrType eq 'uo' and SettleType ne 'CASH' THEN DO;
216 /* 12 */
217 _fi_=-1;
218 _eta_=-1;
219 END;
220 ELSE
221 return(.);
222 end;
223 else
224 do;
225 if upcase(CallPutType) eq 'CALL' then do;
226 IF BarrType eq 'di' and SettleType eq 'CASH' THEN DO;
227 /* 13 */
228 _fi_=1;
229 _eta_=1;
230 END;
231 ELSE
232 IF BarrType eq 'ui' and SettleType eq 'CASH' THEN DO;
233 /* 14 */
234 _fi_=1;
235 _eta_=-1;
236 END;
237 ELSE
238 IF BarrType eq 'di' and SettleType ne 'CASH' THEN DO;
239 /* 15 */
240 _fi_=1;
241 _eta_=1;
242 END;
243 ELSE
244 IF BarrType eq 'ui' and SettleType ne 'CASH' THEN DO;
245 /* 16 */
246 _fi_=1;
247 _eta_=-1;
248 END;
249 ELSE
250 IF BarrType eq 'do' and SettleType eq 'CASH' THEN DO;
251 /* 21 */
252 _fi_=1;
253 _eta_=1;
254 END;
255 ELSE
256 IF BarrType eq 'uo' and SettleType eq 'CASH' THEN DO;
257 /* 22 */
258 _fi_=1;
259 _eta_=-1;
260 END;
261 ELSE
262 IF BarrType eq 'do' and SettleType ne 'CASH' THEN DO;
263 /* 23 */
264 _fi_=1;
265 _eta_=1;
266 END;
267 ELSE
268 IF BarrType eq 'uo' and SettleType ne 'CASH' THEN DO;
269 /* 24 */
270 _fi_=1;
271 _eta_=-1;
272 END;
273 ELSE
274 return (.);
275 end;
276 else
277 do;
278 /* PUT */
279 IF BarrType eq 'di' and SettleType eq 'CASH' THEN DO;
280 /* 17 */
281 _fi_=-1;
282 _eta_=1;
283 END;
284 ELSE
285 IF BarrType eq 'ui' and SettleType eq 'CASH' THEN DO;
286 /* 18 */
287 _fi_=-1;
288 _eta_=-1;
289 END;
290 ELSE
291 IF BarrType eq 'di' and SettleType ne 'CASH' THEN DO;
292 /* 19 */
293 _fi_=-1;
294 _eta_=1;
295 END;
296 ELSE
297 IF BarrType eq 'ui' and SettleType ne 'CASH' THEN DO;
298 /* 20 */
299 _fi_=-1;
300 _eta_=-1;
301 END;
302 ELSE
303 IF BarrType eq 'do' and SettleType eq 'CASH' THEN DO;
304 /* 25 */
305 _fi_=-1;
306 _eta_=1;
307 END;
308 ELSE
309 IF BarrType eq 'uo' and SettleType eq 'CASH' THEN DO;
310 /* 26 */
311 _fi_ = -1;
312 /* _fi_=1; correct typo - be sure this is correct */
313 _eta_=-1;
314 END;
315 ELSE
316 IF BarrType eq 'do' and SettleType ne 'CASH' THEN DO;
317 /* 27 */
318 _fi_=-1;
319 _eta_=1;
320 END;
321 ELSE
322 IF BarrType eq 'uo' and SettleType ne 'CASH' THEN DO;
323 /* 28 */
324 _fi_=-1;
325 _eta_=-1;
326 END;
327 ELSE
328 return(.);
329 end;
330 end;
331 /* Calculate constants used in pricing */
332 _mu_=(CostofCarry - ((volatility*volatility)/2) ) / (volatility*volatility);
333 _lambda_=sqrt( _mu_*_mu_ + ((2*RiskFreeRate)/(volatility*volatility)));
334 x1=(log(Price/Strike) / (volatility*sqrt(TimeToExpiration))) + (_mu_+1)* volatility*sqrt(TimeToExpiration);
335 x2=(log(Price/Barrier) / (volatility*sqrt(TimeToExpiration))) + (_mu_+1)* volatility*sqrt(TimeToExpiration);
336 y1=(log((Barrier*Barrier)/(Strike*Price)) / (volatility*sqrt( TimeToExpiration))) + (_mu_+1)*volatility*sqrt(TimeToExpiration);
337 y2=(log(Barrier/Price) / (volatility*sqrt(TimeToExpiration))) + (_mu_+1)* volatility*sqrt(TimeToExpiration);
338 z=(log(Barrier/Price) / (volatility*sqrt(TimeToExpiration))) + (_lambda_)* volatility*sqrt(TimeToExpiration);
339 A1=Price * exp((CostofCarry - RiskFreeRate)*(TimeToExpiration)) * probnorm(_fi_*x1);
340 B1=Cash_Amt * exp(- RiskFreeRate*(TimeToExpiration)) * probnorm(_fi_*x1 - _fi_*volatility*sqrt(TimeToExpiration));
341 A2=Price * exp((CostofCarry - RiskFreeRate)*(TimeToExpiration)) * probnorm(_fi_*x2);
342 B2=Cash_Amt * exp(- RiskFreeRate*(TimeToExpiration)) * probnorm(_fi_*x2 - _fi_*volatility*sqrt(TimeToExpiration));
343 A3=Price * exp((CostofCarry - RiskFreeRate)*(TimeToExpiration)) * probnorm(_eta_*y1) * ( (Barrier/Price)**(2*_mu_+2) ) ;
344 B3=Cash_Amt * exp(- RiskFreeRate*(TimeToExpiration)) * probnorm(_eta_*y1 - _eta_*volatility*sqrt(TimeToExpiration)) * ( (Barrier/Price)**(2* _mu_) );
345 A4=Price * exp((CostofCarry - RiskFreeRate)*(TimeToExpiration)) * probnorm(_eta_*y2) * ( (Barrier/Price)**(2*_mu_+2) ) ;
346 B4=Cash_Amt * exp(- RiskFreeRate*(TimeToExpiration)) * probnorm(_eta_*y2 - _eta_*volatility*sqrt(TimeToExpiration)) * ( (Barrier/Price)**(2* _mu_) );
347 A56 = ( ( (Barrier/Price)**(_mu_ + _lambda_) ) * probnorm(_eta_*z) + ( (Barrier/Price)**(_mu_ - _lambda_) ) * probnorm(_eta_*z - 2*_eta_*_lambda_*volatility*sqrt(TimeToExpiration)) );
348 A5 = Cash_Amt * A56;
349 A6 = Barrier * A56;
350 /* this is for asset at-hit */
351 /* Price the option, checking for breached barriers */
352 if upcase(CallPutType) not in ( 'CALL', 'PUT' ) then do;
353 IF BarrType eq 'di' and SettleType eq 'CASH' and PayAtHitFlg eq 1 THEN DO;
354/*1 */
355 OptionPrice=A5;
356 IF Price_Chk_Barrier_Down le Barrier THEN DO;
357 /* down and in Cash at hit */
358 OptionPrice=Cash_Amt;
359 END;
360 END;
361 ELSE
362 IF BarrType eq 'ui' and SettleType eq 'CASH' and PayAtHitFlg eq 1 THEN DO;
363/*2 */
364 OptionPrice=A5;
365 IF Price_Chk_Barrier_Up ge Barrier THEN DO;
366 /* up and in Cash at hit */
367 OptionPrice=Cash_Amt;
368 END;
369 END;
370 ELSE
371 IF BarrType eq 'di' and SettleType ne 'CASH' and PayAtHitFlg eq 1 THEN DO;
372/*3 */
373 OptionPrice=A6;
374 IF Price_Chk_Barrier_Down le Barrier THEN DO;
375 /* down and in asset at hit */
376 OptionPrice=Price;
377 END;
378 END;
379 ELSE
380 IF BarrType eq 'ui' and SettleType ne 'CASH' and PayAtHitFlg eq 1 THEN DO;
381/*4 */
382 OptionPrice=A6;
383 IF Price_Chk_Barrier_Up ge Barrier THEN DO;
384 /* up and in asset at hit */
385 OptionPrice=Price;
386 END;
387 END;
388 ELSE
389 IF BarrType eq 'di' and SettleType eq 'CASH' and PayAtHitFlg ne 1 THEN DO;
390/*5 */
391 OptionPrice=B2+B4;
392 IF Price_Chk_Barrier_Down le Barrier THEN DO;
393 /* down and in Cash at expiration */
394 OptionPrice=Cash_Amt*exp(-RiskFreeRate*TimeToExpiration);
395 END;
396 END;
397 ELSE
398 IF BarrType eq 'ui' and SettleType eq 'CASH' and PayAtHitFlg ne 1 THEN DO;
399/*6 */
400 OptionPrice=B2+B4;
401 IF Price_Chk_Barrier_Up ge Barrier THEN DO;
402 /* up and in Cash at expiration */
403 OptionPrice=Cash_Amt*exp(-RiskFreeRate*TimeToExpiration);
404 END;
405 END;
406 ELSE
407 IF BarrType eq 'di' and SettleType ne 'CASH' and PayAtHitFlg ne 1 THEN DO;
408/*7 */
409 OptionPrice=A2+A4;
410 IF Price_Chk_Barrier_Down le Barrier THEN DO;
411 /* down and in asset at expiration */
412 OptionPrice=Price*exp(-YieldParam*TimeToExpiration);
413 END;
414 END;
415 ELSE
416 IF BarrType eq 'ui' and SettleType ne 'CASH' and PayAtHitFlg ne 1 THEN DO;
417/*8 */
418 OptionPrice=A2+A4;
419 IF Price_Chk_Barrier_Up ge Barrier THEN DO;
420 /* up and in asset at expiration */
421 OptionPrice=Price*exp(-YieldParam*TimeToExpiration);
422 END;
423 END;
424 ELSE
425 IF BarrType eq 'do' and SettleType eq 'CASH' THEN DO;
426 /* 9 */
427 OptionPrice=B2-B4;
428 IF Price_Chk_Barrier_Down le Barrier THEN DO;
429 /* down and out */
430 OptionPrice=0;
431 END;
432 END;
433 ELSE
434 IF BarrType eq 'uo' and SettleType eq 'CASH' THEN DO;
435 /* 10 */
436 OptionPrice=B2-B4;
437 IF Price_Chk_Barrier_Up ge Barrier THEN DO;
438 /* up and out */
439 OptionPrice=0;
440 END;
441 END;
442 ELSE
443 IF BarrType eq 'do' and SettleType ne 'CASH' THEN DO;
444 /* 11 */
445 OptionPrice=A2-A4;
446 IF Price_Chk_Barrier_Down le Barrier THEN DO;
447 /* down and out */
448 OptionPrice=0;
449 END;
450 END;
451 ELSE
452 IF BarrType eq 'uo' and SettleType ne 'CASH' THEN DO;
453 /* 12 */
454 OptionPrice=A2-A4;
455 IF Price_Chk_Barrier_Up ge Barrier THEN DO;
456 /* up and out */
457 OptionPrice=0;
458 END;
459 END;
460 end;
461 else
462 do;
463 if upcase(CallPutType) eq 'CALL' then do;
464 IF BarrType eq 'di' and SettleType eq 'CASH' THEN DO;
465 /* 13 */
466 IF Strike ge Barrier THEN DO;
467 OptionPrice=B3;
468 END;
469 ELSE
470 DO;
471 OptionPrice=B1-B2+B4;
472 END;
473 IF Price_Chk_Barrier_Down le Barrier THEN DO;
474 /* down and in cash AT EXPIRATION */
475 OptionPrice = rsk_binary_cash_option_pf( CallPutType, Price, Cash_Amt, Strike, RiskFreeRate, YieldParam, TimeToExpiration, Volatility );
476 END;
477 END;
478 ELSE
479 IF BarrType eq 'ui' and SettleType eq 'CASH' THEN DO;
480 /* 14 */
481 IF Strike ge Barrier THEN DO;
482 OptionPrice=B1;
483 END;
484 ELSE
485 DO;
486 OptionPrice=B2-B3+B4;
487 END;
488 IF Price_Chk_Barrier_Up ge Barrier THEN DO;
489 /* up and in cash AT EXPIRATION */
490 OptionPrice = rsk_binary_cash_option_pf( CallPutType, Price, Cash_Amt, Strike, RiskFreeRate, YieldParam, TimeToExpiration, Volatility );
491 END;
492 END;
493 ELSE
494 IF BarrType eq 'di' and SettleType ne 'CASH' THEN DO;
495 /* 15 */
496 IF Strike ge Barrier THEN DO;
497 OptionPrice=A3;
498 END;
499 ELSE
500 DO;
501 OptionPrice=A1-A2+A4;
502 END;
503 IF Price_Chk_Barrier_Down le Barrier THEN DO;
504 /* down and in asset AT EXPIRATION */
505 OptionPrice = rsk_binary_asset_option_pf( CallPutType, Price, Strike, RiskFreeRate, YieldParam, TimeToExpiration, Volatility );
506 END;
507 END;
508 ELSE
509 IF BarrType eq 'ui' and SettleType ne 'CASH' THEN DO;
510 /* 16 */
511 IF Strike ge Barrier THEN DO;
512 OptionPrice=A1;
513 END;
514 ELSE
515 DO;
516 OptionPrice=A2-A3+A4;
517 END;
518 IF Price_Chk_Barrier_Up ge Barrier THEN DO;
519 /* up and in asset AT EXPIRATION */
520 OptionPrice = rsk_binary_asset_option_pf( CallPutType, Price, Strike, RiskFreeRate, YieldParam, TimeToExpiration, Volatility );
521 END;
522 END;
523 ELSE
524 IF BarrType eq 'do' and SettleType eq 'CASH' THEN DO;
525 /* 21 */
526 IF Strike ge Barrier THEN DO;
527 OptionPrice=B1-B3;
528 END;
529 ELSE
530 DO;
531 OptionPrice=B2-B4;
532 END;
533 IF Price_Chk_Barrier_Down le Barrier THEN DO;
534 /* down and out */
535 OptionPrice=0;
536 END;
537 END;
538 ELSE
539 IF BarrType eq 'uo' and SettleType eq 'CASH' THEN DO;
540 /* 22 */
541 IF Strike ge Barrier THEN DO;
542 OptionPrice=0;
543 END;
544 ELSE
545 DO;
546 OptionPrice=B1-B2+B3-B4;
547 END;
548 IF Price_Chk_Barrier_Up ge Barrier THEN DO;
549 /* up and out */
550 OptionPrice=0;
551 END;
552 END;
553 ELSE
554 IF BarrType eq 'do' and SettleType ne 'CASH' THEN DO;
555 /* 23 */
556 IF Strike ge Barrier THEN DO;
557 OptionPrice=A1-A3;
558 END;
559 ELSE
560 DO;
561 OptionPrice=A2-A4;
562 END;
563 IF Price_Chk_Barrier_Down le Barrier THEN DO;
564 /* down and out */
565 OptionPrice=0;
566 END;
567 END;
568 ELSE
569 IF BarrType eq 'uo' and SettleType ne 'CASH' THEN DO;
570 /* 24 */
571 IF Strike ge Barrier THEN DO;
572 OptionPrice=0;
573 END;
574 ELSE
575 DO;
576 OptionPrice=A1-A2+A3-A4;
577 END;
578 IF Price_Chk_Barrier_Up ge Barrier THEN DO;
579 /* up and out */
580 OptionPrice=0;
581 END;
582 END;
583 end;
584 else
585 do;
586 /* PUT */
587 IF BarrType eq 'di' and SettleType eq 'CASH' THEN DO;
588 /* 17 */
589 IF Strike ge Barrier THEN DO;
590 OptionPrice=B2-B3+B4;
591 END;
592 ELSE
593 DO;
594 OptionPrice=B1;
595 END;
596 IF Price_Chk_Barrier_Down le Barrier THEN DO;
597 /* down and in cash AT EXPIRATION */
598 OptionPrice = rsk_binary_cash_option_pf( CallPutType, Price, Cash_Amt, Strike, RiskFreeRate, YieldParam, TimeToExpiration, Volatility );
599 END;
600 END;
601 ELSE
602 IF BarrType eq 'ui' and SettleType eq 'CASH' THEN DO;
603 /* 18 */
604 IF Strike ge Barrier THEN DO;
605 OptionPrice=B1-B2+B4;
606 END;
607 ELSE
608 DO;
609 OptionPrice=B3;
610 END;
611 IF Price_Chk_Barrier_Up ge Barrier THEN DO;
612 /* up and in cash AT EXPIRATION */
613 OptionPrice = rsk_binary_cash_option_pf( CallPutType, Price, Cash_Amt, Strike, RiskFreeRate, YieldParam, TimeToExpiration, Volatility );
614 END;
615 END;
616 ELSE
617 IF BarrType eq 'di' and SettleType ne 'CASH' THEN DO;
618 /* 19 */
619 IF Strike ge Barrier THEN DO;
620 OptionPrice=A2-A3+A4;
621 END;
622 ELSE
623 DO;
624 OptionPrice=A1;
625 END;
626 IF Price_Chk_Barrier_Down le Barrier THEN DO;
627 /* down and in asset AT EXPIRATION */
628 OptionPrice = rsk_binary_asset_option_pf( CallPutType, Price, Strike, RiskFreeRate, YieldParam, TimeToExpiration, Volatility );
629 END;
630 END;
631 ELSE
632 IF BarrType eq 'ui' and SettleType ne 'CASH' THEN DO;
633 /* 20 */
634 IF Strike ge Barrier THEN DO;
635 OptionPrice=A1-A2+A3;
636 END;
637 ELSE
638 DO;
639 OptionPrice=A4;
640 END;
641 IF Price_Chk_Barrier_Up ge Barrier THEN DO;
642 /* up and in asset AT EXPIRATION */
643 OptionPrice = rsk_binary_asset_option_pf( CallPutType, Price, Strike, RiskFreeRate, YieldParam, TimeToExpiration, Volatility );
644 END;
645 END;
646 ELSE
647 IF BarrType eq 'do' and SettleType eq 'CASH' THEN DO;
648 /* 25 */
649 IF Strike ge Barrier THEN DO;
650 OptionPrice=B1-B2+B3-B4;
651 END;
652 ELSE
653 DO;
654 OptionPrice=0;
655 END;
656 IF Price_Chk_Barrier_Down le Barrier THEN DO;
657 /* down and out */
658 OptionPrice=0;
659 END;
660 END;
661 ELSE
662 IF BarrType eq 'uo' and SettleType eq 'CASH' THEN DO;
663 /* 26 */
664 IF Strike ge Barrier THEN DO;
665 OptionPrice=B2-B4;
666 END;
667 ELSE
668 DO;
669 OptionPrice=B1-B3;
670 END;
671 IF Price_Chk_Barrier_Up ge Barrier THEN DO;
672 /* up and out */
673 OptionPrice=0;
674 END;
675 END;
676 ELSE
677 IF BarrType eq 'do' and SettleType ne 'CASH' THEN DO;
678 /* 27 */
679 IF Strike ge Barrier THEN DO;
680 OptionPrice=A1-A2+A3-A4;
681 END;
682 ELSE
683 DO;
684 OptionPrice=0;
685 END;
686 IF Price_Chk_Barrier_Down le Barrier THEN DO;
687 /* down and out */
688 OptionPrice=0;
689 END;
690 END;
691 ELSE
692 IF BarrType eq 'uo' and SettleType ne 'CASH' THEN DO;
693 /* 28 */
694 IF Strike ge Barrier THEN DO;
695 OptionPrice=A2-A4;
696 END;
697 ELSE
698 DO;
699 OptionPrice=A1-A3;
700 END;
701 IF Price_Chk_Barrier_Up ge Barrier THEN DO;
702 /* up and out */
703 OptionPrice=0;
704 END;
705 END;
706 end;
707 end;
708 return(OptionPrice);
709
710 endsub;
711
712
713 %mend;