tarf_monte_carlo 3.14 → 3.16

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: d8d2906e29ad90b4dc0ff480eec64fed2a8d7aaca0e5933de6fa1d672185a38b
4
- data.tar.gz: d8afc4b56ea885bcd67299273ab887b2c97b6e73e6d218729a9e39b54433a240
3
+ metadata.gz: 54ce8c237aa74a9e1ba9364b4ca30009af7a01e27b0b3d1881d31e2d611877d6
4
+ data.tar.gz: 0fb60c7a494442af9621f8d686e161718381e3e4c88b2862c9af2b27de5267f8
5
5
  SHA512:
6
- metadata.gz: ae61b13786e7deb50903881364d793c96db0d453f34f54dd6dd4040a4eb3f86cfaeb6217be6433cbc8f9827c7ba12caabcfc2953edf3a18088a17eceda03fafc
7
- data.tar.gz: 546c462c9ccb5038e9ebb385aec5ccc1f66745d011d72f55c68afa9ec0a83847b0d8beea21bc531610453bd473e82e3a6792c0dc9138125247c32afd2228539d
6
+ metadata.gz: 41673dec376daaad4d6b364f4fde9c6c6a4ed4022ed733dd8ce6cf15db70fb1e07fec9b065cccb646dc544c18d020d4055548be0174ee2833c5ad3ec0cd2523a
7
+ data.tar.gz: ba2e90612c68f7aaea158e7c7c43b19520e745eb8761d03f176f4051ac37fda5cc9ad819d42844334a0d32774aaae5c6f60cc68c326d66f65d3da5a27e08468e
@@ -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
@@ -126,16 +136,17 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
126
136
  DFs_array[leg] = NUM2DBL( rb_ary_entry(DFs, leg) );
127
137
  }
128
138
  // extra tarf structures
129
- if ( KType == PIVOT_POINTS ) {
139
+ if ( KType == PIVOT_POINTS || KType == PIVOT_ABSOLUTE || KType == PIVOT_LEGS ) {
130
140
  for (leg = 0; leg < NL; ++leg) {
131
141
  Ps_array[leg] = NUM2DBL( rb_ary_entry(Ps, leg) );
132
142
  }
133
- } else if ( KType == COLLAR_POINTS ) {
143
+ } else if ( KType == COLLAR_POINTS || KType == COLLAR_ABSOLUTE || KType == COLLAR_LEGS ) {
134
144
  for (leg = 0; leg < NL; ++leg) {
135
145
  CFs_array[leg] = NUM2DBL( rb_ary_entry(CFs, leg) );
136
146
  }
137
- } else if ( KType == DUAL_STRIKE_POINTS ) {
147
+ } else if ( KType == DOUBLE_STRIKE_POINTS || KType == DOUBLE_STRIKE_ABSOLUTE || KType == DOUBLE_STRIKE_LEGS) {
138
148
  for (leg = 0; leg < NL; ++leg) {
149
+ Ps_array[leg] = NUM2DBL( rb_ary_entry(Ps, leg) );
139
150
  LSts_array[leg] = NUM2DBL( rb_ary_entry(LSts, leg) );
140
151
  USts_array[leg] = NUM2DBL( rb_ary_entry(USts, leg) );
141
152
  }
@@ -186,13 +197,64 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
186
197
  Spot = Spot * exp( drift + vSqrdt * eps );
187
198
  Spot_dash = Spot_dash * exp( drift + vSqrdt * eps_dash );
188
199
 
189
- if ( BS == BUY ) {
190
- // profit if spot is higher than market price
191
- profit_loss = ( Spot - ( *( Xs_array + leg ) ) );
200
+ // Payoff of Dual strike points is independent of direction
201
+ if ( KType == DOUBLE_STRIKE_POINTS || KType == DOUBLE_STRIKE_ABSOLUTE || KType == DOUBLE_STRIKE_LEGS ) {
202
+ if ( Spot < *( LSts_array + leg ) ) {
203
+ profit_loss = Spot - (*( LSts_array + leg ));
204
+ } else if(Spot > *( USts_array + leg )){
205
+ profit_loss = (*( USts_array + leg ) - Spot);
206
+ } else if(Spot >= *( LSts_array + leg ) && (Spot < *(Ps_array + leg))) {
207
+ profit_loss = Spot - (*( LSts_array + leg ));
208
+ } else {
209
+ profit_loss = (*( USts_array + leg )) - Spot;
210
+ }
211
+ // dash
212
+ if ( Spot_dash < *( LSts_array + leg ) ) {
213
+ profit_loss_dash = Spot_dash - (*( LSts_array + leg ));
214
+ } else if(Spot_dash > *( USts_array + leg )){
215
+ profit_loss_dash = (*( USts_array + leg ) - Spot_dash);
216
+ } else if(Spot_dash >= *( LSts_array + leg ) && (Spot_dash < *(Ps_array + leg))) {
217
+ profit_loss_dash = Spot_dash - (*( LSts_array + leg ));
218
+ } else {
219
+ profit_loss_dash = (*( USts_array + leg )) - Spot_dash;
220
+ }
221
+ } else if ( BS == BUY ) {
222
+ if ( KType == PIVOT_POINTS || KType == PIVOT_ABSOLUTE || KType == PIVOT_LEGS ) {
223
+ if ( *( Xs_array + leg ) > Spot && Spot > *( Ps_array + leg ) ) {
224
+ profit_loss = 0.0;
225
+ } else {
226
+ profit_loss = Spot - (*( Xs_array + leg ));
227
+ }
228
+ // dash
229
+ if ( *( Xs_array + leg ) > Spot_dash && Spot_dash > *( Ps_array + leg ) ) {
230
+ profit_loss_dash = 0.0;
231
+ } else {
232
+ profit_loss_dash = Spot_dash - (*( Xs_array + leg ));
233
+ }
234
+ } else if ( KType == COLLAR_POINTS || KType == COLLAR_ABSOLUTE || KType == COLLAR_LEGS ) {
235
+ if ( *( Xs_array + leg ) > Spot && Spot > *( CFs_array + leg ) ) {
236
+ profit_loss = 0.0;
237
+ } else if(Spot <= *( CFs_array + leg )){
238
+ profit_loss = Spot - (*( CFs_array + leg ));
239
+ } else {
240
+ profit_loss = Spot - (*( Xs_array + leg ));
241
+ }
242
+ // dash
243
+ if ( *( Xs_array + leg ) > Spot_dash && Spot_dash > *( CFs_array + leg ) ) {
244
+ profit_loss_dash = 0.0;
245
+ } else if(Spot_dash <= *( CFs_array + leg )){
246
+ profit_loss_dash = Spot_dash - (*( CFs_array + leg ));
247
+ } else {
248
+ profit_loss_dash = Spot_dash - (*( Xs_array + leg ));
249
+ }
250
+ } else {
192
251
  // profit if spot is higher than market price
193
- profit_loss_dash = ( Spot_dash - ( *( Xs_array + leg ) ) );
252
+ profit_loss = ( Spot - ( *( Xs_array + leg ) ) );
253
+ // profit if spot is higher than market price
254
+ profit_loss_dash = ( Spot_dash - ( *( Xs_array + leg ) ) );
255
+ }
194
256
  } else if ( BS == SELL ) {
195
- if ( KType == PIVOT_POINTS ) {
257
+ if ( KType == PIVOT_POINTS || KType == PIVOT_ABSOLUTE || KType == PIVOT_LEGS ) {
196
258
  if ( *( Xs_array + leg ) < Spot && Spot < *( Ps_array + leg ) ) {
197
259
  profit_loss = 0.0;
198
260
  } else {
@@ -204,6 +266,22 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
204
266
  } else {
205
267
  profit_loss_dash = ( ( *( Xs_array + leg ) ) - Spot_dash );
206
268
  }
269
+ } else if ( KType == COLLAR_POINTS || KType == COLLAR_ABSOLUTE || KType == COLLAR_LEGS ) {
270
+ if ( *( Xs_array + leg ) < Spot && Spot < *( CFs_array + leg ) ) {
271
+ profit_loss = 0.0;
272
+ } else if(Spot >= *( CFs_array + leg )){
273
+ profit_loss = ( ( *( CFs_array + leg ) ) - Spot );
274
+ } else {
275
+ profit_loss = ( ( *( Xs_array + leg ) ) - Spot );
276
+ }
277
+ // dash
278
+ if ( *( Xs_array + leg ) < Spot_dash && Spot_dash < *( CFs_array + leg ) ) {
279
+ profit_loss_dash = 0.0;
280
+ } else if(Spot_dash >= *( CFs_array + leg )){
281
+ profit_loss_dash = ( ( *( CFs_array + leg ) ) - Spot_dash );
282
+ } else {
283
+ profit_loss_dash = ( ( *( Xs_array + leg ) ) - Spot_dash );
284
+ }
207
285
  } else {
208
286
  // profit if spot is lower than market price
209
287
  profit_loss = ( ( *( Xs_array + leg ) ) - Spot );
@@ -234,7 +312,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
234
312
  // legs loop end
235
313
  // start from the Knock value
236
314
  double ko_so_far = K, ko_so_far_dash = K;
237
- if( KType == ABSOLUTE ) {
315
+ if( KType == ABSOLUTE || KType == PIVOT_ABSOLUTE || KType == COLLAR_ABSOLUTE || KType == DOUBLE_STRIKE_ABSOLUTE ) {
238
316
  for( leg = 0; leg < NL; ++leg ) {
239
317
  // simulation normal
240
318
  if( ko_so_far > 0.0 ) {
@@ -274,7 +352,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
274
352
  }
275
353
  }
276
354
  }
277
- } else if( KType == POINTS || KType == PIVOT_POINTS || KType == COLLAR_POINTS || KType == DUAL_STRIKE_POINTS ) {
355
+ } else if( KType == POINTS || KType == PIVOT_POINTS || KType == COLLAR_POINTS || KType == DOUBLE_STRIKE_POINTS ) {
278
356
  for( leg = 0; leg < NL; ++leg ) {
279
357
  // simulation normal
280
358
  if ( ko_so_far > 0.0 ) {
@@ -308,7 +386,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
308
386
  }
309
387
  }
310
388
  }
311
- } else if( KType == LEGS ) {
389
+ } else if( KType == LEGS || KType == PIVOT_LEGS || KType == COLLAR_LEGS || KType == DOUBLE_STRIKE_LEGS ) {
312
390
  for( leg = 0; leg < NL; ++leg ) {
313
391
  // simulation normal
314
392
  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-2.3.gem
2
+ # gem push -v tarf_monte_carlo-3.15.3.gem
3
3
  # gem yank tarf_monte_carlo -v 2.3
4
4
 
5
5
  module TarfMonteCarlo
6
- VERSION = "3.14"
6
+ VERSION = "3.16"
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.14'
4
+ version: '3.16'
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-15 00:00:00.000000000 Z
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler