tarf_monte_carlo 3.15.1 → 3.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c46dcadc23792b6ddc2ecf64ddd7c9fd3ff8f2d0e63ff724980d9b4e035ef7ba
4
- data.tar.gz: 4c9758d8596cb11ccb4d341b74eae1d89e8f375b4bde8d37f2307fa919d1bac2
3
+ metadata.gz: 63529c3feb06da0ff7629efee32fdcc556e3f5e3a4097c2aee0cd7be486fefc6
4
+ data.tar.gz: 7f6820db997c5ca7a1625a6ac749c43e4d157bcdd014fb444dfa78e36d353ce4
5
5
  SHA512:
6
- metadata.gz: 52b46220de4844bcacaeca2be8828123e62c55c2f0a8209ea7e30558f31be31a996ecda344548b81a7a8861e08b5ece70de3dbf59564ee62d5af4ae509d72d24
7
- data.tar.gz: 7bdb222b49e64f948b28277ddb45782f8023f1b9ac6afc235f2802f24e4c268bb67ec75ffadfc366f779e3cdc6bafb9cd0a19f03af71136e2386a0b40259e339
6
+ metadata.gz: 3ff13cfe43ccc9aeb464109f4145c166bf52656af5a7dbc55d988d35616dda050fca0aa1afa7bd2b5497c405efae45fd7573029da5e8a9aacee02fd1bab67c6e
7
+ data.tar.gz: bdd9417450d94711960a3ad1f66f173e685a07ca633f4cd779ccb2465e7490aa55cd2ee4f47c1cb10c9e70056a911bd78f94794e94efaf663ba62ee552cee1be
@@ -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.1.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.1"
6
+ VERSION = "3.18"
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.1
4
+ version: '3.18'
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