tarf_monte_carlo 3.15 → 3.17

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: 0f33686b3c3246f31356eb1f1cc2161bb1a23a87f305b4a34e370d6c59584180
4
- data.tar.gz: 3576f3fdb01ab53522ee92926d7536994551cc97503a9497c894b904c06582aa
3
+ metadata.gz: dfddf29d3a8c0d3029234c9acba98d0579c2cd035395594b730b74dadd9353ff
4
+ data.tar.gz: ee157914ed8faedc35096514802b25bd89eebdb6485300ad9e6762563ee65a1f
5
5
  SHA512:
6
- metadata.gz: 27375bd106d3365323189a6d00ab4398b2d6d94d32fa82ed6ea69dc4d1f050a78d333ce4a694f8fd0a722f5c380b4e76ff946269b6b8cd5f29a02243120cf2d9
7
- data.tar.gz: 5465e552c843af156e62bccbd1dbe34779c1f9e06f6596b2f142a817c4465299d635a8a1e8e4be0576e64ceae3f4017613209984aed02a2c0e4a2071425b9356
6
+ metadata.gz: f1645aef91181a04b99a91bf8ae9bfb983b82b0cfd27b2932914042481642ca1f77a096f65def64ab94f71f7c6876a5d89fc03f8125a9115e952c3058125f62a
7
+ data.tar.gz: 341783f3006b2c2d81181b3a1f7ca15c70550233e28991da9561f85dd60716a9190f6f126d6b2cf811841f15e2992f78b9c26d72383255c0b2a2c39c8bfcc066
@@ -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,15 +199,23 @@ 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 )){
195
206
  profit_loss = (*( USts_array + leg ) - Spot);
196
207
  } else if(Spot >= *( LSts_array + leg ) && (Spot < *(Ps_array + leg))) {
197
- profit_loss = (*( LSts_array + leg )) - Spot;
208
+ profit_loss = Spot - (*( LSts_array + leg ));
198
209
  } else {
199
- profit_loss = Spot - (*( USts_array + leg ))
210
+ profit_loss = (*( USts_array + leg )) - Spot;
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
+ }
200
219
  }
201
220
  // dash
202
221
  if ( Spot_dash < *( LSts_array + leg ) ) {
@@ -204,13 +223,12 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
204
223
  } else if(Spot_dash > *( USts_array + leg )){
205
224
  profit_loss_dash = (*( USts_array + leg ) - Spot_dash);
206
225
  } else if(Spot_dash >= *( LSts_array + leg ) && (Spot_dash < *(Ps_array + leg))) {
207
- profit_loss_dash = (*( LSts_array + leg )) - Spot_dash;
226
+ profit_loss_dash = Spot_dash - (*( LSts_array + leg ));
208
227
  } else {
209
- profit_loss_dash = Spot_dash - (*( USts_array + leg ))
228
+ profit_loss_dash = (*( USts_array + leg )) - Spot_dash;
210
229
  }
211
- }
212
- else if ( BS == BUY ) {
213
- if ( KType == PIVOT_POINTS ) {
230
+ } else if ( BS == BUY ) {
231
+ if ( KType == PIVOT_POINTS || KType == PIVOT_ABSOLUTE || KType == PIVOT_LEGS ) {
214
232
  if ( *( Xs_array + leg ) > Spot && Spot > *( Ps_array + leg ) ) {
215
233
  profit_loss = 0.0;
216
234
  } else {
@@ -222,7 +240,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
222
240
  } else {
223
241
  profit_loss_dash = Spot_dash - (*( Xs_array + leg ));
224
242
  }
225
- } else if ( KType == COLLAR_POINTS ) {
243
+ } else if ( KType == COLLAR_POINTS || KType == COLLAR_ABSOLUTE || KType == COLLAR_LEGS ) {
226
244
  if ( *( Xs_array + leg ) > Spot && Spot > *( CFs_array + leg ) ) {
227
245
  profit_loss = 0.0;
228
246
  } else if(Spot <= *( CFs_array + leg )){
@@ -245,7 +263,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
245
263
  profit_loss_dash = ( Spot_dash - ( *( Xs_array + leg ) ) );
246
264
  }
247
265
  } else if ( BS == SELL ) {
248
- if ( KType == PIVOT_POINTS ) {
266
+ if ( KType == PIVOT_POINTS || KType == PIVOT_ABSOLUTE || KType == PIVOT_LEGS ) {
249
267
  if ( *( Xs_array + leg ) < Spot && Spot < *( Ps_array + leg ) ) {
250
268
  profit_loss = 0.0;
251
269
  } else {
@@ -257,7 +275,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
257
275
  } else {
258
276
  profit_loss_dash = ( ( *( Xs_array + leg ) ) - Spot_dash );
259
277
  }
260
- } else if ( KType == COLLAR_POINTS ) {
278
+ } else if ( KType == COLLAR_POINTS || KType == COLLAR_ABSOLUTE || KType == COLLAR_LEGS ) {
261
279
  if ( *( Xs_array + leg ) < Spot && Spot < *( CFs_array + leg ) ) {
262
280
  profit_loss = 0.0;
263
281
  } else if(Spot >= *( CFs_array + leg )){
@@ -303,7 +321,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
303
321
  // legs loop end
304
322
  // start from the Knock value
305
323
  double ko_so_far = K, ko_so_far_dash = K;
306
- if( KType == ABSOLUTE ) {
324
+ if( KType == ABSOLUTE || KType == PIVOT_ABSOLUTE || KType == COLLAR_ABSOLUTE || KType == DOUBLE_STRIKE_ABSOLUTE ) {
307
325
  for( leg = 0; leg < NL; ++leg ) {
308
326
  // simulation normal
309
327
  if( ko_so_far > 0.0 ) {
@@ -343,7 +361,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
343
361
  }
344
362
  }
345
363
  }
346
- } else if( KType == POINTS || KType == PIVOT_POINTS || KType == COLLAR_POINTS || KType == DUAL_STRIKE_POINTS ) {
364
+ } else if( KType == POINTS || KType == PIVOT_POINTS || KType == COLLAR_POINTS || KType == DOUBLE_STRIKE_POINTS ) {
347
365
  for( leg = 0; leg < NL; ++leg ) {
348
366
  // simulation normal
349
367
  if ( ko_so_far > 0.0 ) {
@@ -377,7 +395,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
377
395
  }
378
396
  }
379
397
  }
380
- } else if( KType == LEGS ) {
398
+ } else if( KType == LEGS || KType == PIVOT_LEGS || KType == COLLAR_LEGS || KType == DOUBLE_STRIKE_LEGS ) {
381
399
  for( leg = 0; leg < NL; ++leg ) {
382
400
  // simulation normal
383
401
  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.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"
6
+ VERSION = "3.17"
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'
4
+ version: '3.17'
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