tarf_monte_carlo 3.37 → 3.42

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cde374a7687b72a44d4ac3227cce1e4145a4a8079e9196003e92da327b09ca9
4
- data.tar.gz: '058135bcdcaec69d1f34532412061862516409723c44a7d4e83afa52e399cd5a'
3
+ metadata.gz: 401dcffa11be28cb765633d86b3b3351af887311364893a4b4e98bcda42f1f2b
4
+ data.tar.gz: 8aa5d4b647a4ead25e93d8ec6d5d77f6927d767b368915c367a1557cfcd0d578
5
5
  SHA512:
6
- metadata.gz: bd79246265df4efc0d2474b69233c53a47a57e65073bc0a27ac9af8d4d5f6845b8189de8dd0f89211f26667001c0999f0a42ba7725a67eed7706bdbd4ae58272
7
- data.tar.gz: 5412be0cec43e5f56b4c4be725bf407c093a312f0afbc1f5debc66973f9baed47b305f32447e90b899dedf2d17e349755c6cdaba56559dfc4af5e8abb34ffd7b
6
+ metadata.gz: a955c81445337676aa5c291fed82e34fa74b37a999926158b9cd09bb5c6ae14888f483c43dcafc33b04d43f4fc3c016374f81c19ac39aa71933c6746196a0978
7
+ data.tar.gz: 73b9c4e40243dc65b8f711d515a1ab6196fa4c17991f12d72543cb8918b990e83844f4679e55fb28ebf3bac6857ff0e9cbdd2cf5ef55f4fdeb9dc4fa1b9135f9
@@ -135,9 +135,9 @@ extout_prefix =
135
135
  target_prefix = /tarf_monte_carlo
136
136
  LOCAL_LIBS =
137
137
  LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl -lobjc
138
- ORIG_SRCS = tarf_monte_carlo (1).c tarf_monte_carlo.c
138
+ ORIG_SRCS = tarf_monte_carlo.c
139
139
  SRCS = $(ORIG_SRCS)
140
- OBJS = tarf_monte_carlo (1).o tarf_monte_carlo.o
140
+ OBJS = tarf_monte_carlo.o
141
141
  HDRS =
142
142
  LOCAL_HDRS =
143
143
  TARGET = tarf_monte_carlo
@@ -194,12 +194,23 @@ 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
- metrics = ( double** ) malloc( DATAPOINTS * sizeof(double*) );
198
- for( metric = 0; metric < DATAPOINTS; metric++ ) {
199
- metrics[metric] = ( double* ) malloc( NL * sizeof(double) );
197
+ if (KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE || KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE){
198
+ metrics = ( double** ) malloc( 3 * sizeof(double*) );
199
+ for( metric = 0; metric < 3; metric++ ) {
200
+ metrics[metric] = ( double* ) malloc( DATAPOINTS * sizeof(double) );
201
+ for(leg = 0; leg < DATAPOINTS; leg++) {
202
+ metrics[metric][leg] = 0.0;
203
+ }
204
+ }
205
+ }
206
+ else{
207
+ metrics = ( double** ) malloc( DATAPOINTS * sizeof(double*) );
208
+ for( metric = 0; metric < DATAPOINTS; metric++ ) {
209
+ metrics[metric] = ( double* ) malloc( NL * sizeof(double) );
200
210
 
201
- for(leg = 0; leg < NL; leg++) {
202
- metrics[metric][leg] = 0.0;
211
+ for(leg = 0; leg < NL; leg++) {
212
+ metrics[metric][leg] = 0.0;
213
+ }
203
214
  }
204
215
  }
205
216
 
@@ -373,10 +384,12 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
373
384
  //
374
385
  // Store spot and spot dash
375
386
  //
376
- if( point_pos <= SIM_LIMIT && (sim_count + 2) % INTERVAL == 0 ) {
377
- // rb_p(rb_str_new2("Leg:Spots"));
378
- metrics[ point_pos ][ leg ] = Spot;
379
- metrics[ point_pos + 2 ][ leg ] = Spot_dash;
387
+ if (!(KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE || KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE)){
388
+ if( point_pos <= SIM_LIMIT && (sim_count + 2) % INTERVAL == 0 ) {
389
+ // rb_p(rb_str_new2("Leg:Spots"));
390
+ metrics[ point_pos ][ leg ] = Spot;
391
+ metrics[ point_pos + 2 ][ leg ] = Spot_dash;
392
+ }
380
393
  }
381
394
 
382
395
  // if excuted UNCHAINED method
@@ -404,6 +417,12 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
404
417
  else{
405
418
  sim_dash_pos[NL-1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim_dash[NL-1], dir_sign);
406
419
  }
420
+ if ((point_pos < DATAPOINTS) && (sim_count % INTERVAL) == 0){
421
+ metrics[0][point_pos] = sim[NL-1];
422
+ metrics[1][point_pos] = (knockedLeg >= 0) ? ( *( Xs_array + (knockedLeg) ) ) : 0;
423
+ metrics[0][point_pos+1] = sim_dash[NL-1];
424
+ metrics[1][point_pos+1] = (knockedLeg_dash >= 0) ? ( *( Xs_array + (knockedLeg_dash) ) ) : 0;
425
+ }
407
426
  } else if(KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE){
408
427
  if(knockedLeg >= 0){
409
428
  sim_pos[knockedLeg] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + knockedLeg ) ), sim[knockedLeg], dir_sign);
@@ -419,6 +438,14 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
419
438
  double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + 0 ) ), sim_dash[NL-1]);
420
439
  sim_dash_pos[NL-1] = european_payoff(( *( Xs_array + 0 ) ), sim_dash[NL-1], cp_sign, dir_sign, equivalent_notional);
421
440
  }
441
+
442
+ if ((point_pos < DATAPOINTS) && (sim_count % INTERVAL) == 0){
443
+ metrics[0][point_pos] = (knockedLeg >= 0) ? sim[knockedLeg] : sim[NL-1];
444
+ metrics[1][point_pos] = ( *( Xs_array + 0 ) );
445
+ metrics[0][point_pos+1] = (knockedLeg_dash >= 0) ? sim[knockedLeg_dash] : sim[NL-1];
446
+ metrics[1][point_pos+1] = ( *( Xs_array + 0 ) );
447
+ }
448
+
422
449
  } else if( KType == ABSOLUTE || KType == PIVOT_ABSOLUTE || KType == COLLAR_ABSOLUTE || KType == DOUBLE_STRIKE_ABSOLUTE ) {
423
450
  for( leg = 0; leg < NL; ++leg ) {
424
451
  // simulation normal
@@ -526,10 +553,12 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
526
553
  //
527
554
  // store and send whichever payoff you want
528
555
  //
529
- if( point_pos <= SIM_LIMIT && (sim_count + 2) % INTERVAL == 0 ) {
530
- // rb_p(rb_str_new2("Leg:Payoffs"));
531
- metrics[ point_pos + 1 ][ leg ] = (sim_pos[leg] + sim_neg[leg]);
532
- metrics[ point_pos + 3 ][ leg ] = (sim_dash_pos[leg] + sim_dash_neg[leg]);
556
+ if (!(KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE || KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE)){
557
+ if( point_pos <= SIM_LIMIT && (sim_count + 2) % INTERVAL == 0 ) {
558
+ // rb_p(rb_str_new2("Leg:Payoffs"));
559
+ metrics[ point_pos + 1 ][ leg ] = (sim_pos[leg] + sim_neg[leg]);
560
+ metrics[ point_pos + 3 ][ leg ] = (sim_dash_pos[leg] + sim_dash_neg[leg]);
561
+ }
533
562
  }
534
563
 
535
564
  sim_pos_sum += sim_pos[leg] * ( *( DFs_array + leg ) );
@@ -543,15 +572,22 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
543
572
  pvs_pos[sim_count + 1] = sim_dash_pos_sum;
544
573
  pvs_neg[sim_count] = sim_neg_sum;
545
574
  pvs_neg[sim_count + 1] = sim_dash_neg_sum;
575
+ if ((point_pos < DATAPOINTS) && (sim_count % INTERVAL) == 0){
576
+ metrics[2][point_pos] = sim_pos_sum;
577
+ metrics[2][point_pos+1] = sim_dash_pos_sum;
578
+ point_pos += 2;
579
+ }
546
580
 
547
581
  //
548
582
  // increment metric storing point by 4
549
583
  // Note: no limit condition here
550
584
  //
551
- if( (sim_count + 2) % INTERVAL == 0 ) {
552
- // rb_p(rb_str_new2("T:"));
553
- // rb_p(INT2NUM(point_pos));
554
- point_pos += 4;
585
+ if (!(KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE || KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE)){
586
+ if( (sim_count + 2) % INTERVAL == 0 ) {
587
+ // rb_p(rb_str_new2("T:"));
588
+ // rb_p(INT2NUM(point_pos));
589
+ point_pos += 4;
590
+ }
555
591
  }
556
592
  }
557
593
  // run simulations loop
@@ -585,14 +621,28 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
585
621
  //
586
622
  // rb_p(rb_str_new2("Converting metrics"));
587
623
  VALUE final_metrics = rb_ary_new();
588
- for(metric = 0; metric < DATAPOINTS; metric++) {
589
- VALUE leg_metrics = rb_ary_new();
624
+
625
+ if (KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE || KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE){
626
+ for(metric = 0; metric < 3; metric++) {
627
+ VALUE leg_metrics = rb_ary_new();
628
+
629
+ for(leg = 0; leg < DATAPOINTS; leg++) {
630
+ rb_ary_push( leg_metrics, DBL2NUM( metrics[metric][leg] ) );
631
+ }
590
632
 
591
- for(leg = 0; leg < NL; leg++) {
592
- rb_ary_push( leg_metrics, DBL2NUM( metrics[metric][leg] ) );
633
+ rb_ary_push(final_metrics, leg_metrics);
593
634
  }
635
+ }
636
+ else{
637
+ for(metric = 0; metric < DATAPOINTS; metric++) {
638
+ VALUE leg_metrics = rb_ary_new();
639
+
640
+ for(leg = 0; leg < NL; leg++) {
641
+ rb_ary_push( leg_metrics, DBL2NUM( metrics[metric][leg] ) );
642
+ }
594
643
 
595
- rb_ary_push(final_metrics, leg_metrics);
644
+ rb_ary_push(final_metrics, leg_metrics);
645
+ }
596
646
  }
597
647
 
598
648
  // rb_p(rb_str_new2("Generating output hash"));
@@ -605,7 +655,8 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
605
655
  //
606
656
  // free your arrays from memory once you're done using them
607
657
  //
608
- for(metric = 0; metric < DATAPOINTS; metric++) {
658
+ int dp = (KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE || KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE) ? 3 : DATAPOINTS;
659
+ for(metric = 0; metric < dp; metric++) {
609
660
  free( metrics[metric] );
610
661
  }
611
662
  free(metrics);
@@ -3,5 +3,5 @@
3
3
  # gem yank tarf_monte_carlo -v 2.3
4
4
 
5
5
  module TarfMonteCarlo
6
- VERSION = "3.37"
6
+ VERSION = "3.42"
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tarf_monte_carlo
3
3
  version: !ruby/object:Gem::Version
4
- version: '3.37'
4
+ version: '3.42'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vivek Routh