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 +4 -4
- data/.gitignore +0 -0
- data/ext/tarf_monte_carlo/tarf_monte_carlo.c +94 -19
- 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: c46dcadc23792b6ddc2ecf64ddd7c9fd3ff8f2d0e63ff724980d9b4e035ef7ba
|
4
|
+
data.tar.gz: 4c9758d8596cb11ccb4d341b74eae1d89e8f375b4bde8d37f2307fa919d1bac2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
-
|
179
|
-
|
180
|
-
|
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
|
-
|
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 (
|
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 (
|
194
|
-
profit_loss_dash =
|
195
|
-
} else
|
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 ) {
|
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.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-
|
11
|
+
date: 2020-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|