1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "op_financial.hxx"
12 #include "formulagroup.hxx"
13 #include "document.hxx"
14 #include "formulacell.hxx"
15 #include "tokenarray.hxx"
16 #include "compiler.hxx"
17 #include "interpre.hxx"
18 #include <formula/vectortoken.hxx>
21 using namespace formula
;
23 namespace sc
{ namespace opencl
{
24 // Definitions of inline functions
25 #include "opinlinefun_finacial.cxx"
27 void RRI::GenSlidingWindowFunction(
28 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
30 ss
<< "\ndouble " << sSymName
;
31 ss
<< "_"<< BinFuncName() <<"(";
32 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
36 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
39 ss
<< " double tmp = " << GetBottom() <<";\n";
40 ss
<< " int gid0 = get_global_id(0);\n";
41 ss
<< " double fv;\n";
42 ss
<< " double pv;\n";
43 ss
<< " double nper;\n";
44 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
45 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
46 formula::SingleVectorRefToken
*>(tmpCur0
);
48 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
49 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
50 formula::SingleVectorRefToken
*>(tmpCur1
);
52 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
53 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
54 formula::SingleVectorRefToken
*>(tmpCur2
);
56 ss
<< " int buffer_nper_len = ";
57 ss
<< tmpCurDVR0
->GetArrayLength();
60 ss
<< " int buffer_pv_len = ";
61 ss
<< tmpCurDVR1
->GetArrayLength();
64 ss
<< " int buffer_fv_len = ";
65 ss
<< tmpCurDVR2
->GetArrayLength();
68 ss
<<" if(gid0>=buffer_nper_len || isNan(";
69 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
71 ss
<<" nper = 0;\n\telse \n";
73 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
76 ss
<<" if(gid0>=buffer_pv_len || isNan(";
77 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
79 ss
<<" pv = 0;\n\telse \n";
81 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
84 ss
<<" if(gid0>=buffer_pv_len || isNan(";
85 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
87 ss
<<" fv = 0;\n\telse \n";
89 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
91 ss
<< " tmp = pow(fv*pow(pv,-1),1.0*pow(nper,-1))-1;\n";
92 ss
<< " return tmp;\n";
96 void OpNominal::GenSlidingWindowFunction(
97 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&
100 ss
<< "\ndouble " << sSymName
;
101 ss
<< "_"<< BinFuncName() <<"(";
102 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
106 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
109 ss
<< "double tmp = 0;\n\t";
110 ss
<< "double temp = 0;\n\t";
111 ss
<< "int gid0 = get_global_id(0);\n\t";
112 ss
<< "double tmp0=0,tmp1=0;\n";
113 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
115 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
117 if (pCur
->GetType() == formula::svSingleVectorRef
)
119 const formula::SingleVectorRefToken
* pSVR
=
120 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
121 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
123 else if (pCur
->GetType() == formula::svDouble
)
130 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
132 ss
<<" temp="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
134 ss
<<" if (isNan(temp))\n";
135 ss
<<" tmp"<<i
<<"= 0;\n";
137 ss
<<" tmp"<<i
<<"=temp;\n";
142 ss
<<" tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef(
147 ss
<<"if(tmp1==0)\n\t";
148 ss
<<"\treturn 0;\n\t";
149 ss
<<"tmp=pow( tmp1,-1);\n\t";
150 ss
<<"tmp=( pow( tmp0+ 1.0, tmp ) - 1.0 ) *";
152 ss
<< "return tmp;\n";
156 void OpDollarde::GenSlidingWindowFunction(
157 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
159 ss
<< "\ndouble " << sSymName
;
160 ss
<< "_"<< BinFuncName() <<"(";
161 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
165 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
168 ss
<< "double tmp = " << GetBottom() <<";\n\t";
169 ss
<< "int gid0 = get_global_id(0);\n\t";
170 ss
<< "double fInt = " << GetBottom() <<";\n\t";
171 ss
<< "double dollar;\n\t";
172 ss
<< "double fFrac;\n\t";
173 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
174 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
175 formula::SingleVectorRefToken
*>(tmpCur0
);
176 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
177 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
178 formula::SingleVectorRefToken
*>(tmpCur1
);
179 ss
<< "int buffer_dollar_len = ";
180 ss
<< tmpCurDVR0
->GetArrayLength();
182 ss
<< "int buffer_frac_len = ";
183 ss
<< tmpCurDVR1
->GetArrayLength();
185 ss
<<"if((gid0)>=buffer_dollar_len || isNan(";
186 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
188 ss
<<"dollar = 0;\n\telse \n\t\t";
190 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
192 ss
<<"if((gid0)>=buffer_frac_len || isNan(";
193 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
195 ss
<<"fFrac = 0;\n\telse \n\t\t";
197 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
199 ss
<< "tmp = modf( dollar , &fInt );\n\t";
200 ss
<< "tmp /= fFrac;\n\t";
201 ss
<< "tmp *= pow( 10.0 , ceil( log10(fFrac ) ) );\n\t";
202 ss
<< "tmp += fInt;\t";
203 ss
<< "\n\treturn tmp;\n";
207 void OpDollarfr::GenSlidingWindowFunction(std::stringstream
&ss
,
208 const std::string
&sSymName
, SubArguments
&vSubArguments
)
210 ss
<< "\ndouble " << sSymName
;
211 ss
<< "_"<< BinFuncName() <<"(";
212 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
216 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
219 ss
<< "double tmp = " << GetBottom() <<";\n\t";
220 ss
<< "int gid0 = get_global_id(0);\n\t";
221 ss
<< "double fInt = " << GetBottom() <<";\n\t";
222 ss
<< "double dollar;\n\t";
223 ss
<< "double fFrac;\n\t";
224 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
225 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
226 formula::SingleVectorRefToken
*>(tmpCur0
);
227 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
228 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
229 formula::SingleVectorRefToken
*>(tmpCur1
);
230 ss
<< "int buffer_dollar_len = ";
231 ss
<< tmpCurDVR0
->GetArrayLength();
233 ss
<< "int buffer_frac_len = ";
234 ss
<< tmpCurDVR1
->GetArrayLength();
236 ss
<<"if((gid0)>=buffer_dollar_len || isNan(";
237 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
239 ss
<<"dollar = 0;\n\telse \n\t\t";
241 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
243 ss
<<"if((gid0)>=buffer_frac_len || isNan(";
244 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
246 ss
<<"fFrac = 0;\n\telse \n\t\t";
248 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
250 ss
<< "tmp = modf( dollar , &fInt );\n\t";
251 ss
<< "tmp *= fFrac;\n\t";
252 ss
<< "tmp *= pow( 10.0 , -ceil( log10(fFrac ) ) );\n\t";
253 ss
<< "tmp += fInt;\t";
254 ss
<< "\n\treturn tmp;\n";
258 void OpDISC::BinInlineFun(std::set
<std::string
>& decls
,
259 std::set
<std::string
>& funs
)
261 decls
.insert(GetYearFrac_newDecl
);decls
.insert(DaysToDate_newDecl
);
262 decls
.insert(DaysInMonthDecl
);decls
.insert(IsLeapYearDecl
);
263 funs
.insert(GetYearFrac_new
);funs
.insert(DaysToDate_new
);
264 funs
.insert(DaysInMonth
);funs
.insert(IsLeapYear
);
267 void OpDISC::GenSlidingWindowFunction(std::stringstream
& ss
,
268 const std::string
&sSymName
, SubArguments
& vSubArguments
)
270 ss
<< "\ndouble " << sSymName
;
271 ss
<< "_" << BinFuncName() << "(";
272 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
276 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
279 ss
<< " double tmp = " << GetBottom() << ";\n";
280 ss
<< " int gid0 = get_global_id(0);\n";
281 ss
<< " double arg0 = " << GetBottom() << ";\n";
282 ss
<< " double arg1 = " << GetBottom() << ";\n";
283 ss
<< " double arg2 = " << GetBottom() << ";\n";
284 ss
<< " double arg3 = " << GetBottom() << ";\n";
285 ss
<< " double arg4 = " << GetBottom() << ";\n";
286 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
288 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
290 if (pCur
->GetType() == formula::svSingleVectorRef
)
292 const formula::SingleVectorRefToken
* pSVR
=
293 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
294 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
296 else if (pCur
->GetType() == formula::svDouble
)
300 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
303 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
305 ss
<< " arg" << i
<< " = 0;\n";
307 ss
<< " arg" << i
<< " = ";
308 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
313 ss
<< " arg" << i
<< " = ";
314 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
317 ss
<< " int nNullDate = 693594;\n";
318 ss
<< " tmp = 1.0 - arg2 / arg3;\n";
320 ss
<< " GetYearFrac_new(nNullDate, (int)arg0, (int)arg1, (int)arg4);\n";
321 ss
<< " return tmp;\n";
325 void OpINTRATE::BinInlineFun(std::set
<std::string
>& decls
,
326 std::set
<std::string
>& funs
)
328 decls
.insert(GetYearDiff_newDecl
);decls
.insert(GetDiffDate_newDecl
);
329 decls
.insert(DaysToDate_newDecl
);decls
.insert(GetNullDateDecl
);
330 decls
.insert(DateToDaysDecl
);decls
.insert(DaysInMonthDecl
);
331 decls
.insert(IsLeapYearDecl
);
332 funs
.insert(GetYearDiff_new
);funs
.insert(GetDiffDate_new
);
333 funs
.insert(DaysToDate_new
);funs
.insert(GetNullDate
);
334 funs
.insert(DateToDays
);funs
.insert(DaysInMonth
);
335 funs
.insert(IsLeapYear
);
338 void OpINTRATE::GenSlidingWindowFunction(std::stringstream
& ss
,
339 const std::string
&sSymName
, SubArguments
& vSubArguments
)
341 ss
<< "\ndouble " << sSymName
;
342 ss
<< "_" << BinFuncName() << "(";
343 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
347 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
350 ss
<< " double tmp = " << GetBottom() << ";\n";
351 ss
<< " int gid0 = get_global_id(0);\n";
352 ss
<< " double arg0 = " << GetBottom() << ";\n";
353 ss
<< " double arg1 = " << GetBottom() << ";\n";
354 ss
<< " double arg2 = " << GetBottom() << ";\n";
355 ss
<< " double arg3 = " << GetBottom() << ";\n";
356 ss
<< " double arg4 = " << GetBottom() << ";\n";
357 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
359 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
361 if (pCur
->GetType() == formula::svSingleVectorRef
)
363 const formula::SingleVectorRefToken
* pSVR
=
364 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
365 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
367 else if (pCur
->GetType() == formula::svDouble
)
371 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
374 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
376 ss
<< " arg" << i
<< " = 0;\n";
378 ss
<< " arg" << i
<< " = ";
379 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
384 ss
<< " arg" << i
<< " = ";
385 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
388 ss
<< " int nNullDate = GetNullDate();\n";
389 ss
<< " tmp = arg3 * pow(arg2,-1) - 1.0;\n";
390 ss
<< " tmp = tmp * pow(GetYearDiff_new(nNullDate, (int)arg0,";
391 ss
<< " (int)arg1,(int)arg4),-1);\n";
392 ss
<< " return tmp;\n";
396 void OpFV::BinInlineFun(std::set
<std::string
>& decls
,
397 std::set
<std::string
>& funs
)
399 decls
.insert(GetZwDecl
);
403 void OpFV::GenSlidingWindowFunction(std::stringstream
& ss
,
404 const std::string
&sSymName
, SubArguments
& vSubArguments
)
406 ss
<< "\ndouble " << sSymName
;
407 ss
<< "_"<< BinFuncName() <<"(";
408 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
412 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
415 ss
<< " double tmp = " << GetBottom() << ";\n";
416 ss
<< " int gid0 = get_global_id(0);\n";
417 ss
<< " double arg0 = " << GetBottom() << ";\n";
418 ss
<< " double arg1 = " << GetBottom() << ";\n";
419 ss
<< " double arg2 = " << GetBottom() << ";\n";
420 ss
<< " double arg3 = " << GetBottom() << ";\n";
421 ss
<< " double arg4 = " << GetBottom() << ";\n";
422 unsigned j
= vSubArguments
.size();
425 FormulaToken
* pCur
= vSubArguments
[j
]->GetFormulaToken();
427 if(pCur
->GetType() == formula::svSingleVectorRef
)
429 const formula::SingleVectorRefToken
* pSVR
=
430 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
431 ss
<< " if(gid0 >= " << pSVR
->GetArrayLength() << " || isNan(";
432 ss
<< vSubArguments
[j
]->GenSlidingWindowDeclRef();
434 ss
<< " arg" << j
<< " = " <<GetBottom() << ";\n";
436 ss
<< " arg" << j
<< " = ";
437 ss
<< vSubArguments
[j
]->GenSlidingWindowDeclRef();
441 ss
<< " tmp = GetZw(arg0, arg1, arg2, arg3, arg4);\n";
442 ss
<< " return tmp;\n";
446 void OpIPMT::BinInlineFun(std::set
<std::string
>& decls
,
447 std::set
<std::string
>& funs
)
449 decls
.insert(GetZwDecl
);
453 void OpIPMT::GenSlidingWindowFunction(std::stringstream
& ss
,
454 const std::string
&sSymName
, SubArguments
& vSubArguments
)
456 ss
<< "\ndouble " << sSymName
;
457 ss
<< "_"<< BinFuncName() <<"(";
458 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
462 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
465 ss
<< " double tmp = " << GetBottom() << ";\n";
466 ss
<< " int gid0 = get_global_id(0);\n";
467 ss
<< " double arg0 = " << GetBottom() << ";\n";
468 ss
<< " double arg1 = " << GetBottom() << ";\n";
469 ss
<< " double arg2 = " << GetBottom() << ";\n";
470 ss
<< " double arg3 = " << GetBottom() << ";\n";
471 ss
<< " double arg4 = " << GetBottom() << ";\n";
472 ss
<< " double arg5 = " << GetBottom() << ";\n";
473 unsigned j
= vSubArguments
.size();
476 FormulaToken
* pCur
= vSubArguments
[j
]->GetFormulaToken();
478 if(pCur
->GetType() == formula::svSingleVectorRef
)
480 const formula::SingleVectorRefToken
* pSVR
=
481 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
482 ss
<< " if(gid0 >= " << pSVR
->GetArrayLength() << " || isNan(";
483 ss
<< vSubArguments
[j
]->GenSlidingWindowDeclRef();
485 ss
<< " arg" << j
<< " = " <<GetBottom() << ";\n";
487 ss
<< " arg" << j
<< " = ";
488 ss
<< vSubArguments
[j
]->GenSlidingWindowDeclRef();
492 ss
<< " double pmt ;\n";
493 ss
<< " if(arg0 == 0.0)\n";
494 ss
<< " return 0;\n";
495 ss
<< " double temp1 = 0;\n";
496 ss
<< " double abl = pow(1.0 + arg0, arg2);\n";
497 ss
<< " temp1 -= arg4;\n";
498 ss
<< " temp1 -= arg3 * abl;\n";
499 ss
<< " pmt = temp1 / (1.0 + arg0 * arg5) /";
500 ss
<< " ( (abl - 1.0) / arg0);\n";
501 ss
<< " double temp = pow( 1 + arg0, arg1 - 2);\n";
502 ss
<< " if(arg1 == 1.0)\n";
504 ss
<< " if(arg5 > 0.0)\n";
505 ss
<< " tmp = 0.0;\n";
507 ss
<< " tmp = -arg3;\n";
511 ss
<< " if(arg5 > 0.0)\n";
512 ss
<< " tmp = GetZw(arg0, arg1 - 2.0, pmt, arg3, 1.0)";
515 ss
<< " tmp = GetZw(arg0, arg1 - 1.0, pmt, arg3, 0.0);\n";
517 ss
<< " tmp = tmp * arg0;\n";
518 ss
<< " return tmp;\n";
521 void OpISPMT::GenSlidingWindowFunction(std::stringstream
& ss
,
522 const std::string
&sSymName
, SubArguments
& vSubArguments
)
524 ss
<< "\ndouble " << sSymName
;
525 ss
<< "_" << BinFuncName() <<"(";
526 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
530 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
533 ss
<< " double tmp = " << GetBottom() << ";\n";
534 ss
<< " int gid0 = get_global_id(0);\n";
535 ss
<< " double arg0 = " << GetBottom() << ";\n";
536 ss
<< " double arg1 = " << GetBottom() << ";\n";
537 ss
<< " double arg2 = " << GetBottom() << ";\n";
538 ss
<< " double arg3 = " << GetBottom() << ";\n";
539 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
541 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
543 if (pCur
->GetType() == formula::svSingleVectorRef
)
545 const formula::SingleVectorRefToken
* pSVR
=
546 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
547 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
549 else if (pCur
->GetType() == formula::svDouble
)
553 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
556 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
558 ss
<< " arg" << i
<< " = 0;\n";
560 ss
<< " arg" << i
<< " = ";
561 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
566 ss
<< " arg" << i
<< " = ";
567 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
570 ss
<< " tmp = arg3 * arg0 * ( arg1 - arg2) * pow(arg2, -1);\n";
571 ss
<< " return tmp;\n";
575 void OpDuration::GenSlidingWindowFunction(std::stringstream
& ss
,
576 const std::string
&sSymName
, SubArguments
& vSubArguments
)
578 ss
<< "\ndouble " << sSymName
;
579 ss
<< "_" << BinFuncName() <<"(";
580 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
584 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
587 ss
<< " double tmp = " << GetBottom() << ";\n";
588 ss
<< " int gid0 = get_global_id(0);\n";
589 ss
<< " double arg0 = " << GetBottom() << ";\n";
590 ss
<< " double arg1 = " << GetBottom() << ";\n";
591 ss
<< " double arg2 = " << GetBottom() << ";\n";
592 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
594 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
596 if (pCur
->GetType() == formula::svSingleVectorRef
)
598 const formula::SingleVectorRefToken
* pSVR
=
599 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
600 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
602 else if (pCur
->GetType() == formula::svDouble
)
606 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
609 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
611 ss
<< " arg" << i
<< " = 0;\n";
613 ss
<< " arg" << i
<< " = ";
614 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
619 ss
<< " arg" << i
<< " = ";
620 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
623 ss
<< " tmp = log(arg2 * pow( arg1,-1)) / log(arg0 + 1.0);\n";
624 ss
<< " return tmp;\n";
628 void OpDuration_ADD::BinInlineFun(std::set
<std::string
>& decls
,
629 std::set
<std::string
>& funs
)
631 decls
.insert(GetDurationDecl
);decls
.insert(lcl_GetcoupnumDecl
);
632 decls
.insert(GetYearFracDecl
);decls
.insert(DaysToDateDecl
);
633 decls
.insert(GetNullDateDecl
);decls
.insert(DateToDaysDecl
);
634 decls
.insert(DaysInMonthDecl
);decls
.insert(IsLeapYearDecl
);
635 funs
.insert(GetDuration
);funs
.insert(lcl_Getcoupnum
);
636 funs
.insert(GetYearFrac
);funs
.insert(DaysToDate
);
637 funs
.insert(GetNullDate
);funs
.insert(DateToDays
);
638 funs
.insert(DaysInMonth
);funs
.insert(IsLeapYear
);
641 void OpDuration_ADD::GenSlidingWindowFunction(std::stringstream
& ss
,
642 const std::string
&sSymName
, SubArguments
& vSubArguments
)
644 ss
<< "\ndouble " << sSymName
;
645 ss
<< "_"<< BinFuncName() <<"(";
646 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
650 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
653 ss
<< " double tmp = " << GetBottom() << ";\n";
654 ss
<< " int gid0 = get_global_id(0);\n";
655 ss
<< " double arg0 = " << GetBottom() << ";\n";
656 ss
<< " double arg1 = " << GetBottom() << ";\n";
657 ss
<< " double arg2 = " << GetBottom() << ";\n";
658 ss
<< " double arg3 = " << GetBottom() << ";\n";
659 ss
<< " double arg4 = " << GetBottom() << ";\n";
660 ss
<< " double arg5 = " << GetBottom() << ";\n";
661 unsigned j
= vSubArguments
.size();
664 FormulaToken
* pCur
= vSubArguments
[j
]->GetFormulaToken();
666 if(pCur
->GetType() == formula::svSingleVectorRef
)
668 const formula::SingleVectorRefToken
* pSVR
=
669 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
670 ss
<< " if(gid0 >= " << pSVR
->GetArrayLength() << " || isNan(";
671 ss
<< vSubArguments
[j
]->GenSlidingWindowDeclRef();
673 ss
<< " arg" << j
<< " = " <<GetBottom() << ";\n";
675 ss
<< " arg" << j
<< " = ";
676 ss
<< vSubArguments
[j
]->GenSlidingWindowDeclRef();
680 ss
<< " int nNullDate = GetNullDate();\n";
681 ss
<< " tmp = GetDuration( nNullDate, (int)arg0, (int)arg1, arg2,";
682 ss
<< " arg3, (int)arg4, (int)arg5);\n";
683 ss
<< " return tmp;\n";
686 void OpMDuration::BinInlineFun(std::set
<std::string
>& decls
,
687 std::set
<std::string
>& funs
)
689 decls
.insert(GetDuration_newDecl
);decls
.insert(lcl_Getcoupnum_newDecl
);
690 decls
.insert(addMonthsDecl
);decls
.insert(checklessthanDecl
);
691 decls
.insert(setDayDecl
);decls
.insert(ScaDateDecl
);
692 decls
.insert(GetYearFracDecl
);decls
.insert(DaysToDateDecl
);
693 decls
.insert(DaysInMonthDecl
);decls
.insert(IsLeapYearDecl
);
694 funs
.insert(GetDuration_new
);funs
.insert(lcl_Getcoupnum_new
);
695 funs
.insert(addMonths
);funs
.insert(checklessthan
);
696 funs
.insert(setDay
);funs
.insert(ScaDate
);
697 funs
.insert(GetYearFrac
);funs
.insert(DaysToDate
);
698 funs
.insert(DaysInMonth
);funs
.insert(IsLeapYear
);
701 void OpMDuration::GenSlidingWindowFunction(std::stringstream
& ss
,
702 const std::string
&sSymName
, SubArguments
& vSubArguments
)
704 ss
<< "\ndouble " << sSymName
;
705 ss
<< "_"<< BinFuncName() <<"(";
706 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
710 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
713 ss
<< " double tmp = " << GetBottom() << ";\n";
714 ss
<< " int gid0 = get_global_id(0);\n";
715 ss
<< " double arg0 = " << GetBottom() << ";\n";
716 ss
<< " double arg1 = " << GetBottom() << ";\n";
717 ss
<< " double arg2 = " << GetBottom() << ";\n";
718 ss
<< " double arg3 = " << GetBottom() << ";\n";
719 ss
<< " double arg4 = " << GetBottom() << ";\n";
720 ss
<< " double arg5 = " << GetBottom() << ";\n";
721 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
723 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
725 if (pCur
->GetType() == formula::svSingleVectorRef
)
727 const formula::SingleVectorRefToken
* pSVR
=
728 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
729 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
731 else if (pCur
->GetType() == formula::svDouble
)
735 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
738 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
740 ss
<< " arg" << i
<< " = 0;\n";
742 ss
<< " arg" << i
<< " = ";
743 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
748 ss
<< " arg" << i
<< " = ";
749 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
752 ss
<< " int nNullDate = 693594;\n";
753 ss
<< " tmp = GetDuration_new( nNullDate, (int)arg0, (int)arg1, arg2,";
754 ss
<< " arg3, (int)arg4, (int)arg5);\n";
755 ss
<< " tmp = tmp * pow(1.0 + arg3 * pow((int)arg4, -1.0), -1);\n";
756 ss
<< " return tmp;\n";
759 void Fvschedule::GenSlidingWindowFunction(
760 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
762 FormulaToken
* pCur
= vSubArguments
[1]->GetFormulaToken();
764 const formula::DoubleVectorRefToken
* pCurDVR
=
765 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
766 size_t nCurWindowSize
= pCurDVR
->GetRefRowSize();
767 ss
<< "\ndouble " << sSymName
;
768 ss
<< "_"<< BinFuncName() <<"(";
769 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
773 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
776 ss
<< "double tmp = 1.0;\n\t";
777 ss
<< "int gid0 = get_global_id(0);\n\t";
778 ss
<< "double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
780 ss
<< "if (isNan(arg0))\n\t\t";
781 ss
<< "arg0 = 0;\n\t";
782 ss
<< "double arg1;\n\t";
783 ss
<< "int arrayLength = " << pCurDVR
->GetArrayLength() << ";\n\t";
784 ss
<< "for (int i = 0; i + gid0 < arrayLength &&";
785 ss
<< " i < " << nCurWindowSize
<< "; i++){\n\t\t";
787 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n\t\t\t";
788 ss
<< "if (isNan(arg1))\n\t\t\t\t";
789 ss
<< "arg1 = 0;\n\t\t\t";
790 ss
<< "tmp *= arg1 + 1.0;\n\t\t";
792 ss
<< "return (double)tmp * arg0";
795 void Cumipmt::BinInlineFun(std::set
<std::string
>& decls
,
796 std::set
<std::string
>& funs
)
798 decls
.insert(GetRmz_newDecl
); decls
.insert(GetZw_newDecl
);
799 funs
.insert(GetRmz_new
);funs
.insert(GetZw_new
);
801 void Cumipmt::GenSlidingWindowFunction(
802 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&
805 ss
<< "\ndouble " << sSymName
;
806 ss
<< "_"<< BinFuncName() <<"(";
807 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
811 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
814 ss
<< " int gid0 = get_global_id(0);\n";
815 ss
<< " double fRate,fVal;\n";
816 ss
<< " int nStartPer,nEndPer,nNumPeriods,nPayType;\n";
817 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
818 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
819 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
820 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
821 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
822 FormulaToken
*tmpCur5
= vSubArguments
[5]->GetFormulaToken();
823 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
825 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
826 formula::SingleVectorRefToken
*>(tmpCur0
);
827 ss
<<" if(gid0 >= "<<tmpCurDVR0
->GetArrayLength()<<" || isNan(";
828 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
830 ss
<<" fRate = 0;\n else\n";
832 ss
<<" fRate = "<<vSubArguments
[0]->GenSlidingWindowDeclRef();
834 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
836 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
837 formula::SingleVectorRefToken
*>(tmpCur1
);
838 ss
<<" if(gid0 >= "<<tmpCurDVR1
->GetArrayLength()<<" || isNan(";
839 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
841 ss
<<" nNumPeriods = 0;\n else\n";
843 ss
<<" nNumPeriods = (int)";
844 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
846 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
848 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
849 formula::SingleVectorRefToken
*>(tmpCur2
);
850 ss
<<" if(gid0 >= "<<tmpCurDVR2
->GetArrayLength()<<" || isNan(";
851 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
853 ss
<<" fVal = 0;\n else\n";
855 ss
<<" fVal = "<<vSubArguments
[2]->GenSlidingWindowDeclRef();
857 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
859 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
860 formula::SingleVectorRefToken
*>(tmpCur3
);
861 ss
<<" if(gid0 >= "<<tmpCurDVR3
->GetArrayLength()<<" || isNan(";
862 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
864 ss
<<" nStartPer = 0;\n else\n";
866 ss
<<" nStartPer = (int)";
867 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
869 if(tmpCur4
->GetType() == formula::svSingleVectorRef
)
871 const formula::SingleVectorRefToken
*tmpCurDVR4
= static_cast<const
872 formula::SingleVectorRefToken
*>(tmpCur4
);
873 ss
<<" if(gid0 >= "<<tmpCurDVR4
->GetArrayLength()<<" || isNan(";
874 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
876 ss
<<" nEndPer = 0;\n else\n";
878 ss
<<" nEndPer = (int)";
879 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
882 if(tmpCur5
->GetType() == formula::svSingleVectorRef
)
884 const formula::SingleVectorRefToken
*tmpCurDVR5
= static_cast<const
885 formula::SingleVectorRefToken
*>(tmpCur5
);
886 ss
<<" if(gid0 >= "<<tmpCurDVR5
->GetArrayLength()<<" || isNan(";
887 ss
<<vSubArguments
[5]->GenSlidingWindowDeclRef();
889 ss
<<" nPayType = 0;\n else\n";
891 ss
<<" nPayType = (int)"<<vSubArguments
[5]->GenSlidingWindowDeclRef();
893 ss
<<" double fRmz;\n";
894 ss
<<" fRmz = GetRmz_new( fRate, nNumPeriods, fVal, 0.0, nPayType );\n";
895 ss
<<" double tmp = 0.0;\n";
896 ss
<<" if( nStartPer == 1 )\n";
898 ss
<<" if( nPayType <= 0 )\n";
899 ss
<<" tmp = -fVal;\n";
900 ss
<<" nStartPer++;\n";
902 ss
<<" for( ; nStartPer<= nEndPer ; nStartPer++ )\n";
904 ss
<<" if( nPayType > 0 )\n";
905 ss
<<" tmp += GetZw_new( fRate, nStartPer - 2 , ";
906 ss
<<"fRmz, fVal, 1 ) - fRmz;\n";
908 ss
<<" tmp += GetZw_new( fRate, nStartPer - 1 , ";
909 ss
<<"fRmz, fVal, 0 );\n";
911 ss
<<" tmp *= fRate;\n";
912 ss
<<" return tmp;\n";
916 void IRR::GenSlidingWindowFunction(std::stringstream
&ss
,
917 const std::string
&sSymName
, SubArguments
&vSubArguments
)
919 ss
<< "\ndouble " << sSymName
;
920 ss
<< "_" << BinFuncName() << "(";
921 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
925 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
928 ss
<< " #define Epsilon 1.0E-7\n";
929 ss
<< " int gid0 = get_global_id(0);\n";
930 FormulaToken
* pSur
= vSubArguments
[1]->GetFormulaToken();
932 ss
<< " double fSchaetzwert = ";
933 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
934 ss
<< " double fEps = 1.0;\n";
935 ss
<< " double x = 0.0, xNeu = 0.0, fZaehler = 0.0, fNenner = 0.0;\n";
936 ss
<< " double nCount = 0.0;\n";
937 if (pSur
->GetType() == formula::svSingleVectorRef
)
939 const formula::SingleVectorRefToken
* pSVR
=
940 static_cast< const formula::SingleVectorRefToken
* >(pSur
);
941 ss
<< " if (gid0 >= " << pSVR
->GetArrayLength() << ")\n";
942 ss
<< " fSchaetzwert = 0.1;\n";
943 ss
<< " if (isNan(fSchaetzwert))\n";
947 else if (pSur
->GetType() == formula::svDouble
)
949 ss
<< " if (isNan(fSchaetzwert))\n";
953 ss
<< " x = fSchaetzwert;\n";
954 ss
<< " unsigned short nItCount = 0;\n";
955 ss
<< " while (fEps > Epsilon && nItCount < 20){\n";
956 ss
<< " nCount = 0.0; fZaehler = 0.0; fNenner = 0.0;\n";
957 ss
<< " double arg0, arg1;\n";
958 ss
<< " int i = 0;\n";
959 FormulaToken
* pCur
= vSubArguments
[0]->GetFormulaToken();
961 const formula::DoubleVectorRefToken
* pDVR
=
962 static_cast<const formula::DoubleVectorRefToken
* >(pCur
);
963 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
965 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
966 ss
<< "i = gid0; i < " << pDVR
->GetArrayLength();
967 ss
<< " && i < " << nCurWindowSize
<< " /2*2; i++){\n";
969 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
972 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
973 ss
<< " if (!isNan(arg0)){\n";
974 ss
<< " fZaehler += arg0 / pow(1.0 + x, nCount);\n";
975 ss
<< " fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
976 ss
<< " nCount += 1;\n";
978 ss
<< " if (!isNan(arg1)){\n";
979 ss
<< " fZaehler += arg1 / pow(1.0 + x, nCount);\n";
980 ss
<< " fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
981 ss
<< " nCount += 1;\n";
984 ss
<< "if(i < " << pDVR
->GetArrayLength();
985 ss
<< " && i < " << nCurWindowSize
<< ") ;{\n";
987 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
988 ss
<< "; i < " << pDVR
->GetArrayLength();
989 ss
<< " && i < (gid0+" << nCurWindowSize
<< " )/2*2; i++){\n";
991 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
992 ss
<< " if (!isNan(arg0)){\n";
993 ss
<< " fZaehler += arg0 / pow(1.0 + x, nCount);\n";
994 ss
<< " fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
995 ss
<< " nCount += 1;\n";
999 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1000 ss
<< " if (!isNan(arg1)){\n";
1001 ss
<< " fZaehler += arg1 / pow(1.0 + x, nCount);\n";
1002 ss
<< " fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
1003 ss
<< " nCount+=1;\n";
1006 ss
<< " if(i < " << pDVR
->GetArrayLength();
1007 ss
<< " && i < gid0+" << nCurWindowSize
<< "){\n";
1009 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
1010 ss
<< " ; i + gid0 < " << pDVR
->GetArrayLength();
1011 ss
<< " && i < " << nCurWindowSize
<< " /2*2; i++){\n";
1013 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1016 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1017 ss
<< " if (!isNan(arg0)){\n";
1018 ss
<< " fZaehler += arg0 / pow(1.0 + x, nCount);\n";
1019 ss
<< " fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
1020 ss
<< " nCount += 1;\n";
1022 ss
<< " if (!isNan(arg1)){\n";
1023 ss
<< " fZaehler += arg1 / pow(1.0 + x, nCount);\n";
1024 ss
<< " fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
1025 ss
<< " nCount+=1;\n";
1028 ss
<< " if(i + gid0 < " << pDVR
->GetArrayLength() << " &&";
1029 ss
<< " i < " << nCurWindowSize
<< "){\n";
1032 ss
<< "; i < " << nCurWindowSize
<< " /2*2; i++){\n";
1034 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1037 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1038 ss
<< " if (!isNan(arg0)){\n";
1039 ss
<< " fZaehler += arg0 / pow(1.0 + x, nCount);\n";
1040 ss
<< " fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
1041 ss
<< " nCount += 1;\n";
1043 ss
<< " if (!isNan(arg1)){\n";
1044 ss
<< " fZaehler += arg1 / pow(1.0 + x, nCount);\n";
1045 ss
<< " fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
1046 ss
<< " nCount+=1;\n";
1049 ss
<< "if(i<" << nCurWindowSize
<< "){\n";
1053 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1054 ss
<< " if (isNan(arg0))\n";
1055 ss
<< " continue;\n";
1056 ss
<< " fZaehler += arg0 / pow(1.0+x, nCount);\n";
1057 ss
<< " fNenner += -nCount * arg0 / pow(1.0+x,nCount+1.0);\n";
1058 ss
<< " nCount+=1;\n";
1060 ss
<< " xNeu = x - fZaehler / fNenner;\n";
1061 ss
<< " fEps = fabs(xNeu - x);\n";
1062 ss
<< " x = xNeu;\n";
1063 ss
<< " nItCount++;\n }\n";
1064 ss
<< " if (fSchaetzwert == 0.0 && fabs(x) < Epsilon)\n";
1065 ss
<< " x = 0.0;\n";
1066 ss
<< " if (fEps < Epsilon)\n";
1067 ss
<< " return x;\n";
1069 ss
<< " return (double)523;\n";
1073 void XNPV::GenSlidingWindowFunction(
1074 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
1076 FormulaToken
*pCur
= vSubArguments
[1]->GetFormulaToken();
1078 const formula::DoubleVectorRefToken
* pCurDVR
=
1079 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
1080 size_t nCurWindowSize
= pCurDVR
->GetRefRowSize();
1081 ss
<< "\ndouble " << sSymName
;
1082 ss
<< "_"<< BinFuncName() <<"( ";
1083 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1087 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1091 ss
<< "double result = 0.0;\n\t";
1092 ss
<< "int gid0 = get_global_id(0);\n\t";
1093 ss
<< "int i=0;\n\t";
1094 ss
<< "double date;\n\t";
1095 ss
<< "double value;\n\t";
1096 ss
<< "double rate;\n\t";
1097 ss
<< "double dateNull;\n\t";
1098 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1099 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
1100 formula::SingleVectorRefToken
*>(tmpCur0
);
1102 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
1103 const formula::DoubleVectorRefToken
*tmpCurDVR1
= static_cast<const
1104 formula::DoubleVectorRefToken
*>(tmpCur1
);
1106 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1107 const formula::DoubleVectorRefToken
*tmpCurDVR2
= static_cast<const
1108 formula::DoubleVectorRefToken
*>(tmpCur2
);
1109 ss
<< "int buffer_rate_len = ";
1110 ss
<< tmpCurDVR0
->GetArrayLength();
1112 ss
<< "int buffer_value_len = ";
1113 ss
<< tmpCurDVR1
->GetArrayLength();
1115 ss
<< "int buffer_date_len = ";
1116 ss
<< tmpCurDVR2
->GetArrayLength();
1118 ss
<<"if((gid0)>=buffer_date_len || isNan(";
1119 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1121 ss
<<"return NAN;\n\telse \n";
1123 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1125 ss
<<"if((gid0)>=buffer_rate_len || isNan(";
1126 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1128 ss
<<"return NAN;\n\telse \n";
1130 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1132 ss
<<"if(1 == buffer_date_len )\n";
1134 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1136 ss
<< "for (int i = ";
1137 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed())
1139 ss
<< "gid0; i < "<< nCurWindowSize
<<"; i++)\n\t\t";
1141 else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
1143 ss
<< "0; i < gid0+"<< nCurWindowSize
<<"; i++)\n\t\t";
1147 ss
<< "0; i < "<< nCurWindowSize
<<"; i++)\n\t\t";
1150 if (!pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
1152 ss
<< "if((i+gid0)>=buffer_value_len || (i+gid0)>=buffer_date_len)\n\t\t";
1153 ss
<< "return result;\n\telse \n\t\t";
1157 ss
<< "if(i>=buffer_value_len || i>=buffer_date_len)\n\t\t";
1158 ss
<< "return result;\n\telse \n\t\t";
1162 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef(true);
1165 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef(true);
1167 ss
<< "result += value/(pow((rate+1),(date-dateNull)/365));\n";
1169 ss
<< "return result;\n";
1173 void PriceMat::BinInlineFun(std::set
<std::string
>& decls
,
1174 std::set
<std::string
>& funs
)
1176 decls
.insert(GetYearFracDecl
);decls
.insert(GetNullDateDecl
);
1177 decls
.insert(DateToDaysDecl
);decls
.insert(DaysToDateDecl
);
1178 decls
.insert(DaysInMonthDecl
);decls
.insert(IsLeapYearDecl
);
1180 funs
.insert(GetYearFrac
);funs
.insert(GetNullDate
);
1181 funs
.insert(DateToDays
);funs
.insert(DaysToDate
);
1182 funs
.insert(DaysInMonth
);funs
.insert(IsLeapYear
);
1184 void PriceMat::GenSlidingWindowFunction(
1185 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
1187 ss
<< "\ndouble " << sSymName
;
1188 ss
<< "_"<< BinFuncName() <<"(";
1189 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1193 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1196 ss
<< "int gid0 = get_global_id(0);\n\t";
1197 ss
<< "double result=0;\n\t";
1198 ss
<< "int nNullDate = GetNullDate( );\n\t";
1199 ss
<<"int settle;\n\t";
1200 ss
<<"int mat;\n\t";
1201 ss
<<"int issue;\n\t";
1202 ss
<<"double rate;\n\t";
1203 ss
<<"double yield;\n\t";
1204 ss
<<"int nBase;\n\t";
1205 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1206 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
1207 formula::SingleVectorRefToken
*>(tmpCur0
);
1208 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
1209 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
1210 formula::SingleVectorRefToken
*>(tmpCur1
);
1211 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1212 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
1213 formula::SingleVectorRefToken
*>(tmpCur2
);
1214 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
1215 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
1216 formula::SingleVectorRefToken
*>(tmpCur3
);
1217 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
1218 const formula::SingleVectorRefToken
*tmpCurDVR4
= static_cast<const
1219 formula::SingleVectorRefToken
*>(tmpCur4
);
1220 FormulaToken
*tmpCur5
= vSubArguments
[5]->GetFormulaToken();
1221 const formula::SingleVectorRefToken
*tmpCurDVR5
= static_cast<const
1222 formula::SingleVectorRefToken
*>(tmpCur5
);
1224 ss
<< "int buffer_settle_len = ";
1225 ss
<< tmpCurDVR0
->GetArrayLength();
1227 ss
<< "int buffer_mat_len = ";
1228 ss
<< tmpCurDVR1
->GetArrayLength();
1230 ss
<< "int buffer_issue_len = ";
1231 ss
<< tmpCurDVR2
->GetArrayLength();
1233 ss
<< "int buffer_rate_len = ";
1234 ss
<< tmpCurDVR3
->GetArrayLength();
1236 ss
<< "int buffer_yield_len = ";
1237 ss
<< tmpCurDVR4
->GetArrayLength();
1239 ss
<< "int buffer_base_len = ";
1240 ss
<< tmpCurDVR5
->GetArrayLength();
1242 ss
<<"if(gid0>=buffer_settle_len || isNan(";
1243 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1245 ss
<<"settle = 0;\n\telse \n\t\t";
1247 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1249 ss
<<"if(gid0>=buffer_mat_len || isNan(";
1250 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1252 ss
<<"mat = 0;\n\telse \n\t\t";
1254 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1256 ss
<<"if(gid0>=buffer_issue_len || isNan(";
1257 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1259 ss
<<"issue = 0;\n\telse \n\t\t";
1261 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1263 ss
<<"if(gid0>=buffer_rate_len || isNan(";
1264 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
1266 ss
<<"rate = 0;\n\telse \n\t\t";
1268 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
1270 ss
<<"if(gid0>=buffer_yield_len || isNan(";
1271 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
1273 ss
<<"yield = 0;\n\telse \n\t\t";
1275 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
1277 ss
<<"if(gid0>=buffer_base_len || isNan(";
1278 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
1280 ss
<<"nBase = 0;\n\telse \n\t\t";
1282 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
1284 ss
<< "double fIssMat = GetYearFrac( nNullDate, issue, mat, nBase);\n";
1285 ss
<<"double fIssSet = GetYearFrac( nNullDate, issue, settle,nBase);\n";
1286 ss
<<"double fSetMat = GetYearFrac( nNullDate, settle, mat, nBase);\n";
1287 ss
<<"result = 1.0 + fIssMat * rate;\n\t";
1288 ss
<<"result /= 1.0 + fSetMat * yield;\n\t";
1289 ss
<<"result -= fIssSet * rate;\n\t";
1290 ss
<<"result*= 100.0;\n\t";
1291 ss
<<"return result;\n\t";
1295 void OpSYD::GenSlidingWindowFunction(std::stringstream
&ss
,
1296 const std::string
&sSymName
, SubArguments
&vSubArguments
)
1298 ss
<< "\ndouble " << sSymName
;
1299 ss
<< "_"<< BinFuncName() <<"(";
1300 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1304 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1307 ss
<< " int gid0 = get_global_id(0);\n";
1308 ss
<< " double result=0;\n";
1309 ss
<< " double cost;\n";
1310 ss
<< " double salvage;\n";
1311 ss
<< " double life;\n";
1312 ss
<< " double period;\n";
1313 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1314 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
1315 formula::SingleVectorRefToken
*>(tmpCur0
);
1317 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
1318 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
1319 formula::SingleVectorRefToken
*>(tmpCur1
);
1321 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1322 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
1323 formula::SingleVectorRefToken
*>(tmpCur2
);
1325 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
1326 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
1327 formula::SingleVectorRefToken
*>(tmpCur3
);
1329 ss
<< " int buffer_cost_len = ";
1330 ss
<< tmpCurDVR0
->GetArrayLength();
1333 ss
<< " int buffer_salvage_len = ";
1334 ss
<< tmpCurDVR1
->GetArrayLength();
1337 ss
<< " int buffer_life_len = ";
1338 ss
<< tmpCurDVR2
->GetArrayLength();
1340 ss
<< " int buffer_period_len = ";
1341 ss
<< tmpCurDVR3
->GetArrayLength();
1344 ss
<<" if(gid0>=buffer_cost_len || isNan(";
1345 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1347 ss
<<" cost = 0;\n\telse \n";
1349 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1351 ss
<<" if(gid0>=buffer_salvage_len || isNan(";
1352 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1354 ss
<<" salvage = 0;\n\telse \n";
1356 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1358 ss
<<" if(gid0>=buffer_life_len || isNan(";
1359 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1361 ss
<<" life = 0;\n\telse \n";
1363 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1365 ss
<<" if(gid0>=buffer_period_len || isNan(";
1366 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
1368 ss
<<" period = 0;\n\telse \n";
1370 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
1372 ss
<<" double tmpvalue = ((life*(life+1))*pow(2.0,-1));\n";
1373 ss
<<" result = ((cost-salvage)*(life-period+1)";
1374 ss
<< "*pow(tmpvalue,-1));\n";
1375 ss
<<" return result;\n";
1379 void MIRR::GenSlidingWindowFunction(
1380 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
1382 FormulaToken
* pCur
= vSubArguments
[0]->GetFormulaToken();
1384 const formula::DoubleVectorRefToken
* pCurDVR
=
1385 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
1386 size_t nCurWindowSize
= pCurDVR
->GetRefRowSize();
1387 FormulaToken
* pCur1
= vSubArguments
[1]->GetFormulaToken();
1389 const formula::SingleVectorRefToken
* pSVR1
=
1390 static_cast< const formula::SingleVectorRefToken
* >(pCur1
);
1392 FormulaToken
* pCur2
= vSubArguments
[2]->GetFormulaToken();
1394 const formula::SingleVectorRefToken
* pSVR2
=
1395 static_cast< const formula::SingleVectorRefToken
* >(pCur2
);
1398 ss
<< "\ndouble " << sSymName
;
1399 ss
<< "_"<< BinFuncName() <<"(";
1400 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1404 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1407 ss
<< "double tmp = " << GetBottom() <<";\n\t";
1408 ss
<< "int gid0 = get_global_id(0);\n\t";
1409 ss
<< "double arg0, arg1, arg2;\n\t";
1410 ss
<< "arg1 = " << vSubArguments
[1]->GenSlidingWindowDeclRef();
1412 ss
<< "arg2 = " << vSubArguments
[2]->GenSlidingWindowDeclRef();
1414 ss
<< "int argLen1 = " << pSVR1
->GetArrayLength() << ";\n\t";
1415 ss
<< "int argLen2 = " << pSVR2
->GetArrayLength() << ";\n\t";
1416 ss
<< "if (gid0 >= argLen1)\n\t\t";
1417 ss
<< "arg1 = 0.0;\n\t";
1418 ss
<< "if (gid0 >= argLen2)\n\t\t";
1419 ss
<< "arg2 = 0.0;\n\t";
1420 ss
<< "if (isNan(arg1))\n\t\t";
1421 ss
<< "arg1 = 0.0;\n\t";
1422 ss
<< "if (isNan(arg2))\n\t\t";
1423 ss
<< "arg2 = 0.0;\n\t";
1424 ss
<< "double invest = arg1 + 1.0;\n\t";
1425 ss
<< "double reinvest = arg2 + 1.0;\n\t";
1426 ss
<< "double NPV_invest = 0.0;\n\t";
1427 ss
<< "double Pow_invest = 1.0;\n\t";
1428 ss
<< "double NPV_reinvest = 0.0;\n\t";
1429 ss
<< "double Pow_reinvest = 1.0;\n\t";
1430 ss
<< "int nCount = 0;\n\t";
1431 ss
<< "int arrayLength = " << pCurDVR
->GetArrayLength() << ";\n\t";
1432 ss
<< "for (int i = 0; i + gid0 < arrayLength &&";
1433 ss
<< " i < " << nCurWindowSize
<< "; i++){\n\t\t";
1434 ss
<< "arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
1436 ss
<< "if (isNan(arg0))\n\t\t\t";
1437 ss
<< "continue;\n\t\t";
1438 ss
<< "if (arg0 > 0.0)\n\t\t\t";
1439 ss
<< "NPV_reinvest += arg0 * Pow_reinvest;\n\t\t";
1440 ss
<< "else if (arg0 < 0.0)\n\t\t\t";
1441 ss
<< "NPV_invest += arg0 * Pow_invest;\n\t\t";
1442 ss
<< "Pow_reinvest /= reinvest;\n\t\t";
1443 ss
<< "Pow_invest /= invest;\n\t\t";
1444 ss
<< "nCount++;\n\t";
1447 ss
<< "-NPV_reinvest /NPV_invest * pow(reinvest,(double)nCount-1);\n\t";
1448 ss
<< "tmp = pow(tmp, 1.0 / (nCount - 1)) - 1.0;\n\t";
1449 ss
<< "return (double)tmp;\n";
1453 void OpEffective::GenSlidingWindowFunction(std::stringstream
& ss
,
1454 const std::string
&sSymName
, SubArguments
& vSubArguments
)
1456 ss
<< "\ndouble " << sSymName
;
1457 ss
<< "_" << BinFuncName() << "(";
1458 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1462 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1465 ss
<< " double tmp = " << GetBottom() <<";\n";
1466 ss
<< " int gid0 = get_global_id(0);\n\t";
1467 ss
<< " double arg0 = " << GetBottom() << ";\n";
1468 ss
<< " double arg1 = " << GetBottom() << ";\n";
1469 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1471 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
1473 if (pCur
->GetType() == formula::svSingleVectorRef
)
1475 const formula::SingleVectorRefToken
* pSVR
=
1476 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
1477 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
1479 else if (pCur
->GetType() == formula::svDouble
)
1483 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
1485 ss
<< " if (isNan(";
1486 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
1488 ss
<< " arg" << i
<< " = 0;\n";
1490 ss
<< " arg" << i
<< " = ";
1491 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1496 ss
<< " arg" << i
<< " = ";
1497 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1500 ss
<< " tmp = pow(1.0 + arg0 * pow(arg1, -1), arg1)-1.0;\n";
1501 ss
<< " return tmp;\n";
1505 void OpTbilleq::BinInlineFun(std::set
<std::string
>& decls
,
1506 std::set
<std::string
>& funs
)
1508 decls
.insert(GetDiffDate360_Decl
);decls
.insert(GetDiffDate360Decl
);
1509 decls
.insert(DateToDaysDecl
);decls
.insert(DaysToDate_LocalBarrierDecl
);
1510 decls
.insert(DaysInMonthDecl
);decls
.insert(GetNullDateDecl
);
1511 decls
.insert(IsLeapYearDecl
);
1512 funs
.insert(GetDiffDate360_
);funs
.insert(GetDiffDate360
);
1513 funs
.insert(DateToDays
);funs
.insert(DaysToDate_LocalBarrier
);
1514 funs
.insert(DaysInMonth
);funs
.insert(GetNullDate
);
1515 funs
.insert(IsLeapYear
);
1517 void OpTbilleq::GenSlidingWindowFunction(
1518 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
1520 ss
<< "\ndouble " << sSymName
;
1521 ss
<< "_"<< BinFuncName() <<"(";
1522 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1526 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1529 ss
<< " int gid0 = get_global_id(0);\n";
1530 ss
<< "double tmp = 0;\n\t";
1531 ss
<< "double tmp000;\n\t";
1532 ss
<< "double tmp001;\n\t";
1533 ss
<< "double tmp002;\n\t";
1535 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1536 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
1537 formula::SingleVectorRefToken
*>(tmpCur0
);
1539 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
1540 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
1541 formula::SingleVectorRefToken
*>(tmpCur1
);
1543 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1544 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
1545 formula::SingleVectorRefToken
*>(tmpCur2
);
1547 ss
<< "int buffer_tmp000_len = ";
1548 ss
<< tmpCurDVR0
->GetArrayLength();
1551 ss
<< "int buffer_tmp001_len = ";
1552 ss
<< tmpCurDVR1
->GetArrayLength();
1555 ss
<< "int buffer_tmp002_len = ";
1556 ss
<< tmpCurDVR2
->GetArrayLength();
1559 ss
<<"if(gid0>=buffer_tmp000_len || isNan(";
1560 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1562 ss
<<"tmp000 = 0;\n\telse \n\t\t";
1564 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1567 ss
<<"if(gid0>=buffer_tmp001_len || isNan(";
1568 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1570 ss
<<"tmp001 = 0;\n\telse \n\t\t";
1572 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1575 ss
<<"if(gid0>=buffer_tmp002_len || isNan(";
1576 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1578 ss
<<"tmp002 = 0;\n\telse \n\t\t";
1580 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1583 ss
<<"tmp001+=1.0;\n";
1584 ss
<<"int nDiff =GetDiffDate360(GetNullDate(),tmp000,tmp001,true);\n";
1585 ss
<<"tmp =( 365 * tmp002 ) / ( 360 - ( tmp002 * ( nDiff ) ) );\n";
1586 ss
<< "return tmp;\n";
1589 void OpCumprinc::BinInlineFun(std::set
<std::string
>& decls
,
1590 std::set
<std::string
>& funs
)
1592 decls
.insert(GetRmz_newDecl
); decls
.insert(GetZw_newDecl
);
1593 funs
.insert(GetRmz_new
);funs
.insert(GetZw_new
);
1595 void OpCumprinc::GenSlidingWindowFunction(std::stringstream
&ss
,
1596 const std::string
&sSymName
, SubArguments
&vSubArguments
)
1598 ss
<< "\ndouble " << sSymName
;
1599 ss
<< "_"<< BinFuncName() <<"(";
1600 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1604 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1607 ss
<< " double tmp = " << GetBottom() <<";\n";
1608 ss
<< " int gid0 = get_global_id(0);\n";
1609 ss
<< " double fRate,fVal;\n";
1610 ss
<< " int nStartPer,nEndPer,nNumPeriods,nPayType;\n";
1611 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1612 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
1613 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1614 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
1615 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
1616 FormulaToken
*tmpCur5
= vSubArguments
[5]->GetFormulaToken();
1617 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
1619 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
1620 formula::SingleVectorRefToken
*>(tmpCur0
);
1621 ss
<<" if(gid0 >= "<<tmpCurDVR0
->GetArrayLength()<<" || isNan(";
1622 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
1624 ss
<<" fRate = 0;\n else\n";
1626 ss
<<" fRate = "<<vSubArguments
[0]->GenSlidingWindowDeclRef();
1628 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
1630 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
1631 formula::SingleVectorRefToken
*>(tmpCur1
);
1632 ss
<<" if(gid0 >= "<<tmpCurDVR1
->GetArrayLength()<<" || isNan(";
1633 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
1635 ss
<<" nNumPeriods = 0;\n else\n";
1637 ss
<<" nNumPeriods = (int)";
1638 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
1640 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
1642 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
1643 formula::SingleVectorRefToken
*>(tmpCur2
);
1644 ss
<<" if(gid0 >= "<<tmpCurDVR2
->GetArrayLength()<<" || isNan(";
1645 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
1647 ss
<<" fVal = 0;\n else\n";
1649 ss
<<" fVal = "<<vSubArguments
[2]->GenSlidingWindowDeclRef();
1651 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
1653 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
1654 formula::SingleVectorRefToken
*>(tmpCur3
);
1655 ss
<<" if(gid0 >= "<<tmpCurDVR3
->GetArrayLength()<<" || isNan(";
1656 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
1658 ss
<<" nStartPer = 0;\n else\n";
1660 ss
<<" nStartPer = (int)";
1661 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
1663 if(tmpCur4
->GetType() == formula::svSingleVectorRef
)
1665 const formula::SingleVectorRefToken
*tmpCurDVR4
= static_cast<const
1666 formula::SingleVectorRefToken
*>(tmpCur4
);
1667 ss
<<" if(gid0 >= "<<tmpCurDVR4
->GetArrayLength()<<" || isNan(";
1668 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
1670 ss
<<" nEndPer = 0;\n else\n";
1672 ss
<<" nEndPer = (int)";
1673 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
1676 if(tmpCur5
->GetType() == formula::svSingleVectorRef
)
1678 const formula::SingleVectorRefToken
*tmpCurDVR5
= static_cast<const
1679 formula::SingleVectorRefToken
*>(tmpCur5
);
1680 ss
<<" if(gid0 >= "<<tmpCurDVR5
->GetArrayLength()<<" || isNan(";
1681 ss
<<vSubArguments
[5]->GenSlidingWindowDeclRef();
1683 ss
<<" nPayType = 0;\n else\n";
1685 ss
<<" nPayType = (int)";
1686 ss
<<vSubArguments
[5]->GenSlidingWindowDeclRef();
1688 ss
<<" double fRmz;\n";
1689 ss
<<" fRmz = GetRmz_new( fRate, nNumPeriods,fVal,0.0,nPayType );\n";
1690 ss
<<" if(nStartPer == 1)\n";
1692 ss
<<" if( nPayType <= 0 )\n";
1693 ss
<<" tmp = fRmz + fVal * fRate;\n";
1695 ss
<<" tmp = fRmz;\n";
1696 ss
<<" nStartPer=nStartPer+1;\n";
1698 ss
<<" for( int i = nStartPer ; i <= nEndPer ; i++ )\n";
1700 ss
<<" if( nPayType > 0 )\n";
1701 ss
<<" tmp += fRmz - ( GetZw_new( fRate,i - 2,";
1702 ss
<<"fRmz,fVal,1)- fRmz ) * fRate;\n";
1704 ss
<<" tmp += fRmz - GetZw_new( fRate, i - 1,";
1705 ss
<<"fRmz,fVal,0 ) * fRate;\n";
1707 ss
<<" return tmp;\n";
1710 void OpAccrint::BinInlineFun(std::set
<std::string
>& decls
,
1711 std::set
<std::string
>& funs
)
1713 decls
.insert(IsLeapYearDecl
); decls
.insert(DaysInMonthDecl
);
1714 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDaysDecl
);
1715 decls
.insert(GetNullDateDecl
); decls
.insert(GetDiffDateDecl
);
1716 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
1717 funs
.insert(DaysToDate
);funs
.insert(DateToDays
);
1718 funs
.insert(GetNullDate
);funs
.insert(GetDiffDate
);
1720 void OpAccrint::GenSlidingWindowFunction(
1721 std::stringstream
&ss
, const std::string
&sSymName
,
1722 SubArguments
&vSubArguments
)
1724 ss
<< "\ndouble " << sSymName
;
1725 ss
<< "_"<< BinFuncName() <<"(";
1726 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1730 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1733 ss
<< " int gid0 = get_global_id(0);\n";
1734 ss
<< " double tmp = 0;\n";
1735 ss
<< " int nStartDate,nEndDate,mode,freq;\n";
1736 ss
<< " int nDays1stYear=0;\n";
1737 ss
<< " double fVal,fRate;\n";
1738 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1739 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
1740 formula::SingleVectorRefToken
*>(tmpCur0
);
1741 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1742 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
1743 formula::SingleVectorRefToken
*>(tmpCur2
);
1744 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
1745 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
1746 formula::SingleVectorRefToken
*>(tmpCur3
);
1747 FormulaToken
* tmpCur4
= vSubArguments
[4]->GetFormulaToken();
1748 const formula::SingleVectorRefToken
*tmpCurDVR4
= static_cast<const
1749 formula::SingleVectorRefToken
*>(tmpCur4
);
1750 FormulaToken
* tmpCur5
= vSubArguments
[5]->GetFormulaToken();
1751 const formula::SingleVectorRefToken
*tmpCurDVR5
= static_cast<const
1752 formula::SingleVectorRefToken
*>(tmpCur5
);
1753 FormulaToken
* tmpCur6
= vSubArguments
[6]->GetFormulaToken();
1754 const formula::SingleVectorRefToken
*tmpCurDVR6
= static_cast<const
1755 formula::SingleVectorRefToken
*>(tmpCur6
);
1756 ss
<< " int buffer_nIssue_len = ";
1757 ss
<< tmpCurDVR0
->GetArrayLength();
1759 ss
<< " int buffer_nSettle_len = ";
1760 ss
<< tmpCurDVR2
->GetArrayLength();
1762 ss
<< " int buffer_fRate_len = ";
1763 ss
<< tmpCurDVR3
->GetArrayLength();
1765 ss
<< " int buffer_fVal_len = ";
1766 ss
<< tmpCurDVR4
->GetArrayLength();
1768 ss
<< " int buffer_nFreq_len = ";
1769 ss
<< tmpCurDVR5
->GetArrayLength();
1771 ss
<< " int buffer_nMode_len = ";
1772 ss
<< tmpCurDVR6
->GetArrayLength();
1774 ss
<<" if(gid0 >= buffer_nIssue_len || isNan(";
1775 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
1777 ss
<<" nStartDate = 0;\n else\n";
1778 ss
<<" nStartDate=(int)";
1779 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
1781 ss
<<" if(gid0 >= buffer_nSettle_len || isNan(";
1782 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
1784 ss
<<" nEndDate = 0;\n else\n";
1785 ss
<<" nEndDate=(int)";
1786 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1788 ss
<<" if(gid0 >= buffer_fRate_len || isNan(";
1789 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
1791 ss
<<" fRate = 0;\n else\n";
1793 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
1795 ss
<<" if(gid0 >= buffer_fVal_len || isNan(";
1796 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
1798 ss
<<" fVal = 0;\n else\n";
1800 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
1802 ss
<<" if(gid0 >= buffer_nFreq_len || isNan(";
1803 ss
<<vSubArguments
[5]->GenSlidingWindowDeclRef();
1805 ss
<<" freq = 0;\n else\n";
1806 ss
<<" freq= (int)";
1807 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
1809 ss
<<" if(gid0 >= buffer_nMode_len || isNan(";
1810 ss
<<vSubArguments
[6]->GenSlidingWindowDeclRef();
1812 ss
<<" mode = 0;\n else\n";
1813 ss
<<" mode = (int)";
1814 ss
<< vSubArguments
[6]->GenSlidingWindowDeclRef();
1816 ss
<<" int nNullDate=GetNullDate();\n";
1817 ss
<<" int nTotalDays = GetDiffDate(nNullDate,nStartDate,";
1818 ss
<<"nEndDate, mode,&nDays1stYear);\n";
1819 ss
<<" tmp = fVal*fRate*convert_double(nTotalDays)";
1820 ss
<<"/convert_double(nDays1stYear);\n";
1821 ss
<<" return tmp;\n";
1825 void OpAccrintm::BinInlineFun(std::set
<std::string
>& decls
,
1826 std::set
<std::string
>& funs
)
1828 decls
.insert(IsLeapYearDecl
); decls
.insert(DaysInMonthDecl
);
1829 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDaysDecl
);
1830 decls
.insert(GetNullDateDecl
); decls
.insert(GetDiffDateDecl
);
1831 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
1832 funs
.insert(DaysToDate
);funs
.insert(DateToDays
);
1833 funs
.insert(GetNullDate
);funs
.insert(GetDiffDate
);
1835 void OpAccrintm::GenSlidingWindowFunction(
1836 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
1838 ss
<< "\ndouble " << sSymName
;
1839 ss
<< "_"<< BinFuncName() <<"(";
1840 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1844 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1847 ss
<< "int gid0 = get_global_id(0);\n\t";
1848 ss
<< "double tmp = " << GetBottom() <<";\n\t";
1849 ss
<< "int nStartDate,nEndDate,mode;\n\t";
1850 ss
<< "double fRate,fVal;\n\t";
1851 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1852 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
1853 formula::SingleVectorRefToken
*>(tmpCur0
);
1854 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
1855 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
1856 formula::SingleVectorRefToken
*>(tmpCur1
);
1858 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1859 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
1860 formula::SingleVectorRefToken
*>(tmpCur2
);
1862 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
1863 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
1864 formula::SingleVectorRefToken
*>(tmpCur3
);
1866 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
1867 const formula::SingleVectorRefToken
*tmpCurDVR4
= static_cast<const
1868 formula::SingleVectorRefToken
*>(tmpCur4
);
1869 ss
<< "int buffer_nIssue_len = ";
1870 ss
<< tmpCurDVR0
->GetArrayLength();
1873 ss
<< "int buffer_nSettle_len = ";
1874 ss
<< tmpCurDVR1
->GetArrayLength();
1877 ss
<< "int buffer_fRate_len = ";
1878 ss
<< tmpCurDVR2
->GetArrayLength();
1881 ss
<< "int buffer_fVal_len = ";
1882 ss
<< tmpCurDVR3
->GetArrayLength();
1885 ss
<< "int buffer_nMode_len = ";
1886 ss
<< tmpCurDVR4
->GetArrayLength();
1888 ss
<<"if(gid0 >= buffer_nIssue_len || isNan(";
1889 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
1891 ss
<<"nStartDate = 0;\n\telse\n\t\t";
1892 ss
<< "nStartDate=(int)";
1893 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1895 ss
<<"if(gid0 >= buffer_nSettle_len || isNan(";
1896 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
1898 ss
<<"nEndDate = 0;\n\telse\n\t\t";
1899 ss
<< "nEndDate=(int)";
1900 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1903 ss
<<"if(gid0 >= buffer_fRate_len || isNan(";
1904 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
1906 ss
<<"fRate = 0;\n\telse\n\t\t";
1908 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1910 ss
<<"if(gid0 >= buffer_fVal_len || isNan(";
1911 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
1913 ss
<<"fVal = 0;\n\telse\n\t\t";
1915 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
1917 ss
<<"if(gid0 >= buffer_nMode_len || isNan(";
1918 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
1920 ss
<<"mode = 0;\n\telse\n\t\t";
1921 ss
<< "mode = (int)";
1922 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
1924 ss
<<"int nDays1stYear=0;\n\t";
1925 ss
<<"int nNullDate=GetNullDate();\n\t";
1926 ss
<<"int nTotalDays = GetDiffDate(nNullDate,nStartDate,";
1927 ss
<<"nEndDate, mode,&nDays1stYear);\n\t";
1928 ss
<<"tmp = fVal*fRate*convert_double(nTotalDays)";
1929 ss
<<"/convert_double(nDays1stYear);\n\t";
1930 ss
<< "return tmp;\n";
1934 void OpYield::BinInlineFun(std::set
<std::string
>& decls
,
1935 std::set
<std::string
>& funs
)
1937 decls
.insert(getYield_Decl
);decls
.insert(getPrice_Decl
);
1938 decls
.insert(coupnumDecl
);decls
.insert(coupdaysncDecl
);
1939 decls
.insert(coupdaybsDecl
);decls
.insert(coupdaysDecl
);
1940 decls
.insert(lcl_GetcoupnumDecl
);decls
.insert(lcl_GetcoupdaysDecl
);
1941 decls
.insert(lcl_GetcoupdaybsDecl
);decls
.insert(getDiffDecl
);
1942 decls
.insert(getDaysInYearRangeDecl
);decls
.insert(GetDaysInYearDecl
);
1943 decls
.insert(GetDaysInYearsDecl
);decls
.insert(getDaysInMonthRangeDecl
);
1944 decls
.insert(addMonthsDecl
);decls
.insert(ScaDateDecl
);
1945 decls
.insert(GetNullDateDecl
);decls
.insert(DateToDaysDecl
);
1946 decls
.insert(DaysToDateDecl
);decls
.insert(DaysInMonthDecl
);
1947 decls
.insert(IsLeapYearDecl
);
1949 funs
.insert(getYield_
);funs
.insert(getPrice_
);
1950 funs
.insert(coupnum
);funs
.insert(coupdaysnc
);
1951 funs
.insert(coupdaybs
);funs
.insert(coupdays
);
1952 funs
.insert(lcl_Getcoupnum
);funs
.insert(lcl_Getcoupdays
);
1953 funs
.insert(lcl_Getcoupdaybs
);funs
.insert(getDiff
);
1954 funs
.insert(getDaysInYearRange
);funs
.insert(GetDaysInYear
);
1955 funs
.insert(GetDaysInYears
);funs
.insert(getDaysInMonthRange
);
1956 funs
.insert(addMonths
);funs
.insert(ScaDate
);
1957 funs
.insert(GetNullDate
);funs
.insert(DateToDays
);
1958 funs
.insert(DaysToDate
);funs
.insert(DaysInMonth
);
1959 funs
.insert(IsLeapYear
);
1962 void OpYield::GenSlidingWindowFunction(
1963 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
1965 ss
<< "\ndouble " << sSymName
;
1966 ss
<< "_"<< BinFuncName() <<"(";
1967 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1971 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1974 ss
<< "double tmp = 0;\n\t";
1975 ss
<< "int gid0 = get_global_id(0);\n\t";
1976 ss
<< "double tmp000;\n\t";
1977 ss
<< "double tmp001;\n\t";
1978 ss
<< "double tmp002;\n\t";
1979 ss
<< "double tmp003;\n\t";
1980 ss
<< "double tmp004;\n\t";
1981 ss
<< "double tmp005;\n\t";
1982 ss
<< "double tmp006;\n\t";
1984 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1985 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
1986 formula::SingleVectorRefToken
*>(tmpCur0
);
1988 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
1989 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
1990 formula::SingleVectorRefToken
*>(tmpCur1
);
1992 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1993 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
1994 formula::SingleVectorRefToken
*>(tmpCur2
);
1996 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
1997 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
1998 formula::SingleVectorRefToken
*>(tmpCur3
);
2000 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
2001 const formula::SingleVectorRefToken
*tmpCurDVR4
= static_cast<const
2002 formula::SingleVectorRefToken
*>(tmpCur4
);
2004 FormulaToken
*tmpCur5
= vSubArguments
[5]->GetFormulaToken();
2005 const formula::SingleVectorRefToken
*tmpCurDVR5
= static_cast<const
2006 formula::SingleVectorRefToken
*>(tmpCur5
);
2008 FormulaToken
*tmpCur6
= vSubArguments
[6]->GetFormulaToken();
2009 const formula::SingleVectorRefToken
*tmpCurDVR6
= static_cast<const
2010 formula::SingleVectorRefToken
*>(tmpCur6
);
2012 ss
<< "int buffer_tmp000_len = ";
2013 ss
<< tmpCurDVR0
->GetArrayLength();
2016 ss
<< "int buffer_tmp001_len = ";
2017 ss
<< tmpCurDVR1
->GetArrayLength();
2020 ss
<< "int buffer_tmp002_len = ";
2021 ss
<< tmpCurDVR2
->GetArrayLength();
2024 ss
<< "int buffer_tmp003_len = ";
2025 ss
<< tmpCurDVR3
->GetArrayLength();
2028 ss
<< "int buffer_tmp004_len = ";
2029 ss
<< tmpCurDVR4
->GetArrayLength();
2032 ss
<< "int buffer_tmp005_len = ";
2033 ss
<< tmpCurDVR5
->GetArrayLength();
2036 ss
<< "int buffer_tmp006_len = ";
2037 ss
<< tmpCurDVR6
->GetArrayLength();
2040 ss
<<"if(gid0>=buffer_tmp000_len || isNan(";
2041 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2043 ss
<<"tmp000 = 0;\n\telse \n\t\t";
2045 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2048 ss
<<"if(gid0>=buffer_tmp001_len || isNan(";
2049 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
2051 ss
<<"tmp001 = 0;\n\telse \n\t\t";
2053 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
2056 ss
<<"if(gid0>=buffer_tmp002_len || isNan(";
2057 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
2059 ss
<<"tmp002 = 0;\n\telse \n\t\t";
2061 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
2064 ss
<<"if(gid0>=buffer_tmp003_len || isNan(";
2065 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
2067 ss
<<"tmp003 = 0;\n\telse \n\t\t";
2069 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
2072 ss
<<"if(gid0>=buffer_tmp004_len || isNan(";
2073 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
2075 ss
<<"tmp004 = 0;\n\telse \n\t\t";
2077 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
2080 ss
<<"if(gid0>=buffer_tmp005_len || isNan(";
2081 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
2083 ss
<<"tmp005 = 0;\n\telse \n\t\t";
2085 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
2088 ss
<<"if(gid0>=buffer_tmp006_len || isNan(";
2089 ss
<< vSubArguments
[6]->GenSlidingWindowDeclRef();
2091 ss
<<"tmp006 = 0;\n\telse \n\t\t";
2093 ss
<< vSubArguments
[6]->GenSlidingWindowDeclRef();
2096 ss
<< "tmp = getYield_(";
2097 ss
<< "GetNullDate(),tmp000,tmp001,tmp002,tmp003,tmp004,tmp005,tmp006);\n\t ";
2098 ss
<< "return tmp;\n";
2102 void OpSLN::GenSlidingWindowFunction(std::stringstream
&ss
,
2103 const std::string
&sSymName
, SubArguments
&vSubArguments
)
2105 ss
<< "\ndouble " << sSymName
;
2106 ss
<< "_"<< BinFuncName() <<"(";
2107 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2111 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2114 ss
<< " double tmp = 0;\n";
2115 ss
<< " int gid0 = get_global_id(0);\n";
2116 ss
<< " double wert;\n";
2117 ss
<< " double rest;\n";
2118 ss
<< " double dauer;\n";
2120 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
2121 const formula::SingleVectorRefToken
*tmpCurDVR0
=
2122 static_cast<const formula::SingleVectorRefToken
*>(tmpCur0
);
2123 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
2124 const formula::SingleVectorRefToken
*tmpCurDVR1
=
2125 static_cast<const formula::SingleVectorRefToken
*>(tmpCur1
);
2126 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
2127 const formula::SingleVectorRefToken
*tmpCurDVR2
=
2128 static_cast<const formula::SingleVectorRefToken
*>(tmpCur2
);
2129 ss
<< " int buffer_wert_len = ";
2130 ss
<< tmpCurDVR0
->GetArrayLength();
2132 ss
<< " int buffer_rest_len = ";
2133 ss
<< tmpCurDVR1
->GetArrayLength();
2135 ss
<< " int buffer_dauer_len = ";
2136 ss
<< tmpCurDVR2
->GetArrayLength();
2138 ss
<<" if(gid0>=buffer_wert_len || isNan(";
2139 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2141 ss
<<" wert = 0;\n\telse \n";
2143 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2145 ss
<<" if(gid0>=buffer_rest_len || isNan(";
2146 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
2148 ss
<<" rest = 0;\n\telse \n";
2150 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
2152 ss
<<" if(gid0>=buffer_dauer_len || isNan(";
2153 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
2155 ss
<<" dauer = 0;\n\telse \n";
2157 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
2159 ss
<< " tmp = (wert-rest)*pow(dauer,-1);\n";
2160 ss
<< " return tmp;\n";
2164 void OpYieldmat::BinInlineFun(std::set
<std::string
>& decls
,
2165 std::set
<std::string
>& funs
)
2167 decls
.insert(GetYearFrac_newDecl
);decls
.insert(GetNullDateDecl
);
2168 decls
.insert(DateToDaysDecl
);decls
.insert(DaysToDate_newDecl
);
2169 decls
.insert(DaysInMonthDecl
);decls
.insert(IsLeapYearDecl
);
2170 decls
.insert(GetYieldmatDecl
);
2172 funs
.insert(GetYearFrac_new
);funs
.insert(GetNullDate
);
2173 funs
.insert(DateToDays
);funs
.insert(DaysToDate_new
);
2174 funs
.insert(DaysInMonth
);funs
.insert(IsLeapYear
);
2175 funs
.insert(GetYieldmat
);
2178 void OpYieldmat::GenSlidingWindowFunction(
2179 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
2181 ss
<< "\ndouble " << sSymName
;
2182 ss
<< "_"<< BinFuncName() <<"(";
2183 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2187 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2190 ss
<< "double tmp = 0;\n\t";
2191 ss
<< "int gid0 = get_global_id(0);\n\t";
2192 ss
<< "double tmp000;\n\t";
2193 ss
<< "double tmp001;\n\t";
2194 ss
<< "double tmp002;\n\t";
2195 ss
<< "double tmp003;\n\t";
2196 ss
<< "double tmp004;\n\t";
2197 ss
<< "double tmp005;\n\t";
2199 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
2200 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
2201 formula::SingleVectorRefToken
*>(tmpCur0
);
2203 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
2204 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
2205 formula::SingleVectorRefToken
*>(tmpCur1
);
2207 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
2208 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
2209 formula::SingleVectorRefToken
*>(tmpCur2
);
2211 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
2212 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
2213 formula::SingleVectorRefToken
*>(tmpCur3
);
2215 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
2216 const formula::SingleVectorRefToken
*tmpCurDVR4
= static_cast<const
2217 formula::SingleVectorRefToken
*>(tmpCur4
);
2219 FormulaToken
*tmpCur5
= vSubArguments
[5]->GetFormulaToken();
2220 const formula::SingleVectorRefToken
*tmpCurDVR5
= static_cast<const
2221 formula::SingleVectorRefToken
*>(tmpCur5
);
2223 ss
<< "int buffer_tmp000_len = ";
2224 ss
<< tmpCurDVR0
->GetArrayLength();
2227 ss
<< "int buffer_tmp001_len = ";
2228 ss
<< tmpCurDVR1
->GetArrayLength();
2231 ss
<< "int buffer_tmp002_len = ";
2232 ss
<< tmpCurDVR2
->GetArrayLength();
2235 ss
<< "int buffer_tmp003_len = ";
2236 ss
<< tmpCurDVR3
->GetArrayLength();
2239 ss
<< "int buffer_tmp004_len = ";
2240 ss
<< tmpCurDVR4
->GetArrayLength();
2243 ss
<< "int buffer_tmp005_len = ";
2244 ss
<< tmpCurDVR5
->GetArrayLength();
2247 ss
<<"if(gid0>=buffer_tmp000_len || isNan(";
2248 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2250 ss
<<"tmp000 = 0;\n\telse \n\t\t";
2252 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2255 ss
<<"if(gid0>=buffer_tmp001_len || isNan(";
2256 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
2258 ss
<<"tmp001 = 0;\n\telse \n\t\t";
2260 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
2263 ss
<<"if(gid0>=buffer_tmp002_len || isNan(";
2264 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
2266 ss
<<"tmp002 = 0;\n\telse \n\t\t";
2268 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
2271 ss
<<"if(gid0>=buffer_tmp003_len || isNan(";
2272 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
2274 ss
<<"tmp003 = 0;\n\telse \n\t\t";
2276 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
2279 ss
<<"if(gid0>=buffer_tmp004_len || isNan(";
2280 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
2282 ss
<<"tmp004 = 0;\n\telse \n\t\t";
2284 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
2287 ss
<<"if(gid0>=buffer_tmp005_len || isNan(";
2288 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
2290 ss
<<"tmp005 = 0;\n\telse \n\t\t";
2292 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
2295 ss
<< "tmp = GetYieldmat(";
2296 ss
<<"GetNullDate(),tmp000,tmp001,tmp002,tmp003,tmp004,tmp005);\n\t";
2297 ss
<< "return tmp;\n";
2301 void OpPMT::GenSlidingWindowFunction(std::stringstream
&ss
,
2302 const std::string
&sSymName
, SubArguments
&vSubArguments
)
2304 ss
<< "\ndouble " << sSymName
;
2305 ss
<< "_"<< BinFuncName() <<"(";
2306 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2310 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2313 ss
<<" double tmp = 0;\n";
2314 ss
<<" double temp=0.0;\n";
2315 ss
<<" int gid0 = get_global_id(0);\n";
2316 ss
<<" double tmp0=0,tmp1=0,tmp2=0;\n";
2317 ss
<<" double tmp3=0,tmp4=0;\n";
2318 size_t i
= vSubArguments
.size();
2321 for (i
= 0; i
< vSubArguments
.size(); i
++)
2323 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2325 if (pCur
->GetType() == formula::svSingleVectorRef
)
2327 const formula::SingleVectorRefToken
* pSVR
=
2328 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
2329 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
2331 else if (pCur
->GetType() == formula::svDouble
)
2338 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2340 ss
<<" temp="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
2342 ss
<<" if (isNan(temp))\n";
2343 ss
<<" tmp"<<i
<<"= 0;\n";
2345 ss
<<" tmp"<<i
<<"=temp;\n";
2350 ss
<<" tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef(
2355 ss
<<" if(tmp0==0.0)\n";
2356 ss
<<" return -(tmp2+tmp3)/tmp1;\n";
2357 ss
<<" tmp-=tmp3;\n";
2358 ss
<<" tmp=tmp-tmp2*pow(1.0+tmp0,tmp1);\n";
2359 ss
<<" tmp=tmp*pow(( (1.0+tmp0*tmp4)* ";
2360 ss
<<"( (pow(1.0+tmp0,tmp1)-1.0)/tmp0)),-1);\n";
2361 ss
<<" return tmp;\n";
2365 void OpNPV::GenSlidingWindowFunction(std::stringstream
&ss
,
2366 const std::string
&sSymName
, SubArguments
&vSubArguments
)
2368 ss
<< "\ndouble " << sSymName
;
2369 ss
<< "_"<< BinFuncName() <<"(";
2370 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2374 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2377 ss
<< " double tmp = 0.0;\n";
2378 ss
<< " int gid0 = get_global_id(0);\n";
2379 ss
<< " int nCount = 1;\n";
2380 ss
<< " double arg0=";
2381 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
2384 for (size_t i
= 1; i
< vSubArguments
.size(); i
++)
2386 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2388 if (pCur
->GetType() == formula::svDoubleVectorRef
)
2390 const formula::DoubleVectorRefToken
* pDVR
=
2391 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
2392 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
2393 ss
<< " for (int i = ";
2394 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
2395 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
2396 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
2397 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
2398 ss
<< "0; i < " << pDVR
->GetArrayLength();
2399 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
2400 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
2401 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
2402 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
2405 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
2408 else if (pCur
->GetType() == formula::svSingleVectorRef
)
2410 const formula::SingleVectorRefToken
* pSVR
=
2411 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
2412 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
2414 else if (pCur
->GetType() == formula::svDouble
)
2420 ss
<< "nCount += 1;\n";
2422 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2424 ss
<< " double temp=";
2425 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2427 ss
<< " double temp1=1.0;";
2428 ss
<< " if (isNan(temp)){\n";
2429 ss
<< " tmp += 0;}\n";
2431 ss
<< " for(int i=1;i<nCount;i+=2)\n";
2432 ss
<< " temp1*=pow(1.0f+ arg0 ,2);\n";
2433 ss
<< " if(nCount%2)\n";
2434 ss
<< " temp1*=1.0f+ arg0;\n";
2435 ss
<< " tmp +=temp/ temp1;\n";
2436 ss
<< " nCount += 1;\n";
2442 ss
<< " double temp=";
2443 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2445 ss
<< " double temp1=1.0;";
2446 ss
<< " for(int i=1;i<nCount;i+=2)";
2447 ss
<< " temp1*=pow(1.0f+ arg0 ,2);\n";
2448 ss
<< " if(nCount%2)";
2449 ss
<< " temp1*=1.0f+ arg0;\n";
2450 ss
<< " tmp +=temp/ temp1;\n";
2451 ss
<< " nCount += 1;\n";
2454 ss
<< " return tmp;\n";
2458 void OpPrice::BinInlineFun(std::set
<std::string
>& decls
,
2459 std::set
<std::string
>& funs
)
2461 decls
.insert(getPrice_new_Decl
);
2462 decls
.insert(IsLeapYearDecl
);decls
.insert(DaysInMonthDecl
);
2463 decls
.insert(DaysToDateDecl
);
2464 decls
.insert(DateToDaysDecl
);
2465 decls
.insert(ScaDateDecl
);
2466 decls
.insert(setDayDecl
);decls
.insert(checklessthanDecl
);
2467 decls
.insert(addMonthsDecl
);decls
.insert(lcl_Getcoupnum_newDecl
);
2468 decls
.insert(coupnum_newDecl
);
2469 decls
.insert(DateToDays_newDecl
);
2470 decls
.insert(getDaysInMonthRangeDecl
);
2471 decls
.insert(GetDaysInYearsDecl
); decls
.insert(GetDaysInYearDecl
);
2472 decls
.insert(getDaysInYearRangeDecl
); decls
.insert(getDiffDecl
);
2473 decls
.insert(coupdaybs_newDecl
);
2474 decls
.insert(lcl_Getcoupdays_newDecl
);
2475 decls
.insert(lcl_Getcoupdaybs_newDecl
);
2476 decls
.insert(coupdays_newDecl
);
2477 decls
.insert(coupdaysnc_newDecl
);
2478 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth_new
);
2479 funs
.insert(DaysToDate
);funs
.insert(DateToDays_new
);
2480 funs
.insert(DateToDays
);
2481 funs
.insert(ScaDate
);
2482 funs
.insert(addMonths
);funs
.insert(getDaysInMonthRange
);
2483 funs
.insert(GetDaysInYears
);funs
.insert(GetDaysInYear
);
2484 funs
.insert(getDaysInYearRange
);funs
.insert(getDiff
);
2485 funs
.insert(setDay
);funs
.insert(checklessthan
);
2486 funs
.insert(lcl_Getcoupdaybs_new
);
2487 funs
.insert(coupdaybs_new
);
2488 funs
.insert(lcl_Getcoupdays_new
);
2489 funs
.insert(coupdaysnc_new
);
2490 funs
.insert(coupdays_new
);
2491 funs
.insert(setDay
);funs
.insert(checklessthan
);
2492 funs
.insert(lcl_Getcoupnum_new
);
2493 funs
.insert(coupnum_new
);funs
.insert(getPrice_new
);
2495 void OpPrice::GenSlidingWindowFunction(std::stringstream
&ss
,
2496 const std::string
&sSymName
, SubArguments
&vSubArguments
)
2498 ss
<< "\ndouble " << sSymName
;
2499 ss
<< "_"<< BinFuncName() <<"(";
2500 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2504 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2507 ss
<<" double tmp = 0;\n";
2508 ss
<<" int gid0 = get_global_id(0);\n";
2509 ss
<<" double tmp0=0;\n";
2510 ss
<<" double tmp1=0;\n";
2511 ss
<<" double tmp2=0;\n";
2512 ss
<<" double tmp3=0;\n";
2513 ss
<<" double tmp4=0,tmp5=0;\n";
2514 ss
<<" double tmp6=0;\n";
2516 for (size_t i
= 0; i
< vSubArguments
.size(); i
++)
2518 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2520 if (pCur
->GetType() == formula::svSingleVectorRef
)
2522 const formula::SingleVectorRefToken
* pSVR
=
2523 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
2524 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
2526 else if (pCur
->GetType() == formula::svDouble
)
2533 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2535 ss
<< " if (isNan(";
2536 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2538 ss
<< " tmp"<<i
<<"= 0;\n";
2540 ss
<< " tmp"<<i
<<"=";
2541 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2546 ss
<< " tmp"<<i
<<"=";
2547 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2551 ss
<< " if(tmp4*tmp5 == 0) return NAN;\n";
2552 ss
<< " tmp = getPrice_(tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);\n";
2553 ss
<< " return tmp;\n";
2557 void OpOddlprice::BinInlineFun(std::set
<std::string
>& decls
,
2558 std::set
<std::string
>& funs
)
2560 decls
.insert(GetOddlpriceDecl
);decls
.insert(GetDiffDateDecl
);
2561 decls
.insert(GetYearDiffDecl
);decls
.insert(IsLeapYearDecl
);
2562 decls
.insert(GetNullDateDecl
);decls
.insert(DateToDaysDecl
);
2563 decls
.insert(DaysToDateDecl
);decls
.insert(DaysInMonthDecl
);
2564 decls
.insert(GetYearFracDecl
);
2565 funs
.insert(GetOddlprice
);funs
.insert(GetDiffDate
);
2566 funs
.insert(GetYearDiff
);funs
.insert(IsLeapYear
);
2567 funs
.insert(GetNullDate
);funs
.insert(DaysInMonth
);
2568 funs
.insert(DaysToDate
);funs
.insert(DateToDays
);
2569 funs
.insert(GetYearFrac
);
2571 void OpOddlprice::GenSlidingWindowFunction(std::stringstream
&ss
,
2572 const std::string
&sSymName
, SubArguments
&vSubArguments
)
2574 ss
<< "\ndouble " << sSymName
;
2575 ss
<< "_"<< BinFuncName() <<"(";
2576 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2580 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2583 ss
<<" double tmp = 0;\n";
2584 ss
<<" int gid0 = get_global_id(0);\n";
2585 ss
<<" double tmp0=0;\n";
2586 ss
<<" double tmp1=0;\n";
2587 ss
<<" double tmp2=0;\n";
2588 ss
<<" double tmp3=0;\n";
2589 ss
<<" double tmp4=0;\n";
2590 ss
<<" double tmp5=0;\n";
2591 ss
<<" double tmp6=0;\n";
2592 ss
<<" double tmp7=0;\n";
2594 for (size_t i
= 0; i
< vSubArguments
.size(); i
++)
2596 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2598 if (pCur
->GetType() == formula::svDoubleVectorRef
)
2600 const formula::DoubleVectorRefToken
* pDVR
=
2601 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
2602 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
2603 ss
<< " for (int i = ";
2604 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
2605 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
2606 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
2607 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
2608 ss
<< "0; i < " << pDVR
->GetArrayLength();
2609 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
2610 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
2611 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
2612 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
2615 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
2618 else if (pCur
->GetType() == formula::svSingleVectorRef
)
2620 const formula::SingleVectorRefToken
* pSVR
=
2621 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
2622 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
2624 else if (pCur
->GetType() == formula::svDouble
)
2631 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2633 ss
<< " if (isNan(";
2634 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2636 ss
<< " tmp"<<i
<<"= 0;\n";
2638 ss
<< " tmp"<<i
<<"=";
2639 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
2645 ss
<< " tmp"<<i
<<"=";
2646 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
2650 ss
<<" int nNullDate = GetNullDate();\n";
2651 ss
<<" tmp = GetOddlprice(nNullDate,tmp0,tmp1,";
2652 ss
<<"tmp2,tmp3,tmp4,tmp5,tmp6,tmp7);\n";
2653 ss
<<" return tmp;\n";
2656 void OpOddlyield::BinInlineFun(std::set
<std::string
>& decls
,
2657 std::set
<std::string
>& funs
)
2659 decls
.insert(GetDiffDateDecl
);decls
.insert(DaysToDateDecl
);
2660 decls
.insert(GetYearDiffDecl
);decls
.insert(IsLeapYearDecl
);
2661 decls
.insert(GetNullDateDecl
);decls
.insert(DateToDaysDecl
);
2662 decls
.insert(DaysInMonthDecl
);
2663 decls
.insert(GetYearFracDecl
);decls
.insert(GetOddlyieldDecl
);
2664 funs
.insert(GetDiffDate
);funs
.insert(DaysToDate
);
2665 funs
.insert(GetYearDiff
);funs
.insert(IsLeapYear
);
2666 funs
.insert(GetNullDate
);funs
.insert(DaysInMonth
);
2667 funs
.insert(DateToDays
);
2668 funs
.insert(GetYearFrac
);funs
.insert(GetOddlyield
);
2670 void OpOddlyield::GenSlidingWindowFunction(std::stringstream
&ss
,
2671 const std::string
&sSymName
, SubArguments
&vSubArguments
)
2673 ss
<< "\ndouble " << sSymName
;
2674 ss
<< "_"<< BinFuncName() <<"(";
2675 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2679 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2682 ss
<<" double tmp = 0;\n";
2683 ss
<<" int gid0 = get_global_id(0);\n";
2684 ss
<<" double tmp0=0;\n";
2685 ss
<<" double tmp1=0;\n";
2686 ss
<<" double tmp2=0;\n";
2687 ss
<<" double tmp3=0;\n";
2688 ss
<<" double tmp4=0;\n";
2689 ss
<<" double tmp5=0;\n";
2690 ss
<<" double tmp6=0;\n";
2691 ss
<<" double tmp7=0;\n";
2693 for (size_t i
= 0; i
< vSubArguments
.size(); i
++)
2695 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2697 if (pCur
->GetType() == formula::svDoubleVectorRef
)
2699 const formula::DoubleVectorRefToken
* pDVR
=
2700 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
2701 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
2702 ss
<< " for (int i = ";
2703 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
2704 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
2705 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
2706 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
2707 ss
<< "0; i < " << pDVR
->GetArrayLength();
2708 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
2709 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
2710 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
2711 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
2714 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
2717 else if (pCur
->GetType() == formula::svSingleVectorRef
)
2719 const formula::SingleVectorRefToken
* pSVR
=
2720 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
2721 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
2723 else if (pCur
->GetType() == formula::svDouble
)
2730 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2732 ss
<< " if (isNan(";
2733 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2735 ss
<< " tmp"<<i
<<"= 0;\n";
2737 ss
<< " tmp"<<i
<<"=";
2738 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
2744 ss
<< " tmp"<<i
<<"=";
2745 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
2749 ss
<<" int nNullDate = GetNullDate();\n";
2750 ss
<<" tmp = GetOddlyield(nNullDate,tmp0,tmp1";
2751 ss
<<",tmp2,tmp3,tmp4,tmp5,tmp6,tmp7);\n";
2752 ss
<<" return tmp;\n";
2755 void OpPriceDisc::BinInlineFun(std::set
<std::string
>& decls
,
2756 std::set
<std::string
>& funs
)
2758 decls
.insert(GetYearDiffDecl
);decls
.insert(getDiffDecl
);
2759 decls
.insert(getDaysInYearRangeDecl
);decls
.insert(GetDaysInYearDecl
);
2760 decls
.insert(GetDaysInYearsDecl
);decls
.insert(getDaysInMonthRangeDecl
);
2761 decls
.insert(addMonthsDecl
);decls
.insert(ScaDateDecl
);
2762 decls
.insert(GetNullDateDecl
);decls
.insert(DateToDaysDecl
);
2763 decls
.insert(DaysToDateDecl
);decls
.insert(DaysInMonthDecl
);
2764 decls
.insert(IsLeapYearDecl
);decls
.insert(GetDiffDateDecl
);
2765 funs
.insert(GetYearDiff
);funs
.insert(getDiff
);
2766 funs
.insert(getDaysInYearRange
);funs
.insert(GetDaysInYear
);
2767 funs
.insert(GetDaysInYears
);funs
.insert(getDaysInMonthRange
);
2768 funs
.insert(addMonths
);funs
.insert(ScaDate
);
2769 funs
.insert(GetNullDate
);funs
.insert(DateToDays
);
2770 funs
.insert(DaysToDate
);funs
.insert(DaysInMonth
);
2771 funs
.insert(IsLeapYear
);funs
.insert(GetDiffDate
);
2773 void OpPriceDisc::GenSlidingWindowFunction(std::stringstream
&ss
,
2774 const std::string
&sSymName
, SubArguments
&vSubArguments
)
2776 ss
<< "\ndouble " << sSymName
;
2777 ss
<< "_"<< BinFuncName() <<"(";
2778 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2782 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2785 ss
<< " double tmp = 0;\n";
2786 ss
<< " int gid0 = get_global_id(0);\n";
2787 ss
<<" double tmp0=0;\n";
2788 ss
<<" double tmp1=0;\n";
2789 ss
<<" double tmp2=0;\n";
2790 ss
<<" double tmp3=0;\n";
2791 ss
<<" double tmp4=0;\n";
2793 for (size_t i
= 0; i
< vSubArguments
.size(); i
++)
2795 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2797 if (pCur
->GetType() == formula::svSingleVectorRef
)
2799 const formula::SingleVectorRefToken
* pSVR
=
2800 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
2801 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
2803 else if (pCur
->GetType() == formula::svDouble
)
2810 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2812 ss
<< " if (isNan(";
2813 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2815 ss
<< " tmp"<<i
<<"= 0;\n";
2817 ss
<< " tmp"<<i
<<"=";
2818 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
2824 ss
<< " tmp"<<i
<<"=";
2825 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
2829 ss
<<" int nNullDate = GetNullDate();\n";
2830 ss
<<" tmp=tmp3* ( 1.0 -tmp2*GetYearDiff( nNullDate, ";
2831 ss
<<"tmp0,tmp1,tmp4));\n";
2832 ss
<<" return tmp;\n";
2835 void OpNper::GenSlidingWindowFunction(std::stringstream
&ss
,
2836 const std::string
&sSymName
, SubArguments
&vSubArguments
)
2838 ss
<< "\ndouble " << sSymName
;
2839 ss
<< "_"<< BinFuncName() <<"(";
2840 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2844 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2847 ss
<< " double tmp = 0;\n";
2848 ss
<< " int gid0 = get_global_id(0);\n";
2849 ss
<<" double tmp0=0;\n";
2850 ss
<<" double tmp1=0;\n";
2851 ss
<<" double tmp2=0;\n";
2852 ss
<<" double tmp3=0;\n";
2853 ss
<<" double tmp4=0;\n";
2855 for (size_t i
= 0; i
< vSubArguments
.size(); i
++)
2857 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2859 if (pCur
->GetType() == formula::svSingleVectorRef
)
2861 const formula::SingleVectorRefToken
* pSVR
=
2862 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
2863 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
2865 else if (pCur
->GetType() == formula::svDouble
)
2872 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2874 ss
<< " if (isNan(";
2875 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2877 ss
<< " tmp"<<i
<<"= 0;\n";
2879 ss
<< " tmp"<<i
<<"=";
2880 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
2886 ss
<< " tmp"<<i
<<"=";
2887 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
2891 ss
<<" if (tmp0 == 0.0)\n";
2892 ss
<<" tmp=(-1*(tmp2 + tmp3)/tmp1);\n";
2893 ss
<<" else if (tmp4 > 0.0)\n";
2894 ss
<<" tmp=log(-1*(tmp0*tmp3-tmp1*(1.0+tmp0))*";
2895 ss
<<"pow((tmp0*tmp2+tmp1*(1.0+tmp0)),-1))/log(1.0+tmp0);\n";
2897 ss
<<" tmp=log(-1*(tmp0*tmp3-tmp1)*pow(tmp0*tmp2+tmp1,-1))";
2898 ss
<<"/log(1.0+tmp0);\n";
2899 ss
<<" return tmp;\n";
2903 void OpPPMT::BinInlineFun(std::set
<std::string
>& decls
,
2904 std::set
<std::string
>& funs
)
2906 decls
.insert(GetZwDecl
);
2910 void OpPPMT::GenSlidingWindowFunction(std::stringstream
&ss
,
2911 const std::string
&sSymName
, SubArguments
&vSubArguments
)
2913 ss
<< "\ndouble " << sSymName
;
2914 ss
<< "_"<< BinFuncName() <<"(";
2915 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2919 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2922 ss
<<" double tmp = 0;\n";
2923 ss
<<" int gid0 = get_global_id(0);\n";
2924 ss
<<" double arg=0;\n";
2925 ss
<<" double tmp0=0;\n";
2926 ss
<<" double tmp1=0;\n";
2927 ss
<<" double tmp2=0;\n";
2928 ss
<<" double tmp3=0;\n";
2929 ss
<<" double tmp4=0,tmp5=0;\n";
2932 for (size_t i
= 0; i
< vSubArguments
.size(); i
++)
2934 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2936 if (pCur
->GetType() == formula::svSingleVectorRef
)
2938 const formula::SingleVectorRefToken
* pSVR
=
2939 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
2940 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
2942 else if (pCur
->GetType() == formula::svDouble
)
2949 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2952 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2954 ss
<< " if (isNan(arg))\n";
2955 ss
<< " tmp"<<i
<<"= 0;\n";
2957 ss
<< " tmp"<<i
<<"=arg;\n";
2962 ss
<<" tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
2966 ss
<<" double pmt=0 ;\n";
2967 ss
<<" if(tmp0==0.0)\n";
2968 ss
<<" return -(tmp3+tmp4)/tmp2;\n";
2969 ss
<<" pmt=pmt-tmp4-tmp3*pow(1.0+tmp0,tmp2);\n";
2970 ss
<<" pmt=pmt*pow(( (1.0+tmp0*tmp5)* ";
2971 ss
<<"( (pow(1.0+tmp0,tmp2)-1.0)/tmp0)),-1);\n";
2972 ss
<<" double temp = pow( 1+tmp0,tmp1-2);\n";
2973 ss
<<" double re;\n";
2974 ss
<<" if(tmp1==1.0){\n";
2975 ss
<<" if(tmp5>0.0)\n";
2982 ss
<<" if(tmp5>0.0)\n ";
2983 ss
<<" re=GetZw(tmp0, tmp1-2.0, pmt, tmp3, 1.0) - pmt;\n";
2985 ss
<<" re=GetZw(tmp0, tmp1-1.0, pmt, tmp3, 0.0);\n";
2987 ss
<<" re = re * tmp0;\n";
2988 ss
<<" tmp = pmt - re;\n";
2989 ss
<<" return tmp;\n";
2993 void OpCoupdaybs::BinInlineFun(std::set
<std::string
>& decls
,
2994 std::set
<std::string
>& funs
)
2996 decls
.insert(IsLeapYearDecl
); decls
.insert(DaysInMonthDecl
);
2997 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDays_newDecl
);
2998 decls
.insert(GetNullDate_newDecl
); decls
.insert(ScaDateDecl
);
2999 decls
.insert(addMonthsDecl
); decls
.insert(getDaysInMonthRangeDecl
);
3000 decls
.insert(GetDaysInYearsDecl
);
3001 decls
.insert(getDaysInYearRangeDecl
); decls
.insert(getDiffDecl
);
3002 decls
.insert(setDayDecl
);decls
.insert(checklessthanDecl
);
3003 decls
.insert(lcl_Getcoupdaybs_newDecl
);
3004 decls
.insert(coupdaybs_newDecl
);
3005 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
3006 funs
.insert(DaysToDate
);funs
.insert(DateToDays_new
);
3007 funs
.insert(GetNullDate_new
);funs
.insert(ScaDate
);
3008 funs
.insert(addMonths
);funs
.insert(getDaysInMonthRange
);
3009 funs
.insert(GetDaysInYears
);
3010 funs
.insert(getDaysInYearRange
);funs
.insert(getDiff
);
3011 funs
.insert(setDay
);funs
.insert(checklessthan
);
3012 funs
.insert(lcl_Getcoupdaybs_new
);
3013 funs
.insert(coupdaybs_new
);
3015 void OpCoupdaybs::GenSlidingWindowFunction(
3016 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&
3019 ss
<< "\ndouble " << sSymName
;
3020 ss
<< "_"<< BinFuncName() <<"(";
3021 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3025 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3028 ss
<< " double tmp = 0;\n";
3029 ss
<< " int gid0 = get_global_id(0);\n";
3030 ss
<< " int nSettle,nMat,nFreq,nBase;\n";
3031 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3032 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3033 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3034 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3035 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
3037 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
3038 formula::SingleVectorRefToken
*>(tmpCur0
);
3039 ss
<<" if(isNan("<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3040 ss
<<")||(gid0 >="<<tmpCurDVR0
->GetArrayLength()<<"))\n";
3041 ss
<<" nSettle = 0;\n else\n";
3043 ss
<<" nSettle=(int)";
3044 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3046 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
3048 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
3049 formula::SingleVectorRefToken
*>(tmpCur1
);
3050 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3051 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
3052 ss
<<" nMat = 0;\n else\n";
3055 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3057 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
3059 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
3060 formula::SingleVectorRefToken
*>(tmpCur2
);
3061 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
3062 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
3063 ss
<<" nFreq = 0;\n else\n";
3065 ss
<< " nFreq=(int)";
3066 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
3068 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
3070 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
3071 formula::SingleVectorRefToken
*>(tmpCur3
);
3072 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
3073 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
3074 ss
<<" nBase = 0;\n else\n";
3076 ss
<< " nBase=(int)";
3077 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
3079 ss
<<" tmp = coupdaybs_new(nSettle,nMat,nFreq,nBase);\n";
3080 ss
<<" return tmp;\n";
3084 void OpCoupdays::BinInlineFun(std::set
<std::string
>& decls
,
3085 std::set
<std::string
>& funs
)
3087 decls
.insert(IsLeapYearDecl
); decls
.insert(DaysInMonthDecl
);
3088 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDays_newDecl
);
3089 decls
.insert(GetNullDate_newDecl
); decls
.insert(ScaDateDecl
);
3090 decls
.insert(addMonthsDecl
); decls
.insert(getDaysInMonthRangeDecl
);
3091 decls
.insert(GetDaysInYearsDecl
); decls
.insert(GetDaysInYearDecl
);
3092 decls
.insert(getDaysInYearRangeDecl
); decls
.insert(getDiffDecl
);
3093 decls
.insert(setDayDecl
);decls
.insert(checklessthanDecl
);
3094 decls
.insert(lcl_Getcoupdays_newDecl
);
3095 decls
.insert(coupdays_newDecl
);
3096 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
3097 funs
.insert(DaysToDate
);funs
.insert(DateToDays_new
);
3098 funs
.insert(GetNullDate_new
);funs
.insert(ScaDate
);
3099 funs
.insert(addMonths
);funs
.insert(getDaysInMonthRange
);
3100 funs
.insert(GetDaysInYears
);funs
.insert(GetDaysInYear
);
3101 funs
.insert(getDaysInYearRange
);funs
.insert(getDiff
);
3102 funs
.insert(lcl_Getcoupdays_new
);
3103 funs
.insert(setDay
);funs
.insert(checklessthan
);
3104 funs
.insert(coupdays_new
);
3106 void OpCoupdays::GenSlidingWindowFunction(
3107 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&
3110 ss
<< "\ndouble " << sSymName
;
3111 ss
<< "_"<< BinFuncName() <<"(";
3112 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3116 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3119 ss
<< " double tmp = 0;\n";
3120 ss
<< " int gid0 = get_global_id(0);\n";
3121 ss
<< " int nSettle,nMat,nFreq,nBase;\n";
3122 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3123 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3124 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3125 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3126 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
3128 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
3129 formula::SingleVectorRefToken
*>(tmpCur0
);
3130 ss
<<" if(isNan("<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3131 ss
<<")||(gid0 >="<<tmpCurDVR0
->GetArrayLength()<<"))\n";
3132 ss
<<" nSettle = 0;\n else\n";
3134 ss
<<" nSettle=(int)";
3135 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3137 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
3139 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
3140 formula::SingleVectorRefToken
*>(tmpCur1
);
3141 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3142 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
3143 ss
<<" nMat = 0;\n else\n";
3146 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3148 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
3150 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
3151 formula::SingleVectorRefToken
*>(tmpCur2
);
3152 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
3153 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
3154 ss
<<" nFreq = 0;\n else\n";
3156 ss
<< " nFreq=(int)";
3157 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
3159 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
3161 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
3162 formula::SingleVectorRefToken
*>(tmpCur3
);
3163 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
3164 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
3165 ss
<<" nBase = 0;\n else\n";
3167 ss
<< " nBase=(int)";
3168 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
3170 ss
<<" tmp = coupdays_new(nSettle,nMat,nFreq,nBase);\n";
3171 ss
<<" return tmp;\n";
3174 void OpCouppcd::BinInlineFun(std::set
<std::string
>& decls
,
3175 std::set
<std::string
>& funs
)
3177 decls
.insert(IsLeapYearDecl
); decls
.insert(DaysInMonthDecl
);
3178 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDaysDecl
);
3179 decls
.insert(GetNullDateDecl
);
3180 decls
.insert(ScaDateDecl
);
3181 decls
.insert(addMonthsDecl
);
3182 decls
.insert(setDayDecl
);decls
.insert(checklessthanDecl
);
3183 decls
.insert(lcl_GetCouppcdDecl
);
3184 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
3185 funs
.insert(DaysToDate
);funs
.insert(DateToDays
);
3186 funs
.insert(GetNullDate
);
3187 funs
.insert(ScaDate
);
3188 funs
.insert(addMonths
);
3189 funs
.insert(setDay
);funs
.insert(checklessthan
);
3190 funs
.insert(lcl_GetCouppcd
);
3192 void OpCouppcd::GenSlidingWindowFunction(
3193 std::stringstream
&ss
, const std::string
&sSymName
,
3194 SubArguments
&vSubArguments
)
3196 ss
<< "\ndouble " << sSymName
;
3197 ss
<< "_"<< BinFuncName() <<"(";
3198 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3202 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3205 ss
<< " double tmp = 0;\n";
3206 ss
<< " int gid0 = get_global_id(0);\n";
3207 ss
<< " int nSettle,nMat,nFreq,nBase;\n";
3208 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3209 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3210 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3211 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3212 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
3214 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
3215 formula::SingleVectorRefToken
*>(tmpCur0
);
3216 ss
<<" if(isNan("<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3217 ss
<<")||(gid0 >="<<tmpCurDVR0
->GetArrayLength()<<"))\n";
3218 ss
<<" nSettle = 0;\n else\n";
3220 ss
<<" nSettle=(int)";
3221 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3223 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
3225 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
3226 formula::SingleVectorRefToken
*>(tmpCur1
);
3227 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3228 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
3229 ss
<<" nMat = 0;\n else\n";
3232 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3234 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
3236 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
3237 formula::SingleVectorRefToken
*>(tmpCur2
);
3238 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
3239 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
3240 ss
<<" nFreq = 0;\n else\n";
3242 ss
<< " nFreq=(int)";
3243 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
3245 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
3247 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
3248 formula::SingleVectorRefToken
*>(tmpCur3
);
3249 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
3250 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
3251 ss
<<" nBase = 0;\n else\n";
3253 ss
<< " nBase=(int)";
3254 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
3256 ss
<<" int nNullDate=693594;\n";
3257 ss
<<" tmp = lcl_GetCouppcd(nNullDate,nSettle,nMat,nFreq,nBase);\n";
3258 ss
<<" return tmp;\n";
3261 void OpCoupncd::BinInlineFun(std::set
<std::string
>& decls
,
3262 std::set
<std::string
>& funs
)
3264 decls
.insert(IsLeapYearDecl
); decls
.insert(DaysInMonthDecl
);
3265 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDaysDecl
);
3266 decls
.insert(GetNullDateDecl
);
3267 decls
.insert(ScaDateDecl
);
3268 decls
.insert(addMonthsDecl
);
3269 decls
.insert(setDayDecl
);decls
.insert(checklessthanDecl
);
3270 decls
.insert(lcl_GetCoupncdDecl
);
3271 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
3272 funs
.insert(DaysToDate
);funs
.insert(DateToDays
);
3273 funs
.insert(GetNullDate
);
3274 funs
.insert(ScaDate
);
3275 funs
.insert(addMonths
);
3276 funs
.insert(setDay
);funs
.insert(checklessthan
);
3277 funs
.insert(lcl_GetCoupncd
);
3279 void OpCoupncd::GenSlidingWindowFunction(
3280 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&
3283 ss
<< "\ndouble " << sSymName
;
3284 ss
<< "_"<< BinFuncName() <<"(";
3285 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3289 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3292 ss
<< " double tmp = 0;\n";
3293 ss
<< " int gid0 = get_global_id(0);\n";
3294 ss
<< " int nSettle,nMat,nFreq,nBase;\n";
3295 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3296 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3297 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3298 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3299 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
3301 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
3302 formula::SingleVectorRefToken
*>(tmpCur0
);
3303 ss
<<" if(isNan("<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3304 ss
<<")||(gid0 >="<<tmpCurDVR0
->GetArrayLength()<<"))\n";
3305 ss
<<" nSettle = 0;\n else\n";
3307 ss
<<" nSettle=(int)";
3308 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3310 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
3312 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
3313 formula::SingleVectorRefToken
*>(tmpCur1
);
3314 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3315 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
3316 ss
<<" nMat = 0;\n else\n";
3319 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3321 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
3323 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
3324 formula::SingleVectorRefToken
*>(tmpCur2
);
3325 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
3326 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
3327 ss
<<" nFreq = 0;\n else\n";
3329 ss
<< " nFreq=(int)";
3330 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
3332 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
3334 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
3335 formula::SingleVectorRefToken
*>(tmpCur3
);
3336 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
3337 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
3338 ss
<<" nBase = 0;\n else\n";
3340 ss
<< " nBase=(int)";
3341 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
3343 ss
<<" int nNullDate=693594;\n";
3344 ss
<<" tmp = lcl_GetCoupncd(nNullDate,nSettle,nMat,nFreq,nBase);\n";
3345 ss
<<" return tmp;\n";
3349 void OpCoupdaysnc::BinInlineFun(std::set
<std::string
>& decls
,
3350 std::set
<std::string
>& funs
)
3352 decls
.insert(IsLeapYearDecl
); decls
.insert(DaysInMonth_newDecl
);
3353 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDaysDecl
);
3354 decls
.insert(DateToDays_newDecl
);
3355 decls
.insert(ScaDateDecl
);
3356 decls
.insert(addMonthsDecl
); decls
.insert(getDaysInMonthRangeDecl
);
3357 decls
.insert(GetDaysInYearsDecl
); decls
.insert(GetDaysInYearDecl
);
3358 decls
.insert(getDaysInYearRangeDecl
); decls
.insert(getDiffDecl
);
3359 decls
.insert(setDayDecl
);decls
.insert(checklessthanDecl
);
3360 decls
.insert(coupdaybs_newDecl
);
3361 decls
.insert(lcl_Getcoupdays_newDecl
);
3362 decls
.insert(lcl_Getcoupdaybs_newDecl
);
3363 decls
.insert(coupdays_newDecl
);
3364 decls
.insert(coupdaysnc_newDecl
);
3365 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth_new
);
3366 funs
.insert(DaysToDate
);funs
.insert(DateToDays_new
);
3367 funs
.insert(DateToDays
);
3368 funs
.insert(ScaDate
);
3369 funs
.insert(addMonths
);funs
.insert(getDaysInMonthRange
);
3370 funs
.insert(GetDaysInYears
);funs
.insert(GetDaysInYear
);
3371 funs
.insert(getDaysInYearRange
);funs
.insert(getDiff
);
3372 funs
.insert(setDay
);funs
.insert(checklessthan
);
3373 funs
.insert(lcl_Getcoupdaybs_new
);
3374 funs
.insert(coupdaybs_new
);
3375 funs
.insert(lcl_Getcoupdays_new
);
3376 funs
.insert(coupdaysnc_new
);
3377 funs
.insert(coupdays_new
);
3379 void OpCoupdaysnc::GenSlidingWindowFunction(
3380 std::stringstream
&ss
, const std::string
&sSymName
,
3381 SubArguments
&vSubArguments
)
3383 ss
<< "\ndouble " << sSymName
;
3384 ss
<< "_"<< BinFuncName() <<"(";
3385 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3389 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3392 ss
<< " double tmp = 0;\n";
3393 ss
<< " int gid0 = get_global_id(0);\n";
3394 ss
<< " int nSettle,nMat,nFreq,nBase;\n";
3395 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3396 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3397 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3398 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3399 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
3401 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
3402 formula::SingleVectorRefToken
*>(tmpCur0
);
3403 ss
<<" if(isNan("<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3404 ss
<<")||(gid0 >="<<tmpCurDVR0
->GetArrayLength()<<"))\n";
3405 ss
<<" nSettle = 0;\n else\n";
3407 ss
<<" nSettle=(int)";
3408 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3410 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
3412 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
3413 formula::SingleVectorRefToken
*>(tmpCur1
);
3414 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3415 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
3416 ss
<<" nMat = 0;\n else\n";
3419 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3421 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
3423 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
3424 formula::SingleVectorRefToken
*>(tmpCur2
);
3425 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
3426 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
3427 ss
<<" nFreq = 0;\n else\n";
3429 ss
<< " nFreq=(int)";
3430 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
3432 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
3434 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
3435 formula::SingleVectorRefToken
*>(tmpCur3
);
3436 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
3437 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
3438 ss
<<" nBase = 0;\n else\n";
3440 ss
<< " nBase=(int)";
3441 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
3443 ss
<<" tmp = coupdaysnc_new(nSettle,nMat,nFreq,nBase);\n";
3444 ss
<<" return tmp;\n";
3448 void OpCoupnum::BinInlineFun(std::set
<std::string
>& decls
,
3449 std::set
<std::string
>& funs
)
3451 decls
.insert(IsLeapYearDecl
);decls
.insert(DaysInMonthDecl
);
3452 decls
.insert(DaysToDateDecl
);
3453 decls
.insert(DateToDaysDecl
);
3454 decls
.insert(ScaDateDecl
);
3455 decls
.insert(setDayDecl
);decls
.insert(checklessthanDecl
);
3456 decls
.insert(addMonthsDecl
);decls
.insert(lcl_Getcoupnum_newDecl
);
3457 decls
.insert(coupnum_newDecl
);
3458 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth_new
);
3459 funs
.insert(DaysToDate
);
3460 funs
.insert(DateToDays
);
3461 funs
.insert(ScaDate
);
3462 funs
.insert(setDay
);funs
.insert(checklessthan
);
3463 funs
.insert(addMonths
);funs
.insert(lcl_Getcoupnum_new
);
3464 funs
.insert(coupnum_new
);
3466 void OpCoupnum::GenSlidingWindowFunction(std::stringstream
&ss
,
3467 const std::string
&sSymName
, SubArguments
&vSubArguments
)
3469 ss
<< "\ndouble " << sSymName
;
3470 ss
<< "_"<< BinFuncName() <<"(";
3471 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3475 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3478 ss
<< " double tmp = 0;\n";
3479 ss
<< " int gid0 = get_global_id(0);\n";
3480 ss
<< " int nSettle,nMat,nFreq,nBase;\n";
3481 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3482 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3483 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3484 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3485 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
3487 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
3488 formula::SingleVectorRefToken
*>(tmpCur0
);
3489 ss
<<" if(isNan("<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3490 ss
<<")||(gid0 >="<<tmpCurDVR0
->GetArrayLength()<<"))\n";
3491 ss
<<" nSettle = 0;\n else\n";
3493 ss
<<" nSettle=(int)";
3494 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3496 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
3498 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
3499 formula::SingleVectorRefToken
*>(tmpCur1
);
3500 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3501 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
3502 ss
<<" nMat = 0;\n else\n";
3505 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3507 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
3509 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
3510 formula::SingleVectorRefToken
*>(tmpCur2
);
3511 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
3512 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
3513 ss
<<" nFreq = 0;\n else\n";
3515 ss
<< " nFreq=(int)";
3516 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
3518 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
3520 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
3521 formula::SingleVectorRefToken
*>(tmpCur3
);
3522 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
3523 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
3524 ss
<<" nBase = 0;\n else\n";
3526 ss
<< " nBase=(int)";
3527 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
3529 ss
<<" tmp = coupnum_new(nSettle,nMat,nFreq,nBase);\n";
3530 ss
<<" return tmp;\n";
3533 void OpAmordegrc::BinInlineFun(std::set
<std::string
>& decls
,
3534 std::set
<std::string
>& funs
)
3536 decls
.insert(nKorrValDecl
); decls
.insert(RoundDecl
);
3537 decls
.insert(IsLeapYearDecl
);decls
.insert(DaysInMonthDecl
);
3538 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDaysDecl
);
3539 decls
.insert(GetNullDateDecl
); decls
.insert(GetYearFracDecl
);
3541 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
3542 funs
.insert(DaysToDate
);funs
.insert(DateToDays
);
3543 funs
.insert(GetNullDate
);funs
.insert(GetYearFrac
);
3545 void OpAmordegrc::GenSlidingWindowFunction(std::stringstream
&ss
,
3546 const std::string
&sSymName
, SubArguments
&vSubArguments
)
3548 ss
<< "\ndouble " << sSymName
;
3549 ss
<< "_"<< BinFuncName() <<"(";
3550 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3554 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3557 ss
<< "int gid0 = get_global_id(0);\n";
3558 ss
<< " double tmp = " << GetBottom() <<";\n";
3559 ss
<< " double fCost,fRestVal,fPer,fRate;\n";
3560 ss
<< " int nDate,nFirstPer,nBase;\n";
3561 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3562 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3563 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3564 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3565 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
3566 FormulaToken
*tmpCur5
= vSubArguments
[5]->GetFormulaToken();
3567 FormulaToken
*tmpCur6
= vSubArguments
[6]->GetFormulaToken();
3568 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
3570 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
3571 formula::SingleVectorRefToken
*>(tmpCur0
);
3572 ss
<<" if(isNan("<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3573 ss
<<")||(gid0 >="<<tmpCurDVR0
->GetArrayLength()<<"))\n";
3574 ss
<<" fCost = 0;\n else\n";
3577 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3579 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
3581 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
3582 formula::SingleVectorRefToken
*>(tmpCur1
);
3583 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3584 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
3585 ss
<<" nDate = 0;\n else\n";
3587 ss
<< " nDate=(int)";
3588 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3590 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
3592 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
3593 formula::SingleVectorRefToken
*>(tmpCur2
);
3594 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
3595 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
3596 ss
<<" nFirstPer = 0;\n else\n";
3598 ss
<< " nFirstPer=(int)";
3599 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
3601 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
3603 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
3604 formula::SingleVectorRefToken
*>(tmpCur3
);
3605 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
3606 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
3607 ss
<<" fRestVal = 0;\n else\n";
3610 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
3612 if(tmpCur4
->GetType() == formula::svSingleVectorRef
)
3614 const formula::SingleVectorRefToken
*tmpCurDVR4
= static_cast<const
3615 formula::SingleVectorRefToken
*>(tmpCur4
);
3616 ss
<<" if(isNan(" <<vSubArguments
[4]->GenSlidingWindowDeclRef();
3617 ss
<<")||(gid0 >="<<tmpCurDVR4
->GetArrayLength()<<"))\n";
3618 ss
<<" fPer = 0;\n else\n";
3621 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
3623 if(tmpCur5
->GetType() == formula::svSingleVectorRef
)
3625 const formula::SingleVectorRefToken
*tmpCurDVR5
= static_cast<const
3626 formula::SingleVectorRefToken
*>(tmpCur5
);
3627 ss
<<" if(isNan(" <<vSubArguments
[5]->GenSlidingWindowDeclRef();
3628 ss
<<")||(gid0 >="<<tmpCurDVR5
->GetArrayLength()<<"))\n";
3629 ss
<<" fRate = 0;\n else\n";
3632 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
3634 if(tmpCur6
->GetType() == formula::svSingleVectorRef
)
3636 const formula::SingleVectorRefToken
*tmpCurDVR6
= static_cast<const
3637 formula::SingleVectorRefToken
*>(tmpCur6
);
3638 ss
<<" if(isNan(" <<vSubArguments
[6]->GenSlidingWindowDeclRef();
3639 ss
<<")||(gid0 >="<<tmpCurDVR6
->GetArrayLength()<<"))\n";
3640 ss
<<" nBase = 0;\n else\n";
3642 ss
<< " nBase = (int)";
3643 ss
<< vSubArguments
[6]->GenSlidingWindowDeclRef();
3645 ss
<<" uint nPer = convert_int( fPer );\n";
3646 ss
<<" double fUsePer = 1.0 *pow( fRate,-1);\n";
3647 ss
<<" double fAmorCoeff;\n";
3648 ss
<<" if( fUsePer < 3.0 )\n";
3649 ss
<<" fAmorCoeff = 1.0;\n";
3650 ss
<<" else if( fUsePer < 5.0 )\n";
3651 ss
<<" fAmorCoeff = 1.5;\n";
3652 ss
<<" else if( fUsePer <= 6.0 )\n";
3653 ss
<<" fAmorCoeff = 2.0;\n";
3655 ss
<<" fAmorCoeff = 2.5;\n";
3656 ss
<<" fRate *= fAmorCoeff;\n";
3657 ss
<<" tmp = Round( GetYearFrac( 693594,";
3658 ss
<<"nDate, nFirstPer, nBase ) * fRate * fCost);\n";
3659 ss
<<" fCost = fCost-tmp;\n";
3660 ss
<<" double fRest = fCost - fRestVal;\n";
3661 ss
<<" for( uint n = 0 ; n < nPer ; n++ )\n";
3663 ss
<<" tmp = Round( fRate * fCost);\n";
3664 ss
<<" fRest -= tmp;\n";
3665 ss
<<" if( fRest < 0.0 )\n";
3667 ss
<<" switch( nPer - n )\n";
3671 ss
<<" tmp = Round( fCost * 0.5);\n";
3673 ss
<<" tmp = 0.0;\n";
3676 ss
<<" fCost -= tmp;\n";
3678 ss
<<" return tmp;\n";
3681 void OpAmorlinc::BinInlineFun(std::set
<std::string
>& decls
,
3682 std::set
<std::string
>& funs
)
3684 decls
.insert(nKorrValDecl
); decls
.insert(RoundDecl
);
3685 decls
.insert(IsLeapYearDecl
);decls
.insert(DaysInMonthDecl
);
3686 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDaysDecl
);
3687 decls
.insert(GetYearFracDecl
);
3689 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
3690 funs
.insert(DaysToDate
);funs
.insert(DateToDays
);
3691 funs
.insert(GetYearFrac
);
3693 void OpAmorlinc::GenSlidingWindowFunction(std::stringstream
&ss
,
3694 const std::string
&sSymName
, SubArguments
&vSubArguments
)
3696 ss
<< "\ndouble " << sSymName
;
3697 ss
<< "_"<< BinFuncName() <<"(";
3698 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3702 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3705 ss
<< " int gid0 = get_global_id(0);\n";
3706 ss
<< " double tmp = 0;\n";
3707 ss
<< " double fCost,fRestVal,fPer,fRate;\n";
3708 ss
<< " int nDate,nFirstPer,nBase;\n";
3709 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3710 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3711 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3712 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3713 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
3714 FormulaToken
*tmpCur5
= vSubArguments
[5]->GetFormulaToken();
3715 FormulaToken
*tmpCur6
= vSubArguments
[6]->GetFormulaToken();
3716 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
3718 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
3719 formula::SingleVectorRefToken
*>(tmpCur0
);
3720 ss
<<" if(isNan("<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3721 ss
<<")||(gid0 >="<<tmpCurDVR0
->GetArrayLength()<<"))\n";
3722 ss
<<" fCost = 0;\n else\n";
3725 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3727 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
3729 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
3730 formula::SingleVectorRefToken
*>(tmpCur1
);
3731 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3732 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
3733 ss
<<" nDate = 0;\n else\n";
3735 ss
<< " nDate=(int)";
3736 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3738 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
3740 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
3741 formula::SingleVectorRefToken
*>(tmpCur2
);
3742 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
3743 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
3744 ss
<<" nFirstPer = 0;\n else\n";
3746 ss
<< " nFirstPer=(int)";
3747 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
3749 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
3751 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
3752 formula::SingleVectorRefToken
*>(tmpCur3
);
3753 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
3754 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
3755 ss
<<" fRestVal = 0;\n else\n";
3758 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
3760 if(tmpCur4
->GetType() == formula::svSingleVectorRef
)
3762 const formula::SingleVectorRefToken
*tmpCurDVR4
= static_cast<const
3763 formula::SingleVectorRefToken
*>(tmpCur4
);
3764 ss
<<" if(isNan(" <<vSubArguments
[4]->GenSlidingWindowDeclRef();
3765 ss
<<")||(gid0 >="<<tmpCurDVR4
->GetArrayLength()<<"))\n";
3766 ss
<<" fPer = 0;\n else\n";
3769 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
3771 if(tmpCur5
->GetType() == formula::svSingleVectorRef
)
3773 const formula::SingleVectorRefToken
*tmpCurDVR5
= static_cast<const
3774 formula::SingleVectorRefToken
*>(tmpCur5
);
3775 ss
<<" if(isNan(" <<vSubArguments
[5]->GenSlidingWindowDeclRef();
3776 ss
<<")||(gid0 >="<<tmpCurDVR5
->GetArrayLength()<<"))\n";
3777 ss
<<" fRate = 0;\n else\n";
3780 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
3782 if(tmpCur6
->GetType() == formula::svSingleVectorRef
)
3784 const formula::SingleVectorRefToken
*tmpCurDVR6
= static_cast<const
3785 formula::SingleVectorRefToken
*>(tmpCur6
);
3786 ss
<<" if(isNan(" <<vSubArguments
[6]->GenSlidingWindowDeclRef();
3787 ss
<<")||(gid0 >="<<tmpCurDVR6
->GetArrayLength()<<"))\n";
3788 ss
<<" nBase = 0;\n else\n";
3790 ss
<< " nBase = (int)";
3791 ss
<< vSubArguments
[6]->GenSlidingWindowDeclRef();
3793 ss
<<" int nPer = convert_int( fPer );\n";
3794 ss
<<" double fOneRate = fCost * fRate;\n";
3795 ss
<<" double fCostDelta = fCost - fRestVal;\n";
3796 ss
<<" double f0Rate = GetYearFrac( 693594,";
3797 ss
<<"nDate, nFirstPer, nBase )* fRate * fCost;\n";
3798 ss
<<" int nNumOfFullPeriods = (int)";
3799 ss
<<"( ( fCost - fRestVal - f0Rate) *pow(fOneRate,-1) );\n";
3800 ss
<<" if( nPer == 0 )\n";
3801 ss
<<" tmp = f0Rate;\n";
3802 ss
<<" else if( nPer <= nNumOfFullPeriods )\n";
3803 ss
<<" tmp = fOneRate;\n";
3804 ss
<<" else if( nPer == nNumOfFullPeriods + 1 )\n";
3805 ss
<<" tmp = fCostDelta - fOneRate * nNumOfFullPeriods - f0Rate;\n";
3807 ss
<<" tmp = 0.0;\n";
3808 ss
<<" return tmp;\n";
3811 void OpReceived::BinInlineFun(std::set
<std::string
>& decls
,
3812 std::set
<std::string
>& funs
)
3814 decls
.insert(GetYearDiffDecl
);decls
.insert(GetDiffDateDecl
);
3815 decls
.insert(DaysToDateDecl
);decls
.insert(DaysInMonthDecl
);
3816 decls
.insert(GetNullDateDecl
);decls
.insert(IsLeapYearDecl
);
3817 decls
.insert(DateToDaysDecl
);
3818 funs
.insert(GetDiffDate
);funs
.insert(DaysToDate
);
3819 funs
.insert(DaysInMonth
);funs
.insert(GetNullDate
);
3820 funs
.insert(DateToDays
);funs
.insert(IsLeapYear
);
3821 funs
.insert(GetYearDiff
);
3824 void OpReceived::GenSlidingWindowFunction(std::stringstream
&ss
,
3825 const std::string
&sSymName
, SubArguments
&vSubArguments
)
3827 ss
<< "\ndouble " << sSymName
;
3828 ss
<< "_"<< BinFuncName() <<"(";
3829 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3833 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3836 ss
<< " double tmp = " << GetBottom() <<";\n";
3837 ss
<< " int gid0 = get_global_id(0);\n";
3838 ss
<< " int nSettle, nMat;\n";
3839 ss
<< " double fInvest,fDisc;\n";
3840 ss
<< " int rOB;\n";
3841 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3842 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
3843 formula::SingleVectorRefToken
*>(tmpCur0
);
3844 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3845 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
3846 formula::SingleVectorRefToken
*>(tmpCur1
);
3847 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3848 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
3849 formula::SingleVectorRefToken
*>(tmpCur2
);
3850 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3851 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
3852 formula::SingleVectorRefToken
*>(tmpCur3
);
3853 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
3854 const formula::SingleVectorRefToken
*tmpCurDVR4
= static_cast<const
3855 formula::SingleVectorRefToken
*>(tmpCur4
);
3856 ss
<< " int buffer_settle_len = ";
3857 ss
<< tmpCurDVR0
->GetArrayLength();
3859 ss
<< " int buffer_mat_len = ";
3860 ss
<< tmpCurDVR1
->GetArrayLength();
3862 ss
<< " int buffer_invest_len = ";
3863 ss
<< tmpCurDVR2
->GetArrayLength();
3865 ss
<< " int buffer_disc_len = ";
3866 ss
<< tmpCurDVR3
->GetArrayLength();
3868 ss
<< " int buffer_rob_len = ";
3869 ss
<< tmpCurDVR4
->GetArrayLength();
3871 ss
<<" if(gid0 >= buffer_settle_len || isNan(";
3872 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3874 ss
<<" nSettle = 0;\n\telse\n";
3875 ss
<<" nSettle = (int)"<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3877 ss
<<" if(gid0 >= buffer_mat_len || isNan(";
3878 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3880 ss
<<" nMat = 0;\n\telse\n";
3881 ss
<<" nMat = (int)";
3882 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3884 ss
<<" if(gid0 >= buffer_invest_len || isNan(";
3885 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
3887 ss
<<" fInvest = 0;\n\telse\n";
3888 ss
<<" fInvest = "<<vSubArguments
[2]->GenSlidingWindowDeclRef();
3890 ss
<<" if(gid0 >= buffer_disc_len || isNan(";
3891 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
3893 ss
<<" fDisc = 0;\n\telse\n";
3894 ss
<<" fDisc = "<<vSubArguments
[3]->GenSlidingWindowDeclRef();
3896 ss
<<" if(gid0 >= buffer_rob_len || isNan(";
3897 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
3899 ss
<<" rOB = 0;\n\telse\n";
3900 ss
<<" rOB = (int)"<<vSubArguments
[4]->GenSlidingWindowDeclRef();
3902 ss
<< " double tmpvalue = (1.0-(fDisc";
3903 ss
<<" * GetYearDiff( GetNullDate()";
3904 ss
<<",nSettle,nMat,rOB)));\n";
3905 ss
<< " tmp = fInvest*pow(tmpvalue,-1);\n";
3906 ss
<< " return tmp;\n";
3910 void OpYielddisc::BinInlineFun(std::set
<std::string
>& decls
,
3911 std::set
<std::string
>& funs
)
3913 decls
.insert(GetYearFracDecl
);decls
.insert(GetNullDateDecl
);
3914 decls
.insert(DateToDaysDecl
);decls
.insert(DaysToDateDecl
);
3915 decls
.insert(DaysInMonthDecl
);decls
.insert(IsLeapYearDecl
);
3917 funs
.insert(GetYearFrac
);funs
.insert(GetNullDate
);
3918 funs
.insert(DateToDays
);funs
.insert(DaysToDate
);
3919 funs
.insert(DaysInMonth
);funs
.insert(IsLeapYear
);
3921 void OpYielddisc::GenSlidingWindowFunction(
3922 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
3924 ss
<< "\ndouble " << sSymName
;
3925 ss
<< "_"<< BinFuncName() <<"(";
3926 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3930 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3933 ss
<< "double tmp = 0;\n\t";
3934 ss
<< "int gid0 = get_global_id(0);\n\t";
3935 ss
<< "double tmp000;\n\t";
3936 ss
<< "double tmp001;\n\t";
3937 ss
<< "double tmp002;\n\t";
3938 ss
<< "double tmp003;\n\t";
3939 ss
<< "double tmp004;\n\t";
3941 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3942 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
3943 formula::SingleVectorRefToken
*>(tmpCur0
);
3945 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3946 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
3947 formula::SingleVectorRefToken
*>(tmpCur1
);
3949 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3950 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
3951 formula::SingleVectorRefToken
*>(tmpCur2
);
3953 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3954 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
3955 formula::SingleVectorRefToken
*>(tmpCur3
);
3957 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
3958 const formula::SingleVectorRefToken
*tmpCurDVR4
= static_cast<const
3959 formula::SingleVectorRefToken
*>(tmpCur4
);
3961 ss
<< "int buffer_tmp000_len = ";
3962 ss
<< tmpCurDVR0
->GetArrayLength();
3965 ss
<< "int buffer_tmp001_len = ";
3966 ss
<< tmpCurDVR1
->GetArrayLength();
3969 ss
<< "int buffer_tmp002_len = ";
3970 ss
<< tmpCurDVR2
->GetArrayLength();
3973 ss
<< "int buffer_tmp003_len = ";
3974 ss
<< tmpCurDVR3
->GetArrayLength();
3977 ss
<< "int buffer_tmp004_len = ";
3978 ss
<< tmpCurDVR4
->GetArrayLength();
3981 ss
<<"if(gid0>=buffer_tmp000_len || isNan(";
3982 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3984 ss
<<"tmp000 = 0;\n\telse \n\t\t";
3986 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3989 ss
<<"if(gid0>=buffer_tmp001_len || isNan(";
3990 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3992 ss
<<"tmp001 = 0;\n\telse \n\t\t";
3994 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3997 ss
<<"if(gid0>=buffer_tmp002_len || isNan(";
3998 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
4000 ss
<<"tmp002 = 0;\n\telse \n\t\t";
4002 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
4005 ss
<<"if(gid0>=buffer_tmp003_len || isNan(";
4006 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
4008 ss
<<"tmp003 = 0;\n\telse \n\t\t";
4010 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
4013 ss
<<"if(gid0>=buffer_tmp004_len || isNan(";
4014 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
4016 ss
<<"tmp004 = 0;\n\telse \n\t\t";
4018 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
4021 ss
<< "tmp = (tmp003/tmp002)-1;\n\t";
4022 ss
<< "tmp /= GetYearFrac( GetNullDate(),tmp000,tmp001,tmp004);\n\t";
4023 ss
<< "return tmp;\n";
4027 void OpTbillprice::BinInlineFun(std::set
<std::string
>& decls
,
4028 std::set
<std::string
>& funs
)
4030 decls
.insert(GetYearFracDecl
);
4031 decls
.insert(DateToDaysDecl
);decls
.insert(DaysToDateDecl
);
4032 decls
.insert(DaysInMonthDecl
);decls
.insert(IsLeapYearDecl
);
4034 funs
.insert(GetYearFrac
);
4035 funs
.insert(DateToDays
);funs
.insert(DaysToDate
);
4036 funs
.insert(DaysInMonth
);funs
.insert(IsLeapYear
);
4039 void OpTbillprice::GenSlidingWindowFunction(
4040 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
4042 ss
<< "\ndouble " << sSymName
;
4043 ss
<< "_"<< BinFuncName() <<"(";
4044 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4048 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4051 ss
<< " int gid0 = get_global_id(0);\n";
4052 ss
<< " double tmp = 0;\n";
4054 ss
<< " int singleIndex = gid0;\n";
4055 ss
<< " int doubleIndex = gid0;\n";
4056 ss
<< " int i = gid0;\n";
4057 GenTmpVariables(ss
,vSubArguments
);
4058 CheckAllSubArgumentIsNan(ss
,vSubArguments
);
4060 ss
<< " tmp1+=1.0;\n";
4061 ss
<< " double fFraction =GetYearFrac(693594,tmp0,tmp1,0);\n";
4062 ss
<< " tmp = 100.0 * ( 1.0 - tmp2 * fFraction );\n";
4063 ss
<< " return tmp;\n";
4066 void RATE::BinInlineFun(std::set
<std::string
>& decls
,
4067 std::set
<std::string
>& funs
)
4069 decls
.insert(approxEqualDecl
);decls
.insert(nKorrValDecl
);
4070 decls
.insert(SCdEpsilonDecl
);decls
.insert(RoundDecl
);
4071 funs
.insert(approxEqual
);funs
.insert(Round
);
4074 void RATE::GenSlidingWindowFunction(
4075 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
4077 ss
<< "\ndouble " << sSymName
;
4078 ss
<< "_"<< BinFuncName() <<"(";
4079 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4083 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4086 FormulaToken
* pCur
= vSubArguments
[5]->GetFormulaToken();
4088 const formula::SingleVectorRefToken
* pSVR
=
4089 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
4092 ss
<< " double result;\n";
4093 ss
<< " int gid0 = get_global_id(0);\n";
4094 ss
<< " bool bValid = true, bFound = false;\n";
4095 ss
<< " double fX, fXnew, fTerm, fTermDerivation;\n";
4096 ss
<< " double fGeoSeries, fGeoSeriesDerivation;\n";
4097 ss
<< " int nIterationsMax = 150;\n";
4098 ss
<< " int nCount = 0;\n";
4099 ss
<< " double fEpsilonSmall = 1.0E-14;\n";
4100 ss
<< " double arg0, arg1, arg2, arg3, arg4, arg5;\n";
4101 ss
<< " arg0=" << vSubArguments
[0]->GenSlidingWindowDeclRef()<<";\n";
4102 ss
<< " arg1=" << vSubArguments
[1]->GenSlidingWindowDeclRef()<<";\n";
4103 ss
<< " arg2=" << vSubArguments
[2]->GenSlidingWindowDeclRef()<<";\n";
4104 ss
<< " arg3=" << vSubArguments
[3]->GenSlidingWindowDeclRef()<<";\n";
4105 ss
<< " arg4=" << vSubArguments
[4]->GenSlidingWindowDeclRef()<<";\n";
4106 ss
<< " arg5=" << vSubArguments
[5]->GenSlidingWindowDeclRef()<<";\n";
4107 ss
<< " int guessLen = " << pSVR
->GetArrayLength() << ";\n";
4108 ss
<< " if (isNan(arg0) || isNan(arg1) || isNan(arg2)){\n";
4109 ss
<< " result = 523;\n";
4110 ss
<< " return result;\n";
4112 ss
<< " if (isNan(arg3))\n";
4113 ss
<< " arg3 = 0.0;\n";
4114 ss
<< " if (isNan(arg4))\n";
4115 ss
<< " arg4 = 0.0;\n";
4116 ss
<< " if (isNan(arg5))\n";
4117 ss
<< " arg5 = 0.1;\n";
4118 ss
<< " if (gid0 >= guessLen)\n";
4119 ss
<< " arg5 = 0.1;\n";
4120 ss
<< " arg3 = arg3 - arg1 * arg4;\n";
4121 ss
<< " arg2 = arg2 + arg1 * arg4;\n";
4122 ss
<< " if (arg0 == Round(arg0)){\n";
4123 ss
<< " fX = arg5;\n";
4124 ss
<< " double fPowN, fPowNminus1;\n";
4125 ss
<< " while (!bFound && nCount < nIterationsMax)\n";
4127 ss
<< " fPowNminus1 = pow( 1.0+fX, arg0-1.0);\n";
4128 ss
<< " fPowN = fPowNminus1 * (1.0+fX);\n";
4129 ss
<< " if (approxEqual( fabs(fX), 0.0))\n";
4131 ss
<< " fGeoSeries = arg0;\n";
4132 ss
<< " fGeoSeriesDerivation = arg0 * (arg0-1.0)";
4133 ss
<< "*pow(2.0,-1);\n";
4137 ss
<< " fGeoSeries = (fPowN-1.0)*pow(fX,-1);\n";
4138 ss
<< " fGeoSeriesDerivation =";
4139 ss
<< " arg0 * fPowNminus1 * pow( fX , -1) - fGeoSeries * pow(fX, -1);\n";
4141 ss
<< " fTerm = arg3 + arg2 *fPowN+ arg1 * fGeoSeries;\n";
4142 ss
<< " fTermDerivation = arg2 * arg0 * fPowNminus1 +";
4143 ss
<< "arg1 * fGeoSeriesDerivation;\n";
4144 ss
<< " if (fabs(fTerm) < fEpsilonSmall)\n";
4145 ss
<< " bFound = true;\n";
4148 ss
<< " if (approxEqual(fabs(fTermDerivation), 0.0))\n";
4149 ss
<< " fXnew = fX + 1.1 * SCdEpsilon;\n";
4151 ss
<< " fXnew = fX - fTerm ";
4152 ss
<< "*pow( fTermDerivation,-1);\n";
4153 ss
<< " nCount++;\n";
4154 ss
<< " bFound = (fabs(fXnew - fX) < SCdEpsilon);\n";
4155 ss
<< " fX = fXnew;\n";
4161 ss
<< " fX = (arg5 < -1.0) ? -1.0 : arg5;\n";
4162 ss
<< " while (bValid && !bFound && nCount < nIterationsMax)\n";
4164 ss
<< " if (approxEqual(fabs(fX), 0.0)){\n";
4165 ss
<< " fGeoSeries = arg0;\n";
4166 ss
<< " fGeoSeriesDerivation = arg0 * ";
4167 ss
<< "(arg0-1.0)* pow(2.0,-1);\n";
4169 ss
<< " fGeoSeries = (pow( 1.0+fX, arg0) - 1.0)";
4170 ss
<< " *pow( fX,-1);\n";
4171 ss
<< " fGeoSeriesDerivation =";
4172 ss
<< " arg0 * pow(1.0+fX,arg0-1.0) *pow(fX,-1)";
4173 ss
<< " - fGeoSeries *pow( fX,-1);\n";
4175 ss
<< " fTerm = arg3 + arg2 *pow(1.0+fX, arg0)";
4176 ss
<< "+ arg1 * fGeoSeries;\n";
4177 ss
<< " fTermDerivation =";
4178 ss
<< "arg2*arg0*pow(1.0+fX,arg0-1.0)";
4179 ss
<< "+arg1*fGeoSeriesDerivation;\n";
4180 ss
<< " if (fabs(fTerm) < fEpsilonSmall)\n";
4181 ss
<< " bFound = true;\n";
4183 ss
<< " if (approxEqual(fabs(fTermDerivation), 0.0))\n";
4184 ss
<< " fXnew = fX + 1.1 * SCdEpsilon;\n";
4186 ss
<< " fXnew = fX - fTerm ";
4187 ss
<< "*pow( fTermDerivation,-1);\n";
4188 ss
<< " nCount++;\n";
4189 ss
<< " bFound = (fabs(fXnew - fX) < SCdEpsilon);\n";
4190 ss
<< " fX = fXnew;\n";
4191 ss
<< " bValid = (fX >= -1.0);\n";
4195 ss
<< " if (bValid && bFound)\n";
4196 ss
<< " result = fX;\n";
4198 ss
<< " result = 523;\n";
4199 ss
<< " return result;\n";
4203 void OpTbillyield::BinInlineFun(std::set
<std::string
>& decls
,
4204 std::set
<std::string
>& funs
)
4206 decls
.insert(GetDiffDate360Decl
);decls
.insert(IsLeapYearDecl
);
4207 decls
.insert(DateToDaysDecl
);decls
.insert(DaysToDate_LocalBarrierDecl
);
4208 decls
.insert(DaysInMonthDecl
);decls
.insert(GetNullDateDecl
);
4209 decls
.insert(GetDiffDate360_Decl
);
4210 funs
.insert(GetDiffDate360
);funs
.insert(DateToDays
);
4211 funs
.insert(DaysToDate_LocalBarrier
);funs
.insert(IsLeapYear
);
4212 funs
.insert(DaysInMonth
);funs
.insert(GetNullDate
);
4213 funs
.insert(GetDiffDate360_
);
4217 void OpTbillyield::GenSlidingWindowFunction(
4218 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
4220 ss
<< "\ndouble " << sSymName
;
4221 ss
<< "_"<< BinFuncName() <<"(";
4222 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4226 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4229 ss
<< "int gid0 = get_global_id(0);\n\t";
4230 ss
<< "double tmp = 0;\n\t";
4231 ss
<< "double tmp000;\n\t";
4232 ss
<< "double tmp001;\n\t";
4233 ss
<< "double tmp002;\n\t";
4235 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
4236 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
4237 formula::SingleVectorRefToken
*>(tmpCur0
);
4239 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
4240 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
4241 formula::SingleVectorRefToken
*>(tmpCur1
);
4243 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
4244 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
4245 formula::SingleVectorRefToken
*>(tmpCur2
);
4247 ss
<< "int buffer_tmp000_len = ";
4248 ss
<< tmpCurDVR0
->GetArrayLength();
4251 ss
<< "int buffer_tmp001_len = ";
4252 ss
<< tmpCurDVR1
->GetArrayLength();
4255 ss
<< "int buffer_tmp002_len = ";
4256 ss
<< tmpCurDVR2
->GetArrayLength();
4259 ss
<<"if(gid0>=buffer_tmp000_len || isNan(";
4260 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
4262 ss
<<"tmp000 = 0;\n\telse \n\t\t";
4264 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
4267 ss
<<"if(gid0>=buffer_tmp001_len || isNan(";
4268 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
4270 ss
<<"tmp001 = 0;\n\telse \n\t\t";
4272 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
4275 ss
<<"if(gid0>=buffer_tmp002_len || isNan(";
4276 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
4278 ss
<<"tmp002 = 0;\n\telse \n\t\t";
4280 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
4282 ss
<<" int nDiff=GetDiffDate360(GetNullDate(),tmp000,tmp001,true);\n";
4284 ss
<<" tmp=100.0;\n";
4285 ss
<<" tmp = tmp *pow( tmp002,-1);\n";
4286 ss
<<" tmp = tmp - 1.0;\n";
4287 ss
<<" tmp = tmp * pow( nDiff,-1.0 );\n";
4288 ss
<<" tmp = tmp * 360.0;\n";
4289 ss
<<" return tmp;\n";
4292 void OpDDB::GenSlidingWindowFunction(std::stringstream
& ss
,
4293 const std::string
&sSymName
, SubArguments
& vSubArguments
)
4295 ss
<< "\ndouble " << sSymName
;
4296 ss
<< "_"<< BinFuncName() <<"(";
4297 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4301 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4304 ss
<< " int gid0 = get_global_id(0);\n";
4305 ss
<< " double tmp = 0;\n";
4306 ss
<< " double fWert,fRest,fDauer,fPeriode,fFaktor;\n";
4307 ss
<< " double fZins, fAlterWert, fNeuerWert;\n";
4309 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
4310 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
4311 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
4312 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
4313 FormulaToken
* tmpCur4
= vSubArguments
[4]->GetFormulaToken();
4314 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
4316 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
4317 formula::SingleVectorRefToken
*>(tmpCur0
);
4318 ss
<<" if(gid0 >= "<<tmpCurDVR0
->GetArrayLength()<<" || isNan(";
4319 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
4321 ss
<<" fWert = 0;\n else\n";
4323 ss
<<" fWert = "<<vSubArguments
[0]->GenSlidingWindowDeclRef();
4325 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
4327 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
4328 formula::SingleVectorRefToken
*>(tmpCur1
);
4329 ss
<<" if(gid0 >= "<<tmpCurDVR1
->GetArrayLength()<<" || isNan(";
4330 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
4332 ss
<<" fRest = 0;\n else\n";
4335 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
4337 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
4339 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
4340 formula::SingleVectorRefToken
*>(tmpCur2
);
4341 ss
<<" if(gid0 >= "<<tmpCurDVR2
->GetArrayLength()<<" || isNan(";
4342 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
4344 ss
<<" fDauer = 0;\n else\n";
4347 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
4349 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
4351 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
4352 formula::SingleVectorRefToken
*>(tmpCur3
);
4353 ss
<<" if(gid0 >= "<<tmpCurDVR3
->GetArrayLength()<<" || isNan(";
4354 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
4356 ss
<<" fPeriode = 0;\n else\n";
4358 ss
<<" fPeriode = "<<vSubArguments
[3]->GenSlidingWindowDeclRef();
4360 if(tmpCur4
->GetType() == formula::svSingleVectorRef
)
4362 const formula::SingleVectorRefToken
*tmpCurDVR4
= static_cast<const
4363 formula::SingleVectorRefToken
*>(tmpCur4
);
4364 ss
<<" if(gid0 >= "<<tmpCurDVR4
->GetArrayLength()<<" || isNan(";
4365 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
4367 ss
<<" fFaktor = 0;\n else\n";
4369 ss
<<" fFaktor = "<<vSubArguments
[4]->GenSlidingWindowDeclRef();
4371 ss
<<" fZins = fFaktor * pow(fDauer,-1);\n";
4372 ss
<<" if (fZins >= 1.0)\n";
4374 ss
<<" fZins = 1.0;\n";
4375 ss
<<" if (fPeriode == 1.0)\n";
4376 ss
<<" fAlterWert = fWert;\n";
4378 ss
<<" fAlterWert = 0.0;\n";
4381 ss
<<" fAlterWert = fWert * pow(1.0 - fZins, fPeriode - 1);\n";
4382 ss
<<" fNeuerWert = fWert * pow(1.0 - fZins, fPeriode);\n";
4383 ss
<<" if (fNeuerWert < fRest)\n";
4384 ss
<<" tmp = fAlterWert - fRest;\n";
4386 ss
<<" tmp = fAlterWert - fNeuerWert;\n";
4387 ss
<<" if (tmp < 0.0)\n";
4388 ss
<<" tmp = 0.0;\n";
4389 ss
<<" return tmp;\n";
4392 void OpPV::GenSlidingWindowFunction(
4393 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&
4396 ss
<< "\ndouble " << sSymName
;
4397 ss
<< "_"<< BinFuncName() <<"(";
4398 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4402 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4405 ss
<< " double result = 0;\n";
4406 ss
<< " int gid0 = get_global_id(0);\n";
4407 ss
<< " double zins;\n";
4408 ss
<< " double zzr;\n";
4409 ss
<< " double rmz;\n";
4410 ss
<< " double zw;\n";
4411 ss
<< " double flag;\n";
4413 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
4414 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
4415 formula::SingleVectorRefToken
*>(tmpCur0
);
4417 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
4418 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
4419 formula::SingleVectorRefToken
*>(tmpCur1
);
4421 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
4422 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
4423 formula::SingleVectorRefToken
*>(tmpCur2
);
4425 if(vSubArguments
.size()>3)
4427 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
4428 const formula::SingleVectorRefToken
* tmpCurDVR3
= static_cast<const formula::SingleVectorRefToken
*>(
4430 ss
<< " int buffer_zw_len = ";
4431 ss
<< tmpCurDVR3
->GetArrayLength();
4435 if(vSubArguments
.size()>4)
4437 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
4438 const formula::SingleVectorRefToken
* tmpCurDVR4
= static_cast<const formula::SingleVectorRefToken
*>(
4440 ss
<< " int buffer_flag_len = ";
4441 ss
<< tmpCurDVR4
->GetArrayLength();
4445 ss
<< " int buffer_zins_len = ";
4446 ss
<< tmpCurDVR0
->GetArrayLength();
4449 ss
<< " int buffer_zzr_len = ";
4450 ss
<< tmpCurDVR1
->GetArrayLength();
4453 ss
<< " int buffer_rmz_len = ";
4454 ss
<< tmpCurDVR2
->GetArrayLength();
4457 ss
<<" if(gid0>=buffer_zins_len || isNan(";
4458 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
4460 ss
<<" zins = 0;\n else \n";
4462 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
4465 ss
<<" if(gid0>=buffer_zzr_len || isNan(";
4466 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
4468 ss
<<" zzr = 0;\n else \n";
4470 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
4473 ss
<<" if(gid0>=buffer_rmz_len || isNan(";
4474 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
4476 ss
<<" rmz = 0;\n else \n";
4478 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
4481 if(vSubArguments
.size()>3)
4483 ss
<<" if(gid0>=buffer_zw_len || isNan(";
4484 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
4486 ss
<<" zw = 0;\n else \n";
4488 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
4495 if(vSubArguments
.size()>4)
4497 ss
<<" if(gid0>=buffer_flag_len || isNan(";
4498 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
4500 ss
<<" flag = 0;\n else \n";
4502 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
4508 ss
<< " if(zins == 0)\n";
4509 ss
<< " result=zw+rmz*zzr;\n";
4510 ss
<< " else if(flag > 0)\n";
4511 ss
<< " result=(zw*pow(1+zins,-zzr))+";
4512 ss
<< "(rmz*(1-pow(1+zins,-zzr+1))*pow(zins,-1))+rmz;\n";
4514 ss
<< " result=(zw*pow(1+zins,-zzr))+";
4515 ss
<< "(rmz*(1-pow(1+zins,-zzr))*pow(zins,-1));\n";
4516 ss
<< " return -result;\n";
4519 void OpVDB::BinInlineFun(std::set
<std::string
>& decls
,
4520 std::set
<std::string
>& funs
)
4522 decls
.insert(ScGetGDADecl
);decls
.insert(DblMinDecl
);
4523 decls
.insert(ScInterVDBDecl
);decls
.insert(VDBImplementDecl
);
4524 funs
.insert(ScGetGDA
);funs
.insert(DblMin
);
4525 funs
.insert(ScInterVDB
);funs
.insert(VDBImplement
);
4528 void OpVDB::GenSlidingWindowFunction(
4529 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
4531 ss
<< "\ndouble " << sSymName
;
4532 ss
<< "_"<< BinFuncName() <<"(";
4533 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4537 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4540 ss
<< " int gid0 = get_global_id(0);\n";
4541 ss
<< " int singleIndex = gid0;\n";
4542 ss
<< " double result = 0;\n";
4543 if(vSubArguments
.size()<5)
4545 ss
<< " result = -DBL_MAX;\n";
4546 ss
<< " return result;\n";
4549 GenTmpVariables(ss
,vSubArguments
);
4550 CheckAllSubArgumentIsNan(ss
,vSubArguments
);
4551 if(vSubArguments
.size() <= 6)
4553 ss
<< " int tmp6 = 0;\n";
4555 if(vSubArguments
.size() == 5)
4557 ss
<< " double tmp5= 2.0;\n";
4559 ss
<< " if(tmp3 < 0 || tmp4<tmp3 || tmp4>tmp2 || tmp0<0 ||tmp1>tmp0";
4560 ss
<< "|| tmp5 <=0)\n";
4561 ss
<< " result = -DBL_MAX;\n";
4564 ss
<< "VDBImplement(tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);\n";
4565 ss
<< " return result;\n";
4571 void OpXirr::GenSlidingWindowFunction(std::stringstream
&ss
,
4572 const std::string
&sSymName
, SubArguments
&vSubArguments
)
4574 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
4575 const formula::DoubleVectorRefToken
*pCurDVR
= static_cast<const
4576 formula::DoubleVectorRefToken
*>(tmpCur
);
4577 size_t nCurWindowSize
= pCurDVR
->GetArrayLength() <
4578 pCurDVR
->GetRefRowSize() ? pCurDVR
->GetArrayLength():
4579 pCurDVR
->GetRefRowSize() ;
4580 ss
<< "\ndouble " << sSymName
;
4581 ss
<< "_"<< BinFuncName() <<"(";
4582 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4586 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4589 ss
<< " int gid0 = get_global_id(0);\n";
4590 ss
<< " int doubleIndex = gid0;\n";
4591 ss
<< " int singleIndex = gid0;\n";
4592 ss
<< " double result = 0;\n";
4593 ss
<< " int i=0;\n";
4594 if(vSubArguments
.size()<2)
4596 ss
<< " result = -DBL_MAX;\n";
4597 ss
<< " return result;\n";
4600 GenTmpVariables(ss
,vSubArguments
);
4601 if(vSubArguments
.size() == 2)
4603 ss
<< " double tmp2 = 0.1;\n";
4606 CheckSubArgumentIsNan(ss
,vSubArguments
,2);
4608 ss
<< " if(tmp2<=-1)\n";
4609 ss
<< " result = -DBL_MAX;\n";
4612 ss
<< " double fMaxEps = 1e-10;\n";
4613 ss
<< " int nMaxIter = 50;\n";
4614 ss
<< " double fNewRate, fRateEps, fResultValue, fResultValue2;\n";
4615 ss
<< " int nIter = 0;\n";
4616 ss
<< " int bContLoop;\n";
4617 ss
<< " int windowsSize = ";
4618 ss
<< nCurWindowSize
;
4620 CheckSubArgumentIsNan(ss
,vSubArguments
,0);
4621 CheckSubArgumentIsNan(ss
,vSubArguments
,1);
4622 ss
<< " double D_0 = tmp1;\n";
4623 ss
<< " double V_0 = tmp0;\n";
4624 ss
<< " double fResultRate = tmp2;\n";
4625 ss
<< " double r;\n";
4626 ss
<< " double fResult;\n";
4629 ss
<< " fResultValue = V_0;\n";
4630 ss
<< " r = fResultRate + 1;\n";
4632 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed()) {
4633 ss
<< "gid0+1; i < "<< nCurWindowSize
<<"; i++)\n";
4634 } else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed()) {
4635 ss
<< "1; i < gid0+"<< nCurWindowSize
<<"; i++)\n";
4637 ss
<< "1; i < "<< nCurWindowSize
<<"; i++)\n";
4640 if(!pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
4642 ss
<< " doubleIndex =i+gid0;\n";
4645 ss
<< " doubleIndex =i;\n";
4647 CheckSubArgumentIsNan(ss
,vSubArguments
,0);
4648 CheckSubArgumentIsNan(ss
,vSubArguments
,1);
4649 ss
<< " fResultValue += tmp0/pow(r,(tmp1 - D_0)/365.0);\n";
4651 ss
<< " fResultValue2 = 0;\n";
4654 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed()) {
4655 ss
<< "gid0+1; i < "<< nCurWindowSize
<<"; i++)\n";
4656 } else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed()) {
4657 ss
<< "1; i < gid0+"<< nCurWindowSize
<<"; i++)\n";
4659 ss
<< "1; i < "<< nCurWindowSize
<<"; i++)\n";
4662 if(!pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
4664 ss
<< " doubleIndex =i+gid0;\n";
4667 ss
<< " doubleIndex =i;\n";
4669 CheckSubArgumentIsNan(ss
,vSubArguments
,0);
4670 CheckSubArgumentIsNan(ss
,vSubArguments
,1);
4671 ss
<< " double E_i = (tmp1 - D_0)/365.0;\n";
4672 ss
<< " fResultValue2 -= E_i * tmp0 / pow(r,E_i + 1.0);\n";
4674 ss
<< " fNewRate = fResultRate - fResultValue / fResultValue2;\n";
4675 ss
<< " fRateEps = fabs( fNewRate - fResultRate );\n";
4676 ss
<< " fResultRate = fNewRate;\n";
4677 ss
<< " bContLoop = (fRateEps > fMaxEps) && (fabs( fResultValue ) > fMaxEps);\n";
4679 ss
<< " while( bContLoop && (++nIter < nMaxIter) );\n";
4680 ss
<< " if( bContLoop )\n";
4681 ss
<< " result = -DBL_MAX;\n";
4682 ss
<< " result = fResultRate;\n";
4684 ss
<< " return result;\n";
4689 void OpDB::GenSlidingWindowFunction(std::stringstream
& ss
,
4690 const std::string
&sSymName
, SubArguments
& vSubArguments
)
4692 ss
<< "\ndouble " << sSymName
;
4693 ss
<< "_"<< BinFuncName() <<"(";
4694 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4698 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4701 ss
<< " int gid0 = get_global_id(0);\n";
4702 ss
<< " double nWert,nRest,nDauer,nPeriode;\n";
4703 ss
<< " int nMonate;\n";
4704 ss
<< " double tmp = 0;\n";
4705 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
4706 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
4707 formula::SingleVectorRefToken
*>(tmpCur0
);
4708 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
4709 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
4710 formula::SingleVectorRefToken
*>(tmpCur1
);
4711 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
4712 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
4713 formula::SingleVectorRefToken
*>(tmpCur2
);
4714 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
4715 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
4716 formula::SingleVectorRefToken
*>(tmpCur3
);
4717 FormulaToken
* tmpCur4
= vSubArguments
[4]->GetFormulaToken();
4718 const formula::SingleVectorRefToken
*tmpCurDVR4
= static_cast<const
4719 formula::SingleVectorRefToken
*>(tmpCur4
);
4720 ss
<< " int buffer_wert_len = ";
4721 ss
<< tmpCurDVR0
->GetArrayLength();
4723 ss
<< " int buffer_rest_len = ";
4724 ss
<< tmpCurDVR1
->GetArrayLength();
4726 ss
<< " int buffer_dauer_len = ";
4727 ss
<< tmpCurDVR2
->GetArrayLength();
4729 ss
<< " int buffer_periode_len = ";
4730 ss
<< tmpCurDVR3
->GetArrayLength();
4732 ss
<< " int buffer_nMonate_len = ";
4733 ss
<< tmpCurDVR4
->GetArrayLength();
4735 ss
<<" if(gid0 >= buffer_wert_len || isNan(";
4736 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
4738 ss
<<" nWert = 0;\n else\n";
4739 ss
<<" nWert = "<<vSubArguments
[0]->GenSlidingWindowDeclRef();
4741 ss
<<" if(gid0 >= buffer_rest_len || isNan(";
4742 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
4744 ss
<<" nRest = 0;\n else\n";
4746 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
4748 ss
<<" if(gid0 >= buffer_dauer_len || isNan(";
4749 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
4751 ss
<<" nDauer = 0;\n else\n";
4752 ss
<<" nDauer = "<<vSubArguments
[2]->GenSlidingWindowDeclRef();
4754 ss
<<" if(gid0 >= buffer_periode_len || isNan(";
4755 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
4757 ss
<<" nPeriode = 0;\n else\n";
4758 ss
<<" nPeriode = "<<vSubArguments
[3]->GenSlidingWindowDeclRef();
4760 ss
<<" if(gid0 >= buffer_nMonate_len || isNan(";
4761 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
4763 ss
<<" nMonate = 0;\n else\n";
4764 ss
<<" nMonate = (int)"<<vSubArguments
[4]->GenSlidingWindowDeclRef();
4766 ss
<<" double nAbRate = 1.0 - pow(nRest / nWert, 1.0 / nDauer);\n";
4767 ss
<<" nAbRate = ((int)(nAbRate * 1000.0 + 0.5)) / 1000.0;\n";
4768 ss
<<" double nErsteAbRate = nWert * nAbRate * nMonate / 12.0;\n";
4769 ss
<<" double nGda2 = 0.0;\n";
4770 ss
<<" if ((int)(nPeriode) == 1)\n";
4771 ss
<<" nGda2 = nErsteAbRate;\n";
4774 ss
<<" double nSummAbRate = nErsteAbRate;\n";
4775 ss
<<" double nMin = nDauer;\n";
4776 ss
<<" if (nMin > nPeriode) nMin = nPeriode;\n";
4777 ss
<<" int iMax = (int)nMin;\n";
4778 ss
<<" for (int i = 2; i <= iMax; i++)\n";
4780 ss
<<" nGda2 = (nWert - nSummAbRate) * nAbRate;\n";
4781 ss
<<" nSummAbRate += nGda2;\n";
4783 ss
<<" if (nPeriode > nDauer)\n";
4784 ss
<<" nGda2 = ((nWert - nSummAbRate)";
4785 ss
<<"* nAbRate * (12.0 - nMonate)) / 12.0;\n";
4787 ss
<<" tmp = nGda2;\n";
4788 ss
<<" return tmp;\n";
4793 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */