tarf_monte_carlo 3.38 → 3.39

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6cb2b1cffe291ac211ef3517133affc4d62c2368f815a08a502a56650aee788
4
- data.tar.gz: b17cfb2cce1123ab4c363d08a2eb214d14530d11249ed757c52e938bebacb38f
3
+ metadata.gz: 2e7279ef5830fc815c5c7b634bceb83e463233ec0d6f329c10c3bb5745ccbbfd
4
+ data.tar.gz: 04af76f8b9fa855336483d31e06a34793d522e39587d893cec07bbd0d24a0ed1
5
5
  SHA512:
6
- metadata.gz: fb8b79a26f30802f2016981c4a96d68c193c794a76bd5b7b2f4f24d8805d0afc72150440b17b182898508a2cbc25675c7bba3bbc67288edec0aa8b8270c78bbc
7
- data.tar.gz: bbe9daf65b7c7197fe76a4f2542ea422340399e2d8c46e4169d303f1da8475f2eef33e19b2e2f706fd3c3ef79de588fc3ebce5228c95be0afcc8bd6610522282
6
+ metadata.gz: 000c137cc26ca306b2055bc10a12a5871d1b06dc5b1c0de52c93a4e8d1349c7e0f20121eb3e526bf12e23c51a8c2f20b318f981eb89d11e63d7c6cdf36692e91
7
+ data.tar.gz: a78e88a10174d913f1de0dacd80b5c33d08163a1a1bf8c69e8fa51534b47b4f8ab628445298495dfe835972c16328d8407b8f3cb7907c0f3d92e2e554905931f
@@ -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 ((sim_count % INTERVAL) == 0){
421
+ metrics[0][sim_count] = sim[NL-1];
422
+ metrics[1][sim_count] = (knockedLeg >= 0) ? ( *( Xs_array + (knockedLeg) ) ) : 0;
423
+ metrics[0][sim_count+1] = sim_dash[NL-1];
424
+ metrics[1][sim_count+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 ((sim_count % INTERVAL) == 0){
443
+ metrics[0][sim_count] = (knockedLeg >= 0) ? sim[knockedLeg] : sim[NL-1];
444
+ metrics[1][sim_count] = ( *( Xs_array + 0 ) );
445
+ metrics[0][sim_count+1] = (knockedLeg_dash >= 0) ? sim[knockedLeg_dash] : sim[NL-1];
446
+ metrics[1][sim_count+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,6 +572,10 @@ 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 ((sim_count % INTERVAL) == 0){
576
+ metrics[2][sim_count] = sim_pos_sum;
577
+ metrics[2][sim_count+1] = sim_dash_pos_sum;
578
+ }
571
579
 
572
580
  //
573
581
  // increment metric storing point by 4
@@ -610,14 +618,28 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
610
618
  //
611
619
  // rb_p(rb_str_new2("Converting metrics"));
612
620
  VALUE final_metrics = rb_ary_new();
613
- for(metric = 0; metric < SCount; metric++) {
614
- VALUE leg_metrics = rb_ary_new();
615
621
 
616
- for(leg = 0; leg < 5; leg++) {
617
- rb_ary_push( leg_metrics, DBL2NUM( data[metric][leg] ) );
622
+ if (KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE || KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE){
623
+ for(metric = 0; metric < 3; metric++) {
624
+ VALUE leg_metrics = rb_ary_new();
625
+
626
+ for(leg = 0; leg < DATAPOINTS; leg++) {
627
+ rb_ary_push( leg_metrics, DBL2NUM( metrics[metric][leg] ) );
628
+ }
629
+
630
+ rb_ary_push(final_metrics, leg_metrics);
618
631
  }
632
+ }
633
+ else{
634
+ for(metric = 0; metric < DATAPOINTS; metric++) {
635
+ VALUE leg_metrics = rb_ary_new();
619
636
 
620
- rb_ary_push(final_metrics, leg_metrics);
637
+ for(leg = 0; leg < NL; leg++) {
638
+ rb_ary_push( leg_metrics, DBL2NUM( metrics[metric][leg] ) );
639
+ }
640
+
641
+ rb_ary_push(final_metrics, leg_metrics);
642
+ }
621
643
  }
622
644
 
623
645
  // rb_p(rb_str_new2("Generating output hash"));
@@ -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.39"
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.39'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vivek Routh