tarf_monte_carlo 3.69 → 3.70
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/tarf_monte_carlo/tarf_monte_carlo.c +4 -18
- data/lib/tarf_monte_carlo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aac96f23c9d9e9a4c66983afc7b7bc7c6d1ae2b982686dad3d76f426ff413bae
|
4
|
+
data.tar.gz: e7a775cdac4703922ef797c42c9a56a3780b99004ca43747e390a2c778652dc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 403b211c16baa7a9645be1ab217fbbbb7c879c18e439739c9f0ccd773b8a22f8ca4fc2656381d2135af41e2cce92f56a67d23d7883127dad27bf5eb2a5715fd2
|
7
|
+
data.tar.gz: fe1f4c219ab019318e3d6675a971a87c9bd7f50e4e759cfe0b48e507bf1ee247bb13c8828a00f70185483aa9d637f59c233f28c46a495739bdedf27ed4d6346d
|
@@ -211,7 +211,6 @@ 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];
|
215
214
|
double **metrics;
|
216
215
|
if (barrier_variations(KType)){
|
217
216
|
metrics = ( double** ) malloc( BARRIER_DP * sizeof(double*) );
|
@@ -235,10 +234,6 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
235
234
|
|
236
235
|
// run simulations loop
|
237
236
|
for( sim_count = 0; sim_count < SCount; sim_count += 2 ) {
|
238
|
-
|
239
|
-
testing[sim_count] = -1;
|
240
|
-
testing[sim_count+1] = -1;
|
241
|
-
|
242
237
|
// initial spot rate for each iteration would be current spot rate
|
243
238
|
double Spot = S, Spot_dash = S;
|
244
239
|
double sim[NL], sim_pos[NL], sim_neg[NL], sim_dash[NL], sim_dash_pos[NL], sim_dash_neg[NL];
|
@@ -288,14 +283,14 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
288
283
|
profit_loss_dash = Spot_dash;
|
289
284
|
|
290
285
|
// Both Until KI & Exp
|
291
|
-
if ( ((
|
286
|
+
if ( ((*(Barrier_array + leg) - *(Xs_array + leg)) * cp_sign <= 0) && ((*(Barrier2_array + leg) - *(Xs_array + leg)) * cp_sign >= 0) ){
|
292
287
|
if ((knockedLeg == -1) && ((*(Barrier_array + leg) - Spot) * cp_sign >= 0)){ knockedLeg = leg; }
|
293
288
|
if ((knockedLeg2 == -1) && ((*(Barrier2_array + leg) - Spot) * cp_sign <= 0)){ knockedLeg2 = leg; }
|
294
289
|
|
295
290
|
if ((knockedLeg_dash == -1) && ((*(Barrier_array + leg) - Spot_dash) * cp_sign >= 0)){ knockedLeg_dash = leg; }
|
296
291
|
if ((knockedLeg2_dash == -1) && ((*(Barrier2_array + leg) - Spot_dash) * cp_sign <= 0)){ knockedLeg2_dash = leg; }
|
297
292
|
}
|
298
|
-
else if( ((
|
293
|
+
else if( ((*(Barrier_array + leg) - *(Xs_array + leg)) * cp_sign >= 0) && ((*(Barrier2_array + leg) - *(Xs_array + leg)) * cp_sign <= 0) ){
|
299
294
|
if ((knockedLeg == -1) && ((*(Barrier_array + leg) - Spot) * cp_sign <= 0)){ knockedLeg = leg; }
|
300
295
|
if ((knockedLeg2 == -1) && ((*(Barrier2_array + leg) - Spot) * cp_sign >= 0)){ knockedLeg2 = leg; }
|
301
296
|
|
@@ -303,7 +298,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
303
298
|
if ((knockedLeg2_dash == -1) && ((*(Barrier2_array + leg) - Spot_dash) * cp_sign >= 0)){ knockedLeg2_dash = leg; }
|
304
299
|
}
|
305
300
|
// Only Until Exp
|
306
|
-
else if( (KType == FX_AMERICAN_BARRIER_KIKO_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) ){
|
307
302
|
if ((knockedLeg == -1) && ((*(Barrier_array + leg) - Spot) * cp_sign <= 0)){ knockedLeg = leg; }
|
308
303
|
if ((knockedLeg2 == -1) && ((*(Barrier2_array + leg) - Spot) * cp_sign <= 0)){ knockedLeg2 = leg; }
|
309
304
|
|
@@ -311,7 +306,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
311
306
|
if ((knockedLeg2_dash == -1) && ((*(Barrier2_array + leg) - Spot_dash) * cp_sign <= 0)){ knockedLeg2_dash = leg; }
|
312
307
|
}
|
313
308
|
|
314
|
-
else if( (KType == FX_AMERICAN_BARRIER_KIKO_UNTIL_EXP) && ((
|
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) ){
|
315
310
|
if ((knockedLeg == -1) && ((*(Barrier_array + leg) - Spot) * cp_sign >= 0)){ knockedLeg = leg; }
|
316
311
|
if ((knockedLeg2 == -1) && ((*(Barrier2_array + leg) - Spot) * cp_sign >= 0)){ knockedLeg2 = leg; }
|
317
312
|
|
@@ -581,9 +576,6 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
581
576
|
metrics[3][point_pos+1] = knockedLeg_dash;
|
582
577
|
}
|
583
578
|
} else if(KType == FX_AMERICAN_BARRIER_KIKO_UNTIL_KI){
|
584
|
-
testing[sim_count] = knockedLeg2;
|
585
|
-
testing[sim_count + 1] = knockedLeg2_dash;
|
586
|
-
|
587
579
|
if(knockedLeg >= 0 && knockedLeg2 >= 0){
|
588
580
|
if(knockedLeg < knockedLeg2){
|
589
581
|
double equivalent_notional = *( Ns_array + knockedLeg );
|
@@ -847,18 +839,12 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
847
839
|
}
|
848
840
|
}
|
849
841
|
|
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
|
-
|
855
842
|
// rb_p(rb_str_new2("Generating output hash"));
|
856
843
|
VALUE final_pvs = rb_hash_new();
|
857
844
|
rb_hash_aset(final_pvs, rb_str_new2("positive_pv"), DBL2NUM( pvs_pos_sum / SCount ));
|
858
845
|
rb_hash_aset(final_pvs, rb_str_new2("negative_pv"), DBL2NUM( pvs_neg_sum / SCount ));
|
859
846
|
rb_hash_aset(final_pvs, rb_str_new2("total_pv"), DBL2NUM( (pvs_neg_sum + pvs_pos_sum) / SCount ));
|
860
847
|
rb_hash_aset(final_pvs, rb_str_new2("metrics"), final_metrics);
|
861
|
-
rb_hash_aset(final_pvs, rb_str_new2("testing"), testing_data);
|
862
848
|
|
863
849
|
//
|
864
850
|
// free your arrays from memory once you're done using them
|