tarf_monte_carlo 3.14 → 3.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/tarf_monte_carlo/tarf_monte_carlo.c +90 -12
- data/lib/tarf_monte_carlo/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54ce8c237aa74a9e1ba9364b4ca30009af7a01e27b0b3d1881d31e2d611877d6
|
4
|
+
data.tar.gz: 0fb60c7a494442af9621f8d686e161718381e3e4c88b2862c9af2b27de5267f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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 ==
|
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
|
-
|
190
|
-
|
191
|
-
|
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
|
-
|
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 ==
|
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 ) {
|
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.
|
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-
|
11
|
+
date: 2020-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|