tarf_monte_carlo 3.33 → 3.38

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: f01c36b2c17eecf4dc3dae2cabe4e7eaecc613f70813de0f80bcfee81abd8005
4
- data.tar.gz: e914b80b2b9c54f40e117aa65ada3caac54bfcc603114292d712b1d7eeb20e68
3
+ metadata.gz: f6cb2b1cffe291ac211ef3517133affc4d62c2368f815a08a502a56650aee788
4
+ data.tar.gz: b17cfb2cce1123ab4c363d08a2eb214d14530d11249ed757c52e938bebacb38f
5
5
  SHA512:
6
- metadata.gz: 2d81d72be8b60152e95b2144961cb4529aebe67f07a9eda582897c0befb1ba595c96af7e4b3a856273de752d805650b8497eec0396469575c8bd04a7643dba97
7
- data.tar.gz: b1000f8b7e734018cf5db0cdc60c467cd8792c43e4adec6da70950b6f3fd3de83c47a1a2fd7f8a39fb94b25edce659374bf78438f6690f8e5d6b11d82583f187
6
+ metadata.gz: fb8b79a26f30802f2016981c4a96d68c193c794a76bd5b7b2f4f24d8805d0afc72150440b17b182898508a2cbc25675c7bba3bbc67288edec0aa8b8270c78bbc
7
+ data.tar.gz: bbe9daf65b7c7197fe76a4f2542ea422340399e2d8c46e4169d303f1da8475f2eef33e19b2e2f706fd3c3ef79de588fc3ebce5228c95be0afcc8bd6610522282
@@ -58,7 +58,7 @@ VALUE cTarfMonteCarlo = Qnil;
58
58
  void Init_tarf_monte_carlo();
59
59
  double european_payoff(double, double, int, int, double);
60
60
  double get_equivalent_notional(int, double, float);
61
- double get_equivalent_rebate(int, double, float);
61
+ double get_equivalent_rebate(int, double, float, int);
62
62
 
63
63
  // Prototype for our methods - methods are prefixed by 'method_' here
64
64
  VALUE method_box_muller( VALUE );
@@ -93,8 +93,9 @@ double get_equivalent_notional(int conversion_sign, double notional, float rate)
93
93
  return (conversion_sign == 1) ? (notional / rate) : notional;
94
94
  }
95
95
 
96
- double get_equivalent_rebate(int conversion_sign, double rebate, float rate){
97
- return (conversion_sign == 1) ? (rebate * rate) : rebate;
96
+ double get_equivalent_rebate(int conversion_sign, double rebate, float rate, int dir_sign){
97
+ double total = (conversion_sign == 1) ? (rebate * rate) : rebate;
98
+ return (-1 * dir_sign * total);
98
99
  }
99
100
 
100
101
  // main method for running monte carlo simulation from sidekiq worker/outside method
@@ -193,7 +194,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
193
194
  // first create a 1-D array of pointers, and then, for each array entry, create another 1-D array.
194
195
  //
195
196
  double **metrics;
196
- double data[SCount];
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) );
@@ -206,12 +207,21 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
206
207
  // run simulations loop
207
208
  for( sim_count = 0; sim_count < SCount; sim_count += 2 ) {
208
209
  // initial spot rate for each iteration would be current spot rate
209
- data[sim_count] = 0;
210
- data[sim_count + 1] = 0;
211
-
212
210
  double Spot = S, Spot_dash = S;
213
211
  double sim[NL], sim_pos[NL], sim_neg[NL], sim_dash[NL], sim_dash_pos[NL], sim_dash_neg[NL];
214
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
+
215
225
  // reset all simulation leg specific results
216
226
  for ( leg = 0; leg < NL; ++leg ) {
217
227
  sim[leg] = 0.0;
@@ -395,34 +405,44 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
395
405
  if(KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE){
396
406
  if(knockedLeg >= 0){
397
407
  double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + knockedLeg ) ), sim[NL-1]);
398
- data[sim_count] = equivalent_notional;
399
408
  sim_pos[NL-1] = european_payoff(( *( Xs_array + (knockedLeg) ) ), sim[NL-1], cp_sign, dir_sign, equivalent_notional);
400
409
  }
401
410
  else{
402
- sim_pos[NL-1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim[NL-1]);
411
+ sim_pos[NL-1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim[NL-1], dir_sign);
403
412
  }
404
413
  if(knockedLeg_dash >= 0 ){
405
414
  double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + knockedLeg_dash ) ), sim_dash[NL-1]);
406
- data[sim_count + 1] = equivalent_notional;
407
415
  sim_dash_pos[NL-1] = european_payoff(( *( Xs_array + (knockedLeg_dash) ) ), sim_dash[NL-1], cp_sign, dir_sign, equivalent_notional);
408
416
  }
409
417
  else{
410
- sim_dash_pos[NL-1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim_dash[NL-1]);
418
+ sim_dash_pos[NL-1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim_dash[NL-1], dir_sign);
411
419
  }
412
420
  } else if(KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE){
413
421
  if(knockedLeg >= 0){
414
- sim_pos[knockedLeg] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + knockedLeg ) ), sim[knockedLeg]);
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];
415
426
  }
416
427
  else{
417
428
  double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + 0 ) ), sim[NL-1]);
429
+ data[sim_count][0] = equivalent_notional;
418
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];
419
433
  }
420
434
  if(knockedLeg_dash >= 0 ){
421
- sim_dash_pos[knockedLeg_dash] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + knockedLeg_dash ) ), sim[knockedLeg_dash]);
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];
422
439
  }
423
440
  else{
424
441
  double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + 0 ) ), sim_dash[NL-1]);
442
+ data[sim_count + 1][0] = equivalent_notional;
425
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];
426
446
  }
427
447
  } else if( KType == ABSOLUTE || KType == PIVOT_ABSOLUTE || KType == COLLAR_ABSOLUTE || KType == DOUBLE_STRIKE_ABSOLUTE ) {
428
448
  for( leg = 0; leg < NL; ++leg ) {
@@ -591,13 +611,13 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
591
611
  // rb_p(rb_str_new2("Converting metrics"));
592
612
  VALUE final_metrics = rb_ary_new();
593
613
  for(metric = 0; metric < SCount; metric++) {
594
- // VALUE leg_metrics = rb_ary_new();
614
+ VALUE leg_metrics = rb_ary_new();
595
615
 
596
- // for(leg = 0; leg < NL; leg++) {
597
- // rb_ary_push( leg_metrics, DBL2NUM( metrics[metric][leg] ) );
598
- // }
616
+ for(leg = 0; leg < 5; leg++) {
617
+ rb_ary_push( leg_metrics, DBL2NUM( data[metric][leg] ) );
618
+ }
599
619
 
600
- rb_ary_push(final_metrics, data[metric]);
620
+ rb_ary_push(final_metrics, leg_metrics);
601
621
  }
602
622
 
603
623
  // 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.33"
6
+ VERSION = "3.38"
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.33'
4
+ version: '3.38'
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-05 00:00:00.000000000 Z
11
+ date: 2020-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler