tarf_monte_carlo 3.28 → 3.33
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 +4 -4
- data/ext/tarf_monte_carlo/tarf_monte_carlo.c +22 -14
- data/lib/tarf_monte_carlo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f01c36b2c17eecf4dc3dae2cabe4e7eaecc613f70813de0f80bcfee81abd8005
|
|
4
|
+
data.tar.gz: e914b80b2b9c54f40e117aa65ada3caac54bfcc603114292d712b1d7eeb20e68
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2d81d72be8b60152e95b2144961cb4529aebe67f07a9eda582897c0befb1ba595c96af7e4b3a856273de752d805650b8497eec0396469575c8bd04a7643dba97
|
|
7
|
+
data.tar.gz: b1000f8b7e734018cf5db0cdc60c467cd8792c43e4adec6da70950b6f3fd3de83c47a1a2fd7f8a39fb94b25edce659374bf78438f6690f8e5d6b11d82583f187
|
|
@@ -90,11 +90,11 @@ double european_payoff(double strike, double spot, int cp_sign, int dir_sign, do
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
double get_equivalent_notional(int conversion_sign, double notional, float rate){
|
|
93
|
-
return (conversion_sign == 1) ? (notional / rate) : notional
|
|
93
|
+
return (conversion_sign == 1) ? (notional / rate) : notional;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
double get_equivalent_rebate(int conversion_sign, double rebate, float rate){
|
|
97
|
-
return (conversion_sign == 1) ? (rebate * rate) : rebate
|
|
97
|
+
return (conversion_sign == 1) ? (rebate * rate) : rebate;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
// main method for running monte carlo simulation from sidekiq worker/outside method
|
|
@@ -122,6 +122,8 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
|
122
122
|
int dir_sign = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("direction_sign")) );
|
|
123
123
|
int dir2_sign = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("direction2_sign")) );
|
|
124
124
|
int cp_sign = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("callput_sign")) );
|
|
125
|
+
int conversion_sign = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("conversion_sign")) );
|
|
126
|
+
int rebate_conversion_sign = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("rebate_conversion_sign")) );
|
|
125
127
|
|
|
126
128
|
// assign leg specific attributes
|
|
127
129
|
double *pvs_pos = ( double* ) malloc( SCount * sizeof(double) );
|
|
@@ -191,6 +193,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
|
191
193
|
// first create a 1-D array of pointers, and then, for each array entry, create another 1-D array.
|
|
192
194
|
//
|
|
193
195
|
double **metrics;
|
|
196
|
+
double data[SCount];
|
|
194
197
|
metrics = ( double** ) malloc( DATAPOINTS * sizeof(double*) );
|
|
195
198
|
for( metric = 0; metric < DATAPOINTS; metric++ ) {
|
|
196
199
|
metrics[metric] = ( double* ) malloc( NL * sizeof(double) );
|
|
@@ -203,6 +206,9 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
|
203
206
|
// run simulations loop
|
|
204
207
|
for( sim_count = 0; sim_count < SCount; sim_count += 2 ) {
|
|
205
208
|
// initial spot rate for each iteration would be current spot rate
|
|
209
|
+
data[sim_count] = 0;
|
|
210
|
+
data[sim_count + 1] = 0;
|
|
211
|
+
|
|
206
212
|
double Spot = S, Spot_dash = S;
|
|
207
213
|
double sim[NL], sim_pos[NL], sim_neg[NL], sim_dash[NL], sim_dash_pos[NL], sim_dash_neg[NL];
|
|
208
214
|
|
|
@@ -241,10 +247,10 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
|
241
247
|
double knockin = (Spot - *(Barrier_array + leg)) * dir2_sign;
|
|
242
248
|
double knockin_dash = (Spot_dash - *(Barrier_array + leg)) * dir2_sign;
|
|
243
249
|
|
|
244
|
-
if(knockedLeg == -1 && knockin
|
|
250
|
+
if(knockedLeg == -1 && knockin >= 0){
|
|
245
251
|
knockedLeg = leg;
|
|
246
252
|
}
|
|
247
|
-
if(knockedLeg_dash == -1 && knockin_dash
|
|
253
|
+
if(knockedLeg_dash == -1 && knockin_dash >= 0){
|
|
248
254
|
knockedLeg_dash = leg;
|
|
249
255
|
}
|
|
250
256
|
} else if ( KType == DOUBLE_STRIKE_POINTS || KType == DOUBLE_STRIKE_ABSOLUTE || KType == DOUBLE_STRIKE_LEGS ) {
|
|
@@ -389,28 +395,30 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
|
389
395
|
if(KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE){
|
|
390
396
|
if(knockedLeg >= 0){
|
|
391
397
|
double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + knockedLeg ) ), sim[NL-1]);
|
|
398
|
+
data[sim_count] = equivalent_notional;
|
|
392
399
|
sim_pos[NL-1] = european_payoff(( *( Xs_array + (knockedLeg) ) ), sim[NL-1], cp_sign, dir_sign, equivalent_notional);
|
|
393
400
|
}
|
|
394
401
|
else{
|
|
395
|
-
sim_pos[NL-1] = get_equivalent_rebate(
|
|
402
|
+
sim_pos[NL-1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim[NL-1]);
|
|
396
403
|
}
|
|
397
404
|
if(knockedLeg_dash >= 0 ){
|
|
398
405
|
double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + knockedLeg_dash ) ), sim_dash[NL-1]);
|
|
406
|
+
data[sim_count + 1] = equivalent_notional;
|
|
399
407
|
sim_dash_pos[NL-1] = european_payoff(( *( Xs_array + (knockedLeg_dash) ) ), sim_dash[NL-1], cp_sign, dir_sign, equivalent_notional);
|
|
400
408
|
}
|
|
401
409
|
else{
|
|
402
|
-
sim_dash_pos[NL-1] = get_equivalent_rebate(
|
|
410
|
+
sim_dash_pos[NL-1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim_dash[NL-1]);
|
|
403
411
|
}
|
|
404
412
|
} else if(KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE){
|
|
405
413
|
if(knockedLeg >= 0){
|
|
406
|
-
sim_pos[knockedLeg] = get_equivalent_rebate(
|
|
414
|
+
sim_pos[knockedLeg] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + knockedLeg ) ), sim[knockedLeg]);
|
|
407
415
|
}
|
|
408
416
|
else{
|
|
409
417
|
double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + 0 ) ), sim[NL-1]);
|
|
410
418
|
sim_pos[NL-1] = european_payoff(( *( Xs_array + 0 ) ), sim[NL-1], cp_sign, dir_sign, equivalent_notional);
|
|
411
419
|
}
|
|
412
420
|
if(knockedLeg_dash >= 0 ){
|
|
413
|
-
sim_dash_pos[knockedLeg_dash] = get_equivalent_rebate(
|
|
421
|
+
sim_dash_pos[knockedLeg_dash] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + knockedLeg_dash ) ), sim[knockedLeg_dash]);
|
|
414
422
|
}
|
|
415
423
|
else{
|
|
416
424
|
double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + 0 ) ), sim_dash[NL-1]);
|
|
@@ -582,14 +590,14 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
|
582
590
|
//
|
|
583
591
|
// rb_p(rb_str_new2("Converting metrics"));
|
|
584
592
|
VALUE final_metrics = rb_ary_new();
|
|
585
|
-
for(metric = 0; metric <
|
|
586
|
-
VALUE leg_metrics = rb_ary_new();
|
|
593
|
+
for(metric = 0; metric < SCount; metric++) {
|
|
594
|
+
// VALUE leg_metrics = rb_ary_new();
|
|
587
595
|
|
|
588
|
-
for(leg = 0; leg < NL; leg++) {
|
|
589
|
-
|
|
590
|
-
}
|
|
596
|
+
// for(leg = 0; leg < NL; leg++) {
|
|
597
|
+
// rb_ary_push( leg_metrics, DBL2NUM( metrics[metric][leg] ) );
|
|
598
|
+
// }
|
|
591
599
|
|
|
592
|
-
rb_ary_push(final_metrics,
|
|
600
|
+
rb_ary_push(final_metrics, data[metric]);
|
|
593
601
|
}
|
|
594
602
|
|
|
595
603
|
// rb_p(rb_str_new2("Generating output hash"));
|
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.
|
|
4
|
+
version: '3.33'
|
|
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-
|
|
11
|
+
date: 2020-10-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|