tarf_monte_carlo 3.12 → 3.15.2
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 +4 -4
- data/.gitignore +0 -0
- data/ext/tarf_monte_carlo/tarf_monte_carlo.c +88 -18
- 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: bc23d4cbeb2b027663b1e8f6a2a3bcb559f4c63874bb2751358ce2e11e76412c
|
|
4
|
+
data.tar.gz: 102bee43e62b5bff5e30e478b5bf030d5b5530c1bea05f49376bc2511d6c5716
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c635e944069ef99ea9f7b3cb1d5d18c07b0427288c91bd7d94a221dc1ec47eaed356aada77b8e51a73a3ef18ee20b9573717269702426f73f6efdb58e8e85fee
|
|
7
|
+
data.tar.gz: ad0c9836a15abc620d10070c08f5cdce970543a58aad47b311151915d39d3f540e7968b02ad63c85eeace9d5bcce17af8b6a1bf7d48d81dd1d927b1ba8476eeb
|
data/.gitignore
CHANGED
|
File without changes
|
|
@@ -124,11 +124,19 @@ 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
|
-
|
|
127
|
+
}
|
|
128
|
+
// extra tarf structures
|
|
129
|
+
if ( KType == PIVOT_POINTS ) {
|
|
130
|
+
for (leg = 0; leg < NL; ++leg) {
|
|
128
131
|
Ps_array[leg] = NUM2DBL( rb_ary_entry(Ps, leg) );
|
|
129
|
-
}
|
|
132
|
+
}
|
|
133
|
+
} else if ( KType == COLLAR_POINTS ) {
|
|
134
|
+
for (leg = 0; leg < NL; ++leg) {
|
|
130
135
|
CFs_array[leg] = NUM2DBL( rb_ary_entry(CFs, leg) );
|
|
131
|
-
}
|
|
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) );
|
|
132
140
|
LSts_array[leg] = NUM2DBL( rb_ary_entry(LSts, leg) );
|
|
133
141
|
USts_array[leg] = NUM2DBL( rb_ary_entry(USts, leg) );
|
|
134
142
|
}
|
|
@@ -179,27 +187,90 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
|
179
187
|
Spot = Spot * exp( drift + vSqrdt * eps );
|
|
180
188
|
Spot_dash = Spot_dash * exp( drift + vSqrdt * eps_dash );
|
|
181
189
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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 = Spot - (*( LSts_array + leg ));
|
|
198
|
+
} else {
|
|
199
|
+
profit_loss = (*( USts_array + leg )) - Spot;
|
|
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 = Spot_dash - (*( LSts_array + leg ));
|
|
208
|
+
} else {
|
|
209
|
+
profit_loss_dash = (*( USts_array + leg )) - Spot_dash;
|
|
210
|
+
}
|
|
211
|
+
} else if ( BS == BUY ) {
|
|
212
|
+
if ( KType == PIVOT_POINTS ) {
|
|
213
|
+
if ( *( Xs_array + leg ) > Spot && Spot > *( Ps_array + leg ) ) {
|
|
214
|
+
profit_loss = 0.0;
|
|
215
|
+
} else {
|
|
216
|
+
profit_loss = Spot - (*( Xs_array + leg ));
|
|
217
|
+
}
|
|
218
|
+
// dash
|
|
219
|
+
if ( *( Xs_array + leg ) > Spot_dash && Spot_dash > *( Ps_array + leg ) ) {
|
|
220
|
+
profit_loss_dash = 0.0;
|
|
221
|
+
} else {
|
|
222
|
+
profit_loss_dash = Spot_dash - (*( Xs_array + leg ));
|
|
223
|
+
}
|
|
224
|
+
} else if ( KType == COLLAR_POINTS ) {
|
|
225
|
+
if ( *( Xs_array + leg ) > Spot && Spot > *( CFs_array + leg ) ) {
|
|
226
|
+
profit_loss = 0.0;
|
|
227
|
+
} else if(Spot <= *( CFs_array + leg )){
|
|
228
|
+
profit_loss = Spot - (*( CFs_array + leg ));
|
|
229
|
+
} else {
|
|
230
|
+
profit_loss = Spot - (*( Xs_array + leg ));
|
|
231
|
+
}
|
|
232
|
+
// dash
|
|
233
|
+
if ( *( Xs_array + leg ) > Spot_dash && Spot_dash > *( CFs_array + leg ) ) {
|
|
234
|
+
profit_loss_dash = 0.0;
|
|
235
|
+
} else if(Spot_dash <= *( CFs_array + leg )){
|
|
236
|
+
profit_loss_dash = Spot_dash - (*( CFs_array + leg ));
|
|
237
|
+
} else {
|
|
238
|
+
profit_loss_dash = Spot_dash - (*( Xs_array + leg ));
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
185
241
|
// profit if spot is higher than market price
|
|
186
|
-
|
|
242
|
+
profit_loss = ( Spot - ( *( Xs_array + leg ) ) );
|
|
243
|
+
// profit if spot is higher than market price
|
|
244
|
+
profit_loss_dash = ( Spot_dash - ( *( Xs_array + leg ) ) );
|
|
245
|
+
}
|
|
187
246
|
} else if ( BS == SELL ) {
|
|
188
247
|
if ( KType == PIVOT_POINTS ) {
|
|
189
|
-
if (
|
|
190
|
-
profit_loss = *( Xs_array + leg ) - Spot;
|
|
191
|
-
} else if ( Spot > *( Xs_array + leg ) && Spot >= *( Ps_array + leg ) ) {
|
|
192
|
-
profit_loss = *( Xs_array + leg ) - Spot;
|
|
193
|
-
} else {
|
|
248
|
+
if ( *( Xs_array + leg ) < Spot && Spot < *( Ps_array + leg ) ) {
|
|
194
249
|
profit_loss = 0.0;
|
|
250
|
+
} else {
|
|
251
|
+
profit_loss = ( ( *( Xs_array + leg ) ) - Spot );
|
|
195
252
|
}
|
|
196
253
|
// dash
|
|
197
|
-
if (
|
|
198
|
-
profit_loss_dash =
|
|
199
|
-
} else
|
|
200
|
-
profit_loss_dash = *( Xs_array + leg ) - Spot_dash;
|
|
254
|
+
if ( *( Xs_array + leg ) < Spot_dash && Spot_dash < *( Ps_array + leg ) ) {
|
|
255
|
+
profit_loss_dash = 0.0;
|
|
256
|
+
} else {
|
|
257
|
+
profit_loss_dash = ( ( *( Xs_array + leg ) ) - Spot_dash );
|
|
258
|
+
}
|
|
259
|
+
} else if ( KType == COLLAR_POINTS ) {
|
|
260
|
+
if ( *( Xs_array + leg ) < Spot && Spot < *( CFs_array + leg ) ) {
|
|
261
|
+
profit_loss = 0.0;
|
|
262
|
+
} else if(Spot >= *( CFs_array + leg )){
|
|
263
|
+
profit_loss = ( ( *( CFs_array + leg ) ) - Spot );
|
|
201
264
|
} else {
|
|
265
|
+
profit_loss = ( ( *( Xs_array + leg ) ) - Spot );
|
|
266
|
+
}
|
|
267
|
+
// dash
|
|
268
|
+
if ( *( Xs_array + leg ) < Spot_dash && Spot_dash < *( CFs_array + leg ) ) {
|
|
202
269
|
profit_loss_dash = 0.0;
|
|
270
|
+
} else if(Spot_dash >= *( CFs_array + leg )){
|
|
271
|
+
profit_loss_dash = ( ( *( CFs_array + leg ) ) - Spot_dash );
|
|
272
|
+
} else {
|
|
273
|
+
profit_loss_dash = ( ( *( Xs_array + leg ) ) - Spot_dash );
|
|
203
274
|
}
|
|
204
275
|
} else {
|
|
205
276
|
// profit if spot is lower than market price
|
|
@@ -229,7 +300,6 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
|
229
300
|
}
|
|
230
301
|
}
|
|
231
302
|
// legs loop end
|
|
232
|
-
|
|
233
303
|
// start from the Knock value
|
|
234
304
|
double ko_so_far = K, ko_so_far_dash = K;
|
|
235
305
|
if( KType == ABSOLUTE ) {
|
|
@@ -272,7 +342,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
|
272
342
|
}
|
|
273
343
|
}
|
|
274
344
|
}
|
|
275
|
-
} else if( KType == POINTS ) {
|
|
345
|
+
} else if( KType == POINTS || KType == PIVOT_POINTS || KType == COLLAR_POINTS || KType == DUAL_STRIKE_POINTS ) {
|
|
276
346
|
for( leg = 0; leg < NL; ++leg ) {
|
|
277
347
|
// simulation normal
|
|
278
348
|
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:
|
|
4
|
+
version: 3.15.2
|
|
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-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|