tarf_monte_carlo 3.38 → 3.43

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: f6cb2b1cffe291ac211ef3517133affc4d62c2368f815a08a502a56650aee788
4
- data.tar.gz: b17cfb2cce1123ab4c363d08a2eb214d14530d11249ed757c52e938bebacb38f
3
+ metadata.gz: 88cc80746dba47969e5cdc166b6510be889fd4c090ec1415cfdc066f47e32ebc
4
+ data.tar.gz: 4c7ab741260ab16d84a21659176211a466585d61be1c5adbdda62503173afa95
5
5
  SHA512:
6
- metadata.gz: fb8b79a26f30802f2016981c4a96d68c193c794a76bd5b7b2f4f24d8805d0afc72150440b17b182898508a2cbc25675c7bba3bbc67288edec0aa8b8270c78bbc
7
- data.tar.gz: bbe9daf65b7c7197fe76a4f2542ea422340399e2d8c46e4169d303f1da8475f2eef33e19b2e2f706fd3c3ef79de588fc3ebce5228c95be0afcc8bd6610522282
6
+ metadata.gz: 421f79a3b144d3066b04576f79b2041b24d3643322c76c4a06cca0be951069cff5e8d999cc3eaa6e2dcf62b81a321c7c8c5018aeefb1b3269d86d751d39251c7
7
+ data.tar.gz: 35b4d0df1af4fa5ca3ab88617c9516543a1c6127bf49287f21f19d00c1afa8bc13489fdb67bf808bcd8ac8d1348544a75fe3132f90f5f1d7979cdb7beae47a00
@@ -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,13 +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
- double data[SCount][5];
198
- metrics = ( double** ) malloc( DATAPOINTS * sizeof(double*) );
199
- for( metric = 0; metric < DATAPOINTS; metric++ ) {
200
- 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) );
201
210
 
202
- for(leg = 0; leg < NL; leg++) {
203
- metrics[metric][leg] = 0.0;
211
+ for(leg = 0; leg < NL; leg++) {
212
+ metrics[metric][leg] = 0.0;
213
+ }
204
214
  }
205
215
  }
206
216
 
@@ -210,18 +220,6 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
210
220
  double Spot = S, Spot_dash = S;
211
221
  double sim[NL], sim_pos[NL], sim_neg[NL], sim_dash[NL], sim_dash_pos[NL], sim_dash_neg[NL];
212
222
 
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
-
225
223
  // reset all simulation leg specific results
226
224
  for ( leg = 0; leg < NL; ++leg ) {
227
225
  sim[leg] = 0.0;
@@ -386,10 +384,12 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
386
384
  //
387
385
  // Store spot and spot dash
388
386
  //
389
- if( point_pos <= SIM_LIMIT && (sim_count + 2) % INTERVAL == 0 ) {
390
- // rb_p(rb_str_new2("Leg:Spots"));
391
- metrics[ point_pos ][ leg ] = Spot;
392
- 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
+ }
393
393
  }
394
394
 
395
395
  // if excuted UNCHAINED method
@@ -417,33 +417,35 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
417
417
  else{
418
418
  sim_dash_pos[NL-1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim_dash[NL-1], dir_sign);
419
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
+ }
420
426
  } else if(KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE){
421
427
  if(knockedLeg >= 0){
422
428
  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];
426
429
  }
427
430
  else{
428
431
  double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + 0 ) ), sim[NL-1]);
429
- data[sim_count][0] = equivalent_notional;
430
432
  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];
433
433
  }
434
434
  if(knockedLeg_dash >= 0 ){
435
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];
439
436
  }
440
437
  else{
441
438
  double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + 0 ) ), sim_dash[NL-1]);
442
- data[sim_count + 1][0] = equivalent_notional;
443
439
  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];
446
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
+
447
449
  } else if( KType == ABSOLUTE || KType == PIVOT_ABSOLUTE || KType == COLLAR_ABSOLUTE || KType == DOUBLE_STRIKE_ABSOLUTE ) {
448
450
  for( leg = 0; leg < NL; ++leg ) {
449
451
  // simulation normal
@@ -551,10 +553,12 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
551
553
  //
552
554
  // store and send whichever payoff you want
553
555
  //
554
- if( point_pos <= SIM_LIMIT && (sim_count + 2) % INTERVAL == 0 ) {
555
- // rb_p(rb_str_new2("Leg:Payoffs"));
556
- metrics[ point_pos + 1 ][ leg ] = (sim_pos[leg] + sim_neg[leg]);
557
- 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
+ }
558
562
  }
559
563
 
560
564
  sim_pos_sum += sim_pos[leg] * ( *( DFs_array + leg ) );
@@ -568,15 +572,22 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
568
572
  pvs_pos[sim_count + 1] = sim_dash_pos_sum;
569
573
  pvs_neg[sim_count] = sim_neg_sum;
570
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
+ }
571
580
 
572
581
  //
573
582
  // increment metric storing point by 4
574
583
  // Note: no limit condition here
575
584
  //
576
- if( (sim_count + 2) % INTERVAL == 0 ) {
577
- // rb_p(rb_str_new2("T:"));
578
- // rb_p(INT2NUM(point_pos));
579
- 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
+ }
580
591
  }
581
592
  }
582
593
  // run simulations loop
@@ -610,14 +621,28 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
610
621
  //
611
622
  // rb_p(rb_str_new2("Converting metrics"));
612
623
  VALUE final_metrics = rb_ary_new();
613
- for(metric = 0; metric < SCount; metric++) {
614
- 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
+ }
615
632
 
616
- for(leg = 0; leg < 5; leg++) {
617
- rb_ary_push( leg_metrics, DBL2NUM( data[metric][leg] ) );
633
+ rb_ary_push(final_metrics, leg_metrics);
618
634
  }
635
+ }
636
+ else{
637
+ for(metric = 0; metric < DATAPOINTS; metric++) {
638
+ VALUE leg_metrics = rb_ary_new();
619
639
 
620
- rb_ary_push(final_metrics, leg_metrics);
640
+ for(leg = 0; leg < NL; leg++) {
641
+ rb_ary_push( leg_metrics, DBL2NUM( metrics[metric][leg] ) );
642
+ }
643
+
644
+ rb_ary_push(final_metrics, leg_metrics);
645
+ }
621
646
  }
622
647
 
623
648
  // rb_p(rb_str_new2("Generating output hash"));
@@ -630,7 +655,8 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
630
655
  //
631
656
  // free your arrays from memory once you're done using them
632
657
  //
633
- 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++) {
634
660
  free( metrics[metric] );
635
661
  }
636
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.38"
6
+ VERSION = "3.43"
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.38'
4
+ version: '3.43'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vivek Routh
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  requirements: []
143
- rubygems_version: 3.0.6
143
+ rubygems_version: 3.0.8
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: Monte Carlo Simulation.