tarf_monte_carlo 3.24 → 3.29

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82676c437016c3396bd0732ee1d20db01a0d4fea1243b3a4555a3b746024874b
4
- data.tar.gz: 774bf6b5cd0f5193c23477bd190aa88d538ae8f5977151e4129928ec13775354
3
+ metadata.gz: f522654ff1db977c9473f222c2759823b5abfabec305a05f46808509a089e997
4
+ data.tar.gz: 9057078c47fe076d38ba905d9bef3e857c8afff6962c3cbdc3afb73b88f41807
5
5
  SHA512:
6
- metadata.gz: f51579af9e3911d5a23324af39aee42d877e7067d86cf2781889de751fb49fff7df31be62acc450aaed89c7bf85d3f0759c34fb94de6445c47f4392226623e3b
7
- data.tar.gz: fdaff8bcd7ec29be4c0478cad38fe3469baea9ce657262c6e5422967968ccd7a463da96a477cc27bcc9906b5245a28707afac62cb4d1a93c29b9f73a51b25386
6
+ metadata.gz: dbe7c24227ce0280a09b0d055e1158f2585b6b46307065fa6d460ab8ed53b8a2423c398e2dd5ae6273249a0bfd10b0beb8abcedf4337597ffa2097940ed0efbd
7
+ data.tar.gz: 5f59b811c836dfb9b13cbafc7264651aad54a03a7420042543549e25548de72574a82274b54e1951d9dd9d3b763af0437ef95d35ff6b6fd29161ce355280fe2f
@@ -0,0 +1,264 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ # V=0 quiet, V=1 verbose. other values don't work.
5
+ V = 0
6
+ Q1 = $(V:1=)
7
+ Q = $(Q1:0=@)
8
+ ECHO1 = $(V:1=@ :)
9
+ ECHO = $(ECHO1:0=@ echo)
10
+ NULLCMD = :
11
+
12
+ #### Start of system configuration section. ####
13
+
14
+ srcdir = .
15
+ topdir = /Users/vivektripathi/.rvm/rubies/ruby-2.5.1/include/ruby-2.5.0
16
+ hdrdir = $(topdir)
17
+ arch_hdrdir = /Users/vivektripathi/.rvm/rubies/ruby-2.5.1/include/ruby-2.5.0/x86_64-darwin18
18
+ PATH_SEPARATOR = :
19
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
20
+ prefix = $(DESTDIR)/Users/vivektripathi/.rvm/rubies/ruby-2.5.1
21
+ rubysitearchprefix = $(rubylibprefix)/$(sitearch)
22
+ rubyarchprefix = $(rubylibprefix)/$(arch)
23
+ rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
24
+ exec_prefix = $(prefix)
25
+ vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
26
+ sitearchhdrdir = $(sitehdrdir)/$(sitearch)
27
+ rubyarchhdrdir = $(rubyhdrdir)/$(arch)
28
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
29
+ sitehdrdir = $(rubyhdrdir)/site_ruby
30
+ rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
31
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
32
+ vendorlibdir = $(vendordir)/$(ruby_version)
33
+ vendordir = $(rubylibprefix)/vendor_ruby
34
+ sitearchdir = $(sitelibdir)/$(sitearch)
35
+ sitelibdir = $(sitedir)/$(ruby_version)
36
+ sitedir = $(rubylibprefix)/site_ruby
37
+ rubyarchdir = $(rubylibdir)/$(arch)
38
+ rubylibdir = $(rubylibprefix)/$(ruby_version)
39
+ sitearchincludedir = $(includedir)/$(sitearch)
40
+ archincludedir = $(includedir)/$(arch)
41
+ sitearchlibdir = $(libdir)/$(sitearch)
42
+ archlibdir = $(libdir)/$(arch)
43
+ ridir = $(datarootdir)/$(RI_BASE_NAME)
44
+ mandir = $(datarootdir)/man
45
+ localedir = $(datarootdir)/locale
46
+ libdir = $(exec_prefix)/lib
47
+ psdir = $(docdir)
48
+ pdfdir = $(docdir)
49
+ dvidir = $(docdir)
50
+ htmldir = $(docdir)
51
+ infodir = $(datarootdir)/info
52
+ docdir = $(datarootdir)/doc/$(PACKAGE)
53
+ oldincludedir = $(SDKROOT)/usr/include
54
+ includedir = $(prefix)/include
55
+ localstatedir = $(prefix)/var
56
+ sharedstatedir = $(prefix)/com
57
+ sysconfdir = $(prefix)/etc
58
+ datadir = $(datarootdir)
59
+ datarootdir = $(prefix)/share
60
+ libexecdir = $(exec_prefix)/libexec
61
+ sbindir = $(exec_prefix)/sbin
62
+ bindir = $(exec_prefix)/bin
63
+ archdir = $(rubyarchdir)
64
+
65
+
66
+ CC = gcc
67
+ CXX = g++
68
+ LIBRUBY = $(LIBRUBY_SO)
69
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
70
+ LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
71
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -framework Foundation
72
+ empty =
73
+ OUTFLAG = -o $(empty)
74
+ COUTFLAG = -o $(empty)
75
+ CSRCFLAG = $(empty)
76
+
77
+ RUBY_EXTCONF_H =
78
+ cflags = $(optflags) $(debugflags) $(warnflags)
79
+ cxxflags = $(optflags) $(debugflags) $(warnflags)
80
+ optflags = -O3
81
+ debugflags = -ggdb3
82
+ warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens
83
+ CCDLFLAGS = -fno-common
84
+ CFLAGS = $(CCDLFLAGS) $(cflags) -fno-common -pipe $(ARCH_FLAG)
85
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
86
+ DEFS =
87
+ CPPFLAGS = -I/usr/local/opt/libyaml/include -I/usr/local/opt/libksba/include -I/usr/local/opt/readline/include -I/usr/local/opt/zlib/include -I/usr/local/opt/openssl@1.1/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags)
88
+ CXXFLAGS = $(CCDLFLAGS) $(cxxflags) $(ARCH_FLAG)
89
+ ldflags = -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/zlib/lib -L/usr/local/opt/openssl@1.1/lib
90
+ dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -L/usr/local/opt/libyaml/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/zlib/lib -L/usr/local/opt/openssl@1.1/lib
91
+ ARCH_FLAG =
92
+ DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
93
+ LDSHARED = $(CC) -dynamic -bundle
94
+ LDSHAREDXX = $(CXX) -dynamic -bundle
95
+ AR = libtool -static
96
+ EXEEXT =
97
+
98
+ RUBY_INSTALL_NAME = $(RUBY_BASE_NAME)
99
+ RUBY_SO_NAME = ruby.2.5.1
100
+ RUBYW_INSTALL_NAME =
101
+ RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
102
+ RUBYW_BASE_NAME = rubyw
103
+ RUBY_BASE_NAME = ruby
104
+
105
+ arch = x86_64-darwin18
106
+ sitearch = $(arch)
107
+ ruby_version = 2.5.0
108
+ ruby = $(bindir)/$(RUBY_BASE_NAME)
109
+ RUBY = $(ruby)
110
+ ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/backward.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h
111
+
112
+ RM = rm -f
113
+ RM_RF = $(RUBY) -run -e rm -- -rf
114
+ RMDIRS = rmdir -p
115
+ MAKEDIRS = /usr/local/opt/coreutils/bin/gmkdir -p
116
+ INSTALL = /usr/local/opt/coreutils/bin/ginstall -c
117
+ INSTALL_PROG = $(INSTALL) -m 0755
118
+ INSTALL_DATA = $(INSTALL) -m 644
119
+ COPY = cp
120
+ TOUCH = exit >
121
+
122
+ #### End of system configuration section. ####
123
+
124
+ preload =
125
+ libpath = . $(libdir) /usr/local/opt/libyaml/lib /usr/local/opt/libksba/lib /usr/local/opt/readline/lib /usr/local/opt/zlib/lib /usr/local/opt/openssl@1.1/lib
126
+ LIBPATH = -L. -L$(libdir) -L/usr/local/opt/libyaml/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/zlib/lib -L/usr/local/opt/openssl@1.1/lib
127
+ DEFFILE =
128
+
129
+ CLEANFILES = mkmf.log
130
+ DISTCLEANFILES =
131
+ DISTCLEANDIRS =
132
+
133
+ extout =
134
+ extout_prefix =
135
+ target_prefix = /tarf_monte_carlo
136
+ LOCAL_LIBS =
137
+ LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl -lobjc
138
+ ORIG_SRCS = tarf_monte_carlo (1).c tarf_monte_carlo.c
139
+ SRCS = $(ORIG_SRCS)
140
+ OBJS = tarf_monte_carlo (1).o tarf_monte_carlo.o
141
+ HDRS =
142
+ LOCAL_HDRS =
143
+ TARGET = tarf_monte_carlo
144
+ TARGET_NAME = tarf_monte_carlo
145
+ TARGET_ENTRY = Init_$(TARGET_NAME)
146
+ DLLIB = $(TARGET).bundle
147
+ EXTSTATIC =
148
+ STATIC_LIB =
149
+
150
+ TIMESTAMP_DIR = .
151
+ BINDIR = $(bindir)
152
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
153
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
154
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
155
+ HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
156
+ ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
157
+ TARGET_SO_DIR =
158
+ TARGET_SO = $(TARGET_SO_DIR)$(DLLIB)
159
+ CLEANLIBS = $(TARGET_SO)
160
+ CLEANOBJS = *.o *.bak
161
+
162
+ all: $(DLLIB)
163
+ static: $(STATIC_LIB)
164
+ .PHONY: all install static install-so install-rb
165
+ .PHONY: clean clean-so clean-static clean-rb
166
+
167
+ clean-static::
168
+ clean-rb-default::
169
+ clean-rb::
170
+ clean-so::
171
+ clean: clean-so clean-static clean-rb-default clean-rb
172
+ -$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
173
+
174
+ distclean-rb-default::
175
+ distclean-rb::
176
+ distclean-so::
177
+ distclean-static::
178
+ distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
179
+ -$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
180
+ -$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
181
+ -$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
182
+
183
+ realclean: distclean
184
+ install: install-so install-rb
185
+
186
+ install-so: $(DLLIB) $(TIMESTAMP_DIR)/.sitearchdir.-.tarf_monte_carlo.time
187
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
188
+ clean-static::
189
+ -$(Q)$(RM) $(STATIC_LIB)
190
+ install-rb: pre-install-rb do-install-rb install-rb-default
191
+ install-rb-default: pre-install-rb-default do-install-rb-default
192
+ pre-install-rb: Makefile
193
+ pre-install-rb-default: Makefile
194
+ do-install-rb:
195
+ do-install-rb-default:
196
+ pre-install-rb-default:
197
+ @$(NULLCMD)
198
+ $(TIMESTAMP_DIR)/.sitearchdir.-.tarf_monte_carlo.time:
199
+ $(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
200
+ $(Q) $(TOUCH) $@
201
+
202
+ site-install: site-install-so site-install-rb
203
+ site-install-so: install-so
204
+ site-install-rb: install-rb
205
+
206
+ .SUFFIXES: .c .m .cc .mm .cxx .cpp .o .S
207
+
208
+ .cc.o:
209
+ $(ECHO) compiling $(<)
210
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
211
+
212
+ .cc.S:
213
+ $(ECHO) translating $(<)
214
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
215
+
216
+ .mm.o:
217
+ $(ECHO) compiling $(<)
218
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
219
+
220
+ .mm.S:
221
+ $(ECHO) translating $(<)
222
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
223
+
224
+ .cxx.o:
225
+ $(ECHO) compiling $(<)
226
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
227
+
228
+ .cxx.S:
229
+ $(ECHO) translating $(<)
230
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
231
+
232
+ .cpp.o:
233
+ $(ECHO) compiling $(<)
234
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
235
+
236
+ .cpp.S:
237
+ $(ECHO) translating $(<)
238
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
239
+
240
+ .c.o:
241
+ $(ECHO) compiling $(<)
242
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
243
+
244
+ .c.S:
245
+ $(ECHO) translating $(<)
246
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
247
+
248
+ .m.o:
249
+ $(ECHO) compiling $(<)
250
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
251
+
252
+ .m.S:
253
+ $(ECHO) translating $(<)
254
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
255
+
256
+ $(TARGET_SO): $(OBJS) Makefile
257
+ $(ECHO) linking shared-object tarf_monte_carlo/$(DLLIB)
258
+ -$(Q)$(RM) $(@)
259
+ $(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
260
+ $(Q) $(POSTLINK)
261
+
262
+
263
+
264
+ $(OBJS): $(HDRS) $(ruby_headers)
@@ -41,6 +41,9 @@
41
41
  #define COLLAR_LEGS 11
42
42
  #define DOUBLE_STRIKE_LEGS 12
43
43
 
44
+ #define FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE 13
45
+ #define FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE 14
46
+
44
47
  #define DATAPOINTS 200 // data for plotting
45
48
  #define INTERVAL 50
46
49
  #define SIM_LIMIT 196 // 196 + 4 = 200 simulations nedded
@@ -53,6 +56,9 @@ VALUE cTarfMonteCarlo = Qnil;
53
56
 
54
57
  // Prototype for the initialization method - Ruby calls this, not you
55
58
  void Init_tarf_monte_carlo();
59
+ double european_payoff(double, double, int, int, double);
60
+ double get_equivalent_notional(int, double, float);
61
+ double get_equivalent_rebate(int, double, float);
56
62
 
57
63
  // Prototype for our methods - methods are prefixed by 'method_' here
58
64
  VALUE method_box_muller( VALUE );
@@ -77,11 +83,25 @@ VALUE method_box_muller( VALUE self ) {
77
83
  return DBL2NUM(eps);
78
84
  }
79
85
 
86
+ double european_payoff(double strike, double spot, int cp_sign, int dir_sign, double notional){
87
+ double diff = (spot - strike) * cp_sign;
88
+ diff = diff > 0 ? diff : 0;
89
+ return (diff * notional * dir_sign);
90
+ }
91
+
92
+ double get_equivalent_notional(int conversion_sign, double notional, float rate){
93
+ return (conversion_sign == 1) ? (notional / rate) : notional;
94
+ }
95
+
96
+ double get_equivalent_rebate(int conversion_sign, double rebate, float rate){
97
+ return (conversion_sign == 1) ? (rebate * rate) : rebate;
98
+ }
99
+
80
100
  // main method for running monte carlo simulation from sidekiq worker/outside method
81
101
  VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
82
102
  VALUE MCInputs = rb_ary_shift(args);
83
103
  // rb_p(rb_str_new2("MC Inputs:"));
84
- rb_p(MCInputs);
104
+ // rb_p(MCInputs);
85
105
 
86
106
  // seed value for rand() function
87
107
  srand( time(0) );
@@ -99,6 +119,11 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
99
119
  double S = NUM2DBL( rb_hash_aref(MCInputs, rb_str_new2("spot_rate")) );
100
120
  int Ko_compare_mult = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("multiplier")) );
101
121
  int ConvertNotional = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("convert_notional")) );
122
+ int dir_sign = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("direction_sign")) );
123
+ int dir2_sign = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("direction2_sign")) );
124
+ int cp_sign = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("callput_sign")) );
125
+ int conversion_sign = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("conversion_sign")) );
126
+ int rebate_conversion_sign = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("rebate_conversion_sign")) );
102
127
 
103
128
  // assign leg specific attributes
104
129
  double *pvs_pos = ( double* ) malloc( SCount * sizeof(double) );
@@ -115,6 +140,8 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
115
140
  double *LSts_array = ( double* ) malloc( NL * sizeof(double) );
116
141
  double *USts_array = ( double* ) malloc( NL * sizeof(double) );
117
142
  double *TempNs_array = ( double* ) malloc( NL * sizeof(double) );
143
+ double *Barrier_array = ( double* ) malloc( NL * sizeof(double) );
144
+ double *Rebate_array = ( double* ) malloc( NL * sizeof(double) );
118
145
 
119
146
  VALUE Ls = rb_hash_aref(MCInputs, rb_str_new2("leverage_ratios") );
120
147
  VALUE Ts = rb_hash_aref(MCInputs, rb_str_new2("expiration_times") );
@@ -127,6 +154,8 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
127
154
  VALUE CFs = rb_hash_aref(MCInputs, rb_str_new2("caps") );
128
155
  VALUE LSts = rb_hash_aref(MCInputs, rb_str_new2("lower_strikes") );
129
156
  VALUE USts = rb_hash_aref(MCInputs, rb_str_new2("upper_strikes") );
157
+ VALUE Brs = rb_hash_aref(MCInputs, rb_str_new2("barriers") );
158
+ VALUE Rbts = rb_hash_aref(MCInputs, rb_str_new2("rebates") );
130
159
 
131
160
  for (leg = 0; leg < NL; ++leg) {
132
161
  Ls_array[leg] = NUM2DBL( rb_ary_entry(Ls, leg) );
@@ -153,6 +182,11 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
153
182
  LSts_array[leg] = NUM2DBL( rb_ary_entry(LSts, leg) );
154
183
  USts_array[leg] = NUM2DBL( rb_ary_entry(USts, leg) );
155
184
  }
185
+ } else if (KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE || KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE) {
186
+ for (leg = 0; leg < NL; ++leg) {
187
+ Barrier_array[leg] = NUM2DBL( rb_ary_entry(Brs, leg) );
188
+ Rebate_array[leg] = NUM2DBL( rb_ary_entry(Rbts, leg) );
189
+ }
156
190
  }
157
191
 
158
192
  //
@@ -184,6 +218,8 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
184
218
  sim_dash_neg[leg] = 0.0;
185
219
  }
186
220
 
221
+ int knockedLeg = -1;
222
+ int knockedLeg_dash = -1;
187
223
  // legs loop start
188
224
  for( leg = 0; leg < NL; ++leg ) {
189
225
  double eps, eps_dash, drift, vSqrdt, profit_loss, profit_loss_dash;
@@ -200,8 +236,20 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
200
236
  Spot = Spot * exp( drift + vSqrdt * eps );
201
237
  Spot_dash = Spot_dash * exp( drift + vSqrdt * eps_dash );
202
238
 
203
- // Payoff of Dual strike points is independent of direction
204
- if ( KType == DOUBLE_STRIKE_POINTS || KType == DOUBLE_STRIKE_ABSOLUTE || KType == DOUBLE_STRIKE_LEGS ) {
239
+ if(KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE || KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE){
240
+ profit_loss = Spot;
241
+ profit_loss_dash = Spot_dash;
242
+
243
+ double knockin = (Spot - *(Barrier_array + leg)) * dir2_sign;
244
+ double knockin_dash = (Spot_dash - *(Barrier_array + leg)) * dir2_sign;
245
+
246
+ if(knockedLeg == -1 && knockin > 0){
247
+ knockedLeg = leg;
248
+ }
249
+ if(knockedLeg_dash == -1 && knockin_dash > 0){
250
+ knockedLeg_dash = leg;
251
+ }
252
+ } else if ( KType == DOUBLE_STRIKE_POINTS || KType == DOUBLE_STRIKE_ABSOLUTE || KType == DOUBLE_STRIKE_LEGS ) {
205
253
  if ( Spot < *( LSts_array + leg ) ) {
206
254
  profit_loss = Spot - (*( LSts_array + leg ));
207
255
  } else if(Spot > *( USts_array + leg )){
@@ -248,6 +296,10 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
248
296
  profit_loss = 0.0;
249
297
  } else if(Spot <= *( CFs_array + leg )){
250
298
  profit_loss = Spot - (*( CFs_array + leg ));
299
+
300
+ if (ConvertNotional == 1){
301
+ Ns_array[leg] = *(TempNs_array + leg) / *( CFs_array + leg );
302
+ }
251
303
  } else {
252
304
  profit_loss = Spot - (*( Xs_array + leg ));
253
305
  }
@@ -256,6 +308,10 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
256
308
  profit_loss_dash = 0.0;
257
309
  } else if(Spot_dash <= *( CFs_array + leg )){
258
310
  profit_loss_dash = Spot_dash - (*( CFs_array + leg ));
311
+
312
+ if (ConvertNotional == 1){
313
+ Ns_array[leg] = *(TempNs_array + leg) / *( CFs_array + leg );
314
+ }
259
315
  } else {
260
316
  profit_loss_dash = Spot_dash - (*( Xs_array + leg ));
261
317
  }
@@ -283,6 +339,10 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
283
339
  profit_loss = 0.0;
284
340
  } else if(Spot >= *( CFs_array + leg )){
285
341
  profit_loss = ( ( *( CFs_array + leg ) ) - Spot );
342
+
343
+ if (ConvertNotional == 1){
344
+ Ns_array[leg] = *(TempNs_array + leg) / *( CFs_array + leg );
345
+ }
286
346
  } else {
287
347
  profit_loss = ( ( *( Xs_array + leg ) ) - Spot );
288
348
  }
@@ -291,6 +351,10 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
291
351
  profit_loss_dash = 0.0;
292
352
  } else if(Spot_dash >= *( CFs_array + leg )){
293
353
  profit_loss_dash = ( ( *( CFs_array + leg ) ) - Spot_dash );
354
+
355
+ if (ConvertNotional == 1){
356
+ Ns_array[leg] = *(TempNs_array + leg) / *( CFs_array + leg );
357
+ }
294
358
  } else {
295
359
  profit_loss_dash = ( ( *( Xs_array + leg ) ) - Spot_dash );
296
360
  }
@@ -324,7 +388,37 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
324
388
  // legs loop end
325
389
  // start from the Knock value
326
390
  double ko_so_far = K, ko_so_far_dash = K;
327
- if( KType == ABSOLUTE || KType == PIVOT_ABSOLUTE || KType == COLLAR_ABSOLUTE || KType == DOUBLE_STRIKE_ABSOLUTE ) {
391
+ if(KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE){
392
+ if(knockedLeg >= 0){
393
+ double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + knockedLeg ) ), sim[NL-1]);
394
+ sim_pos[NL-1] = european_payoff(( *( Xs_array + (knockedLeg) ) ), sim[NL-1], cp_sign, dir_sign, equivalent_notional);
395
+ }
396
+ else{
397
+ sim_pos[NL-1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim[NL-1]);
398
+ }
399
+ if(knockedLeg_dash >= 0 ){
400
+ double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + knockedLeg_dash ) ), sim_dash[NL-1]);
401
+ sim_dash_pos[NL-1] = european_payoff(( *( Xs_array + (knockedLeg_dash) ) ), sim_dash[NL-1], cp_sign, dir_sign, equivalent_notional);
402
+ }
403
+ else{
404
+ sim_dash_pos[NL-1] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + 0 ) ), sim_dash[NL-1]);
405
+ }
406
+ } else if(KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE){
407
+ if(knockedLeg >= 0){
408
+ sim_pos[knockedLeg] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + knockedLeg ) ), sim[knockedLeg]);
409
+ }
410
+ else{
411
+ double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + 0 ) ), sim[NL-1]);
412
+ sim_pos[NL-1] = european_payoff(( *( Xs_array + 0 ) ), sim[NL-1], cp_sign, dir_sign, equivalent_notional);
413
+ }
414
+ if(knockedLeg_dash >= 0 ){
415
+ sim_dash_pos[knockedLeg_dash] = get_equivalent_rebate(rebate_conversion_sign, ( *( Rebate_array + knockedLeg_dash ) ), sim[knockedLeg_dash]);
416
+ }
417
+ else{
418
+ double equivalent_notional = get_equivalent_notional(conversion_sign, ( *( Ns_array + 0 ) ), sim_dash[NL-1]);
419
+ sim_dash_pos[NL-1] = european_payoff(( *( Xs_array + 0 ) ), sim_dash[NL-1], cp_sign, dir_sign, equivalent_notional);
420
+ }
421
+ } else if( KType == ABSOLUTE || KType == PIVOT_ABSOLUTE || KType == COLLAR_ABSOLUTE || KType == DOUBLE_STRIKE_ABSOLUTE ) {
328
422
  for( leg = 0; leg < NL; ++leg ) {
329
423
  // simulation normal
330
424
  if( ko_so_far > 0.0 ) {
@@ -367,7 +461,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
367
461
  } else if( KType == POINTS || KType == PIVOT_POINTS || KType == COLLAR_POINTS || KType == DOUBLE_STRIKE_POINTS ) {
368
462
  for( leg = 0; leg < NL; ++leg ) {
369
463
  // simulation normal
370
- rb_p(DBL2NUM(*(Ns_array + leg )));
464
+ // rb_p(DBL2NUM(*(Ns_array + leg )));
371
465
  if ( ko_so_far > 0.0 ) {
372
466
  if( sim[leg] >= 0.0 ) {
373
467
  // knock out condition
@@ -531,4 +625,4 @@ void Init_tarf_monte_carlo() {
531
625
  // void rb_define_singleton_method(VALUE klass, const char *name, VALUE (*func)(), int argc)
532
626
  rb_define_singleton_method(cTarfMonteCarlo, "box_muller", method_box_muller, 0);
533
627
  rb_define_singleton_method(cTarfMonteCarlo, "run_monte_carlo", method_run_monte_carlo, -2);
534
- }
628
+ }
@@ -3,5 +3,5 @@
3
3
  # gem yank tarf_monte_carlo -v 2.3
4
4
 
5
5
  module TarfMonteCarlo
6
- VERSION = "3.24"
6
+ VERSION = "3.29"
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.24'
4
+ version: '3.29'
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-24 00:00:00.000000000 Z
11
+ date: 2020-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,6 +114,7 @@ files:
114
114
  - Rakefile
115
115
  - bin/console
116
116
  - bin/setup
117
+ - ext/tarf_monte_carlo/Makefile
117
118
  - ext/tarf_monte_carlo/extconf.rb
118
119
  - ext/tarf_monte_carlo/tarf_monte_carlo.c
119
120
  - lib/.DS_Store