tarf_monte_carlo 3.13 → 3.15.3

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: bf901445c70d80f370053ffa90ba2cc6fb3e12b9ad7c372777cae63b92ceecdb
4
- data.tar.gz: 04331203b779e146db0e48a7eb9d1a0452c31aee17311c5f3c863d2104bc080b
3
+ metadata.gz: 9f59add36257db0337d6c1a72238af5d328892cb59959117797130e5b90b0f31
4
+ data.tar.gz: d78b75d035a82c487bdc15797e3589ff4c15f33f9180eea8f8d211b847c22fc6
5
5
  SHA512:
6
- metadata.gz: b912836d2d1a64d62c9b1d394be9ca89c5dbeb245312ce18d9490751bf61fd1fc9ade361a60446d1a0b1df7928882e5e4d0691b0e8c7528733f9bdfc49ccf6b2
7
- data.tar.gz: '08248d29944ff3fb8981d7bda9506bd056869575e54cb1ec6aa3be403b945cbe1b11c6bcb1cc42193f5617330d1be6633f4f1c2ab331cd2cc70d4cf455ef7df1'
6
+ metadata.gz: 675daf6c71ee357cc6eca37080acc93fa5211dc9737104c92ef0adc1c9d8bd8b61275d681fa64b1fd3da8832867b1f8e879eea8198d4b29dd06d1188eb645ba7
7
+ data.tar.gz: bbc2a4bfe53e589db3225c86bec1449adee93e2f9022f6b62775eca692b6a62a832988e627be1a0edf35478aa4a876a260735d1d0288eb3fac03023eaf3ae2c7
@@ -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.13"
6
+ VERSION = "3.15.3"
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.13'
4
+ version: 3.15.3
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