tarf_monte_carlo 3.21 → 3.26
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/ext/tarf_monte_carlo/Makefile +264 -0
- data/ext/tarf_monte_carlo/tarf_monte_carlo.c +81 -6
- data/lib/tarf_monte_carlo/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b551fb41bf0f6bada89b8b9b56a1cc16d1b6bdba6c4bece434a5ca8bbb103bc
|
4
|
+
data.tar.gz: 6c76e80342cc906a4ad39665a8cc6ffe460b473e3fd2985bf3df571a6252f1d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fe7a19bb8dd61ca522a23e5a216c726f7af22b385c9d16b111c9c903f5b7414ef64569168ee301e3a5fe62cb5b2f534e3445c65290f355c0d38c10af30ac5b0
|
7
|
+
data.tar.gz: 6115a3972cb63edc48c8ee6c93d6206931608ef780a6322d9c6ff1add58cb3f43562288a0399abac710b4b27c5de5ede3a10d1166834da1044134d444a247c3b
|
@@ -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
|
@@ -99,6 +102,9 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
99
102
|
double S = NUM2DBL( rb_hash_aref(MCInputs, rb_str_new2("spot_rate")) );
|
100
103
|
int Ko_compare_mult = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("multiplier")) );
|
101
104
|
int ConvertNotional = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("convert_notional")) );
|
105
|
+
int dir_sign = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("direction_sign")) );
|
106
|
+
int dir2_sign = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("direction2_sign")) );
|
107
|
+
int cp_sign = NUM2INT( rb_hash_aref(MCInputs, rb_str_new2("callput_sign")) );
|
102
108
|
|
103
109
|
// assign leg specific attributes
|
104
110
|
double *pvs_pos = ( double* ) malloc( SCount * sizeof(double) );
|
@@ -114,6 +120,8 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
114
120
|
double *CFs_array = ( double* ) malloc( NL * sizeof(double) );
|
115
121
|
double *LSts_array = ( double* ) malloc( NL * sizeof(double) );
|
116
122
|
double *USts_array = ( double* ) malloc( NL * sizeof(double) );
|
123
|
+
double *TempNs_array = ( double* ) malloc( NL * sizeof(double) );
|
124
|
+
double *Barrier_array = ( double* ) malloc( NL * sizeof(double) );
|
117
125
|
|
118
126
|
VALUE Ls = rb_hash_aref(MCInputs, rb_str_new2("leverage_ratios") );
|
119
127
|
VALUE Ts = rb_hash_aref(MCInputs, rb_str_new2("expiration_times") );
|
@@ -126,6 +134,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
126
134
|
VALUE CFs = rb_hash_aref(MCInputs, rb_str_new2("caps") );
|
127
135
|
VALUE LSts = rb_hash_aref(MCInputs, rb_str_new2("lower_strikes") );
|
128
136
|
VALUE USts = rb_hash_aref(MCInputs, rb_str_new2("upper_strikes") );
|
137
|
+
VALUE Brs = rb_hash_aref(MCInputs, rb_str_new2("barriers") );
|
129
138
|
|
130
139
|
for (leg = 0; leg < NL; ++leg) {
|
131
140
|
Ls_array[leg] = NUM2DBL( rb_ary_entry(Ls, leg) );
|
@@ -135,6 +144,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
135
144
|
vs_array[leg] = NUM2DBL( rb_ary_entry(vs, leg) );
|
136
145
|
bs_array[leg] = NUM2DBL( rb_ary_entry(bs, leg) );
|
137
146
|
DFs_array[leg] = NUM2DBL( rb_ary_entry(DFs, leg) );
|
147
|
+
TempNs_array[leg] = *(Ns_array + leg);
|
138
148
|
}
|
139
149
|
// extra tarf structures
|
140
150
|
if ( KType == PIVOT_POINTS || KType == PIVOT_ABSOLUTE || KType == PIVOT_LEGS ) {
|
@@ -151,6 +161,10 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
151
161
|
LSts_array[leg] = NUM2DBL( rb_ary_entry(LSts, leg) );
|
152
162
|
USts_array[leg] = NUM2DBL( rb_ary_entry(USts, leg) );
|
153
163
|
}
|
164
|
+
} else if (KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE || KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE) {
|
165
|
+
for (leg = 0; leg < NL; ++leg) {
|
166
|
+
Barrier_array[leg] = NUM2DBL( rb_ary_entry(Brs, leg) );
|
167
|
+
}
|
154
168
|
}
|
155
169
|
|
156
170
|
//
|
@@ -182,6 +196,8 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
182
196
|
sim_dash_neg[leg] = 0.0;
|
183
197
|
}
|
184
198
|
|
199
|
+
int knockedLeg = -1;
|
200
|
+
int knockedLeg_dash = -1;
|
185
201
|
// legs loop start
|
186
202
|
for( leg = 0; leg < NL; ++leg ) {
|
187
203
|
double eps, eps_dash, drift, vSqrdt, profit_loss, profit_loss_dash;
|
@@ -198,8 +214,28 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
198
214
|
Spot = Spot * exp( drift + vSqrdt * eps );
|
199
215
|
Spot_dash = Spot_dash * exp( drift + vSqrdt * eps_dash );
|
200
216
|
|
201
|
-
|
202
|
-
|
217
|
+
if(KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE || KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE){
|
218
|
+
profit_loss = 0;
|
219
|
+
profit_loss_dash = 0;
|
220
|
+
|
221
|
+
double knockin = (Spot - *(Barrier_array + leg)) * dir_sign * cp_sign * dir2_sign;
|
222
|
+
double knockin_dash = (Spot_dash - *(Barrier_array + leg)) * dir_sign * cp_sign * dir2_sign;
|
223
|
+
|
224
|
+
if(knockedLeg == -1 && knockin > 0){
|
225
|
+
knockedLeg = leg;
|
226
|
+
}
|
227
|
+
if(knockedLeg == -1 && knockin < 0 && KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE){
|
228
|
+
profit_loss = dir_sign * dir2_sign * cp_sign * ( Spot - ( *( Xs_array + leg ) ) );
|
229
|
+
}
|
230
|
+
|
231
|
+
if(knockedLeg_dash == -1 && knockin_dash > 0){
|
232
|
+
knockedLeg_dash = leg;
|
233
|
+
}
|
234
|
+
if(knockedLeg_dash == -1 && knockin_dash < 0 && KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE){
|
235
|
+
profit_loss = dir_sign * dir2_sign * cp_sign * ( Spot_dash - ( *( Xs_array + leg ) ) );
|
236
|
+
}
|
237
|
+
|
238
|
+
} else if ( KType == DOUBLE_STRIKE_POINTS || KType == DOUBLE_STRIKE_ABSOLUTE || KType == DOUBLE_STRIKE_LEGS ) {
|
203
239
|
if ( Spot < *( LSts_array + leg ) ) {
|
204
240
|
profit_loss = Spot - (*( LSts_array + leg ));
|
205
241
|
} else if(Spot > *( USts_array + leg )){
|
@@ -211,10 +247,10 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
211
247
|
}
|
212
248
|
|
213
249
|
if (ConvertNotional == 1){
|
214
|
-
if(Spot < *( Ps_array + leg )){
|
215
|
-
Ns_array[leg] =
|
250
|
+
if(Spot < *( Ps_array + leg ) || Spot_dash < *( Ps_array + leg )){
|
251
|
+
Ns_array[leg] = *(TempNs_array + leg) / *( LSts_array + leg );
|
216
252
|
} else {
|
217
|
-
Ns_array[leg] =
|
253
|
+
Ns_array[leg] = *(TempNs_array + leg) / *( USts_array + leg );
|
218
254
|
}
|
219
255
|
}
|
220
256
|
|
@@ -246,6 +282,10 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
246
282
|
profit_loss = 0.0;
|
247
283
|
} else if(Spot <= *( CFs_array + leg )){
|
248
284
|
profit_loss = Spot - (*( CFs_array + leg ));
|
285
|
+
|
286
|
+
if (ConvertNotional == 1){
|
287
|
+
Ns_array[leg] = *(TempNs_array + leg) / *( CFs_array + leg );
|
288
|
+
}
|
249
289
|
} else {
|
250
290
|
profit_loss = Spot - (*( Xs_array + leg ));
|
251
291
|
}
|
@@ -254,6 +294,10 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
254
294
|
profit_loss_dash = 0.0;
|
255
295
|
} else if(Spot_dash <= *( CFs_array + leg )){
|
256
296
|
profit_loss_dash = Spot_dash - (*( CFs_array + leg ));
|
297
|
+
|
298
|
+
if (ConvertNotional == 1){
|
299
|
+
Ns_array[leg] = *(TempNs_array + leg) / *( CFs_array + leg );
|
300
|
+
}
|
257
301
|
} else {
|
258
302
|
profit_loss_dash = Spot_dash - (*( Xs_array + leg ));
|
259
303
|
}
|
@@ -281,6 +325,10 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
281
325
|
profit_loss = 0.0;
|
282
326
|
} else if(Spot >= *( CFs_array + leg )){
|
283
327
|
profit_loss = ( ( *( CFs_array + leg ) ) - Spot );
|
328
|
+
|
329
|
+
if (ConvertNotional == 1){
|
330
|
+
Ns_array[leg] = *(TempNs_array + leg) / *( CFs_array + leg );
|
331
|
+
}
|
284
332
|
} else {
|
285
333
|
profit_loss = ( ( *( Xs_array + leg ) ) - Spot );
|
286
334
|
}
|
@@ -289,6 +337,10 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
289
337
|
profit_loss_dash = 0.0;
|
290
338
|
} else if(Spot_dash >= *( CFs_array + leg )){
|
291
339
|
profit_loss_dash = ( ( *( CFs_array + leg ) ) - Spot_dash );
|
340
|
+
|
341
|
+
if (ConvertNotional == 1){
|
342
|
+
Ns_array[leg] = *(TempNs_array + leg) / *( CFs_array + leg );
|
343
|
+
}
|
292
344
|
} else {
|
293
345
|
profit_loss_dash = ( ( *( Xs_array + leg ) ) - Spot_dash );
|
294
346
|
}
|
@@ -322,7 +374,29 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
322
374
|
// legs loop end
|
323
375
|
// start from the Knock value
|
324
376
|
double ko_so_far = K, ko_so_far_dash = K;
|
325
|
-
if(
|
377
|
+
if(KType == FX_AMERICAN_BARRIER_KNOCKIN_DISCRETE){
|
378
|
+
if(knockedLeg >= 0){
|
379
|
+
sim_pos[knockedLeg] = dir_sign * dir2_sign * cp_sign * ( Spot - ( *( Xs_array + (knockedLeg) ) ) ) * ( *( Ns_array + knockedLeg ) );
|
380
|
+
}
|
381
|
+
if(knockedLeg_dash >= 0 ){
|
382
|
+
sim_dash_pos[knockedLeg_dash] = dir_sign * dir2_sign * cp_sign * ( Spot_dash - ( *( Xs_array + (knockedLeg_dash) ) ) ) * ( *( Ns_array + knockedLeg_dash ) );
|
383
|
+
}
|
384
|
+
} else if(KType == FX_AMERICAN_BARRIER_KNOCKOUT_DISCRETE){
|
385
|
+
int brk_flg = 1;
|
386
|
+
int brk_flg_dash = 1;
|
387
|
+
for( leg = 0; leg < NL; ++leg ) {
|
388
|
+
if((leg != knockedLeg) && brk_flg){
|
389
|
+
sim_pos[leg] = sim[leg] * ( *( Ns_array + leg ) );
|
390
|
+
}else{
|
391
|
+
brk_flg = 0;
|
392
|
+
}
|
393
|
+
if((leg != knockedLeg_dash) && brk_flg_dash){
|
394
|
+
sim_dash_pos[leg] = sim[leg] * ( *( Ns_array + leg ) );
|
395
|
+
}else{
|
396
|
+
brk_flg_dash = 0;
|
397
|
+
}
|
398
|
+
}
|
399
|
+
} else if( KType == ABSOLUTE || KType == PIVOT_ABSOLUTE || KType == COLLAR_ABSOLUTE || KType == DOUBLE_STRIKE_ABSOLUTE ) {
|
326
400
|
for( leg = 0; leg < NL; ++leg ) {
|
327
401
|
// simulation normal
|
328
402
|
if( ko_so_far > 0.0 ) {
|
@@ -365,6 +439,7 @@ VALUE method_run_monte_carlo( VALUE self, VALUE args ) {
|
|
365
439
|
} else if( KType == POINTS || KType == PIVOT_POINTS || KType == COLLAR_POINTS || KType == DOUBLE_STRIKE_POINTS ) {
|
366
440
|
for( leg = 0; leg < NL; ++leg ) {
|
367
441
|
// simulation normal
|
442
|
+
// rb_p(DBL2NUM(*(Ns_array + leg )));
|
368
443
|
if ( ko_so_far > 0.0 ) {
|
369
444
|
if( sim[leg] >= 0.0 ) {
|
370
445
|
// knock out condition
|
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.26'
|
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-
|
11
|
+
date: 2020-10-02 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
|