forked from xlladdins/xll_ml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxll_bootstrap.cpp
More file actions
57 lines (49 loc) · 1.72 KB
/
xll_bootstrap.cpp
File metadata and controls
57 lines (49 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// xll_bootstrap.cpp - bootstrap functions
#include <vector>
#include "fms_bootstrap.h"
#include "xll_fi.h"
using namespace fms;
using namespace xll;
Auto<OpenAfter> xoa_bootstrap_test([](){ curve::bootstrap_test(); return 1; });
AddIn xai_curve_pwflat_bootstrap_(
Function(XLL_HANDLEX, L"xll_curve_pwflat_bootstrap_", L"\\" CATEGORY L".CURVE.PWFLAT.BOOTSTRAP.")
.Arguments({
Arg(XLL_FP, L"i", L"is an array of instrument handles."),
Arg(XLL_FP, L"p", L"is an array of prices."),
})
.Uncalced()
.Category(CATEGORY)
.FunctionHelp(L"Return a handle to a pwflat bootstrapped curve.")
);
HANDLEX WINAPI xll_curve_pwflat_bootstrap_(_FP12* pi, _FP12* pp)
{
#pragma XLLEXPORT
HANDLEX h = INVALID_HANDLEX;
try {
// Validate array sizes
ensure(size(*pi) > 0 || !"bootstrap: instrument array cannot be empty");
ensure(size(*pp) > 0 || !"bootstrap: price array cannot be empty");
ensure(size(*pi) == size(*pp) || !"bootstrap: instrument and price arrays must have same size");
int n = size(*pi);
std::vector<instrument::instrument<>*> is(n);
for (int i = 0; i < n; ++i) {
// Pointers to instruments from the HANDELX in pi.
handle<instrument::base<>> inst(pi->array[i]);
ensure(inst || !__FUNCTION__ ": invalid instrument handle");
is[i] = inst.as<instrument::instrument<>>(); // Get raw pointer from handle
}
// Bootstrap using the corrected function signature
auto f = curve::bootstrap(std::span(is.data(), is.size()), span(*pp));
// Create handle to the bootstrapped curve
handle<curve::base<>> h_(new curve::pwflat(std::move(f)));
ensure(h_);
h = h_.get();
}
catch (const std::exception& ex) {
XLL_ERROR(ex.what());
}
catch (...) {
XLL_ERROR(__FUNCTION__ ": unknown exception");
}
return h;
}