tarf_monte_carlo 3.29 → 3.34
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 +18 -10
- 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: 6ba6dd94cb23ba87cba4dfe1247ff41902d8644efacbbbf1b712ea7d61cc8341
|
4
|
+
data.tar.gz: da934c46905408ad6bc80694e4b2644535078437fd347c8f986aa9eb71c777b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b08cf5f89f3776766cb26d99fdad66b67f2783312ce9489f9ae934ffc359601261b80f9f0f9a2bbb19fd346f8230a3934ce6080ea0b4d755b3bbba34bbc7f1e2
|
7
|
+
data.tar.gz: b016ab0298d3041ab725d37a3a7aa74be2f8fbe33d510c2f6ef1dd55298d1d1209694234a227b028ed01d50009c112a15ebeaf5a07b2edce43e3e098bc01e23f
|
@@ -90,11 +90,13 @@ 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
|
-
|
93
|
+
double eq = (conversion_sign == 1) ? (notional / rate) : notional;
|
94
|
+
return eq;
|
94
95
|
}
|
95
96
|
|
96
97
|
double get_equivalent_rebate(int conversion_sign, double rebate, float rate){
|
97
|
-
|
98
|
+
double eq = (conversion_sign == 1) ? (rebate * rate) : rebate;
|
99
|
+
return eq;
|
98
100
|
}
|
99
101
|
|
100
102
|
// main method for running monte carlo simulation from sidekiq worker/outside method
|
@@ -193,6 +195,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
193
195
|
// first create a 1-D array of pointers, and then, for each array entry, create another 1-D array.
|
194
196
|
//
|
195
197
|
double **metrics;
|
198
|
+
double data[SCount];
|
196
199
|
metrics = ( double** ) malloc( DATAPOINTS * sizeof(double*) );
|
197
200
|
for( metric = 0; metric < DATAPOINTS; metric++ ) {
|
198
201
|
metrics[metric] = ( double* ) malloc( NL * sizeof(double) );
|
@@ -205,6 +208,9 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
205
208
|
// run simulations loop
|
206
209
|
for( sim_count = 0; sim_count < SCount; sim_count += 2 ) {
|
207
210
|
// initial spot rate for each iteration would be current spot rate
|
211
|
+
data[sim_count] = 0;
|
212
|
+
data[sim_count + 1] = 0;
|
213
|
+
|
208
214
|
double Spot = S, Spot_dash = S;
|
209
215
|
double sim[NL], sim_pos[NL], sim_neg[NL], sim_dash[NL], sim_dash_pos[NL], sim_dash_neg[NL];
|
210
216
|
|
@@ -243,10 +249,10 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
243
249
|
double knockin = (Spot - *(Barrier_array + leg)) * dir2_sign;
|
244
250
|
double knockin_dash = (Spot_dash - *(Barrier_array + leg)) * dir2_sign;
|
245
251
|
|
246
|
-
if(knockedLeg == -1 && knockin
|
252
|
+
if(knockedLeg == -1 && knockin >= 0){
|
247
253
|
knockedLeg = leg;
|
248
254
|
}
|
249
|
-
if(knockedLeg_dash == -1 && knockin_dash
|
255
|
+
if(knockedLeg_dash == -1 && knockin_dash >= 0){
|
250
256
|
knockedLeg_dash = leg;
|
251
257
|
}
|
252
258
|
} else if ( KType == DOUBLE_STRIKE_POINTS || KType == DOUBLE_STRIKE_ABSOLUTE || KType == DOUBLE_STRIKE_LEGS ) {
|
@@ -391,6 +397,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
391
397
|
if(KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE){
|
392
398
|
if(knockedLeg >= 0){
|
393
399
|
double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + knockedLeg ) ), sim[NL-1]);
|
400
|
+
data[sim_count] = equivalent_notional;
|
394
401
|
sim_pos[NL-1] = european_payoff(( *( Xs_array + (knockedLeg) ) ), sim[NL-1], cp_sign, dir_sign, equivalent_notional);
|
395
402
|
}
|
396
403
|
else{
|
@@ -398,6 +405,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
398
405
|
}
|
399
406
|
if(knockedLeg_dash >= 0 ){
|
400
407
|
double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + knockedLeg_dash ) ), sim_dash[NL-1]);
|
408
|
+
data[sim_count + 1] = equivalent_notional;
|
401
409
|
sim_dash_pos[NL-1] = european_payoff(( *( Xs_array + (knockedLeg_dash) ) ), sim_dash[NL-1], cp_sign, dir_sign, equivalent_notional);
|
402
410
|
}
|
403
411
|
else{
|
@@ -584,14 +592,14 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
584
592
|
//
|
585
593
|
// rb_p(rb_str_new2("Converting metrics"));
|
586
594
|
VALUE final_metrics = rb_ary_new();
|
587
|
-
for(metric = 0; metric <
|
588
|
-
VALUE leg_metrics = rb_ary_new();
|
595
|
+
for(metric = 0; metric < SCount; metric++) {
|
596
|
+
// VALUE leg_metrics = rb_ary_new();
|
589
597
|
|
590
|
-
for(leg = 0; leg < NL; leg++) {
|
591
|
-
|
592
|
-
}
|
598
|
+
// for(leg = 0; leg < NL; leg++) {
|
599
|
+
// rb_ary_push( leg_metrics, DBL2NUM( metrics[metric][leg] ) );
|
600
|
+
// }
|
593
601
|
|
594
|
-
rb_ary_push(final_metrics,
|
602
|
+
rb_ary_push(final_metrics, data[metric]);
|
595
603
|
}
|
596
604
|
|
597
605
|
// 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.34'
|
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
|