tarf_monte_carlo 3.56 → 3.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/tarf_monte_carlo/tarf_monte_carlo.c +46 -8
- data/lib/tarf_monte_carlo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37cf728f754098494cffed6ce0f9f8c3dde4e593702a748cdc8bca2d1c5182cd
|
4
|
+
data.tar.gz: 76e9c21b88d3ecb5925c525420fc704fcf8e8cf992b2db3bd9f4367c1d20396c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb5a2d931a8ea07cf8fa49b2ca4ef2341474fbf59431b2fb16c8188df43018c146fd70dbb0f907ce921657b01aca8c4e35600ded2075e5bd16d2435619565671
|
7
|
+
data.tar.gz: 490bacf7090a637d5c3b9f54176c80d5419f13f5b8e4320634977bc1815b3f8430dca1072c347b07b268cdec0fc152959e7d4d2f4d459dc0a3c6164516ffb5b5
|
@@ -49,6 +49,8 @@
|
|
49
49
|
#define FX_AMERICAN_BARRIER_KIKO_UNTIL_KI 18
|
50
50
|
#define FX_AMERICAN_BARRIER_BINARY_IN_DISCRETE 19
|
51
51
|
#define FX_AMERICAN_BARRIER_BINARY_OUT_DISCRETE 20
|
52
|
+
#define FX_AMERICAN_BARRIER_BINARY_CALLPUT_IN_DISCRETE 21
|
53
|
+
#define FX_AMERICAN_BARRIER_BINARY_CALLPUT_OUT_DISCRETE 22
|
52
54
|
|
53
55
|
#define DATAPOINTS 200 // data for plotting
|
54
56
|
#define BARRIER_DP 4 // data for plotting
|
@@ -107,7 +109,7 @@ double get_equivalent_rebate(int conversion_sign, double rebate, float rate, int
|
|
107
109
|
}
|
108
110
|
|
109
111
|
bool barrier_variations(int KType){
|
110
|
-
return (KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE || KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE || KType == FX_AMERICAN_BARRIER_WINDOW_KNOCKIN || KType == FX_AMERICAN_BARRIER_WINDOW_KNOCKOUT || KType == FX_AMERICAN_BARRIER_KIKO_UNTIL_EXP || KType == FX_AMERICAN_BARRIER_KIKO_UNTIL_KI || KType == FX_AMERICAN_BARRIER_BINARY_IN_DISCRETE || KType == FX_AMERICAN_BARRIER_BINARY_OUT_DISCRETE);
|
112
|
+
return (KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE || KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE || KType == FX_AMERICAN_BARRIER_WINDOW_KNOCKIN || KType == FX_AMERICAN_BARRIER_WINDOW_KNOCKOUT || KType == FX_AMERICAN_BARRIER_KIKO_UNTIL_EXP || KType == FX_AMERICAN_BARRIER_KIKO_UNTIL_KI || KType == FX_AMERICAN_BARRIER_BINARY_IN_DISCRETE || KType == FX_AMERICAN_BARRIER_BINARY_OUT_DISCRETE || KType == FX_AMERICAN_BARRIER_BINARY_CALLPUT_IN_DISCRETE || KType == FX_AMERICAN_BARRIER_BINARY_CALLPUT_OUT_DISCRETE);
|
111
113
|
}
|
112
114
|
|
113
115
|
bool double_barrier_variations(int KType){
|
@@ -268,7 +270,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
268
270
|
Spot = Spot * exp( drift + vSqrdt * eps );
|
269
271
|
Spot_dash = Spot_dash * exp( drift + vSqrdt * eps_dash );
|
270
272
|
|
271
|
-
if(KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE || KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE || KType == FX_AMERICAN_BARRIER_BINARY_IN_DISCRETE || KType == FX_AMERICAN_BARRIER_BINARY_OUT_DISCRETE){
|
273
|
+
if(KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE || KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE || KType == FX_AMERICAN_BARRIER_BINARY_IN_DISCRETE || KType == FX_AMERICAN_BARRIER_BINARY_OUT_DISCRETE || KType == FX_AMERICAN_BARRIER_BINARY_CALLPUT_IN_DISCRETE || KType == FX_AMERICAN_BARRIER_BINARY_CALLPUT_OUT_DISCRETE){
|
272
274
|
profit_loss = Spot;
|
273
275
|
profit_loss_dash = Spot_dash;
|
274
276
|
|
@@ -472,23 +474,59 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
472
474
|
metrics[1][point_pos+1] = (knockedLeg_dash >= 0) ? ( *( Xs_array + (knockedLeg_dash) ) ) : 0;
|
473
475
|
metrics[3][point_pos+1] = knockedLeg_dash;
|
474
476
|
}
|
475
|
-
} else if(KType == FX_AMERICAN_BARRIER_BINARY_IN_DISCRETE){
|
477
|
+
} else if(KType == FX_AMERICAN_BARRIER_BINARY_IN_DISCRETE || KType == FX_AMERICAN_BARRIER_BINARY_CALLPUT_IN_DISCRETE){
|
476
478
|
if(knockedLeg >= 0){
|
477
479
|
int legIndex = (CP == 2) ? knockedLeg : (NL - 1);
|
478
|
-
|
480
|
+
int itm = true;
|
481
|
+
if (CP <= 1){
|
482
|
+
double tempPayOff = european_payoff(( *( Xs_array + legIndex ) ), sim[NL-1], cp_sign, dir_sign, 1);
|
483
|
+
if(tempPayOff == 0){
|
484
|
+
itm = false;
|
485
|
+
}
|
486
|
+
}
|
487
|
+
if (itm){
|
488
|
+
sim_pos[legIndex] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim[legIndex], dir_sign);
|
489
|
+
}
|
479
490
|
}
|
480
491
|
|
481
492
|
if(knockedLeg_dash >= 0){
|
482
493
|
int legIndex_dash = (CP == 2) ? knockedLeg_dash : (NL - 1);
|
483
|
-
|
494
|
+
int itm = true;
|
495
|
+
if (CP <= 1){
|
496
|
+
double tempPayOff = european_payoff(( *( Xs_array + legIndex_dash ) ), sim_dash[NL-1], cp_sign, dir_sign, 1);
|
497
|
+
if(tempPayOff == 0){
|
498
|
+
itm = false;
|
499
|
+
}
|
500
|
+
}
|
501
|
+
if (itm){
|
502
|
+
sim_dash_pos[legIndex_dash] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim_dash[legIndex_dash], dir_sign);
|
503
|
+
}
|
484
504
|
}
|
485
|
-
} else if(KType == FX_AMERICAN_BARRIER_BINARY_OUT_DISCRETE){
|
505
|
+
} else if(KType == FX_AMERICAN_BARRIER_BINARY_OUT_DISCRETE || KType == FX_AMERICAN_BARRIER_BINARY_CALLPUT_OUT_DISCRETE){
|
486
506
|
if(knockedLeg == -1){
|
487
|
-
|
507
|
+
int itm = true;
|
508
|
+
if (CP <= 1){
|
509
|
+
double tempPayOff = european_payoff(( *( Xs_array + 0 ) ), sim[NL-1], cp_sign, dir_sign, 1);
|
510
|
+
if(tempPayOff == 0){
|
511
|
+
itm = false;
|
512
|
+
}
|
513
|
+
}
|
514
|
+
if (itm){
|
515
|
+
sim_pos[NL - 1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim[NL - 1], dir_sign);
|
516
|
+
}
|
488
517
|
}
|
489
518
|
|
490
519
|
if(knockedLeg_dash == -1){
|
491
|
-
|
520
|
+
int itm = true;
|
521
|
+
if (CP <= 1){
|
522
|
+
double tempPayOff = european_payoff(( *( Xs_array + 0 ) ), sim_dash[NL-1], cp_sign, dir_sign, 1);
|
523
|
+
if(tempPayOff == 0){
|
524
|
+
itm = false;
|
525
|
+
}
|
526
|
+
}
|
527
|
+
if (itm){
|
528
|
+
sim_dash_pos[NL - 1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim_dash[NL - 1], dir_sign);
|
529
|
+
}
|
492
530
|
}
|
493
531
|
} else if(KType == FX_AMERICAN_BARRIER_KIKO_UNTIL_EXP){
|
494
532
|
if(knockedLeg2 >= 0){
|