tarf_monte_carlo 3.64 → 3.69

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: af22d9fe9fe8bc218f93bbba3664ca95e264370aaa6f56972b38ca9650034fae
4
- data.tar.gz: 227a4f7f8c7af066183936588b512f758b0d66bf9a9889ee99f901f61efe4138
3
+ metadata.gz: a09821b8f49b2435d5faac86b35b58e9514de07dcf70200c99d9fe8c2a496cd1
4
+ data.tar.gz: 6f19dd72e7a81ba7ed41f8e40e29a57965acf4e4b5ee78cb1fb2f931d5ae3270
5
5
  SHA512:
6
- metadata.gz: b3c41f13353e8adcc595bf19b2d9f0a4ed9325c90a6cb9f26398291ab9beb7696cdea10541055bb7b43f525312f0c567b318437371d40e95b4d16fd5da34faed
7
- data.tar.gz: c50606f36a09b7b6e4130d1eab36e1a3a80ae5d0d02e1fb786eb55ef26c8a20c0203015dd1cf4ea04fc85f4382ce6083204e326a94e2292f6f3875485a4f4378
6
+ metadata.gz: 3fb2c088e7cd659ebae7db0b3dadb0ddac9e58661ca70383df086ff550f1e7387f384c29f66f216d13b9e0b6f073770521db72815544ac1aa401ac84476a8b93
7
+ data.tar.gz: c686b6a2e6a347ffcb62a293f7b1b39beafae1755b31ab4d9a540b1b8f0b9ce16a3b0ae00ec43447214b4247229d58ea15ae996ee5467205432be179f9fccdb9
@@ -211,6 +211,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
211
211
  //
212
212
  // first create a 1-D array of pointers, and then, for each array entry, create another 1-D array.
213
213
  //
214
+ double testing[SCount];
214
215
  double **metrics;
215
216
  if (barrier_variations(KType)){
216
217
  metrics = ( double** ) malloc( BARRIER_DP * sizeof(double*) );
@@ -234,6 +235,10 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
234
235
 
235
236
  // run simulations loop
236
237
  for( sim_count = 0; sim_count < SCount; sim_count += 2 ) {
238
+
239
+ testing[sim_count] = -1;
240
+ testing[sim_count+1] = -1;
241
+
237
242
  // initial spot rate for each iteration would be current spot rate
238
243
  double Spot = S, Spot_dash = S;
239
244
  double sim[NL], sim_pos[NL], sim_neg[NL], sim_dash[NL], sim_dash_pos[NL], sim_dash_neg[NL];
@@ -283,14 +288,14 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
283
288
  profit_loss_dash = Spot_dash;
284
289
 
285
290
  // Both Until KI & Exp
286
- if ( ((*(Barrier_array + leg) - *(Xs_array + leg)) * cp_sign < 0) && ((*(Barrier2_array + leg) - *(Xs_array + leg)) * cp_sign > 0) ){
291
+ if ( (((*(Barrier_array + leg) - *(Xs_array + leg)) * cp_sign) <= 0) && (((*(Barrier2_array + leg) - *(Xs_array + leg)) * cp_sign) >= 0) ){
287
292
  if ((knockedLeg == -1) && ((*(Barrier_array + leg) - Spot) * cp_sign >= 0)){ knockedLeg = leg; }
288
293
  if ((knockedLeg2 == -1) && ((*(Barrier2_array + leg) - Spot) * cp_sign <= 0)){ knockedLeg2 = leg; }
289
294
 
290
295
  if ((knockedLeg_dash == -1) && ((*(Barrier_array + leg) - Spot_dash) * cp_sign >= 0)){ knockedLeg_dash = leg; }
291
296
  if ((knockedLeg2_dash == -1) && ((*(Barrier2_array + leg) - Spot_dash) * cp_sign <= 0)){ knockedLeg2_dash = leg; }
292
297
  }
293
- else if( ((*(Barrier_array + leg) - *(Xs_array + leg)) * cp_sign > 0) && ((*(Barrier2_array + leg) - *(Xs_array + leg)) * cp_sign < 0) ){
298
+ else if( (((*(Barrier_array + leg) - *(Xs_array + leg)) * cp_sign) >= 0) && (((*(Barrier2_array + leg) - *(Xs_array + leg)) * cp_sign) <= 0) ){
294
299
  if ((knockedLeg == -1) && ((*(Barrier_array + leg) - Spot) * cp_sign <= 0)){ knockedLeg = leg; }
295
300
  if ((knockedLeg2 == -1) && ((*(Barrier2_array + leg) - Spot) * cp_sign >= 0)){ knockedLeg2 = leg; }
296
301
 
@@ -298,7 +303,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
298
303
  if ((knockedLeg2_dash == -1) && ((*(Barrier2_array + leg) - Spot_dash) * cp_sign >= 0)){ knockedLeg2_dash = leg; }
299
304
  }
300
305
  // Only Until Exp
301
- else if( (KType == FX_AMERICAN_BARRIER_KIKO_UNTIL_EXP) && ((*(Barrier_array + leg) - *(Xs_array + leg)) * cp_sign > 0) && ((*(Barrier2_array + leg) - *(Barrier_array + leg)) * cp_sign > 0) ){
306
+ else if( (KType == FX_AMERICAN_BARRIER_KIKO_UNTIL_EXP) && (((*(Barrier_array + leg) - *(Xs_array + leg)) * cp_sign) >= 0) && (((*(Barrier2_array + leg) - *(Barrier_array + leg)) * cp_sign) >= 0) ){
302
307
  if ((knockedLeg == -1) && ((*(Barrier_array + leg) - Spot) * cp_sign <= 0)){ knockedLeg = leg; }
303
308
  if ((knockedLeg2 == -1) && ((*(Barrier2_array + leg) - Spot) * cp_sign <= 0)){ knockedLeg2 = leg; }
304
309
 
@@ -306,7 +311,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
306
311
  if ((knockedLeg2_dash == -1) && ((*(Barrier2_array + leg) - Spot_dash) * cp_sign <= 0)){ knockedLeg2_dash = leg; }
307
312
  }
308
313
 
309
- else if( (KType == FX_AMERICAN_BARRIER_KIKO_UNTIL_EXP) && ((*(Barrier_array + leg) - *(Xs_array + leg)) * cp_sign < 0) && ((*(Barrier2_array + leg) - *(Barrier_array + leg)) * cp_sign < 0) ){
314
+ else if( (KType == FX_AMERICAN_BARRIER_KIKO_UNTIL_EXP) && (((*(Barrier_array + leg) - *(Xs_array + leg)) * cp_sign) <= 0) && (((*(Barrier2_array + leg) - *(Barrier_array + leg)) * cp_sign) <= 0) ){
310
315
  if ((knockedLeg == -1) && ((*(Barrier_array + leg) - Spot) * cp_sign >= 0)){ knockedLeg = leg; }
311
316
  if ((knockedLeg2 == -1) && ((*(Barrier2_array + leg) - Spot) * cp_sign >= 0)){ knockedLeg2 = leg; }
312
317
 
@@ -555,13 +560,13 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
555
560
  }
556
561
  } else if(KType == FX_AMERICAN_BARRIER_KIKO_UNTIL_EXP){
557
562
  if(knockedLeg2 >= 0){
558
- sim_pos[NL-1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim[NL-1], dir_sign);
563
+ sim_pos[NL-1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + knockedLeg2 ) ), sim[NL-1], dir_sign);
559
564
  } else if(knockedLeg >= 0) {
560
565
  double equivalent_notional = *( Ns_array + knockedLeg );
561
566
  sim_pos[NL-1] = european_payoff(( *( Xs_array + (knockedLeg) ) ), sim[NL-1], cp_sign, dir_sign, equivalent_notional);
562
567
  }
563
568
  if(knockedLeg2_dash >= 0){
564
- sim_dash_pos[NL-1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim_dash[NL-1], dir_sign);
569
+ sim_dash_pos[NL-1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + knockedLeg2 ) ), sim_dash[NL-1], dir_sign);
565
570
  } else if(knockedLeg_dash >= 0) {
566
571
  double equivalent_notional = *( Ns_array + knockedLeg_dash );
567
572
  sim_dash_pos[NL-1] = european_payoff(( *( Xs_array + (knockedLeg_dash) ) ), sim_dash[NL-1], cp_sign, dir_sign, equivalent_notional);
@@ -576,15 +581,18 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
576
581
  metrics[3][point_pos+1] = knockedLeg_dash;
577
582
  }
578
583
  } else if(KType == FX_AMERICAN_BARRIER_KIKO_UNTIL_KI){
584
+ testing[sim_count] = knockedLeg2;
585
+ testing[sim_count + 1] = knockedLeg2_dash;
586
+
579
587
  if(knockedLeg >= 0 && knockedLeg2 >= 0){
580
588
  if(knockedLeg < knockedLeg2){
581
589
  double equivalent_notional = *( Ns_array + knockedLeg );
582
590
  sim_pos[NL-1] = european_payoff(( *( Xs_array + (knockedLeg) ) ), sim[NL-1], cp_sign, dir_sign, equivalent_notional);
583
591
  } else {
584
- sim_pos[knockedLeg2] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim[knockedLeg2], dir_sign);
592
+ sim_pos[knockedLeg2] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + knockedLeg2 ) ), sim[knockedLeg2], dir_sign);
585
593
  }
586
594
  } else if(knockedLeg2 >= 0){
587
- sim_pos[knockedLeg2] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim[knockedLeg2], dir_sign);
595
+ sim_pos[knockedLeg2] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + knockedLeg2 ) ), sim[knockedLeg2], dir_sign);
588
596
  } else if(knockedLeg >= 0) {
589
597
  double equivalent_notional = *( Ns_array + knockedLeg );
590
598
  sim_pos[NL-1] = european_payoff(( *( Xs_array + (knockedLeg) ) ), sim[NL-1], cp_sign, dir_sign, equivalent_notional);
@@ -595,10 +603,10 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
595
603
  double equivalent_notional = *( Ns_array + knockedLeg_dash );
596
604
  sim_dash_pos[NL-1] = european_payoff(( *( Xs_array + (knockedLeg_dash) ) ), sim_dash[NL-1], cp_sign, dir_sign, equivalent_notional);
597
605
  } else {
598
- sim_dash_pos[knockedLeg2_dash] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim_dash[knockedLeg2_dash], dir_sign);
606
+ sim_dash_pos[knockedLeg2_dash] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + knockedLeg2_dash ) ), sim_dash[knockedLeg2_dash], dir_sign);
599
607
  }
600
608
  } else if(knockedLeg2_dash >= 0){
601
- sim_dash_pos[knockedLeg2_dash] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim_dash[knockedLeg2_dash], dir_sign);
609
+ sim_dash_pos[knockedLeg2_dash] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + knockedLeg2_dash ) ), sim_dash[knockedLeg2_dash], dir_sign);
602
610
  } else if(knockedLeg_dash >= 0) {
603
611
  double equivalent_notional = *( Ns_array + knockedLeg_dash );
604
612
  sim_dash_pos[NL-1] = european_payoff(( *( Xs_array + (knockedLeg_dash) ) ), sim_dash[NL-1], cp_sign, dir_sign, equivalent_notional);
@@ -839,12 +847,18 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
839
847
  }
840
848
  }
841
849
 
850
+ VALUE testing_data = rb_ary_new();
851
+ for(metric = 0; metric < SCount; metric++) {
852
+ rb_ary_push(testing_data, DBL2NUM(testing[metric]));
853
+ }
854
+
842
855
  // rb_p(rb_str_new2("Generating output hash"));
843
856
  VALUE final_pvs = rb_hash_new();
844
857
  rb_hash_aset(final_pvs, rb_str_new2("positive_pv"), DBL2NUM( pvs_pos_sum / SCount ));
845
858
  rb_hash_aset(final_pvs, rb_str_new2("negative_pv"), DBL2NUM( pvs_neg_sum / SCount ));
846
859
  rb_hash_aset(final_pvs, rb_str_new2("total_pv"), DBL2NUM( (pvs_neg_sum + pvs_pos_sum) / SCount ));
847
860
  rb_hash_aset(final_pvs, rb_str_new2("metrics"), final_metrics);
861
+ rb_hash_aset(final_pvs, rb_str_new2("testing"), testing_data);
848
862
 
849
863
  //
850
864
  // free your arrays from memory once you're done using them
@@ -3,5 +3,5 @@
3
3
  # gem yank tarf_monte_carlo -v 2.3
4
4
 
5
5
  module TarfMonteCarlo
6
- VERSION = "3.64"
6
+ VERSION = "3.69"
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tarf_monte_carlo
3
3
  version: !ruby/object:Gem::Version
4
- version: '3.64'
4
+ version: '3.69'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vivek Routh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-14 00:00:00.000000000 Z
11
+ date: 2020-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler