tarf_monte_carlo 3.11 → 3.15.1

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: 850a097b6405e2fa4e128216700ef8c0a4748e9eddbc08ecadf7e0b1987c7e48
4
- data.tar.gz: 2184d334e6b788c45a555e526a0fcb00788722de7068755dac602523699f80f7
3
+ metadata.gz: c46dcadc23792b6ddc2ecf64ddd7c9fd3ff8f2d0e63ff724980d9b4e035ef7ba
4
+ data.tar.gz: 4c9758d8596cb11ccb4d341b74eae1d89e8f375b4bde8d37f2307fa919d1bac2
5
5
  SHA512:
6
- metadata.gz: de2b4441025568d072934b8c530c6c81f50f659a72347f3e06e4e561d283241c37681ad9425c405054dae83c7838714b8edeb37a298703f8da84ca4ebf337ec3
7
- data.tar.gz: da7fec9328f798922d3fa1e16f6840d9a48654ae597936a3e3d0fe01c73611e08404ab05c9deabfaadd7ef0a95fa55dba7ce2539b8586e10a7dc65be0c35cb50
6
+ metadata.gz: 52b46220de4844bcacaeca2be8828123e62c55c2f0a8209ea7e30558f31be31a996ecda344548b81a7a8861e08b5ece70de3dbf59564ee62d5af4ae509d72d24
7
+ data.tar.gz: 7bdb222b49e64f948b28277ddb45782f8023f1b9ac6afc235f2802f24e4c268bb67ec75ffadfc366f779e3cdc6bafb9cd0a19f03af71136e2386a0b40259e339
data/.gitignore CHANGED
File without changes
@@ -124,10 +124,22 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
124
124
  vs_array[leg] = NUM2DBL( rb_ary_entry(vs, leg) );
125
125
  bs_array[leg] = NUM2DBL( rb_ary_entry(bs, leg) );
126
126
  DFs_array[leg] = NUM2DBL( rb_ary_entry(DFs, leg) );
127
- Ps_array[leg] = NUM2DBL( rb_ary_entry(Ps, leg) );
128
- CFs_array[leg] = NUM2DBL( rb_ary_entry(CFs, leg) );
129
- LSts_array[leg] = NUM2DBL( rb_ary_entry(LSts, leg) );
130
- USts_array[leg] = NUM2DBL( rb_ary_entry(USts, leg) );
127
+ }
128
+ // extra tarf structures
129
+ if ( KType == PIVOT_POINTS ) {
130
+ for (leg = 0; leg < NL; ++leg) {
131
+ Ps_array[leg] = NUM2DBL( rb_ary_entry(Ps, leg) );
132
+ }
133
+ } else if ( KType == COLLAR_POINTS ) {
134
+ for (leg = 0; leg < NL; ++leg) {
135
+ CFs_array[leg] = NUM2DBL( rb_ary_entry(CFs, leg) );
136
+ }
137
+ } else if ( KType == DUAL_STRIKE_POINTS ) {
138
+ for (leg = 0; leg < NL; ++leg) {
139
+ Ps_array[leg] = NUM2DBL( rb_ary_entry(Ps, leg) );
140
+ LSts_array[leg] = NUM2DBL( rb_ary_entry(LSts, leg) );
141
+ USts_array[leg] = NUM2DBL( rb_ary_entry(USts, leg) );
142
+ }
131
143
  }
132
144
 
133
145
  //
@@ -175,27 +187,91 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
175
187
  Spot = Spot * exp( drift + vSqrdt * eps );
176
188
  Spot_dash = Spot_dash * exp( drift + vSqrdt * eps_dash );
177
189
 
178
- if ( BS == BUY ) {
179
- // profit if spot is higher than market price
180
- profit_loss = ( Spot - ( *( Xs_array + leg ) ) );
190
+ // Payoff of Dual strike points is independent of direction
191
+ if ( KType == DUAL_STRIKE_POINTS ) {
192
+ if ( Spot < *( LSts_array + leg ) ) {
193
+ profit_loss = Spot - (*( LSts_array + leg ));
194
+ } else if(Spot > *( USts_array + leg )){
195
+ profit_loss = (*( USts_array + leg ) - Spot);
196
+ } else if(Spot >= *( LSts_array + leg ) && (Spot < *(Ps_array + leg))) {
197
+ profit_loss = (*( LSts_array + leg )) - Spot;
198
+ } else {
199
+ profit_loss = Spot - (*( USts_array + leg ));
200
+ }
201
+ // dash
202
+ if ( Spot_dash < *( LSts_array + leg ) ) {
203
+ profit_loss_dash = Spot_dash - (*( LSts_array + leg ));
204
+ } else if(Spot_dash > *( USts_array + leg )){
205
+ profit_loss_dash = (*( USts_array + leg ) - Spot_dash);
206
+ } else if(Spot_dash >= *( LSts_array + leg ) && (Spot_dash < *(Ps_array + leg))) {
207
+ profit_loss_dash = (*( LSts_array + leg )) - Spot_dash;
208
+ } else {
209
+ profit_loss_dash = Spot_dash - (*( USts_array + leg ));
210
+ }
211
+ }
212
+ else if ( BS == BUY ) {
213
+ if ( KType == PIVOT_POINTS ) {
214
+ if ( *( Xs_array + leg ) > Spot && Spot > *( Ps_array + leg ) ) {
215
+ profit_loss = 0.0;
216
+ } else {
217
+ profit_loss = Spot - (*( Xs_array + leg ));
218
+ }
219
+ // dash
220
+ if ( *( Xs_array + leg ) > Spot_dash && Spot_dash > *( Ps_array + leg ) ) {
221
+ profit_loss_dash = 0.0;
222
+ } else {
223
+ profit_loss_dash = Spot_dash - (*( Xs_array + leg ));
224
+ }
225
+ } else if ( KType == COLLAR_POINTS ) {
226
+ if ( *( Xs_array + leg ) > Spot && Spot > *( CFs_array + leg ) ) {
227
+ profit_loss = 0.0;
228
+ } else if(Spot <= *( CFs_array + leg )){
229
+ profit_loss = Spot - (*( CFs_array + leg ));
230
+ } else {
231
+ profit_loss = Spot - (*( Xs_array + leg ));
232
+ }
233
+ // dash
234
+ if ( *( Xs_array + leg ) > Spot_dash && Spot_dash > *( CFs_array + leg ) ) {
235
+ profit_loss_dash = 0.0;
236
+ } else if(Spot_dash <= *( CFs_array + leg )){
237
+ profit_loss_dash = Spot_dash - (*( CFs_array + leg ));
238
+ } else {
239
+ profit_loss_dash = Spot_dash - (*( Xs_array + leg ));
240
+ }
241
+ } else {
181
242
  // profit if spot is higher than market price
182
- profit_loss_dash = ( Spot_dash - ( *( Xs_array + leg ) ) );
243
+ profit_loss = ( Spot - ( *( Xs_array + leg ) ) );
244
+ // profit if spot is higher than market price
245
+ profit_loss_dash = ( Spot_dash - ( *( Xs_array + leg ) ) );
246
+ }
183
247
  } else if ( BS == SELL ) {
184
248
  if ( KType == PIVOT_POINTS ) {
185
- if ( Spot <= *( Xs_array + leg ) && Spot < *( Ps_array + leg ) ) {
186
- profit_loss = *( Xs_array + leg ) - Spot;
187
- } else if ( Spot > *( Xs_array + leg ) && Spot >= *( Ps_array + leg ) ) {
188
- profit_loss = *( Xs_array + leg ) - Spot;
189
- } else {
249
+ if ( *( Xs_array + leg ) < Spot && Spot < *( Ps_array + leg ) ) {
190
250
  profit_loss = 0.0;
251
+ } else {
252
+ profit_loss = ( ( *( Xs_array + leg ) ) - Spot );
191
253
  }
192
254
  // dash
193
- if ( Spot_dash <= *( Xs_array + leg ) && Spot_dash < *( Ps_array + leg ) ) {
194
- profit_loss_dash = *( Xs_array + leg ) - Spot_dash;
195
- } else if ( Spot_dash > *( Xs_array + leg ) && Spot_dash >= *( Ps_array + leg ) ) {
196
- profit_loss_dash = *( Xs_array + leg ) - Spot_dash;
255
+ if ( *( Xs_array + leg ) < Spot_dash && Spot_dash < *( Ps_array + leg ) ) {
256
+ profit_loss_dash = 0.0;
257
+ } else {
258
+ profit_loss_dash = ( ( *( Xs_array + leg ) ) - Spot_dash );
259
+ }
260
+ } else if ( KType == COLLAR_POINTS ) {
261
+ if ( *( Xs_array + leg ) < Spot && Spot < *( CFs_array + leg ) ) {
262
+ profit_loss = 0.0;
263
+ } else if(Spot >= *( CFs_array + leg )){
264
+ profit_loss = ( ( *( CFs_array + leg ) ) - Spot );
197
265
  } else {
266
+ profit_loss = ( ( *( Xs_array + leg ) ) - Spot );
267
+ }
268
+ // dash
269
+ if ( *( Xs_array + leg ) < Spot_dash && Spot_dash < *( CFs_array + leg ) ) {
198
270
  profit_loss_dash = 0.0;
271
+ } else if(Spot_dash >= *( CFs_array + leg )){
272
+ profit_loss_dash = ( ( *( CFs_array + leg ) ) - Spot_dash );
273
+ } else {
274
+ profit_loss_dash = ( ( *( Xs_array + leg ) ) - Spot_dash );
199
275
  }
200
276
  } else {
201
277
  // profit if spot is lower than market price
@@ -225,7 +301,6 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
225
301
  }
226
302
  }
227
303
  // legs loop end
228
-
229
304
  // start from the Knock value
230
305
  double ko_so_far = K, ko_so_far_dash = K;
231
306
  if( KType == ABSOLUTE ) {
@@ -268,7 +343,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
268
343
  }
269
344
  }
270
345
  }
271
- } else if( KType == POINTS ) {
346
+ } else if( KType == POINTS || KType == PIVOT_POINTS || KType == COLLAR_POINTS || KType == DUAL_STRIKE_POINTS ) {
272
347
  for( leg = 0; leg < NL; ++leg ) {
273
348
  // simulation normal
274
349
  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.1.gem
3
3
  # gem yank tarf_monte_carlo -v 2.3
4
4
 
5
5
  module TarfMonteCarlo
6
- VERSION = "3.11"
6
+ VERSION = "3.15.1"
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.11'
4
+ version: 3.15.1
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-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler