tarf_monte_carlo 3.15.2 → 3.19

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc23d4cbeb2b027663b1e8f6a2a3bcb559f4c63874bb2751358ce2e11e76412c
4
- data.tar.gz: 102bee43e62b5bff5e30e478b5bf030d5b5530c1bea05f49376bc2511d6c5716
3
+ metadata.gz: ebf0762f6765e8ae554a23e3e939185ed44968b85b3fbd22a2a9062c738fd523
4
+ data.tar.gz: 974090ba8593ee28ec2375362edea36cc830cc7db18693b2541864d25139fb33
5
5
  SHA512:
6
- metadata.gz: c635e944069ef99ea9f7b3cb1d5d18c07b0427288c91bd7d94a221dc1ec47eaed356aada77b8e51a73a3ef18ee20b9573717269702426f73f6efdb58e8e85fee
7
- data.tar.gz: ad0c9836a15abc620d10070c08f5cdce970543a58aad47b311151915d39d3f540e7968b02ad63c85eeace9d5bcce17af8b6a1bf7d48d81dd1d927b1ba8476eeb
6
+ metadata.gz: c237e5573ef3f7b3f1c4113f508c128fd3f8c9c5fb0e703545d08489a3bc3d57ebf69a8e64bb87c66b1df38218c90d13a93990a5afe17b4b30c70cf054c7323e
7
+ data.tar.gz: 62723066875cd488f090fb9a7285a8ef29211330744ae35a428d20dcf41c9f818a90d46dc330725af5b8d18e31c076182a8fe31bce6ff99901620d1de3723167
@@ -28,9 +28,19 @@
28
28
  #define ABSOLUTE 1 // knockout by absolute
29
29
  #define POINTS 2 // knockout by points
30
30
  #define LEGS 3 // knockout by legs
31
+
31
32
  #define PIVOT_POINTS 4
32
33
  #define COLLAR_POINTS 5
33
- #define DUAL_STRIKE_POINTS 6
34
+ #define DOUBLE_STRIKE_POINTS 6
35
+
36
+ #define PIVOT_ABSOLUTE 7
37
+ #define COLLAR_ABSOLUTE 8
38
+ #define DOUBLE_STRIKE_ABSOLUTE 9
39
+
40
+ #define PIVOT_LEGS 10
41
+ #define COLLAR_LEGS 11
42
+ #define DOUBLE_STRIKE_LEGS 12
43
+
34
44
  #define DATAPOINTS 200 // data for plotting
35
45
  #define INTERVAL 50
36
46
  #define SIM_LIMIT 196 // 196 + 4 = 200 simulations nedded
@@ -88,6 +98,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
88
98
  int KType = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("knockout_type")) );
89
99
  double S = NUM2DBL( rb_hash_aref(MCInputs, rb_str_new2("spot_rate")) );
90
100
  int Ko_compare_mult = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("multiplier")) );
101
+ int ConvertNotional = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("convert_notional")) );
91
102
 
92
103
  // assign leg specific attributes
93
104
  double *pvs_pos = ( double* ) malloc( SCount * sizeof(double) );
@@ -126,15 +137,15 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
126
137
  DFs_array[leg] = NUM2DBL( rb_ary_entry(DFs, leg) );
127
138
  }
128
139
  // extra tarf structures
129
- if ( KType == PIVOT_POINTS ) {
140
+ if ( KType == PIVOT_POINTS || KType == PIVOT_ABSOLUTE || KType == PIVOT_LEGS ) {
130
141
  for (leg = 0; leg < NL; ++leg) {
131
142
  Ps_array[leg] = NUM2DBL( rb_ary_entry(Ps, leg) );
132
143
  }
133
- } else if ( KType == COLLAR_POINTS ) {
144
+ } else if ( KType == COLLAR_POINTS || KType == COLLAR_ABSOLUTE || KType == COLLAR_LEGS ) {
134
145
  for (leg = 0; leg < NL; ++leg) {
135
146
  CFs_array[leg] = NUM2DBL( rb_ary_entry(CFs, leg) );
136
147
  }
137
- } else if ( KType == DUAL_STRIKE_POINTS ) {
148
+ } else if ( KType == DOUBLE_STRIKE_POINTS || KType == DOUBLE_STRIKE_ABSOLUTE || KType == DOUBLE_STRIKE_LEGS) {
138
149
  for (leg = 0; leg < NL; ++leg) {
139
150
  Ps_array[leg] = NUM2DBL( rb_ary_entry(Ps, leg) );
140
151
  LSts_array[leg] = NUM2DBL( rb_ary_entry(LSts, leg) );
@@ -188,7 +199,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
188
199
  Spot_dash = Spot_dash * exp( drift + vSqrdt * eps_dash );
189
200
 
190
201
  // Payoff of Dual strike points is independent of direction
191
- if ( KType == DUAL_STRIKE_POINTS ) {
202
+ if ( KType == DOUBLE_STRIKE_POINTS || KType == DOUBLE_STRIKE_ABSOLUTE || KType == DOUBLE_STRIKE_LEGS ) {
192
203
  if ( Spot < *( LSts_array + leg ) ) {
193
204
  profit_loss = Spot - (*( LSts_array + leg ));
194
205
  } else if(Spot > *( USts_array + leg )){
@@ -198,6 +209,16 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
198
209
  } else {
199
210
  profit_loss = (*( USts_array + leg )) - Spot;
200
211
  }
212
+
213
+ if (ConvertNotional == 1){
214
+ if(Spot < *( Ps_array + leg )){
215
+ Ns_array[leg] = *(Ns_array + leg) / *( LSts_array + leg );
216
+ } else {
217
+ Ns_array[leg] = *(Ns_array + leg) / *( USts_array + leg );
218
+ }
219
+ }
220
+ rb_p(Ns_array[leg]);
221
+
201
222
  // dash
202
223
  if ( Spot_dash < *( LSts_array + leg ) ) {
203
224
  profit_loss_dash = Spot_dash - (*( LSts_array + leg ));
@@ -209,7 +230,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
209
230
  profit_loss_dash = (*( USts_array + leg )) - Spot_dash;
210
231
  }
211
232
  } else if ( BS == BUY ) {
212
- if ( KType == PIVOT_POINTS ) {
233
+ if ( KType == PIVOT_POINTS || KType == PIVOT_ABSOLUTE || KType == PIVOT_LEGS ) {
213
234
  if ( *( Xs_array + leg ) > Spot && Spot > *( Ps_array + leg ) ) {
214
235
  profit_loss = 0.0;
215
236
  } else {
@@ -221,7 +242,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
221
242
  } else {
222
243
  profit_loss_dash = Spot_dash - (*( Xs_array + leg ));
223
244
  }
224
- } else if ( KType == COLLAR_POINTS ) {
245
+ } else if ( KType == COLLAR_POINTS || KType == COLLAR_ABSOLUTE || KType == COLLAR_LEGS ) {
225
246
  if ( *( Xs_array + leg ) > Spot && Spot > *( CFs_array + leg ) ) {
226
247
  profit_loss = 0.0;
227
248
  } else if(Spot <= *( CFs_array + leg )){
@@ -244,7 +265,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
244
265
  profit_loss_dash = ( Spot_dash - ( *( Xs_array + leg ) ) );
245
266
  }
246
267
  } else if ( BS == SELL ) {
247
- if ( KType == PIVOT_POINTS ) {
268
+ if ( KType == PIVOT_POINTS || KType == PIVOT_ABSOLUTE || KType == PIVOT_LEGS ) {
248
269
  if ( *( Xs_array + leg ) < Spot && Spot < *( Ps_array + leg ) ) {
249
270
  profit_loss = 0.0;
250
271
  } else {
@@ -256,7 +277,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
256
277
  } else {
257
278
  profit_loss_dash = ( ( *( Xs_array + leg ) ) - Spot_dash );
258
279
  }
259
- } else if ( KType == COLLAR_POINTS ) {
280
+ } else if ( KType == COLLAR_POINTS || KType == COLLAR_ABSOLUTE || KType == COLLAR_LEGS ) {
260
281
  if ( *( Xs_array + leg ) < Spot && Spot < *( CFs_array + leg ) ) {
261
282
  profit_loss = 0.0;
262
283
  } else if(Spot >= *( CFs_array + leg )){
@@ -302,7 +323,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
302
323
  // legs loop end
303
324
  // start from the Knock value
304
325
  double ko_so_far = K, ko_so_far_dash = K;
305
- if( KType == ABSOLUTE ) {
326
+ if( KType == ABSOLUTE || KType == PIVOT_ABSOLUTE || KType == COLLAR_ABSOLUTE || KType == DOUBLE_STRIKE_ABSOLUTE ) {
306
327
  for( leg = 0; leg < NL; ++leg ) {
307
328
  // simulation normal
308
329
  if( ko_so_far > 0.0 ) {
@@ -342,7 +363,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
342
363
  }
343
364
  }
344
365
  }
345
- } else if( KType == POINTS || KType == PIVOT_POINTS || KType == COLLAR_POINTS || KType == DUAL_STRIKE_POINTS ) {
366
+ } else if( KType == POINTS || KType == PIVOT_POINTS || KType == COLLAR_POINTS || KType == DOUBLE_STRIKE_POINTS ) {
346
367
  for( leg = 0; leg < NL; ++leg ) {
347
368
  // simulation normal
348
369
  if ( ko_so_far > 0.0 ) {
@@ -376,7 +397,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
376
397
  }
377
398
  }
378
399
  }
379
- } else if( KType == LEGS ) {
400
+ } else if( KType == LEGS || KType == PIVOT_LEGS || KType == COLLAR_LEGS || KType == DOUBLE_STRIKE_LEGS ) {
380
401
  for( leg = 0; leg < NL; ++leg ) {
381
402
  // simulation normal
382
403
  if ( ko_so_far > 0.0 ) {
@@ -1,7 +1,7 @@
1
1
  # gem build tarf_monte_carlo.gemspec
2
- # gem push -v tarf_monte_carlo-3.15.2.gem
2
+ # gem push -v tarf_monte_carlo-3.17.gem
3
3
  # gem yank tarf_monte_carlo -v 2.3
4
4
 
5
5
  module TarfMonteCarlo
6
- VERSION = "3.15.2"
6
+ VERSION = "3.19"
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.15.2
4
+ version: '3.19'
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-09-16 00:00:00.000000000 Z
11
+ date: 2020-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler