tarf_monte_carlo 3.37 → 3.38
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/tarf_monte_carlo/tarf_monte_carlo.c +28 -3
- 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: f6cb2b1cffe291ac211ef3517133affc4d62c2368f815a08a502a56650aee788
|
4
|
+
data.tar.gz: b17cfb2cce1123ab4c363d08a2eb214d14530d11249ed757c52e938bebacb38f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb8b79a26f30802f2016981c4a96d68c193c794a76bd5b7b2f4f24d8805d0afc72150440b17b182898508a2cbc25675c7bba3bbc67288edec0aa8b8270c78bbc
|
7
|
+
data.tar.gz: bbe9daf65b7c7197fe76a4f2542ea422340399e2d8c46e4169d303f1da8475f2eef33e19b2e2f706fd3c3ef79de588fc3ebce5228c95be0afcc8bd6610522282
|
@@ -194,6 +194,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
194
194
|
// first create a 1-D array of pointers, and then, for each array entry, create another 1-D array.
|
195
195
|
//
|
196
196
|
double **metrics;
|
197
|
+
double data[SCount][5];
|
197
198
|
metrics = ( double** ) malloc( DATAPOINTS * sizeof(double*) );
|
198
199
|
for( metric = 0; metric < DATAPOINTS; metric++ ) {
|
199
200
|
metrics[metric] = ( double* ) malloc( NL * sizeof(double) );
|
@@ -209,6 +210,18 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
209
210
|
double Spot = S, Spot_dash = S;
|
210
211
|
double sim[NL], sim_pos[NL], sim_neg[NL], sim_dash[NL], sim_dash_pos[NL], sim_dash_neg[NL];
|
211
212
|
|
213
|
+
data[sim_count][0] = 0;
|
214
|
+
data[sim_count][1] = 0;
|
215
|
+
data[sim_count][2] = 0;
|
216
|
+
data[sim_count][3] = 0;
|
217
|
+
data[sim_count][4] = 0;
|
218
|
+
|
219
|
+
data[sim_count + 1][0] = 0;
|
220
|
+
data[sim_count + 1][1] = 0;
|
221
|
+
data[sim_count + 1][2] = 0;
|
222
|
+
data[sim_count + 1][3] = 0;
|
223
|
+
data[sim_count + 1][4] = 0;
|
224
|
+
|
212
225
|
// reset all simulation leg specific results
|
213
226
|
for ( leg = 0; leg < NL; ++leg ) {
|
214
227
|
sim[leg] = 0.0;
|
@@ -407,17 +420,29 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
407
420
|
} else if(KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE){
|
408
421
|
if(knockedLeg >= 0){
|
409
422
|
sim_pos[knockedLeg] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + knockedLeg ) ), sim[knockedLeg], dir_sign);
|
423
|
+
data[sim_count][1] = sim_pos[knockedLeg];
|
424
|
+
data[sim_count][3] = sim_pos[knockedLeg];
|
425
|
+
data[sim_count][5] = sim[knockedLeg];
|
410
426
|
}
|
411
427
|
else{
|
412
428
|
double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + 0 ) ), sim[NL-1]);
|
429
|
+
data[sim_count][0] = equivalent_notional;
|
413
430
|
sim_pos[NL-1] = european_payoff(( *( Xs_array + 0 ) ), sim[NL-1], cp_sign, dir_sign, equivalent_notional);
|
431
|
+
data[sim_count][2] = sim_pos[NL-1];
|
432
|
+
data[sim_count][5] = sim[NL-1];
|
414
433
|
}
|
415
434
|
if(knockedLeg_dash >= 0 ){
|
416
435
|
sim_dash_pos[knockedLeg_dash] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + knockedLeg_dash ) ), sim[knockedLeg_dash], dir_sign);
|
436
|
+
data[sim_count + 1][1] = sim_dash_pos[knockedLeg_dash];
|
437
|
+
data[sim_count + 1][3] = sim_dash_pos[knockedLeg_dash];
|
438
|
+
data[sim_count + 1][5] = sim[knockedLeg_dash];
|
417
439
|
}
|
418
440
|
else{
|
419
441
|
double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + 0 ) ), sim_dash[NL-1]);
|
442
|
+
data[sim_count + 1][0] = equivalent_notional;
|
420
443
|
sim_dash_pos[NL-1] = european_payoff(( *( Xs_array + 0 ) ), sim_dash[NL-1], cp_sign, dir_sign, equivalent_notional);
|
444
|
+
data[sim_count + 1][2] = sim_dash_pos[NL-1];
|
445
|
+
data[sim_count + 1][5] = sim[NL-1];
|
421
446
|
}
|
422
447
|
} else if( KType == ABSOLUTE || KType == PIVOT_ABSOLUTE || KType == COLLAR_ABSOLUTE || KType == DOUBLE_STRIKE_ABSOLUTE ) {
|
423
448
|
for( leg = 0; leg < NL; ++leg ) {
|
@@ -585,11 +610,11 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
585
610
|
//
|
586
611
|
// rb_p(rb_str_new2("Converting metrics"));
|
587
612
|
VALUE final_metrics = rb_ary_new();
|
588
|
-
for(metric = 0; metric <
|
613
|
+
for(metric = 0; metric < SCount; metric++) {
|
589
614
|
VALUE leg_metrics = rb_ary_new();
|
590
615
|
|
591
|
-
for(leg = 0; leg <
|
592
|
-
rb_ary_push( leg_metrics, DBL2NUM(
|
616
|
+
for(leg = 0; leg < 5; leg++) {
|
617
|
+
rb_ary_push( leg_metrics, DBL2NUM( data[metric][leg] ) );
|
593
618
|
}
|
594
619
|
|
595
620
|
rb_ary_push(final_metrics, leg_metrics);
|