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";
45 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
46 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
47 formula::SingleVectorRefToken
*>(tmpCur0
);
49 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
50 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
51 formula::SingleVectorRefToken
*>(tmpCur1
);
53 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
54 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
55 formula::SingleVectorRefToken
*>(tmpCur2
);
57 ss
<< " int buffer_nper_len = ";
58 ss
<< tmpCurDVR0
->GetArrayLength();
61 ss
<< " int buffer_pv_len = ";
62 ss
<< tmpCurDVR1
->GetArrayLength();
65 ss
<< " int buffer_fv_len = ";
66 ss
<< tmpCurDVR2
->GetArrayLength();
71 ss
<<" if(gid0>=buffer_nper_len || isNan(";
72 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
74 ss
<<" nper = 0;\n\telse \n";
77 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
81 ss
<<" if(gid0>=buffer_pv_len || isNan(";
82 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
84 ss
<<" pv = 0;\n\telse \n";
87 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
91 ss
<<" if(gid0>=buffer_pv_len || isNan(";
92 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
94 ss
<<" fv = 0;\n\telse \n";
97 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
99 ss
<< " tmp = pow(fv*pow(pv,-1),1.0*pow(nper,-1))-1;\n";
100 ss
<< " return tmp;\n";
104 void OpNominal::GenSlidingWindowFunction(
105 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&
108 ss
<< "\ndouble " << sSymName
;
109 ss
<< "_"<< BinFuncName() <<"(";
110 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
114 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
117 ss
<< "double tmp = 0;\n\t";
118 ss
<< "double temp = 0;\n\t";
119 ss
<< "int gid0 = get_global_id(0);\n\t";
120 ss
<< "double tmp0=0,tmp1=0;\n";
121 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
123 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
125 if (pCur
->GetType() == formula::svSingleVectorRef
)
128 const formula::SingleVectorRefToken
* pSVR
=
129 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
130 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
134 else if (pCur
->GetType() == formula::svDouble
)
146 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
148 ss
<<" temp="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
150 ss
<<" if (isNan(temp))\n";
151 ss
<<" tmp"<<i
<<"= 0;\n";
153 ss
<<" tmp"<<i
<<"=temp;\n";
158 ss
<<" tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef(
163 ss
<<" tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
167 ss
<<"if(tmp1==0)\n\t";
168 ss
<<"\treturn 0;\n\t";
169 ss
<<"tmp=pow( tmp1,-1);\n\t";
170 ss
<<"tmp=( pow( tmp0+ 1.0, tmp ) - 1.0 ) *";
172 ss
<< "return tmp;\n";
176 void OpDollarde::GenSlidingWindowFunction(
177 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
179 ss
<< "\ndouble " << sSymName
;
180 ss
<< "_"<< BinFuncName() <<"(";
181 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
185 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
188 ss
<< "double tmp = " << GetBottom() <<";\n\t";
189 ss
<< "int gid0 = get_global_id(0);\n\t";
190 ss
<< "double fInt = " << GetBottom() <<";\n\t";
191 ss
<< "double dollar;\n\t";
192 ss
<< "double fFrac;\n\t";
194 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
195 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
196 formula::SingleVectorRefToken
*>(tmpCur0
);
197 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
198 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
199 formula::SingleVectorRefToken
*>(tmpCur1
);
200 ss
<< "int buffer_dollar_len = ";
201 ss
<< tmpCurDVR0
->GetArrayLength();
203 ss
<< "int buffer_frac_len = ";
204 ss
<< tmpCurDVR1
->GetArrayLength();
208 ss
<<"if((gid0)>=buffer_dollar_len || isNan(";
209 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
211 ss
<<"dollar = 0;\n\telse \n\t\t";
214 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
217 ss
<<"if((gid0)>=buffer_frac_len || isNan(";
218 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
220 ss
<<"fFrac = 0;\n\telse \n\t\t";
223 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
225 ss
<< "tmp = modf( dollar , &fInt );\n\t";
226 ss
<< "tmp /= fFrac;\n\t";
227 ss
<< "tmp *= pow( 10.0 , ceil( log10(fFrac ) ) );\n\t";
228 ss
<< "tmp += fInt;\t";
229 ss
<< "\n\treturn tmp;\n";
233 void OpDollarfr::GenSlidingWindowFunction(std::stringstream
&ss
,
234 const std::string sSymName
, SubArguments
&vSubArguments
)
236 ss
<< "\ndouble " << sSymName
;
237 ss
<< "_"<< BinFuncName() <<"(";
238 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
242 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
245 ss
<< "double tmp = " << GetBottom() <<";\n\t";
246 ss
<< "int gid0 = get_global_id(0);\n\t";
247 ss
<< "double fInt = " << GetBottom() <<";\n\t";
248 ss
<< "double dollar;\n\t";
249 ss
<< "double fFrac;\n\t";
251 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
252 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
253 formula::SingleVectorRefToken
*>(tmpCur0
);
254 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
255 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
256 formula::SingleVectorRefToken
*>(tmpCur1
);
257 ss
<< "int buffer_dollar_len = ";
258 ss
<< tmpCurDVR0
->GetArrayLength();
260 ss
<< "int buffer_frac_len = ";
261 ss
<< tmpCurDVR1
->GetArrayLength();
265 ss
<<"if((gid0)>=buffer_dollar_len || isNan(";
266 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
268 ss
<<"dollar = 0;\n\telse \n\t\t";
271 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
274 ss
<<"if((gid0)>=buffer_frac_len || isNan(";
275 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
277 ss
<<"fFrac = 0;\n\telse \n\t\t";
280 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
282 ss
<< "tmp = modf( dollar , &fInt );\n\t";
283 ss
<< "tmp *= fFrac;\n\t";
284 ss
<< "tmp *= pow( 10.0 , -ceil( log10(fFrac ) ) );\n\t";
285 ss
<< "tmp += fInt;\t";
286 ss
<< "\n\treturn tmp;\n";
290 void OpDISC::BinInlineFun(std::set
<std::string
>& decls
,
291 std::set
<std::string
>& funs
)
293 decls
.insert(GetYearFrac_newDecl
);decls
.insert(DaysToDate_newDecl
);
294 decls
.insert(DaysInMonthDecl
);decls
.insert(IsLeapYearDecl
);
295 funs
.insert(GetYearFrac_new
);funs
.insert(DaysToDate_new
);
296 funs
.insert(DaysInMonth
);funs
.insert(IsLeapYear
);
299 void OpDISC::GenSlidingWindowFunction(std::stringstream
& ss
,
300 const std::string sSymName
, SubArguments
& vSubArguments
)
302 ss
<< "\ndouble " << sSymName
;
303 ss
<< "_" << BinFuncName() << "(";
304 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
308 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
311 ss
<< " double tmp = " << GetBottom() << ";\n";
312 ss
<< " int gid0 = get_global_id(0);\n";
313 ss
<< " double arg0 = " << GetBottom() << ";\n";
314 ss
<< " double arg1 = " << GetBottom() << ";\n";
315 ss
<< " double arg2 = " << GetBottom() << ";\n";
316 ss
<< " double arg3 = " << GetBottom() << ";\n";
317 ss
<< " double arg4 = " << GetBottom() << ";\n";
318 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
320 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
322 if (pCur
->GetType() == formula::svSingleVectorRef
)
325 const formula::SingleVectorRefToken
* pSVR
=
326 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
327 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
330 else if (pCur
->GetType() == formula::svDouble
)
337 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
340 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
342 ss
<< " arg" << i
<< " = 0;\n";
344 ss
<< " arg" << i
<< " = ";
345 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
350 ss
<< " arg" << i
<< " = ";
351 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
355 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
358 ss
<< " int nNullDate = 693594;\n";
359 ss
<< " tmp = 1.0 - arg2 / arg3;\n";
361 ss
<< " GetYearFrac_new(nNullDate, (int)arg0, (int)arg1, (int)arg4);\n";
362 ss
<< " return tmp;\n";
367 void OpINTRATE::BinInlineFun(std::set
<std::string
>& decls
,
368 std::set
<std::string
>& funs
)
370 decls
.insert(GetYearDiff_newDecl
);decls
.insert(GetDiffDate_newDecl
);
371 decls
.insert(DaysToDate_newDecl
);decls
.insert(GetNullDateDecl
);
372 decls
.insert(DateToDaysDecl
);decls
.insert(DaysInMonthDecl
);
373 decls
.insert(IsLeapYearDecl
);
374 funs
.insert(GetYearDiff_new
);funs
.insert(GetDiffDate_new
);
375 funs
.insert(DaysToDate_new
);funs
.insert(GetNullDate
);
376 funs
.insert(DateToDays
);funs
.insert(DaysInMonth
);
377 funs
.insert(IsLeapYear
);
380 void OpINTRATE::GenSlidingWindowFunction(std::stringstream
& ss
,
381 const std::string sSymName
, SubArguments
& vSubArguments
)
383 ss
<< "\ndouble " << sSymName
;
384 ss
<< "_" << BinFuncName() << "(";
385 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
389 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
392 ss
<< " double tmp = " << GetBottom() << ";\n";
393 ss
<< " int gid0 = get_global_id(0);\n";
394 ss
<< " double arg0 = " << GetBottom() << ";\n";
395 ss
<< " double arg1 = " << GetBottom() << ";\n";
396 ss
<< " double arg2 = " << GetBottom() << ";\n";
397 ss
<< " double arg3 = " << GetBottom() << ";\n";
398 ss
<< " double arg4 = " << GetBottom() << ";\n";
399 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
401 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
403 if (pCur
->GetType() == formula::svSingleVectorRef
)
406 const formula::SingleVectorRefToken
* pSVR
=
407 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
408 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
411 else if (pCur
->GetType() == formula::svDouble
)
418 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
421 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
423 ss
<< " arg" << i
<< " = 0;\n";
425 ss
<< " arg" << i
<< " = ";
426 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
431 ss
<< " arg" << i
<< " = ";
432 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
436 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
439 ss
<< " int nNullDate = GetNullDate();\n";
440 ss
<< " tmp = arg3 * pow(arg2,-1) - 1.0;\n";
441 ss
<< " tmp = tmp * pow(GetYearDiff_new(nNullDate, (int)arg0,";
442 ss
<< " (int)arg1,(int)arg4),-1);\n";
443 ss
<< " return tmp;\n";
447 void OpFV::BinInlineFun(std::set
<std::string
>& decls
,
448 std::set
<std::string
>& funs
)
450 decls
.insert(GetZwDecl
);
454 void OpFV::GenSlidingWindowFunction(std::stringstream
& ss
,
455 const std::string sSymName
, SubArguments
& vSubArguments
)
457 ss
<< "\ndouble " << sSymName
;
458 ss
<< "_"<< BinFuncName() <<"(";
459 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
463 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
466 ss
<< " double tmp = " << GetBottom() << ";\n";
467 ss
<< " int gid0 = get_global_id(0);\n";
468 ss
<< " double arg0 = " << GetBottom() << ";\n";
469 ss
<< " double arg1 = " << GetBottom() << ";\n";
470 ss
<< " double arg2 = " << GetBottom() << ";\n";
471 ss
<< " double arg3 = " << GetBottom() << ";\n";
472 ss
<< " double arg4 = " << GetBottom() << ";\n";
473 unsigned j
= vSubArguments
.size();
476 FormulaToken
* pCur
= vSubArguments
[j
]->GetFormulaToken();
478 if(pCur
->GetType() == formula::svSingleVectorRef
)
481 const formula::SingleVectorRefToken
* pSVR
=
482 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
483 ss
<< " if(gid0 >= " << pSVR
->GetArrayLength() << " || isNan(";
484 ss
<< vSubArguments
[j
]->GenSlidingWindowDeclRef();
486 ss
<< " arg" << j
<< " = " <<GetBottom() << ";\n";
489 ss
<< " arg" << j
<< " = ";
490 ss
<< vSubArguments
[j
]->GenSlidingWindowDeclRef();
494 ss
<< " tmp = GetZw(arg0, arg1, arg2, arg3, arg4);\n";
495 ss
<< " return tmp;\n";
499 void OpIPMT::BinInlineFun(std::set
<std::string
>& decls
,
500 std::set
<std::string
>& funs
)
502 decls
.insert(GetZwDecl
);
506 void OpIPMT::GenSlidingWindowFunction(std::stringstream
& ss
,
507 const std::string sSymName
, SubArguments
& vSubArguments
)
509 ss
<< "\ndouble " << sSymName
;
510 ss
<< "_"<< BinFuncName() <<"(";
511 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
515 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
518 ss
<< " double tmp = " << GetBottom() << ";\n";
519 ss
<< " int gid0 = get_global_id(0);\n";
520 ss
<< " double arg0 = " << GetBottom() << ";\n";
521 ss
<< " double arg1 = " << GetBottom() << ";\n";
522 ss
<< " double arg2 = " << GetBottom() << ";\n";
523 ss
<< " double arg3 = " << GetBottom() << ";\n";
524 ss
<< " double arg4 = " << GetBottom() << ";\n";
525 ss
<< " double arg5 = " << GetBottom() << ";\n";
526 unsigned j
= vSubArguments
.size();
529 FormulaToken
* pCur
= vSubArguments
[j
]->GetFormulaToken();
531 if(pCur
->GetType() == formula::svSingleVectorRef
)
534 const formula::SingleVectorRefToken
* pSVR
=
535 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
536 ss
<< " if(gid0 >= " << pSVR
->GetArrayLength() << " || isNan(";
537 ss
<< vSubArguments
[j
]->GenSlidingWindowDeclRef();
539 ss
<< " arg" << j
<< " = " <<GetBottom() << ";\n";
542 ss
<< " arg" << j
<< " = ";
543 ss
<< vSubArguments
[j
]->GenSlidingWindowDeclRef();
547 ss
<< " double pmt ;\n";
548 ss
<< " if(arg0 == 0.0)\n";
549 ss
<< " return 0;\n";
550 ss
<< " double temp1 = 0;\n";
551 ss
<< " double abl = pow(1.0 + arg0, arg2);\n";
552 ss
<< " temp1 -= arg4;\n";
553 ss
<< " temp1 -= arg3 * abl;\n";
554 ss
<< " pmt = temp1 / (1.0 + arg0 * arg5) /";
555 ss
<< " ( (abl - 1.0) / arg0);\n";
556 ss
<< " double temp = pow( 1 + arg0, arg1 - 2);\n";
557 ss
<< " if(arg1 == 1.0)\n";
559 ss
<< " if(arg5 > 0.0)\n";
560 ss
<< " tmp = 0.0;\n";
562 ss
<< " tmp = -arg3;\n";
566 ss
<< " if(arg5 > 0.0)\n";
567 ss
<< " tmp = GetZw(arg0, arg1 - 2.0, pmt, arg3, 1.0)";
570 ss
<< " tmp = GetZw(arg0, arg1 - 1.0, pmt, arg3, 0.0);\n";
572 ss
<< " tmp = tmp * arg0;\n";
573 ss
<< " return tmp;\n";
576 void OpISPMT::GenSlidingWindowFunction(std::stringstream
& ss
,
577 const std::string sSymName
, SubArguments
& vSubArguments
)
579 ss
<< "\ndouble " << sSymName
;
580 ss
<< "_" << BinFuncName() <<"(";
581 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
585 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
588 ss
<< " double tmp = " << GetBottom() << ";\n";
589 ss
<< " int gid0 = get_global_id(0);\n";
590 ss
<< " double arg0 = " << GetBottom() << ";\n";
591 ss
<< " double arg1 = " << GetBottom() << ";\n";
592 ss
<< " double arg2 = " << GetBottom() << ";\n";
593 ss
<< " double arg3 = " << GetBottom() << ";\n";
594 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
596 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
598 if (pCur
->GetType() == formula::svSingleVectorRef
)
601 const formula::SingleVectorRefToken
* pSVR
=
602 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
603 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
606 else if (pCur
->GetType() == formula::svDouble
)
613 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
616 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
618 ss
<< " arg" << i
<< " = 0;\n";
620 ss
<< " arg" << i
<< " = ";
621 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
626 ss
<< " arg" << i
<< " = ";
627 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
631 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
634 ss
<< " tmp = arg3 * arg0 * ( arg1 - arg2) * pow(arg2, -1);\n";
635 ss
<< " return tmp;\n";
639 void OpDuration::GenSlidingWindowFunction(std::stringstream
& ss
,
640 const std::string sSymName
, SubArguments
& vSubArguments
)
642 ss
<< "\ndouble " << sSymName
;
643 ss
<< "_" << BinFuncName() <<"(";
644 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
648 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
651 ss
<< " double tmp = " << GetBottom() << ";\n";
652 ss
<< " int gid0 = get_global_id(0);\n";
653 ss
<< " double arg0 = " << GetBottom() << ";\n";
654 ss
<< " double arg1 = " << GetBottom() << ";\n";
655 ss
<< " double arg2 = " << GetBottom() << ";\n";
656 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
658 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
660 if (pCur
->GetType() == formula::svSingleVectorRef
)
663 const formula::SingleVectorRefToken
* pSVR
=
664 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
665 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
668 else if (pCur
->GetType() == formula::svDouble
)
675 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
678 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
680 ss
<< " arg" << i
<< " = 0;\n";
682 ss
<< " arg" << i
<< " = ";
683 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
688 ss
<< " arg" << i
<< " = ";
689 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
693 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
696 ss
<< " tmp = log(arg2 * pow( arg1,-1)) / log(arg0 + 1.0);\n";
697 ss
<< " return tmp;\n";
701 void OpDuration_ADD::BinInlineFun(std::set
<std::string
>& decls
,
702 std::set
<std::string
>& funs
)
704 decls
.insert(GetDurationDecl
);decls
.insert(lcl_GetcoupnumDecl
);
705 decls
.insert(GetYearFracDecl
);decls
.insert(DaysToDateDecl
);
706 decls
.insert(GetNullDateDecl
);decls
.insert(DateToDaysDecl
);
707 decls
.insert(DaysInMonthDecl
);decls
.insert(IsLeapYearDecl
);
708 funs
.insert(GetDuration
);funs
.insert(lcl_Getcoupnum
);
709 funs
.insert(GetYearFrac
);funs
.insert(DaysToDate
);
710 funs
.insert(GetNullDate
);funs
.insert(DateToDays
);
711 funs
.insert(DaysInMonth
);funs
.insert(IsLeapYear
);
714 void OpDuration_ADD::GenSlidingWindowFunction(std::stringstream
& ss
,
715 const std::string sSymName
, SubArguments
& vSubArguments
)
717 ss
<< "\ndouble " << sSymName
;
718 ss
<< "_"<< BinFuncName() <<"(";
719 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
723 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
726 ss
<< " double tmp = " << GetBottom() << ";\n";
727 ss
<< " int gid0 = get_global_id(0);\n";
728 ss
<< " double arg0 = " << GetBottom() << ";\n";
729 ss
<< " double arg1 = " << GetBottom() << ";\n";
730 ss
<< " double arg2 = " << GetBottom() << ";\n";
731 ss
<< " double arg3 = " << GetBottom() << ";\n";
732 ss
<< " double arg4 = " << GetBottom() << ";\n";
733 ss
<< " double arg5 = " << GetBottom() << ";\n";
734 unsigned j
= vSubArguments
.size();
737 FormulaToken
* pCur
= vSubArguments
[j
]->GetFormulaToken();
739 if(pCur
->GetType() == formula::svSingleVectorRef
)
742 const formula::SingleVectorRefToken
* pSVR
=
743 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
744 ss
<< " if(gid0 >= " << pSVR
->GetArrayLength() << " || isNan(";
745 ss
<< vSubArguments
[j
]->GenSlidingWindowDeclRef();
747 ss
<< " arg" << j
<< " = " <<GetBottom() << ";\n";
750 ss
<< " arg" << j
<< " = ";
751 ss
<< vSubArguments
[j
]->GenSlidingWindowDeclRef();
755 ss
<< " int nNullDate = GetNullDate();\n";
756 ss
<< " tmp = GetDuration( nNullDate, (int)arg0, (int)arg1, arg2,";
757 ss
<< " arg3, (int)arg4, (int)arg5);\n";
758 ss
<< " return tmp;\n";
761 void OpMDuration::BinInlineFun(std::set
<std::string
>& decls
,
762 std::set
<std::string
>& funs
)
764 decls
.insert(GetDuration_newDecl
);decls
.insert(lcl_Getcoupnum_newDecl
);
765 decls
.insert(addMonthsDecl
);decls
.insert(checklessthanDecl
);
766 decls
.insert(setDayDecl
);decls
.insert(ScaDateDecl
);
767 decls
.insert(GetYearFracDecl
);decls
.insert(DaysToDateDecl
);
768 decls
.insert(DaysInMonthDecl
);decls
.insert(IsLeapYearDecl
);
769 funs
.insert(GetDuration_new
);funs
.insert(lcl_Getcoupnum_new
);
770 funs
.insert(addMonths
);funs
.insert(checklessthan
);
771 funs
.insert(setDay
);funs
.insert(ScaDate
);
772 funs
.insert(GetYearFrac
);funs
.insert(DaysToDate
);
773 funs
.insert(DaysInMonth
);funs
.insert(IsLeapYear
);
776 void OpMDuration::GenSlidingWindowFunction(std::stringstream
& ss
,
777 const std::string sSymName
, SubArguments
& vSubArguments
)
779 ss
<< "\ndouble " << sSymName
;
780 ss
<< "_"<< BinFuncName() <<"(";
781 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
785 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
788 ss
<< " double tmp = " << GetBottom() << ";\n";
789 ss
<< " int gid0 = get_global_id(0);\n";
790 ss
<< " double arg0 = " << GetBottom() << ";\n";
791 ss
<< " double arg1 = " << GetBottom() << ";\n";
792 ss
<< " double arg2 = " << GetBottom() << ";\n";
793 ss
<< " double arg3 = " << GetBottom() << ";\n";
794 ss
<< " double arg4 = " << GetBottom() << ";\n";
795 ss
<< " double arg5 = " << GetBottom() << ";\n";
796 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
798 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
800 if (pCur
->GetType() == formula::svSingleVectorRef
)
803 const formula::SingleVectorRefToken
* pSVR
=
804 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
805 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
808 else if (pCur
->GetType() == formula::svDouble
)
815 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
818 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
820 ss
<< " arg" << i
<< " = 0;\n";
822 ss
<< " arg" << i
<< " = ";
823 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
828 ss
<< " arg" << i
<< " = ";
829 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
833 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
836 ss
<< " int nNullDate = 693594;\n";
837 ss
<< " tmp = GetDuration_new( nNullDate, (int)arg0, (int)arg1, arg2,";
838 ss
<< " arg3, (int)arg4, (int)arg5);\n";
839 ss
<< " tmp = tmp * pow(1.0 + arg3 * pow((int)arg4, -1.0), -1);\n";
840 ss
<< " return tmp;\n";
843 void Fvschedule::GenSlidingWindowFunction(
844 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
846 FormulaToken
* pCur
= vSubArguments
[1]->GetFormulaToken();
848 const formula::DoubleVectorRefToken
* pCurDVR
=
849 dynamic_cast<const formula::DoubleVectorRefToken
*>(pCur
);
850 size_t nCurWindowSize
= pCurDVR
->GetRefRowSize();
851 ss
<< "\ndouble " << sSymName
;
852 ss
<< "_"<< BinFuncName() <<"(";
853 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
857 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
860 ss
<< "double tmp = 1.0;\n\t";
861 ss
<< "int gid0 = get_global_id(0);\n\t";
862 ss
<< "double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
865 ss
<< "if (isNan(arg0))\n\t\t";
866 ss
<< "arg0 = 0;\n\t";
868 ss
<< "double arg1;\n\t";
869 ss
<< "int arrayLength = " << pCurDVR
->GetArrayLength() << ";\n\t";
871 ss
<< "for (int i = 0; i + gid0 < arrayLength &&";
872 ss
<< " i < " << nCurWindowSize
<< "; i++){\n\t\t";
874 ss
<< "for (int i = 0; i < " << nCurWindowSize
<< "; i++){\n\t\t";
877 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n\t\t\t";
879 ss
<< "if (isNan(arg1))\n\t\t\t\t";
880 ss
<< "arg1 = 0;\n\t\t\t";
882 ss
<< "tmp *= arg1 + 1.0;\n\t\t";
884 ss
<< "return (double)tmp * arg0";
887 void Cumipmt::BinInlineFun(std::set
<std::string
>& decls
,
888 std::set
<std::string
>& funs
)
890 decls
.insert(GetRmz_newDecl
); decls
.insert(GetZw_newDecl
);
891 funs
.insert(GetRmz_new
);funs
.insert(GetZw_new
);
893 void Cumipmt::GenSlidingWindowFunction(
894 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&
897 ss
<< "\ndouble " << sSymName
;
898 ss
<< "_"<< BinFuncName() <<"(";
899 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
903 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
906 ss
<< " int gid0 = get_global_id(0);\n";
907 ss
<< " double fRate,fVal;\n";
908 ss
<< " int nStartPer,nEndPer,nNumPeriods,nPayType;\n";
910 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
911 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
912 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
913 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
914 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
915 FormulaToken
*tmpCur5
= vSubArguments
[5]->GetFormulaToken();
918 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
920 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
921 formula::SingleVectorRefToken
*>(tmpCur0
);
922 ss
<<" if(gid0 >= "<<tmpCurDVR0
->GetArrayLength()<<" || isNan(";
923 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
925 ss
<<" fRate = 0;\n else\n";
928 ss
<<" fRate = "<<vSubArguments
[0]->GenSlidingWindowDeclRef();
931 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
933 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
934 formula::SingleVectorRefToken
*>(tmpCur1
);
935 ss
<<" if(gid0 >= "<<tmpCurDVR1
->GetArrayLength()<<" || isNan(";
936 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
938 ss
<<" nNumPeriods = 0;\n else\n";
941 ss
<<" nNumPeriods = (int)";
942 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
945 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
947 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
948 formula::SingleVectorRefToken
*>(tmpCur2
);
949 ss
<<" if(gid0 >= "<<tmpCurDVR2
->GetArrayLength()<<" || isNan(";
950 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
952 ss
<<" fVal = 0;\n else\n";
955 ss
<<" fVal = "<<vSubArguments
[2]->GenSlidingWindowDeclRef();
958 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
960 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
961 formula::SingleVectorRefToken
*>(tmpCur3
);
962 ss
<<" if(gid0 >= "<<tmpCurDVR3
->GetArrayLength()<<" || isNan(";
963 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
965 ss
<<" nStartPer = 0;\n else\n";
968 ss
<<" nStartPer = (int)";
969 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
972 if(tmpCur4
->GetType() == formula::svSingleVectorRef
)
974 const formula::SingleVectorRefToken
*tmpCurDVR4
= dynamic_cast<const
975 formula::SingleVectorRefToken
*>(tmpCur4
);
976 ss
<<" if(gid0 >= "<<tmpCurDVR4
->GetArrayLength()<<" || isNan(";
977 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
979 ss
<<" nEndPer = 0;\n else\n";
982 ss
<<" nEndPer = (int)";
983 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
987 if(tmpCur5
->GetType() == formula::svSingleVectorRef
)
989 const formula::SingleVectorRefToken
*tmpCurDVR5
= dynamic_cast<const
990 formula::SingleVectorRefToken
*>(tmpCur5
);
991 ss
<<" if(gid0 >= "<<tmpCurDVR5
->GetArrayLength()<<" || isNan(";
992 ss
<<vSubArguments
[5]->GenSlidingWindowDeclRef();
994 ss
<<" nPayType = 0;\n else\n";
997 ss
<<" nPayType = (int)"<<vSubArguments
[5]->GenSlidingWindowDeclRef();
999 ss
<<" double fRmz;\n";
1000 ss
<<" fRmz = GetRmz_new( fRate, nNumPeriods, fVal, 0.0, nPayType );\n";
1001 ss
<<" double tmp = 0.0;\n";
1002 ss
<<" if( nStartPer == 1 )\n";
1004 ss
<<" if( nPayType <= 0 )\n";
1005 ss
<<" tmp = -fVal;\n";
1006 ss
<<" nStartPer++;\n";
1008 ss
<<" for( ; nStartPer<= nEndPer ; nStartPer++ )\n";
1010 ss
<<" if( nPayType > 0 )\n";
1011 ss
<<" tmp += GetZw_new( fRate, nStartPer - 2 , ";
1012 ss
<<"fRmz, fVal, 1 ) - fRmz;\n";
1014 ss
<<" tmp += GetZw_new( fRate, nStartPer - 1 , ";
1015 ss
<<"fRmz, fVal, 0 );\n";
1017 ss
<<" tmp *= fRate;\n";
1018 ss
<<" return tmp;\n";
1022 void IRR::GenSlidingWindowFunction(std::stringstream
&ss
,
1023 const std::string sSymName
, SubArguments
&vSubArguments
)
1025 ss
<< "\ndouble " << sSymName
;
1026 ss
<< "_" << BinFuncName() << "(";
1027 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1031 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1034 ss
<< " #define Epsilon 1.0E-7\n";
1035 ss
<< " int gid0 = get_global_id(0);\n";
1036 FormulaToken
* pSur
= vSubArguments
[1]->GetFormulaToken();
1038 ss
<< " double fSchaetzwert = ";
1039 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
1040 ss
<< " double fEps = 1.0;\n";
1041 ss
<< " double x = 0.0, xNeu = 0.0, fZaehler = 0.0, fNenner = 0.0;\n";
1042 ss
<< " double nCount = 0.0;\n";
1043 if (pSur
->GetType() == formula::svSingleVectorRef
)
1046 const formula::SingleVectorRefToken
* pSVR
=
1047 dynamic_cast< const formula::SingleVectorRefToken
* >(pSur
);
1048 ss
<< " if (gid0 >= " << pSVR
->GetArrayLength() << ")\n";
1049 ss
<< " fSchaetzwert = 0.1;\n";
1050 ss
<< " if (isNan(fSchaetzwert))\n";
1051 ss
<< " x = 0.1;\n";
1055 else if (pSur
->GetType() == formula::svDouble
)
1058 ss
<< " if (isNan(fSchaetzwert))\n";
1059 ss
<< " x = 0.1;\n";
1063 ss
<< " x = fSchaetzwert;\n";
1064 ss
<< " unsigned short nItCount = 0;\n";
1065 ss
<< " while (fEps > Epsilon && nItCount < 20){\n";
1066 ss
<< " nCount = 0.0; fZaehler = 0.0; fNenner = 0.0;\n";
1067 ss
<< " double arg0, arg1;\n";
1068 ss
<< " int i = 0;\n";
1069 FormulaToken
* pCur
= vSubArguments
[0]->GetFormulaToken();
1071 const formula::DoubleVectorRefToken
* pDVR
=
1072 dynamic_cast<const formula::DoubleVectorRefToken
* >(pCur
);
1073 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
1075 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
1077 ss
<< "i = gid0; i < " << pDVR
->GetArrayLength();
1078 ss
<< " && i < " << nCurWindowSize
<< " /2*2; i++){\n";
1080 ss
<< "i = gid0; i < " << nCurWindowSize
<< " /2*2; i++)\n";
1083 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1084 ss
<< " i++;" << ";\n";
1086 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1088 ss
<< " if (!isNan(arg0)){\n";
1090 ss
<< " fZaehler += arg0 / pow(1.0 + x, nCount);\n";
1091 ss
<< " fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
1092 ss
<< " nCount += 1;\n";
1095 ss
<< " if (!isNan(arg1)){\n";
1097 ss
<< " fZaehler += arg1 / pow(1.0 + x, nCount);\n";
1098 ss
<< " fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
1099 ss
<< " nCount += 1;\n";
1103 ss
<< "if(i < " << pDVR
->GetArrayLength();
1104 ss
<< " && i < " << nCurWindowSize
<< ") ;{\n";
1106 ss
<< " i < " << nCurWindowSize
<< "){\n";
1109 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
1111 ss
<< "; i < " << pDVR
->GetArrayLength();
1112 ss
<< " && i < (gid0+" << nCurWindowSize
<< " )/2*2; i++){\n";
1114 ss
<< "; i < gid0+" << nCurWindowSize
<< " /2*2; i++)\n";
1117 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1119 ss
<< " if (!isNan(arg0)){\n";
1121 ss
<< " fZaehler += arg0 / pow(1.0 + x, nCount);\n";
1122 ss
<< " fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
1123 ss
<< " nCount += 1;\n";
1129 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1131 ss
<< " if (!isNan(arg1)){\n";
1133 ss
<< " fZaehler += arg1 / pow(1.0 + x, nCount);\n";
1134 ss
<< " fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
1135 ss
<< " nCount+=1;\n";
1139 ss
<< " if(i < " << pDVR
->GetArrayLength();
1140 ss
<< " && i < gid0+" << nCurWindowSize
<< "){\n";
1142 ss
<< " i < " << nCurWindowSize
<< "){\n";
1145 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
1147 ss
<< " ; i + gid0 < " << pDVR
->GetArrayLength();
1148 ss
<< " && i < " << nCurWindowSize
<< " /2*2; i++){\n";
1150 ss
<< "; i < " << nCurWindowSize
<< " /2*2; i++)\n";
1153 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1154 ss
<< " i++;" << ";\n";
1156 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1158 ss
<< " if (!isNan(arg0)){\n";
1160 ss
<< " fZaehler += arg0 / pow(1.0 + x, nCount);\n";
1161 ss
<< " fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
1162 ss
<< " nCount += 1;\n";
1165 ss
<< " if (!isNan(arg1)){\n";
1167 ss
<< " fZaehler += arg1 / pow(1.0 + x, nCount);\n";
1168 ss
<< " fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
1169 ss
<< " nCount+=1;\n";
1173 ss
<< " if(i + gid0 < " << pDVR
->GetArrayLength() << " &&";
1174 ss
<< " i < " << nCurWindowSize
<< "){\n";
1176 ss
<< " i < " << nCurWindowSize
<< "){\n";
1181 ss
<< "; i < " << nCurWindowSize
<< " /2*2; i++){\n";
1183 ss
<< "; i < " << nCurWindowSize
<< " /2*2; i++)\n";
1186 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1187 ss
<< " i++;" << ";\n";
1189 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1191 ss
<< " if (!isNan(arg0)){\n";
1193 ss
<< " fZaehler += arg0 / pow(1.0 + x, nCount);\n";
1194 ss
<< " fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
1195 ss
<< " nCount += 1;\n";
1198 ss
<< " if (!isNan(arg1)){\n";
1200 ss
<< " fZaehler += arg1 / pow(1.0 + x, nCount);\n";
1201 ss
<< " fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
1202 ss
<< " nCount+=1;\n";
1206 ss
<< "if(i<" << nCurWindowSize
<< "){\n";
1208 ss
<< " i < " << nCurWindowSize
<< "){\n";
1213 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1215 ss
<< " if (isNan(arg0))\n";
1216 ss
<< " continue;\n";
1218 ss
<< " fZaehler += arg0 / pow(1.0+x, nCount);\n";
1219 ss
<< " fNenner += -nCount * arg0 / pow(1.0+x,nCount+1.0);\n";
1220 ss
<< " nCount+=1;\n";
1222 ss
<< " xNeu = x - fZaehler / fNenner;\n";
1223 ss
<< " fEps = fabs(xNeu - x);\n";
1224 ss
<< " x = xNeu;\n";
1225 ss
<< " nItCount++;\n }\n";
1226 ss
<< " if (fSchaetzwert == 0.0 && fabs(x) < Epsilon)\n";
1227 ss
<< " x = 0.0;\n";
1228 ss
<< " if (fEps < Epsilon)\n";
1229 ss
<< " return x;\n";
1231 ss
<< " return (double)523;\n";
1235 void XNPV::GenSlidingWindowFunction(
1236 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
1238 FormulaToken
*pCur
= vSubArguments
[1]->GetFormulaToken();
1240 const formula::DoubleVectorRefToken
* pCurDVR
=
1241 dynamic_cast<const formula::DoubleVectorRefToken
*>(pCur
);
1242 size_t nCurWindowSize
= pCurDVR
->GetRefRowSize();
1243 ss
<< "\ndouble " << sSymName
;
1244 ss
<< "_"<< BinFuncName() <<"( ";
1245 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1249 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1253 ss
<< "double result = 0.0;\n\t";
1254 ss
<< "int gid0 = get_global_id(0);\n\t";
1255 ss
<< "int i=0;\n\t";
1256 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed()) {
1259 ss
<< "double date;\n\t";
1260 ss
<< "double value;\n\t";
1261 ss
<< "double rate;\n\t";
1262 ss
<< "double dateNull;\n\t";
1264 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1265 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
1266 formula::SingleVectorRefToken
*>(tmpCur0
);
1268 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
1269 const formula::DoubleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
1270 formula::DoubleVectorRefToken
*>(tmpCur1
);
1272 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1273 const formula::DoubleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
1274 formula::DoubleVectorRefToken
*>(tmpCur2
);
1275 ss
<< "int buffer_rate_len = ";
1276 ss
<< tmpCurDVR0
->GetArrayLength();
1278 ss
<< "int buffer_value_len = ";
1279 ss
<< tmpCurDVR1
->GetArrayLength();
1281 ss
<< "int buffer_date_len = ";
1282 ss
<< tmpCurDVR2
->GetArrayLength();
1286 ss
<<"if((i+gid0)>=buffer_date_len || isNan(";
1287 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1289 ss
<<"dateNull = 0;\n\telse \n\t\t";
1292 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1295 ss
<<"if((i+gid0)>=buffer_rate_len || isNan(";
1296 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1298 ss
<<"rate = 0;\n\telse \n\t\t";
1301 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1303 ss
<< "for (int i = ";
1304 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed())
1306 ss
<< "gid0; i < "<< nCurWindowSize
<<"; i++)\n\t\t";
1308 else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
1310 ss
<< "0; i < gid0+"<< nCurWindowSize
<<"; i++)\n\t\t";
1314 ss
<< "0; i < "<< nCurWindowSize
<<"; i++)\n\t\t";
1318 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1320 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
1322 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1323 ss
<< "-dateNull)/365));\n\t";
1326 ss
<< "return result;\n";
1330 void PriceMat::BinInlineFun(std::set
<std::string
>& decls
,
1331 std::set
<std::string
>& funs
)
1333 decls
.insert(GetYearFracDecl
);decls
.insert(GetNullDateDecl
);
1334 decls
.insert(DateToDaysDecl
);decls
.insert(DaysToDateDecl
);
1335 decls
.insert(DaysInMonthDecl
);decls
.insert(IsLeapYearDecl
);
1337 funs
.insert(GetYearFrac
);funs
.insert(GetNullDate
);
1338 funs
.insert(DateToDays
);funs
.insert(DaysToDate
);
1339 funs
.insert(DaysInMonth
);funs
.insert(IsLeapYear
);
1341 void PriceMat::GenSlidingWindowFunction(
1342 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
1344 ss
<< "\ndouble " << sSymName
;
1345 ss
<< "_"<< BinFuncName() <<"(";
1346 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1350 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1353 ss
<< "int gid0 = get_global_id(0);\n\t";
1354 ss
<< "double result=0;\n\t";
1355 ss
<< "int nNullDate = GetNullDate( );\n\t";
1356 ss
<<"int settle;\n\t";
1357 ss
<<"int mat;\n\t";
1358 ss
<<"int issue;\n\t";
1359 ss
<<"double rate;\n\t";
1360 ss
<<"double yield;\n\t";
1361 ss
<<"int nBase;\n\t";
1363 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1364 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
1365 formula::SingleVectorRefToken
*>(tmpCur0
);
1366 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
1367 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
1368 formula::SingleVectorRefToken
*>(tmpCur1
);
1369 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1370 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
1371 formula::SingleVectorRefToken
*>(tmpCur2
);
1372 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
1373 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
1374 formula::SingleVectorRefToken
*>(tmpCur3
);
1375 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
1376 const formula::SingleVectorRefToken
*tmpCurDVR4
= dynamic_cast<const
1377 formula::SingleVectorRefToken
*>(tmpCur4
);
1378 FormulaToken
*tmpCur5
= vSubArguments
[5]->GetFormulaToken();
1379 const formula::SingleVectorRefToken
*tmpCurDVR5
= dynamic_cast<const
1380 formula::SingleVectorRefToken
*>(tmpCur5
);
1382 ss
<< "int buffer_settle_len = ";
1383 ss
<< tmpCurDVR0
->GetArrayLength();
1385 ss
<< "int buffer_mat_len = ";
1386 ss
<< tmpCurDVR1
->GetArrayLength();
1388 ss
<< "int buffer_issue_len = ";
1389 ss
<< tmpCurDVR2
->GetArrayLength();
1391 ss
<< "int buffer_rate_len = ";
1392 ss
<< tmpCurDVR3
->GetArrayLength();
1394 ss
<< "int buffer_yield_len = ";
1395 ss
<< tmpCurDVR4
->GetArrayLength();
1397 ss
<< "int buffer_base_len = ";
1398 ss
<< tmpCurDVR5
->GetArrayLength();
1402 ss
<<"if(gid0>=buffer_settle_len || isNan(";
1403 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1405 ss
<<"settle = 0;\n\telse \n\t\t";
1408 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1411 ss
<<"if(gid0>=buffer_mat_len || isNan(";
1412 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1414 ss
<<"mat = 0;\n\telse \n\t\t";
1417 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1420 ss
<<"if(gid0>=buffer_issue_len || isNan(";
1421 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1423 ss
<<"issue = 0;\n\telse \n\t\t";
1426 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1429 ss
<<"if(gid0>=buffer_rate_len || isNan(";
1430 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
1432 ss
<<"rate = 0;\n\telse \n\t\t";
1435 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
1438 ss
<<"if(gid0>=buffer_yield_len || isNan(";
1439 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
1441 ss
<<"yield = 0;\n\telse \n\t\t";
1444 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
1447 ss
<<"if(gid0>=buffer_base_len || isNan(";
1448 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
1450 ss
<<"nBase = 0;\n\telse \n\t\t";
1453 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
1455 ss
<< "double fIssMat = GetYearFrac( nNullDate, issue, mat, nBase);\n";
1456 ss
<<"double fIssSet = GetYearFrac( nNullDate, issue, settle,nBase);\n";
1457 ss
<<"double fSetMat = GetYearFrac( nNullDate, settle, mat, nBase);\n";
1458 ss
<<"result = 1.0 + fIssMat * rate;\n\t";
1459 ss
<<"result /= 1.0 + fSetMat * yield;\n\t";
1460 ss
<<"result -= fIssSet * rate;\n\t";
1461 ss
<<"result*= 100.0;\n\t";
1462 ss
<<"return result;\n\t";
1466 void OpSYD::GenSlidingWindowFunction(std::stringstream
&ss
,
1467 const std::string sSymName
, SubArguments
&vSubArguments
)
1469 ss
<< "\ndouble " << sSymName
;
1470 ss
<< "_"<< BinFuncName() <<"(";
1471 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1475 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1478 ss
<< " int gid0 = get_global_id(0);\n";
1479 ss
<< " double result=0;\n";
1480 ss
<< " double cost;\n";
1481 ss
<< " double salvage;\n";
1482 ss
<< " double life;\n";
1483 ss
<< " double period;\n";
1485 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1486 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
1487 formula::SingleVectorRefToken
*>(tmpCur0
);
1489 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
1490 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
1491 formula::SingleVectorRefToken
*>(tmpCur1
);
1493 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1494 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
1495 formula::SingleVectorRefToken
*>(tmpCur2
);
1497 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
1498 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
1499 formula::SingleVectorRefToken
*>(tmpCur3
);
1501 ss
<< " int buffer_cost_len = ";
1502 ss
<< tmpCurDVR0
->GetArrayLength();
1505 ss
<< " int buffer_salvage_len = ";
1506 ss
<< tmpCurDVR1
->GetArrayLength();
1509 ss
<< " int buffer_life_len = ";
1510 ss
<< tmpCurDVR2
->GetArrayLength();
1512 ss
<< " int buffer_period_len = ";
1513 ss
<< tmpCurDVR3
->GetArrayLength();
1518 ss
<<" if(gid0>=buffer_cost_len || isNan(";
1519 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1521 ss
<<" cost = 0;\n\telse \n";
1524 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1527 ss
<<" if(gid0>=buffer_salvage_len || isNan(";
1528 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1530 ss
<<" salvage = 0;\n\telse \n";
1533 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1536 ss
<<" if(gid0>=buffer_life_len || isNan(";
1537 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1539 ss
<<" life = 0;\n\telse \n";
1542 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1545 ss
<<" if(gid0>=buffer_period_len || isNan(";
1546 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
1548 ss
<<" period = 0;\n\telse \n";
1551 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
1553 ss
<<" double tmpvalue = ((life*(life+1))*pow(2.0,-1));\n";
1554 ss
<<" result = ((cost-salvage)*(life-period+1)";
1555 ss
<< "*pow(tmpvalue,-1));\n";
1556 ss
<<" return result;\n";
1560 void MIRR::GenSlidingWindowFunction(
1561 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
1563 FormulaToken
* pCur
= vSubArguments
[0]->GetFormulaToken();
1565 const formula::DoubleVectorRefToken
* pCurDVR
=
1566 dynamic_cast<const formula::DoubleVectorRefToken
*>(pCur
);
1567 size_t nCurWindowSize
= pCurDVR
->GetRefRowSize();
1568 FormulaToken
* pCur1
= vSubArguments
[1]->GetFormulaToken();
1570 const formula::SingleVectorRefToken
* pSVR1
=
1571 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur1
);
1573 FormulaToken
* pCur2
= vSubArguments
[2]->GetFormulaToken();
1575 const formula::SingleVectorRefToken
* pSVR2
=
1576 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur2
);
1579 ss
<< "\ndouble " << sSymName
;
1580 ss
<< "_"<< BinFuncName() <<"(";
1581 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1585 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1588 ss
<< "double tmp = " << GetBottom() <<";\n\t";
1589 ss
<< "int gid0 = get_global_id(0);\n\t";
1590 ss
<< "double arg0, arg1, arg2;\n\t";
1591 ss
<< "arg1 = " << vSubArguments
[1]->GenSlidingWindowDeclRef();
1593 ss
<< "arg2 = " << vSubArguments
[2]->GenSlidingWindowDeclRef();
1595 ss
<< "int argLen1 = " << pSVR1
->GetArrayLength() << ";\n\t";
1596 ss
<< "int argLen2 = " << pSVR2
->GetArrayLength() << ";\n\t";
1598 ss
<< "if (gid0 >= argLen1)\n\t\t";
1599 ss
<< "arg1 = 0.0;\n\t";
1600 ss
<< "if (gid0 >= argLen2)\n\t\t";
1601 ss
<< "arg2 = 0.0;\n\t";
1602 ss
<< "if (isNan(arg1))\n\t\t";
1603 ss
<< "arg1 = 0.0;\n\t";
1604 ss
<< "if (isNan(arg2))\n\t\t";
1605 ss
<< "arg2 = 0.0;\n\t";
1607 ss
<< "double invest = arg1 + 1.0;\n\t";
1608 ss
<< "double reinvest = arg2 + 1.0;\n\t";
1609 ss
<< "double NPV_invest = 0.0;\n\t";
1610 ss
<< "double Pow_invest = 1.0;\n\t";
1611 ss
<< "double NPV_reinvest = 0.0;\n\t";
1612 ss
<< "double Pow_reinvest = 1.0;\n\t";
1613 ss
<< "int nCount = 0;\n\t";
1614 ss
<< "int arrayLength = " << pCurDVR
->GetArrayLength() << ";\n\t";
1616 ss
<< "for (int i = 0; i + gid0 < arrayLength &&";
1617 ss
<< " i < " << nCurWindowSize
<< "; i++){\n\t\t";
1619 ss
<< "for (int i = 0; i < " << nCurWindowSize
<< "; i++){\n\t\t";
1621 ss
<< "arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
1624 ss
<< "if (isNan(arg0))\n\t\t\t";
1625 ss
<< "continue;\n\t\t";
1627 ss
<< "if (arg0 > 0.0)\n\t\t\t";
1628 ss
<< "NPV_reinvest += arg0 * Pow_reinvest;\n\t\t";
1629 ss
<< "else if (arg0 < 0.0)\n\t\t\t";
1630 ss
<< "NPV_invest += arg0 * Pow_invest;\n\t\t";
1631 ss
<< "Pow_reinvest /= reinvest;\n\t\t";
1632 ss
<< "Pow_invest /= invest;\n\t\t";
1633 ss
<< "nCount++;\n\t";
1636 ss
<< "-NPV_reinvest /NPV_invest * pow(reinvest,(double)nCount-1);\n\t";
1637 ss
<< "tmp = pow(tmp, 1.0 / (nCount - 1)) - 1.0;\n\t";
1638 ss
<< "return (double)tmp;\n";
1642 void OpEffective::GenSlidingWindowFunction(std::stringstream
& ss
,
1643 const std::string sSymName
, SubArguments
& vSubArguments
)
1645 ss
<< "\ndouble " << sSymName
;
1646 ss
<< "_" << BinFuncName() << "(";
1647 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1651 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1654 ss
<< " double tmp = " << GetBottom() <<";\n";
1655 ss
<< " int gid0 = get_global_id(0);\n\t";
1656 ss
<< " double arg0 = " << GetBottom() << ";\n";
1657 ss
<< " double arg1 = " << GetBottom() << ";\n";
1658 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1660 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
1662 if (pCur
->GetType() == formula::svSingleVectorRef
)
1665 const formula::SingleVectorRefToken
* pSVR
=
1666 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
1667 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
1670 else if (pCur
->GetType() == formula::svDouble
)
1677 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
1679 ss
<< " if (isNan(";
1680 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
1682 ss
<< " arg" << i
<< " = 0;\n";
1684 ss
<< " arg" << i
<< " = ";
1685 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1690 ss
<< " arg" << i
<< " = ";
1691 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1695 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1698 ss
<< " tmp = pow(1.0 + arg0 * pow(arg1, -1), arg1)-1.0;\n";
1699 ss
<< " return tmp;\n";
1703 void OpTbilleq::BinInlineFun(std::set
<std::string
>& decls
,
1704 std::set
<std::string
>& funs
)
1706 decls
.insert(GetDiffDate360_Decl
);decls
.insert(GetDiffDate360Decl
);
1707 decls
.insert(DateToDaysDecl
);decls
.insert(DaysToDate_LocalBarrierDecl
);
1708 decls
.insert(DaysInMonthDecl
);decls
.insert(GetNullDateDecl
);
1709 decls
.insert(IsLeapYearDecl
);
1710 funs
.insert(GetDiffDate360_
);funs
.insert(GetDiffDate360
);
1711 funs
.insert(DateToDays
);funs
.insert(DaysToDate_LocalBarrier
);
1712 funs
.insert(DaysInMonth
);funs
.insert(GetNullDate
);
1713 funs
.insert(IsLeapYear
);
1715 void OpTbilleq::GenSlidingWindowFunction(
1716 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
1718 ss
<< "\ndouble " << sSymName
;
1719 ss
<< "_"<< BinFuncName() <<"(";
1720 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1724 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1727 ss
<< " int gid0 = get_global_id(0);\n";
1728 ss
<< "double tmp = 0;\n\t";
1729 ss
<< "double tmp000;\n\t";
1730 ss
<< "double tmp001;\n\t";
1731 ss
<< "double tmp002;\n\t";
1734 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1735 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
1736 formula::SingleVectorRefToken
*>(tmpCur0
);
1738 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
1739 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
1740 formula::SingleVectorRefToken
*>(tmpCur1
);
1742 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1743 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
1744 formula::SingleVectorRefToken
*>(tmpCur2
);
1746 ss
<< "int buffer_tmp000_len = ";
1747 ss
<< tmpCurDVR0
->GetArrayLength();
1750 ss
<< "int buffer_tmp001_len = ";
1751 ss
<< tmpCurDVR1
->GetArrayLength();
1754 ss
<< "int buffer_tmp002_len = ";
1755 ss
<< tmpCurDVR2
->GetArrayLength();
1760 ss
<<"if(gid0>=buffer_tmp000_len || isNan(";
1761 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1763 ss
<<"tmp000 = 0;\n\telse \n\t\t";
1766 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1770 ss
<<"if(gid0>=buffer_tmp001_len || isNan(";
1771 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1773 ss
<<"tmp001 = 0;\n\telse \n\t\t";
1776 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1780 ss
<<"if(gid0>=buffer_tmp002_len || isNan(";
1781 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1783 ss
<<"tmp002 = 0;\n\telse \n\t\t";
1786 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
1789 ss
<<"tmp001+=1.0;\n";
1790 ss
<<"int nDiff =GetDiffDate360(GetNullDate(),tmp000,tmp001,true);\n";
1791 ss
<<"tmp =( 365 * tmp002 ) / ( 360 - ( tmp002 * ( nDiff ) ) );\n";
1792 ss
<< "return tmp;\n";
1795 void OpCumprinc::BinInlineFun(std::set
<std::string
>& decls
,
1796 std::set
<std::string
>& funs
)
1798 decls
.insert(GetRmz_newDecl
); decls
.insert(GetZw_newDecl
);
1799 funs
.insert(GetRmz_new
);funs
.insert(GetZw_new
);
1801 void OpCumprinc::GenSlidingWindowFunction(std::stringstream
&ss
,
1802 const std::string sSymName
, SubArguments
&vSubArguments
)
1804 ss
<< "\ndouble " << sSymName
;
1805 ss
<< "_"<< BinFuncName() <<"(";
1806 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1810 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1813 ss
<< " double tmp = " << GetBottom() <<";\n";
1814 ss
<< " int gid0 = get_global_id(0);\n";
1815 ss
<< " double fRate,fVal;\n";
1816 ss
<< " int nStartPer,nEndPer,nNumPeriods,nPayType;\n";
1818 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1819 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
1820 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1821 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
1822 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
1823 FormulaToken
*tmpCur5
= vSubArguments
[5]->GetFormulaToken();
1826 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
1828 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
1829 formula::SingleVectorRefToken
*>(tmpCur0
);
1830 ss
<<" if(gid0 >= "<<tmpCurDVR0
->GetArrayLength()<<" || isNan(";
1831 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
1833 ss
<<" fRate = 0;\n else\n";
1836 ss
<<" fRate = "<<vSubArguments
[0]->GenSlidingWindowDeclRef();
1839 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
1841 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
1842 formula::SingleVectorRefToken
*>(tmpCur1
);
1843 ss
<<" if(gid0 >= "<<tmpCurDVR1
->GetArrayLength()<<" || isNan(";
1844 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
1846 ss
<<" nNumPeriods = 0;\n else\n";
1849 ss
<<" nNumPeriods = (int)";
1850 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
1853 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
1855 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
1856 formula::SingleVectorRefToken
*>(tmpCur2
);
1857 ss
<<" if(gid0 >= "<<tmpCurDVR2
->GetArrayLength()<<" || isNan(";
1858 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
1860 ss
<<" fVal = 0;\n else\n";
1863 ss
<<" fVal = "<<vSubArguments
[2]->GenSlidingWindowDeclRef();
1866 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
1868 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
1869 formula::SingleVectorRefToken
*>(tmpCur3
);
1870 ss
<<" if(gid0 >= "<<tmpCurDVR3
->GetArrayLength()<<" || isNan(";
1871 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
1873 ss
<<" nStartPer = 0;\n else\n";
1876 ss
<<" nStartPer = (int)";
1877 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
1880 if(tmpCur4
->GetType() == formula::svSingleVectorRef
)
1882 const formula::SingleVectorRefToken
*tmpCurDVR4
= dynamic_cast<const
1883 formula::SingleVectorRefToken
*>(tmpCur4
);
1884 ss
<<" if(gid0 >= "<<tmpCurDVR4
->GetArrayLength()<<" || isNan(";
1885 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
1887 ss
<<" nEndPer = 0;\n else\n";
1890 ss
<<" nEndPer = (int)";
1891 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
1895 if(tmpCur5
->GetType() == formula::svSingleVectorRef
)
1897 const formula::SingleVectorRefToken
*tmpCurDVR5
= dynamic_cast<const
1898 formula::SingleVectorRefToken
*>(tmpCur5
);
1899 ss
<<" if(gid0 >= "<<tmpCurDVR5
->GetArrayLength()<<" || isNan(";
1900 ss
<<vSubArguments
[5]->GenSlidingWindowDeclRef();
1902 ss
<<" nPayType = 0;\n else\n";
1905 ss
<<" nPayType = (int)";
1906 ss
<<vSubArguments
[5]->GenSlidingWindowDeclRef();
1908 ss
<<" double fRmz;\n";
1909 ss
<<" fRmz = GetRmz_new( fRate, nNumPeriods,fVal,0.0,nPayType );\n";
1910 ss
<<" if(nStartPer == 1)\n";
1912 ss
<<" if( nPayType <= 0 )\n";
1913 ss
<<" tmp = fRmz + fVal * fRate;\n";
1915 ss
<<" tmp = fRmz;\n";
1916 ss
<<" nStartPer=nStartPer+1;\n";
1918 ss
<<" for( int i = nStartPer ; i <= nEndPer ; i++ )\n";
1920 ss
<<" if( nPayType > 0 )\n";
1921 ss
<<" tmp += fRmz - ( GetZw_new( fRate,i - 2,";
1922 ss
<<"fRmz,fVal,1)- fRmz ) * fRate;\n";
1924 ss
<<" tmp += fRmz - GetZw_new( fRate, i - 1,";
1925 ss
<<"fRmz,fVal,0 ) * fRate;\n";
1927 ss
<<" return tmp;\n";
1930 void OpAccrint::BinInlineFun(std::set
<std::string
>& decls
,
1931 std::set
<std::string
>& funs
)
1933 decls
.insert(IsLeapYearDecl
); decls
.insert(DaysInMonthDecl
);
1934 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDaysDecl
);
1935 decls
.insert(GetNullDateDecl
); decls
.insert(GetDiffDateDecl
);
1936 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
1937 funs
.insert(DaysToDate
);funs
.insert(DateToDays
);
1938 funs
.insert(GetNullDate
);funs
.insert(GetDiffDate
);
1940 void OpAccrint::GenSlidingWindowFunction(
1941 std::stringstream
&ss
, const std::string sSymName
,
1942 SubArguments
&vSubArguments
)
1944 ss
<< "\ndouble " << sSymName
;
1945 ss
<< "_"<< BinFuncName() <<"(";
1946 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1950 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1953 ss
<< " int gid0 = get_global_id(0);\n";
1954 ss
<< " double tmp = 0;\n";
1955 ss
<< " int nStartDate,nEndDate,mode,freq;\n";
1956 ss
<< " int nDays1stYear=0;\n";
1957 ss
<< " double fVal,fRate;\n";
1959 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1960 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
1961 formula::SingleVectorRefToken
*>(tmpCur0
);
1962 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1963 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
1964 formula::SingleVectorRefToken
*>(tmpCur2
);
1965 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
1966 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
1967 formula::SingleVectorRefToken
*>(tmpCur3
);
1968 FormulaToken
* tmpCur4
= vSubArguments
[4]->GetFormulaToken();
1969 const formula::SingleVectorRefToken
*tmpCurDVR4
= dynamic_cast<const
1970 formula::SingleVectorRefToken
*>(tmpCur4
);
1971 FormulaToken
* tmpCur5
= vSubArguments
[5]->GetFormulaToken();
1972 const formula::SingleVectorRefToken
*tmpCurDVR5
= dynamic_cast<const
1973 formula::SingleVectorRefToken
*>(tmpCur5
);
1974 FormulaToken
* tmpCur6
= vSubArguments
[6]->GetFormulaToken();
1975 const formula::SingleVectorRefToken
*tmpCurDVR6
= dynamic_cast<const
1976 formula::SingleVectorRefToken
*>(tmpCur6
);
1977 ss
<< " int buffer_nIssue_len = ";
1978 ss
<< tmpCurDVR0
->GetArrayLength();
1980 ss
<< " int buffer_nSettle_len = ";
1981 ss
<< tmpCurDVR2
->GetArrayLength();
1983 ss
<< " int buffer_fRate_len = ";
1984 ss
<< tmpCurDVR3
->GetArrayLength();
1986 ss
<< " int buffer_fVal_len = ";
1987 ss
<< tmpCurDVR4
->GetArrayLength();
1989 ss
<< " int buffer_nFreq_len = ";
1990 ss
<< tmpCurDVR5
->GetArrayLength();
1992 ss
<< " int buffer_nMode_len = ";
1993 ss
<< tmpCurDVR6
->GetArrayLength();
1997 ss
<<" if(gid0 >= buffer_nIssue_len || isNan(";
1998 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
2000 ss
<<" nStartDate = 0;\n else\n";
2002 ss
<<" nStartDate=(int)";
2003 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
2006 ss
<<" if(gid0 >= buffer_nSettle_len || isNan(";
2007 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
2009 ss
<<" nEndDate = 0;\n else\n";
2011 ss
<<" nEndDate=(int)";
2012 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
2015 ss
<<" if(gid0 >= buffer_fRate_len || isNan(";
2016 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
2018 ss
<<" fRate = 0;\n else\n";
2021 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
2024 ss
<<" if(gid0 >= buffer_fVal_len || isNan(";
2025 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
2027 ss
<<" fVal = 0;\n else\n";
2030 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
2033 ss
<<" if(gid0 >= buffer_nFreq_len || isNan(";
2034 ss
<<vSubArguments
[5]->GenSlidingWindowDeclRef();
2036 ss
<<" freq = 0;\n else\n";
2038 ss
<<" freq= (int)";
2039 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
2042 ss
<<" if(gid0 >= buffer_nMode_len || isNan(";
2043 ss
<<vSubArguments
[6]->GenSlidingWindowDeclRef();
2045 ss
<<" mode = 0;\n else\n";
2047 ss
<<" mode = (int)";
2048 ss
<< vSubArguments
[6]->GenSlidingWindowDeclRef();
2050 ss
<<" int nNullDate=GetNullDate();\n";
2051 ss
<<" int nTotalDays = GetDiffDate(nNullDate,nStartDate,";
2052 ss
<<"nEndDate, mode,&nDays1stYear);\n";
2053 ss
<<" tmp = fVal*fRate*convert_double(nTotalDays)";
2054 ss
<<"/convert_double(nDays1stYear);\n";
2055 ss
<<" return tmp;\n";
2059 void OpAccrintm::BinInlineFun(std::set
<std::string
>& decls
,
2060 std::set
<std::string
>& funs
)
2062 decls
.insert(IsLeapYearDecl
); decls
.insert(DaysInMonthDecl
);
2063 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDaysDecl
);
2064 decls
.insert(GetNullDateDecl
); decls
.insert(GetDiffDateDecl
);
2065 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
2066 funs
.insert(DaysToDate
);funs
.insert(DateToDays
);
2067 funs
.insert(GetNullDate
);funs
.insert(GetDiffDate
);
2069 void OpAccrintm::GenSlidingWindowFunction(
2070 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
2072 ss
<< "\ndouble " << sSymName
;
2073 ss
<< "_"<< BinFuncName() <<"(";
2074 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2078 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2081 ss
<< "int gid0 = get_global_id(0);\n\t";
2082 ss
<< "double tmp = " << GetBottom() <<";\n\t";
2083 ss
<< "int nStartDate,nEndDate,mode;\n\t";
2084 ss
<< "double fRate,fVal;\n\t";
2086 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
2087 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
2088 formula::SingleVectorRefToken
*>(tmpCur0
);
2089 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
2090 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
2091 formula::SingleVectorRefToken
*>(tmpCur1
);
2093 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
2094 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
2095 formula::SingleVectorRefToken
*>(tmpCur2
);
2097 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
2098 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
2099 formula::SingleVectorRefToken
*>(tmpCur3
);
2101 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
2102 const formula::SingleVectorRefToken
*tmpCurDVR4
= dynamic_cast<const
2103 formula::SingleVectorRefToken
*>(tmpCur4
);
2104 ss
<< "int buffer_nIssue_len = ";
2105 ss
<< tmpCurDVR0
->GetArrayLength();
2108 ss
<< "int buffer_nSettle_len = ";
2109 ss
<< tmpCurDVR1
->GetArrayLength();
2112 ss
<< "int buffer_fRate_len = ";
2113 ss
<< tmpCurDVR2
->GetArrayLength();
2116 ss
<< "int buffer_fVal_len = ";
2117 ss
<< tmpCurDVR3
->GetArrayLength();
2120 ss
<< "int buffer_nMode_len = ";
2121 ss
<< tmpCurDVR4
->GetArrayLength();
2125 ss
<<"if(gid0 >= buffer_nIssue_len || isNan(";
2126 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
2128 ss
<<"nStartDate = 0;\n\telse\n\t\t";
2130 ss
<< "nStartDate=(int)";
2131 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2134 ss
<<"if(gid0 >= buffer_nSettle_len || isNan(";
2135 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
2137 ss
<<"nEndDate = 0;\n\telse\n\t\t";
2139 ss
<< "nEndDate=(int)";
2140 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
2144 ss
<<"if(gid0 >= buffer_fRate_len || isNan(";
2145 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
2147 ss
<<"fRate = 0;\n\telse\n\t\t";
2150 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
2153 ss
<<"if(gid0 >= buffer_fVal_len || isNan(";
2154 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
2156 ss
<<"fVal = 0;\n\telse\n\t\t";
2159 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
2162 ss
<<"if(gid0 >= buffer_nMode_len || isNan(";
2163 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
2165 ss
<<"mode = 0;\n\telse\n\t\t";
2167 ss
<< "mode = (int)";
2168 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
2170 ss
<<"int nDays1stYear=0;\n\t";
2171 ss
<<"int nNullDate=GetNullDate();\n\t";
2172 ss
<<"int nTotalDays = GetDiffDate(nNullDate,nStartDate,";
2173 ss
<<"nEndDate, mode,&nDays1stYear);\n\t";
2174 ss
<<"tmp = fVal*fRate*convert_double(nTotalDays)";
2175 ss
<<"/convert_double(nDays1stYear);\n\t";
2176 ss
<< "return tmp;\n";
2180 void OpYield::BinInlineFun(std::set
<std::string
>& decls
,
2181 std::set
<std::string
>& funs
)
2183 decls
.insert(getYield_Decl
);decls
.insert(getPrice_Decl
);
2184 decls
.insert(coupnumDecl
);decls
.insert(coupdaysncDecl
);
2185 decls
.insert(coupdaybsDecl
);decls
.insert(coupdaysDecl
);
2186 decls
.insert(lcl_GetcoupnumDecl
);decls
.insert(lcl_GetcoupdaysDecl
);
2187 decls
.insert(lcl_GetcoupdaybsDecl
);decls
.insert(getDiffDecl
);
2188 decls
.insert(getDaysInYearRangeDecl
);decls
.insert(GetDaysInYearDecl
);
2189 decls
.insert(GetDaysInYearsDecl
);decls
.insert(getDaysInMonthRangeDecl
);
2190 decls
.insert(addMonthsDecl
);decls
.insert(ScaDateDecl
);
2191 decls
.insert(GetNullDateDecl
);decls
.insert(DateToDaysDecl
);
2192 decls
.insert(DaysToDateDecl
);decls
.insert(DaysInMonthDecl
);
2193 decls
.insert(IsLeapYearDecl
);
2195 funs
.insert(getYield_
);funs
.insert(getPrice_
);
2196 funs
.insert(coupnum
);funs
.insert(coupdaysnc
);
2197 funs
.insert(coupdaybs
);funs
.insert(coupdays
);
2198 funs
.insert(lcl_Getcoupnum
);funs
.insert(lcl_Getcoupdays
);
2199 funs
.insert(lcl_Getcoupdaybs
);funs
.insert(getDiff
);
2200 funs
.insert(getDaysInYearRange
);funs
.insert(GetDaysInYear
);
2201 funs
.insert(GetDaysInYears
);funs
.insert(getDaysInMonthRange
);
2202 funs
.insert(addMonths
);funs
.insert(ScaDate
);
2203 funs
.insert(GetNullDate
);funs
.insert(DateToDays
);
2204 funs
.insert(DaysToDate
);funs
.insert(DaysInMonth
);
2205 funs
.insert(IsLeapYear
);
2209 void OpYield::GenSlidingWindowFunction(
2210 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
2212 ss
<< "\ndouble " << sSymName
;
2213 ss
<< "_"<< BinFuncName() <<"(";
2214 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2218 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2221 ss
<< "double tmp = " <<"0"<<";\n\t";
2222 ss
<< "int gid0 = get_global_id(0);\n\t";
2223 ss
<< "double tmp000;\n\t";
2224 ss
<< "double tmp001;\n\t";
2225 ss
<< "double tmp002;\n\t";
2226 ss
<< "double tmp003;\n\t";
2227 ss
<< "double tmp004;\n\t";
2228 ss
<< "double tmp005;\n\t";
2229 ss
<< "double tmp006;\n\t";
2233 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
2234 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
2235 formula::SingleVectorRefToken
*>(tmpCur0
);
2237 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
2238 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
2239 formula::SingleVectorRefToken
*>(tmpCur1
);
2241 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
2242 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
2243 formula::SingleVectorRefToken
*>(tmpCur2
);
2245 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
2246 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
2247 formula::SingleVectorRefToken
*>(tmpCur3
);
2249 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
2250 const formula::SingleVectorRefToken
*tmpCurDVR4
= dynamic_cast<const
2251 formula::SingleVectorRefToken
*>(tmpCur4
);
2253 FormulaToken
*tmpCur5
= vSubArguments
[5]->GetFormulaToken();
2254 const formula::SingleVectorRefToken
*tmpCurDVR5
= dynamic_cast<const
2255 formula::SingleVectorRefToken
*>(tmpCur5
);
2257 FormulaToken
*tmpCur6
= vSubArguments
[6]->GetFormulaToken();
2258 const formula::SingleVectorRefToken
*tmpCurDVR6
= dynamic_cast<const
2259 formula::SingleVectorRefToken
*>(tmpCur6
);
2261 ss
<< "int buffer_tmp000_len = ";
2262 ss
<< tmpCurDVR0
->GetArrayLength();
2265 ss
<< "int buffer_tmp001_len = ";
2266 ss
<< tmpCurDVR1
->GetArrayLength();
2269 ss
<< "int buffer_tmp002_len = ";
2270 ss
<< tmpCurDVR2
->GetArrayLength();
2273 ss
<< "int buffer_tmp003_len = ";
2274 ss
<< tmpCurDVR3
->GetArrayLength();
2277 ss
<< "int buffer_tmp004_len = ";
2278 ss
<< tmpCurDVR4
->GetArrayLength();
2281 ss
<< "int buffer_tmp005_len = ";
2282 ss
<< tmpCurDVR5
->GetArrayLength();
2285 ss
<< "int buffer_tmp006_len = ";
2286 ss
<< tmpCurDVR6
->GetArrayLength();
2291 ss
<<"if(gid0>=buffer_tmp000_len || isNan(";
2292 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2294 ss
<<"tmp000 = 0;\n\telse \n\t\t";
2297 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2301 ss
<<"if(gid0>=buffer_tmp001_len || isNan(";
2302 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
2304 ss
<<"tmp001 = 0;\n\telse \n\t\t";
2307 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
2311 ss
<<"if(gid0>=buffer_tmp002_len || isNan(";
2312 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
2314 ss
<<"tmp002 = 0;\n\telse \n\t\t";
2317 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
2321 ss
<<"if(gid0>=buffer_tmp003_len || isNan(";
2322 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
2324 ss
<<"tmp003 = 0;\n\telse \n\t\t";
2327 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
2331 ss
<<"if(gid0>=buffer_tmp004_len || isNan(";
2332 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
2334 ss
<<"tmp004 = 0;\n\telse \n\t\t";
2337 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
2341 ss
<<"if(gid0>=buffer_tmp005_len || isNan(";
2342 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
2344 ss
<<"tmp005 = 0;\n\telse \n\t\t";
2347 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
2351 ss
<<"if(gid0>=buffer_tmp006_len || isNan(";
2352 ss
<< vSubArguments
[6]->GenSlidingWindowDeclRef();
2354 ss
<<"tmp006 = 0;\n\telse \n\t\t";
2357 ss
<< vSubArguments
[6]->GenSlidingWindowDeclRef();
2360 ss
<< "tmp = getYield_(";
2361 ss
<< "GetNullDate(),tmp000,tmp001,tmp002,tmp003,tmp004,tmp005,tmp006);\n\t ";
2362 ss
<< "return tmp;\n";
2366 void OpSLN::GenSlidingWindowFunction(std::stringstream
&ss
,
2367 const std::string sSymName
, SubArguments
&vSubArguments
)
2369 ss
<< "\ndouble " << sSymName
;
2370 ss
<< "_"<< BinFuncName() <<"(";
2371 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2375 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2378 ss
<< " double tmp = " <<"0"<<";\n";
2379 ss
<< " int gid0 = get_global_id(0);\n";
2380 ss
<< " double wert;\n";
2381 ss
<< " double rest;\n";
2382 ss
<< " double dauer;\n";
2385 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
2386 const formula::SingleVectorRefToken
*tmpCurDVR0
=
2387 dynamic_cast<const formula::SingleVectorRefToken
*>(tmpCur0
);
2388 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
2389 const formula::SingleVectorRefToken
*tmpCurDVR1
=
2390 dynamic_cast<const formula::SingleVectorRefToken
*>(tmpCur1
);
2391 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
2392 const formula::SingleVectorRefToken
*tmpCurDVR2
=
2393 dynamic_cast<const formula::SingleVectorRefToken
*>(tmpCur2
);
2394 ss
<< " int buffer_wert_len = ";
2395 ss
<< tmpCurDVR0
->GetArrayLength();
2397 ss
<< " int buffer_rest_len = ";
2398 ss
<< tmpCurDVR1
->GetArrayLength();
2400 ss
<< " int buffer_dauer_len = ";
2401 ss
<< tmpCurDVR2
->GetArrayLength();
2405 ss
<<" if(gid0>=buffer_wert_len || isNan(";
2406 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2408 ss
<<" wert = 0;\n\telse \n";
2411 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2414 ss
<<" if(gid0>=buffer_rest_len || isNan(";
2415 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
2417 ss
<<" rest = 0;\n\telse \n";
2420 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
2423 ss
<<" if(gid0>=buffer_dauer_len || isNan(";
2424 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
2426 ss
<<" dauer = 0;\n\telse \n";
2429 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
2431 ss
<< " tmp = (wert-rest)*pow(dauer,-1);\n";
2432 ss
<< " return tmp;\n";
2436 void OpYieldmat::BinInlineFun(std::set
<std::string
>& decls
,
2437 std::set
<std::string
>& funs
)
2439 decls
.insert(GetYearFrac_newDecl
);decls
.insert(GetNullDateDecl
);
2440 decls
.insert(DateToDaysDecl
);decls
.insert(DaysToDate_newDecl
);
2441 decls
.insert(DaysInMonthDecl
);decls
.insert(IsLeapYearDecl
);
2442 decls
.insert(GetYieldmatDecl
);
2444 funs
.insert(GetYearFrac_new
);funs
.insert(GetNullDate
);
2445 funs
.insert(DateToDays
);funs
.insert(DaysToDate_new
);
2446 funs
.insert(DaysInMonth
);funs
.insert(IsLeapYear
);
2447 funs
.insert(GetYieldmat
);
2450 void OpYieldmat::GenSlidingWindowFunction(
2451 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
2453 ss
<< "\ndouble " << sSymName
;
2454 ss
<< "_"<< BinFuncName() <<"(";
2455 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2459 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2462 ss
<< "double tmp = " <<"0"<<";\n\t";
2463 ss
<< "int gid0 = get_global_id(0);\n\t";
2464 ss
<< "double tmp000;\n\t";
2465 ss
<< "double tmp001;\n\t";
2466 ss
<< "double tmp002;\n\t";
2467 ss
<< "double tmp003;\n\t";
2468 ss
<< "double tmp004;\n\t";
2469 ss
<< "double tmp005;\n\t";
2472 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
2473 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
2474 formula::SingleVectorRefToken
*>(tmpCur0
);
2476 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
2477 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
2478 formula::SingleVectorRefToken
*>(tmpCur1
);
2480 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
2481 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
2482 formula::SingleVectorRefToken
*>(tmpCur2
);
2484 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
2485 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
2486 formula::SingleVectorRefToken
*>(tmpCur3
);
2488 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
2489 const formula::SingleVectorRefToken
*tmpCurDVR4
= dynamic_cast<const
2490 formula::SingleVectorRefToken
*>(tmpCur4
);
2492 FormulaToken
*tmpCur5
= vSubArguments
[5]->GetFormulaToken();
2493 const formula::SingleVectorRefToken
*tmpCurDVR5
= dynamic_cast<const
2494 formula::SingleVectorRefToken
*>(tmpCur5
);
2496 ss
<< "int buffer_tmp000_len = ";
2497 ss
<< tmpCurDVR0
->GetArrayLength();
2500 ss
<< "int buffer_tmp001_len = ";
2501 ss
<< tmpCurDVR1
->GetArrayLength();
2504 ss
<< "int buffer_tmp002_len = ";
2505 ss
<< tmpCurDVR2
->GetArrayLength();
2508 ss
<< "int buffer_tmp003_len = ";
2509 ss
<< tmpCurDVR3
->GetArrayLength();
2512 ss
<< "int buffer_tmp004_len = ";
2513 ss
<< tmpCurDVR4
->GetArrayLength();
2516 ss
<< "int buffer_tmp005_len = ";
2517 ss
<< tmpCurDVR5
->GetArrayLength();
2523 ss
<<"if(gid0>=buffer_tmp000_len || isNan(";
2524 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2526 ss
<<"tmp000 = 0;\n\telse \n\t\t";
2529 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2533 ss
<<"if(gid0>=buffer_tmp001_len || isNan(";
2534 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
2536 ss
<<"tmp001 = 0;\n\telse \n\t\t";
2539 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
2543 ss
<<"if(gid0>=buffer_tmp002_len || isNan(";
2544 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
2546 ss
<<"tmp002 = 0;\n\telse \n\t\t";
2549 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
2553 ss
<<"if(gid0>=buffer_tmp003_len || isNan(";
2554 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
2556 ss
<<"tmp003 = 0;\n\telse \n\t\t";
2559 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
2563 ss
<<"if(gid0>=buffer_tmp004_len || isNan(";
2564 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
2566 ss
<<"tmp004 = 0;\n\telse \n\t\t";
2569 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
2573 ss
<<"if(gid0>=buffer_tmp005_len || isNan(";
2574 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
2576 ss
<<"tmp005 = 0;\n\telse \n\t\t";
2579 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
2582 ss
<< "tmp = GetYieldmat(";
2583 ss
<<"GetNullDate(),tmp000,tmp001,tmp002,tmp003,tmp004,tmp005);\n\t";
2584 ss
<< "return tmp;\n";
2588 void OpPMT::GenSlidingWindowFunction(std::stringstream
&ss
,
2589 const std::string sSymName
, SubArguments
&vSubArguments
)
2591 ss
<< "\ndouble " << sSymName
;
2592 ss
<< "_"<< BinFuncName() <<"(";
2593 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2597 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2600 ss
<<" double tmp = 0;\n";
2601 ss
<<" double temp=0.0;\n";
2602 ss
<<" int gid0 = get_global_id(0);\n";
2603 ss
<<" double tmp0=0,tmp1=0,tmp2=0;\n";
2604 ss
<<" double tmp3=0,tmp4=0;\n";
2605 size_t i
= vSubArguments
.size();
2608 for (i
= 0; i
< vSubArguments
.size(); i
++)
2610 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2612 if (pCur
->GetType() == formula::svSingleVectorRef
)
2615 const formula::SingleVectorRefToken
* pSVR
=
2616 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
2617 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
2621 else if (pCur
->GetType() == formula::svDouble
)
2633 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2635 ss
<<" temp="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
2637 ss
<<" if (isNan(temp))\n";
2638 ss
<<" tmp"<<i
<<"= 0;\n";
2640 ss
<<" tmp"<<i
<<"=temp;\n";
2645 ss
<<" tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef(
2650 ss
<<" tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
2655 ss
<<" if(tmp0==0.0)\n";
2656 ss
<<" return -(tmp2+tmp3)/tmp1;\n";
2657 ss
<<" tmp-=tmp3;\n";
2658 ss
<<" tmp=tmp-tmp2*pow(1.0+tmp0,tmp1);\n";
2659 ss
<<" tmp=tmp*pow(( (1.0+tmp0*tmp4)* ";
2660 ss
<<"( (pow(1.0+tmp0,tmp1)-1.0)/tmp0)),-1);\n";
2661 ss
<<" return tmp;\n";
2665 void OpNPV::GenSlidingWindowFunction(std::stringstream
&ss
,
2666 const std::string sSymName
, SubArguments
&vSubArguments
)
2668 ss
<< "\ndouble " << sSymName
;
2669 ss
<< "_"<< BinFuncName() <<"(";
2670 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2674 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2677 ss
<< " double tmp = 0.0;\n";
2678 ss
<< " int gid0 = get_global_id(0);\n";
2679 ss
<< " int nCount = 1;\n";
2680 ss
<< " double arg0=";
2681 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
2684 for (size_t i
= 1; i
< vSubArguments
.size(); i
++)
2686 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2688 if (pCur
->GetType() == formula::svDoubleVectorRef
)
2690 const formula::DoubleVectorRefToken
* pDVR
=
2691 dynamic_cast<const formula::DoubleVectorRefToken
*>(pCur
);
2692 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
2693 ss
<< " for (int i = ";
2694 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
2696 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
2697 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
2699 ss
<< "gid0; i < "<< nCurWindowSize
<< "; i++)\n";
2701 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
2703 ss
<< "0; i < " << pDVR
->GetArrayLength();
2704 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
2706 ss
<< "0; i < gid0+"<< nCurWindowSize
<< "; i++)\n";
2708 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
2710 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
2711 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
2713 ss
<< "0; i < "<< nCurWindowSize
<< "; i++)\n";
2718 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
2720 ss
<< "0; i < "<< nCurWindowSize
<< "; i++)\n";
2724 else if (pCur
->GetType() == formula::svSingleVectorRef
)
2727 const formula::SingleVectorRefToken
* pSVR
=
2728 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
2729 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
2733 else if (pCur
->GetType() == formula::svDouble
)
2742 ss
<< "nCount += 1;\n";
2746 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2748 ss
<< " double temp=";
2749 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2751 ss
<< " double temp1=1.0;";
2752 ss
<< " if (isNan(temp)){\n";
2753 ss
<< " tmp += 0;}\n";
2755 ss
<< " for(int i=1;i<nCount;i+=2)\n";
2756 ss
<< " temp1*=pow(1.0f+ arg0 ,2);\n";
2757 ss
<< " if(nCount%2)\n";
2758 ss
<< " temp1*=1.0f+ arg0;\n";
2759 ss
<< " tmp +=temp/ temp1;\n";
2760 ss
<< " nCount += 1;\n";
2766 ss
<< " double temp=";
2767 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2769 ss
<< " double temp1=1.0;";
2770 ss
<< " for(int i=1;i<nCount;i+=2)";
2771 ss
<< " temp1*=pow(1.0f+ arg0 ,2);\n";
2772 ss
<< " if(nCount%2)";
2773 ss
<< " temp1*=1.0f+ arg0;\n";
2774 ss
<< " tmp +=temp/ temp1;\n";
2775 ss
<< " nCount += 1;\n";
2778 ss
<< "tmp +="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
2779 ss
<<" / pow(1.0f+ arg0 ,";
2780 ss
<<" (double)nCount );\n";
2781 ss
<< " nCount += 1;\n";
2784 ss
<< " return tmp;\n";
2788 void OpPrice::BinInlineFun(std::set
<std::string
>& decls
,
2789 std::set
<std::string
>& funs
)
2791 decls
.insert(getPrice_new_Decl
);
2792 decls
.insert(IsLeapYearDecl
);decls
.insert(DaysInMonthDecl
);
2793 decls
.insert(DaysToDateDecl
);
2794 decls
.insert(DateToDaysDecl
);
2795 decls
.insert(ScaDateDecl
);
2796 decls
.insert(setDayDecl
);decls
.insert(checklessthanDecl
);
2797 decls
.insert(addMonthsDecl
);decls
.insert(lcl_Getcoupnum_newDecl
);
2798 decls
.insert(coupnum_newDecl
);
2799 decls
.insert(DateToDays_newDecl
);
2800 decls
.insert(getDaysInMonthRangeDecl
);
2801 decls
.insert(GetDaysInYearsDecl
); decls
.insert(GetDaysInYearDecl
);
2802 decls
.insert(getDaysInYearRangeDecl
); decls
.insert(getDiffDecl
);
2803 decls
.insert(coupdaybs_newDecl
);
2804 decls
.insert(lcl_Getcoupdays_newDecl
);
2805 decls
.insert(lcl_Getcoupdaybs_newDecl
);
2806 decls
.insert(coupdays_newDecl
);
2807 decls
.insert(coupdaysnc_newDecl
);
2808 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth_new
);
2809 funs
.insert(DaysToDate
);funs
.insert(DateToDays_new
);
2810 funs
.insert(DateToDays
);
2811 funs
.insert(ScaDate
);
2812 funs
.insert(addMonths
);funs
.insert(getDaysInMonthRange
);
2813 funs
.insert(GetDaysInYears
);funs
.insert(GetDaysInYear
);
2814 funs
.insert(getDaysInYearRange
);funs
.insert(getDiff
);
2815 funs
.insert(setDay
);funs
.insert(checklessthan
);
2816 funs
.insert(lcl_Getcoupdaybs_new
);
2817 funs
.insert(coupdaybs_new
);
2818 funs
.insert(lcl_Getcoupdays_new
);
2819 funs
.insert(coupdaysnc_new
);
2820 funs
.insert(coupdays_new
);
2821 funs
.insert(setDay
);funs
.insert(checklessthan
);
2822 funs
.insert(lcl_Getcoupnum_new
);
2823 funs
.insert(coupnum_new
);funs
.insert(getPrice_new
);
2825 void OpPrice::GenSlidingWindowFunction(std::stringstream
&ss
,
2826 const std::string sSymName
, SubArguments
&vSubArguments
)
2828 ss
<< "\ndouble " << sSymName
;
2829 ss
<< "_"<< BinFuncName() <<"(";
2830 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2834 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2837 ss
<<" double tmp = 0;\n";
2838 ss
<<" int gid0 = get_global_id(0);\n";
2839 ss
<<" double tmp0=0;\n";
2840 ss
<<" double tmp1=0;\n";
2841 ss
<<" double tmp2=0;\n";
2842 ss
<<" double tmp3=0;\n";
2843 ss
<<" double tmp4=0,tmp5=0;\n";
2844 ss
<<" double tmp6=0;\n";
2846 for (size_t i
= 0; i
< vSubArguments
.size(); i
++)
2848 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2850 if (pCur
->GetType() == formula::svSingleVectorRef
)
2853 const formula::SingleVectorRefToken
* pSVR
=
2854 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
2855 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
2859 else if (pCur
->GetType() == formula::svDouble
)
2871 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2873 ss
<< " if (isNan(";
2874 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2876 ss
<< " tmp"<<i
<<"= 0;\n";
2878 ss
<< " tmp"<<i
<<"=";
2879 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2884 ss
<< " tmp"<<i
<<"=";
2885 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2889 ss
<< " tmp"<<i
<<"=";
2890 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
2894 ss
<< " tmp = getPrice_(tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);\n";
2895 ss
<< " return tmp;\n";
2899 void OpOddlprice::BinInlineFun(std::set
<std::string
>& decls
,
2900 std::set
<std::string
>& funs
)
2902 decls
.insert(GetOddlpriceDecl
);decls
.insert(GetDiffDateDecl
);
2903 decls
.insert(GetYearDiffDecl
);decls
.insert(IsLeapYearDecl
);
2904 decls
.insert(GetNullDateDecl
);decls
.insert(DateToDaysDecl
);
2905 decls
.insert(DaysToDateDecl
);decls
.insert(DaysInMonthDecl
);
2906 decls
.insert(GetYearFracDecl
);
2907 funs
.insert(GetOddlprice
);funs
.insert(GetDiffDate
);
2908 funs
.insert(GetYearDiff
);funs
.insert(IsLeapYear
);
2909 funs
.insert(GetNullDate
);funs
.insert(DaysInMonth
);
2910 funs
.insert(DaysToDate
);funs
.insert(DateToDays
);
2911 funs
.insert(GetYearFrac
);
2913 void OpOddlprice::GenSlidingWindowFunction(std::stringstream
&ss
,
2914 const std::string sSymName
, SubArguments
&vSubArguments
)
2916 ss
<< "\ndouble " << sSymName
;
2917 ss
<< "_"<< BinFuncName() <<"(";
2918 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2922 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2925 ss
<<" double tmp = 0;\n";
2926 ss
<<" int gid0 = get_global_id(0);\n";
2927 ss
<<" double tmp0=0;\n";
2928 ss
<<" double tmp1=0;\n";
2929 ss
<<" double tmp2=0;\n";
2930 ss
<<" double tmp3=0;\n";
2931 ss
<<" double tmp4=0;\n";
2932 ss
<<" double tmp5=0;\n";
2933 ss
<<" double tmp6=0;\n";
2934 ss
<<" double tmp7=0;\n";
2937 for (size_t i
= 0; i
< vSubArguments
.size(); i
++)
2939 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2941 if (pCur
->GetType() == formula::svDoubleVectorRef
)
2943 const formula::DoubleVectorRefToken
* pDVR
=
2944 dynamic_cast<const formula::DoubleVectorRefToken
*>(pCur
);
2945 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
2946 ss
<< " for (int i = ";
2947 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
2949 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
2950 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
2952 ss
<< "gid0; i < "<< nCurWindowSize
<< "; i++)\n";
2954 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
2956 ss
<< "0; i < " << pDVR
->GetArrayLength();
2957 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
2959 ss
<< "0; i < gid0+"<< nCurWindowSize
<< "; i++)\n";
2961 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
2963 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
2964 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
2966 ss
<< "0; i < "<< nCurWindowSize
<< "; i++)\n";
2971 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
2973 ss
<< "0; i < "<< nCurWindowSize
<< "; i++)\n";
2976 nItems
+= nCurWindowSize
;
2978 else if (pCur
->GetType() == formula::svSingleVectorRef
)
2981 const formula::SingleVectorRefToken
* pSVR
=
2982 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
2983 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
2988 else if (pCur
->GetType() == formula::svDouble
)
3002 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
3004 ss
<< " if (isNan(";
3005 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3007 ss
<< " tmp"<<i
<<"= 0;\n";
3009 ss
<< " tmp"<<i
<<"=";
3010 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3016 ss
<< " tmp"<<i
<<"=";
3017 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3021 ss
<< " tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3025 ss
<<" int nNullDate = GetNullDate();\n";
3026 ss
<<" tmp = GetOddlprice(nNullDate,tmp0,tmp1,";
3027 ss
<<"tmp2,tmp3,tmp4,tmp5,tmp6,tmp7);\n";
3028 ss
<<" return tmp;\n";
3031 void OpOddlyield::BinInlineFun(std::set
<std::string
>& decls
,
3032 std::set
<std::string
>& funs
)
3034 decls
.insert(GetDiffDateDecl
);decls
.insert(DaysToDateDecl
);
3035 decls
.insert(GetYearDiffDecl
);decls
.insert(IsLeapYearDecl
);
3036 decls
.insert(GetNullDateDecl
);decls
.insert(DateToDaysDecl
);
3037 decls
.insert(DaysInMonthDecl
);
3038 decls
.insert(GetYearFracDecl
);decls
.insert(GetOddlyieldDecl
);
3039 funs
.insert(GetDiffDate
);funs
.insert(DaysToDate
);
3040 funs
.insert(GetYearDiff
);funs
.insert(IsLeapYear
);
3041 funs
.insert(GetNullDate
);funs
.insert(DaysInMonth
);
3042 funs
.insert(DateToDays
);
3043 funs
.insert(GetYearFrac
);funs
.insert(GetOddlyield
);
3045 void OpOddlyield::GenSlidingWindowFunction(std::stringstream
&ss
,
3046 const std::string sSymName
, SubArguments
&vSubArguments
)
3048 ss
<< "\ndouble " << sSymName
;
3049 ss
<< "_"<< BinFuncName() <<"(";
3050 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3054 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3057 ss
<<" double tmp = 0;\n";
3058 ss
<<" int gid0 = get_global_id(0);\n";
3059 ss
<<" double tmp0=0;\n";
3060 ss
<<" double tmp1=0;\n";
3061 ss
<<" double tmp2=0;\n";
3062 ss
<<" double tmp3=0;\n";
3063 ss
<<" double tmp4=0;\n";
3064 ss
<<" double tmp5=0;\n";
3065 ss
<<" double tmp6=0;\n";
3066 ss
<<" double tmp7=0;\n";
3069 for (size_t i
= 0; i
< vSubArguments
.size(); i
++)
3071 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
3073 if (pCur
->GetType() == formula::svDoubleVectorRef
)
3075 const formula::DoubleVectorRefToken
* pDVR
=
3076 dynamic_cast<const formula::DoubleVectorRefToken
*>(pCur
);
3077 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
3078 ss
<< " for (int i = ";
3079 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
3081 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
3082 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
3084 ss
<< "gid0; i < "<< nCurWindowSize
<< "; i++)\n";
3086 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
3088 ss
<< "0; i < " << pDVR
->GetArrayLength();
3089 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
3091 ss
<< "0; i < gid0+"<< nCurWindowSize
<< "; i++)\n";
3093 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
3095 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
3096 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
3098 ss
<< "0; i < "<< nCurWindowSize
<< "; i++)\n";
3103 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
3105 ss
<< "0; i < "<< nCurWindowSize
<< "; i++)\n";
3108 nItems
+= nCurWindowSize
;
3110 else if (pCur
->GetType() == formula::svSingleVectorRef
)
3113 const formula::SingleVectorRefToken
* pSVR
=
3114 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
3115 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
3120 else if (pCur
->GetType() == formula::svDouble
)
3134 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
3136 ss
<< " if (isNan(";
3137 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3139 ss
<< " tmp"<<i
<<"= 0;\n";
3141 ss
<< " tmp"<<i
<<"=";
3142 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3148 ss
<< " tmp"<<i
<<"=";
3149 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3153 ss
<< " tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3157 ss
<<" int nNullDate = GetNullDate();\n";
3158 ss
<<" tmp = GetOddlyield(nNullDate,tmp0,tmp1";
3159 ss
<<",tmp2,tmp3,tmp4,tmp5,tmp6,tmp7);\n";
3160 ss
<<" return tmp;\n";
3163 void OpPriceDisc::BinInlineFun(std::set
<std::string
>& decls
,
3164 std::set
<std::string
>& funs
)
3166 decls
.insert(GetYearDiffDecl
);decls
.insert(getDiffDecl
);
3167 decls
.insert(getDaysInYearRangeDecl
);decls
.insert(GetDaysInYearDecl
);
3168 decls
.insert(GetDaysInYearsDecl
);decls
.insert(getDaysInMonthRangeDecl
);
3169 decls
.insert(addMonthsDecl
);decls
.insert(ScaDateDecl
);
3170 decls
.insert(GetNullDateDecl
);decls
.insert(DateToDaysDecl
);
3171 decls
.insert(DaysToDateDecl
);decls
.insert(DaysInMonthDecl
);
3172 decls
.insert(IsLeapYearDecl
);decls
.insert(GetDiffDateDecl
);
3173 funs
.insert(GetYearDiff
);funs
.insert(getDiff
);
3174 funs
.insert(getDaysInYearRange
);funs
.insert(GetDaysInYear
);
3175 funs
.insert(GetDaysInYears
);funs
.insert(getDaysInMonthRange
);
3176 funs
.insert(addMonths
);funs
.insert(ScaDate
);
3177 funs
.insert(GetNullDate
);funs
.insert(DateToDays
);
3178 funs
.insert(DaysToDate
);funs
.insert(DaysInMonth
);
3179 funs
.insert(IsLeapYear
);funs
.insert(GetDiffDate
);
3181 void OpPriceDisc::GenSlidingWindowFunction(std::stringstream
&ss
,
3182 const std::string sSymName
, SubArguments
&vSubArguments
)
3184 ss
<< "\ndouble " << sSymName
;
3185 ss
<< "_"<< BinFuncName() <<"(";
3186 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3190 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3193 ss
<< " double tmp = 0;\n";
3194 ss
<< " int gid0 = get_global_id(0);\n";
3195 ss
<<" double tmp0=0;\n";
3196 ss
<<" double tmp1=0;\n";
3197 ss
<<" double tmp2=0;\n";
3198 ss
<<" double tmp3=0;\n";
3199 ss
<<" double tmp4=0;\n";
3201 for (size_t i
= 0; i
< vSubArguments
.size(); i
++)
3203 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
3205 if (pCur
->GetType() == formula::svSingleVectorRef
)
3208 const formula::SingleVectorRefToken
* pSVR
=
3209 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
3210 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
3214 else if (pCur
->GetType() == formula::svDouble
)
3226 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
3228 ss
<< " if (isNan(";
3229 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3231 ss
<< " tmp"<<i
<<"= 0;\n";
3233 ss
<< " tmp"<<i
<<"=";
3234 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3240 ss
<< " tmp"<<i
<<"=";
3241 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3245 ss
<< " tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3249 ss
<<" int nNullDate = GetNullDate();\n";
3250 ss
<<" tmp=tmp3* ( 1.0 -tmp2*GetYearDiff( nNullDate, ";
3251 ss
<<"tmp0,tmp1,tmp4));\n";
3252 ss
<<" return tmp;\n";
3255 void OpNper::GenSlidingWindowFunction(std::stringstream
&ss
,
3256 const std::string sSymName
, SubArguments
&vSubArguments
)
3258 ss
<< "\ndouble " << sSymName
;
3259 ss
<< "_"<< BinFuncName() <<"(";
3260 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3264 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3267 ss
<< " double tmp = 0;\n";
3268 ss
<< " int gid0 = get_global_id(0);\n";
3269 ss
<<" double tmp0=0;\n";
3270 ss
<<" double tmp1=0;\n";
3271 ss
<<" double tmp2=0;\n";
3272 ss
<<" double tmp3=0;\n";
3273 ss
<<" double tmp4=0;\n";
3275 for (size_t i
= 0; i
< vSubArguments
.size(); i
++)
3277 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
3279 if (pCur
->GetType() == formula::svSingleVectorRef
)
3282 const formula::SingleVectorRefToken
* pSVR
=
3283 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
3284 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
3289 else if (pCur
->GetType() == formula::svDouble
)
3303 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
3305 ss
<< " if (isNan(";
3306 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3308 ss
<< " tmp"<<i
<<"= 0;\n";
3310 ss
<< " tmp"<<i
<<"=";
3311 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3317 ss
<< " tmp"<<i
<<"=";
3318 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3322 ss
<< " tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3326 ss
<<" if (tmp0 == 0.0)\n";
3327 ss
<<" tmp=(-1*(tmp2 + tmp3)/tmp1);\n";
3328 ss
<<" else if (tmp4 > 0.0)\n";
3329 ss
<<" tmp=log(-1*(tmp0*tmp3-tmp1*(1.0+tmp0))*";
3330 ss
<<"pow((tmp0*tmp2+tmp1*(1.0+tmp0)),-1))/log(1.0+tmp0);\n";
3332 ss
<<" tmp=log(-1*(tmp0*tmp3-tmp1)*pow(tmp0*tmp2+tmp1,-1))";
3333 ss
<<"/log(1.0+tmp0);\n";
3334 ss
<<" return tmp;\n";
3338 void OpPPMT::BinInlineFun(std::set
<std::string
>& decls
,
3339 std::set
<std::string
>& funs
)
3341 decls
.insert(GetZwDecl
);
3345 void OpPPMT::GenSlidingWindowFunction(std::stringstream
&ss
,
3346 const std::string sSymName
, SubArguments
&vSubArguments
)
3348 ss
<< "\ndouble " << sSymName
;
3349 ss
<< "_"<< BinFuncName() <<"(";
3350 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3354 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3357 ss
<<" double tmp = 0;\n";
3358 ss
<<" int gid0 = get_global_id(0);\n";
3359 ss
<<" double arg=0;\n";
3360 ss
<<" double tmp0=0;\n";
3361 ss
<<" double tmp1=0;\n";
3362 ss
<<" double tmp2=0;\n";
3363 ss
<<" double tmp3=0;\n";
3364 ss
<<" double tmp4=0,tmp5=0;\n";
3367 for (size_t i
= 0; i
< vSubArguments
.size(); i
++)
3369 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
3371 if (pCur
->GetType() == formula::svSingleVectorRef
)
3374 const formula::SingleVectorRefToken
* pSVR
=
3375 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
3376 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
3380 else if (pCur
->GetType() == formula::svDouble
)
3392 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
3395 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3397 ss
<< " if (isNan(arg))\n";
3398 ss
<< " tmp"<<i
<<"= 0;\n";
3400 ss
<< " tmp"<<i
<<"=arg;\n";
3405 ss
<<" tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3409 ss
<<"tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3413 ss
<<" double pmt=0 ;\n";
3414 ss
<<" if(tmp0==0.0)\n";
3415 ss
<<" return -(tmp3+tmp4)/tmp2;\n";
3416 ss
<<" pmt=pmt-tmp4-tmp3*pow(1.0+tmp0,tmp2);\n";
3417 ss
<<" pmt=pmt*pow(( (1.0+tmp0*tmp5)* ";
3418 ss
<<"( (pow(1.0+tmp0,tmp2)-1.0)/tmp0)),-1);\n";
3419 ss
<<" double temp = pow( 1+tmp0,tmp1-2);\n";
3420 ss
<<" double re;\n";
3421 ss
<<" if(tmp1==1.0){\n";
3422 ss
<<" if(tmp5>0.0)\n";
3429 ss
<<" if(tmp5>0.0)\n ";
3430 ss
<<" re=GetZw(tmp0, tmp1-2.0, pmt, tmp3, 1.0) - pmt;\n";
3432 ss
<<" re=GetZw(tmp0, tmp1-1.0, pmt, tmp3, 0.0);\n";
3434 ss
<<" re = re * tmp0;\n";
3435 ss
<<" tmp = pmt - re;\n";
3436 ss
<<" return tmp;\n";
3440 void OpCoupdaybs::BinInlineFun(std::set
<std::string
>& decls
,
3441 std::set
<std::string
>& funs
)
3443 decls
.insert(IsLeapYearDecl
); decls
.insert(DaysInMonthDecl
);
3444 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDays_newDecl
);
3445 decls
.insert(GetNullDate_newDecl
); decls
.insert(ScaDateDecl
);
3446 decls
.insert(addMonthsDecl
); decls
.insert(getDaysInMonthRangeDecl
);
3447 decls
.insert(GetDaysInYearsDecl
);
3448 decls
.insert(getDaysInYearRangeDecl
); decls
.insert(getDiffDecl
);
3449 decls
.insert(setDayDecl
);decls
.insert(checklessthanDecl
);
3450 decls
.insert(lcl_Getcoupdaybs_newDecl
);
3451 decls
.insert(coupdaybs_newDecl
);
3452 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
3453 funs
.insert(DaysToDate
);funs
.insert(DateToDays_new
);
3454 funs
.insert(GetNullDate_new
);funs
.insert(ScaDate
);
3455 funs
.insert(addMonths
);funs
.insert(getDaysInMonthRange
);
3456 funs
.insert(GetDaysInYears
);
3457 funs
.insert(getDaysInYearRange
);funs
.insert(getDiff
);
3458 funs
.insert(setDay
);funs
.insert(checklessthan
);
3459 funs
.insert(lcl_Getcoupdaybs_new
);
3460 funs
.insert(coupdaybs_new
);
3462 void OpCoupdaybs::GenSlidingWindowFunction(
3463 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&
3466 ss
<< "\ndouble " << sSymName
;
3467 ss
<< "_"<< BinFuncName() <<"(";
3468 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3472 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3475 ss
<< " double tmp = 0;\n";
3476 ss
<< " int gid0 = get_global_id(0);\n";
3477 ss
<< " int nSettle,nMat,nFreq,nBase;\n";
3479 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3480 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3481 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3482 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3485 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
3487 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_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";
3494 ss
<<" nSettle=(int)";
3495 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3498 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
3500 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
3501 formula::SingleVectorRefToken
*>(tmpCur1
);
3502 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3503 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
3504 ss
<<" nMat = 0;\n else\n";
3508 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3511 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
3513 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
3514 formula::SingleVectorRefToken
*>(tmpCur2
);
3515 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
3516 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
3517 ss
<<" nFreq = 0;\n else\n";
3520 ss
<< " nFreq=(int)";
3521 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
3524 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
3526 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
3527 formula::SingleVectorRefToken
*>(tmpCur3
);
3528 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
3529 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
3530 ss
<<" nBase = 0;\n else\n";
3533 ss
<< " nBase=(int)";
3534 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
3536 ss
<<" tmp = coupdaybs_new(nSettle,nMat,nFreq,nBase);\n";
3537 ss
<<" return tmp;\n";
3541 void OpCoupdays::BinInlineFun(std::set
<std::string
>& decls
,
3542 std::set
<std::string
>& funs
)
3544 decls
.insert(IsLeapYearDecl
); decls
.insert(DaysInMonthDecl
);
3545 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDays_newDecl
);
3546 decls
.insert(GetNullDate_newDecl
); decls
.insert(ScaDateDecl
);
3547 decls
.insert(addMonthsDecl
); decls
.insert(getDaysInMonthRangeDecl
);
3548 decls
.insert(GetDaysInYearsDecl
); decls
.insert(GetDaysInYearDecl
);
3549 decls
.insert(getDaysInYearRangeDecl
); decls
.insert(getDiffDecl
);
3550 decls
.insert(setDayDecl
);decls
.insert(checklessthanDecl
);
3551 decls
.insert(lcl_Getcoupdays_newDecl
);
3552 decls
.insert(coupdays_newDecl
);
3553 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
3554 funs
.insert(DaysToDate
);funs
.insert(DateToDays_new
);
3555 funs
.insert(GetNullDate_new
);funs
.insert(ScaDate
);
3556 funs
.insert(addMonths
);funs
.insert(getDaysInMonthRange
);
3557 funs
.insert(GetDaysInYears
);funs
.insert(GetDaysInYear
);
3558 funs
.insert(getDaysInYearRange
);funs
.insert(getDiff
);
3559 funs
.insert(lcl_Getcoupdays_new
);
3560 funs
.insert(setDay
);funs
.insert(checklessthan
);
3561 funs
.insert(coupdays_new
);
3563 void OpCoupdays::GenSlidingWindowFunction(
3564 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&
3567 ss
<< "\ndouble " << sSymName
;
3568 ss
<< "_"<< BinFuncName() <<"(";
3569 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3573 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3576 ss
<< " double tmp = 0;\n";
3577 ss
<< " int gid0 = get_global_id(0);\n";
3578 ss
<< " int nSettle,nMat,nFreq,nBase;\n";
3580 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3581 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3582 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3583 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3586 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
3588 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
3589 formula::SingleVectorRefToken
*>(tmpCur0
);
3590 ss
<<" if(isNan("<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3591 ss
<<")||(gid0 >="<<tmpCurDVR0
->GetArrayLength()<<"))\n";
3592 ss
<<" nSettle = 0;\n else\n";
3595 ss
<<" nSettle=(int)";
3596 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3599 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
3601 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
3602 formula::SingleVectorRefToken
*>(tmpCur1
);
3603 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3604 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
3605 ss
<<" nMat = 0;\n else\n";
3609 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3612 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
3614 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
3615 formula::SingleVectorRefToken
*>(tmpCur2
);
3616 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
3617 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
3618 ss
<<" nFreq = 0;\n else\n";
3621 ss
<< " nFreq=(int)";
3622 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
3625 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
3627 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
3628 formula::SingleVectorRefToken
*>(tmpCur3
);
3629 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
3630 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
3631 ss
<<" nBase = 0;\n else\n";
3634 ss
<< " nBase=(int)";
3635 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
3637 ss
<<" tmp = coupdays_new(nSettle,nMat,nFreq,nBase);\n";
3638 ss
<<" return tmp;\n";
3641 void OpCouppcd::BinInlineFun(std::set
<std::string
>& decls
,
3642 std::set
<std::string
>& funs
)
3644 decls
.insert(IsLeapYearDecl
); decls
.insert(DaysInMonthDecl
);
3645 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDaysDecl
);
3646 decls
.insert(GetNullDateDecl
);
3647 decls
.insert(ScaDateDecl
);
3648 decls
.insert(addMonthsDecl
);
3649 decls
.insert(setDayDecl
);decls
.insert(checklessthanDecl
);
3650 decls
.insert(lcl_GetCouppcdDecl
);
3651 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
3652 funs
.insert(DaysToDate
);funs
.insert(DateToDays
);
3653 funs
.insert(GetNullDate
);
3654 funs
.insert(ScaDate
);
3655 funs
.insert(addMonths
);
3656 funs
.insert(setDay
);funs
.insert(checklessthan
);
3657 funs
.insert(lcl_GetCouppcd
);
3659 void OpCouppcd::GenSlidingWindowFunction(
3660 std::stringstream
&ss
, const std::string sSymName
,
3661 SubArguments
&vSubArguments
)
3663 ss
<< "\ndouble " << sSymName
;
3664 ss
<< "_"<< BinFuncName() <<"(";
3665 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3669 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3672 ss
<< " double tmp = 0;\n";
3673 ss
<< " int gid0 = get_global_id(0);\n";
3674 ss
<< " int nSettle,nMat,nFreq,nBase;\n";
3676 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3677 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3678 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3679 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3682 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
3684 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
3685 formula::SingleVectorRefToken
*>(tmpCur0
);
3686 ss
<<" if(isNan("<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3687 ss
<<")||(gid0 >="<<tmpCurDVR0
->GetArrayLength()<<"))\n";
3688 ss
<<" nSettle = 0;\n else\n";
3691 ss
<<" nSettle=(int)";
3692 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3695 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
3697 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
3698 formula::SingleVectorRefToken
*>(tmpCur1
);
3699 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3700 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
3701 ss
<<" nMat = 0;\n else\n";
3705 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3708 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
3710 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
3711 formula::SingleVectorRefToken
*>(tmpCur2
);
3712 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
3713 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
3714 ss
<<" nFreq = 0;\n else\n";
3717 ss
<< " nFreq=(int)";
3718 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
3721 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
3723 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
3724 formula::SingleVectorRefToken
*>(tmpCur3
);
3725 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
3726 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
3727 ss
<<" nBase = 0;\n else\n";
3730 ss
<< " nBase=(int)";
3731 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
3733 ss
<<" int nNullDate=693594;\n";
3734 ss
<<" tmp = lcl_GetCouppcd(nNullDate,nSettle,nMat,nFreq,nBase);\n";
3735 ss
<<" return tmp;\n";
3738 void OpCoupncd::BinInlineFun(std::set
<std::string
>& decls
,
3739 std::set
<std::string
>& funs
)
3741 decls
.insert(IsLeapYearDecl
); decls
.insert(DaysInMonthDecl
);
3742 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDaysDecl
);
3743 decls
.insert(GetNullDateDecl
);
3744 decls
.insert(ScaDateDecl
);
3745 decls
.insert(addMonthsDecl
);
3746 decls
.insert(setDayDecl
);decls
.insert(checklessthanDecl
);
3747 decls
.insert(lcl_GetCoupncdDecl
);
3748 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
3749 funs
.insert(DaysToDate
);funs
.insert(DateToDays
);
3750 funs
.insert(GetNullDate
);
3751 funs
.insert(ScaDate
);
3752 funs
.insert(addMonths
);
3753 funs
.insert(setDay
);funs
.insert(checklessthan
);
3754 funs
.insert(lcl_GetCoupncd
);
3756 void OpCoupncd::GenSlidingWindowFunction(
3757 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&
3760 ss
<< "\ndouble " << sSymName
;
3761 ss
<< "_"<< BinFuncName() <<"(";
3762 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3766 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3769 ss
<< " double tmp = 0;\n";
3770 ss
<< " int gid0 = get_global_id(0);\n";
3771 ss
<< " int nSettle,nMat,nFreq,nBase;\n";
3773 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3774 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3775 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3776 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3779 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
3781 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
3782 formula::SingleVectorRefToken
*>(tmpCur0
);
3783 ss
<<" if(isNan("<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3784 ss
<<")||(gid0 >="<<tmpCurDVR0
->GetArrayLength()<<"))\n";
3785 ss
<<" nSettle = 0;\n else\n";
3788 ss
<<" nSettle=(int)";
3789 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3792 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
3794 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
3795 formula::SingleVectorRefToken
*>(tmpCur1
);
3796 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3797 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
3798 ss
<<" nMat = 0;\n else\n";
3802 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3805 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
3807 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
3808 formula::SingleVectorRefToken
*>(tmpCur2
);
3809 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
3810 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
3811 ss
<<" nFreq = 0;\n else\n";
3814 ss
<< " nFreq=(int)";
3815 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
3818 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
3820 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
3821 formula::SingleVectorRefToken
*>(tmpCur3
);
3822 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
3823 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
3824 ss
<<" nBase = 0;\n else\n";
3827 ss
<< " nBase=(int)";
3828 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
3830 ss
<<" int nNullDate=693594;\n";
3831 ss
<<" tmp = lcl_GetCoupncd(nNullDate,nSettle,nMat,nFreq,nBase);\n";
3832 ss
<<" return tmp;\n";
3836 void OpCoupdaysnc::BinInlineFun(std::set
<std::string
>& decls
,
3837 std::set
<std::string
>& funs
)
3839 decls
.insert(IsLeapYearDecl
); decls
.insert(DaysInMonth_newDecl
);
3840 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDaysDecl
);
3841 decls
.insert(DateToDays_newDecl
);
3842 decls
.insert(ScaDateDecl
);
3843 decls
.insert(addMonthsDecl
); decls
.insert(getDaysInMonthRangeDecl
);
3844 decls
.insert(GetDaysInYearsDecl
); decls
.insert(GetDaysInYearDecl
);
3845 decls
.insert(getDaysInYearRangeDecl
); decls
.insert(getDiffDecl
);
3846 decls
.insert(setDayDecl
);decls
.insert(checklessthanDecl
);
3847 decls
.insert(coupdaybs_newDecl
);
3848 decls
.insert(lcl_Getcoupdays_newDecl
);
3849 decls
.insert(lcl_Getcoupdaybs_newDecl
);
3850 decls
.insert(coupdays_newDecl
);
3851 decls
.insert(coupdaysnc_newDecl
);
3852 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth_new
);
3853 funs
.insert(DaysToDate
);funs
.insert(DateToDays_new
);
3854 funs
.insert(DateToDays
);
3855 funs
.insert(ScaDate
);
3856 funs
.insert(addMonths
);funs
.insert(getDaysInMonthRange
);
3857 funs
.insert(GetDaysInYears
);funs
.insert(GetDaysInYear
);
3858 funs
.insert(getDaysInYearRange
);funs
.insert(getDiff
);
3859 funs
.insert(setDay
);funs
.insert(checklessthan
);
3860 funs
.insert(lcl_Getcoupdaybs_new
);
3861 funs
.insert(coupdaybs_new
);
3862 funs
.insert(lcl_Getcoupdays_new
);
3863 funs
.insert(coupdaysnc_new
);
3864 funs
.insert(coupdays_new
);
3866 void OpCoupdaysnc::GenSlidingWindowFunction(
3867 std::stringstream
&ss
, const std::string sSymName
,
3868 SubArguments
&vSubArguments
)
3870 ss
<< "\ndouble " << sSymName
;
3871 ss
<< "_"<< BinFuncName() <<"(";
3872 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3876 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3879 ss
<< " double tmp = 0;\n";
3880 ss
<< " int gid0 = get_global_id(0);\n";
3881 ss
<< " int nSettle,nMat,nFreq,nBase;\n";
3883 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3884 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3885 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3886 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3889 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
3891 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
3892 formula::SingleVectorRefToken
*>(tmpCur0
);
3893 ss
<<" if(isNan("<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3894 ss
<<")||(gid0 >="<<tmpCurDVR0
->GetArrayLength()<<"))\n";
3895 ss
<<" nSettle = 0;\n else\n";
3898 ss
<<" nSettle=(int)";
3899 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3902 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
3904 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
3905 formula::SingleVectorRefToken
*>(tmpCur1
);
3906 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3907 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
3908 ss
<<" nMat = 0;\n else\n";
3912 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3915 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
3917 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
3918 formula::SingleVectorRefToken
*>(tmpCur2
);
3919 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
3920 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
3921 ss
<<" nFreq = 0;\n else\n";
3924 ss
<< " nFreq=(int)";
3925 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
3928 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
3930 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
3931 formula::SingleVectorRefToken
*>(tmpCur3
);
3932 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
3933 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
3934 ss
<<" nBase = 0;\n else\n";
3937 ss
<< " nBase=(int)";
3938 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
3940 ss
<<" tmp = coupdaysnc_new(nSettle,nMat,nFreq,nBase);\n";
3941 ss
<<" return tmp;\n";
3945 void OpCoupnum::BinInlineFun(std::set
<std::string
>& decls
,
3946 std::set
<std::string
>& funs
)
3948 decls
.insert(IsLeapYearDecl
);decls
.insert(DaysInMonthDecl
);
3949 decls
.insert(DaysToDateDecl
);
3950 decls
.insert(DateToDaysDecl
);
3951 decls
.insert(ScaDateDecl
);
3952 decls
.insert(setDayDecl
);decls
.insert(checklessthanDecl
);
3953 decls
.insert(addMonthsDecl
);decls
.insert(lcl_Getcoupnum_newDecl
);
3954 decls
.insert(coupnum_newDecl
);
3955 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth_new
);
3956 funs
.insert(DaysToDate
);
3957 funs
.insert(DateToDays
);
3958 funs
.insert(ScaDate
);
3959 funs
.insert(setDay
);funs
.insert(checklessthan
);
3960 funs
.insert(addMonths
);funs
.insert(lcl_Getcoupnum_new
);
3961 funs
.insert(coupnum_new
);
3963 void OpCoupnum::GenSlidingWindowFunction(std::stringstream
&ss
,
3964 const std::string sSymName
, SubArguments
&vSubArguments
)
3966 ss
<< "\ndouble " << sSymName
;
3967 ss
<< "_"<< BinFuncName() <<"(";
3968 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3972 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3975 ss
<< " double tmp = 0;\n";
3976 ss
<< " int gid0 = get_global_id(0);\n";
3977 ss
<< " int nSettle,nMat,nFreq,nBase;\n";
3979 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3980 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3981 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
3982 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
3985 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
3987 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
3988 formula::SingleVectorRefToken
*>(tmpCur0
);
3989 ss
<<" if(isNan("<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3990 ss
<<")||(gid0 >="<<tmpCurDVR0
->GetArrayLength()<<"))\n";
3991 ss
<<" nSettle = 0;\n else\n";
3994 ss
<<" nSettle=(int)";
3995 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3998 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
4000 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
4001 formula::SingleVectorRefToken
*>(tmpCur1
);
4002 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
4003 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
4004 ss
<<" nMat = 0;\n else\n";
4008 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
4011 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
4013 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
4014 formula::SingleVectorRefToken
*>(tmpCur2
);
4015 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
4016 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
4017 ss
<<" nFreq = 0;\n else\n";
4020 ss
<< " nFreq=(int)";
4021 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
4024 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
4026 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
4027 formula::SingleVectorRefToken
*>(tmpCur3
);
4028 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
4029 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
4030 ss
<<" nBase = 0;\n else\n";
4033 ss
<< " nBase=(int)";
4034 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
4036 ss
<<" tmp = coupnum_new(nSettle,nMat,nFreq,nBase);\n";
4037 ss
<<" return tmp;\n";
4040 void OpAmordegrc::BinInlineFun(std::set
<std::string
>& decls
,
4041 std::set
<std::string
>& funs
)
4043 decls
.insert(nKorrValDecl
); decls
.insert(RoundDecl
);
4044 decls
.insert(IsLeapYearDecl
);decls
.insert(DaysInMonthDecl
);
4045 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDaysDecl
);
4046 decls
.insert(GetNullDateDecl
); decls
.insert(GetYearFracDecl
);
4048 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
4049 funs
.insert(DaysToDate
);funs
.insert(DateToDays
);
4050 funs
.insert(GetNullDate
);funs
.insert(GetYearFrac
);
4052 void OpAmordegrc::GenSlidingWindowFunction(std::stringstream
&ss
,
4053 const std::string sSymName
, SubArguments
&vSubArguments
)
4055 ss
<< "\ndouble " << sSymName
;
4056 ss
<< "_"<< BinFuncName() <<"(";
4057 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4061 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4064 ss
<< "int gid0 = get_global_id(0);\n";
4065 ss
<< " double tmp = " << GetBottom() <<";\n";
4066 ss
<< " double fCost,fRestVal,fPer,fRate;\n";
4067 ss
<< " int nDate,nFirstPer,nBase;\n";
4069 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
4070 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
4071 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
4072 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
4073 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
4074 FormulaToken
*tmpCur5
= vSubArguments
[5]->GetFormulaToken();
4075 FormulaToken
*tmpCur6
= vSubArguments
[6]->GetFormulaToken();
4078 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
4080 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
4081 formula::SingleVectorRefToken
*>(tmpCur0
);
4082 ss
<<" if(isNan("<<vSubArguments
[0]->GenSlidingWindowDeclRef();
4083 ss
<<")||(gid0 >="<<tmpCurDVR0
->GetArrayLength()<<"))\n";
4084 ss
<<" fCost = 0;\n else\n";
4088 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
4091 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
4093 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
4094 formula::SingleVectorRefToken
*>(tmpCur1
);
4095 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
4096 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
4097 ss
<<" nDate = 0;\n else\n";
4100 ss
<< " nDate=(int)";
4101 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
4104 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
4106 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
4107 formula::SingleVectorRefToken
*>(tmpCur2
);
4108 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
4109 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
4110 ss
<<" nFirstPer = 0;\n else\n";
4113 ss
<< " nFirstPer=(int)";
4114 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
4117 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
4119 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
4120 formula::SingleVectorRefToken
*>(tmpCur3
);
4121 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
4122 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
4123 ss
<<" fRestVal = 0;\n else\n";
4127 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
4130 if(tmpCur4
->GetType() == formula::svSingleVectorRef
)
4132 const formula::SingleVectorRefToken
*tmpCurDVR4
= dynamic_cast<const
4133 formula::SingleVectorRefToken
*>(tmpCur4
);
4134 ss
<<" if(isNan(" <<vSubArguments
[4]->GenSlidingWindowDeclRef();
4135 ss
<<")||(gid0 >="<<tmpCurDVR4
->GetArrayLength()<<"))\n";
4136 ss
<<" fPer = 0;\n else\n";
4140 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
4143 if(tmpCur5
->GetType() == formula::svSingleVectorRef
)
4145 const formula::SingleVectorRefToken
*tmpCurDVR5
= dynamic_cast<const
4146 formula::SingleVectorRefToken
*>(tmpCur5
);
4147 ss
<<" if(isNan(" <<vSubArguments
[5]->GenSlidingWindowDeclRef();
4148 ss
<<")||(gid0 >="<<tmpCurDVR5
->GetArrayLength()<<"))\n";
4149 ss
<<" fRate = 0;\n else\n";
4153 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
4156 if(tmpCur6
->GetType() == formula::svSingleVectorRef
)
4158 const formula::SingleVectorRefToken
*tmpCurDVR6
= dynamic_cast<const
4159 formula::SingleVectorRefToken
*>(tmpCur6
);
4160 ss
<<" if(isNan(" <<vSubArguments
[6]->GenSlidingWindowDeclRef();
4161 ss
<<")||(gid0 >="<<tmpCurDVR6
->GetArrayLength()<<"))\n";
4162 ss
<<" nBase = 0;\n else\n";
4165 ss
<< " nBase = (int)";
4166 ss
<< vSubArguments
[6]->GenSlidingWindowDeclRef();
4168 ss
<<" uint nPer = convert_int( fPer );\n";
4169 ss
<<" double fUsePer = 1.0 *pow( fRate,-1);\n";
4170 ss
<<" double fAmorCoeff;\n";
4171 ss
<<" if( fUsePer < 3.0 )\n";
4172 ss
<<" fAmorCoeff = 1.0;\n";
4173 ss
<<" else if( fUsePer < 5.0 )\n";
4174 ss
<<" fAmorCoeff = 1.5;\n";
4175 ss
<<" else if( fUsePer <= 6.0 )\n";
4176 ss
<<" fAmorCoeff = 2.0;\n";
4178 ss
<<" fAmorCoeff = 2.5;\n";
4179 ss
<<" fRate *= fAmorCoeff;\n";
4180 ss
<<" tmp = Round( GetYearFrac( 693594,";
4181 ss
<<"nDate, nFirstPer, nBase ) * fRate * fCost);\n";
4182 ss
<<" fCost = fCost-tmp;\n";
4183 ss
<<" double fRest = fCost - fRestVal;\n";
4184 ss
<<" for( uint n = 0 ; n < nPer ; n++ )\n";
4186 ss
<<" tmp = Round( fRate * fCost);\n";
4187 ss
<<" fRest -= tmp;\n";
4188 ss
<<" if( fRest < 0.0 )\n";
4190 ss
<<" switch( nPer - n )\n";
4194 ss
<<" tmp = Round( fCost * 0.5);\n";
4196 ss
<<" tmp = 0.0;\n";
4199 ss
<<" fCost -= tmp;\n";
4201 ss
<<" return tmp;\n";
4204 void OpAmorlinc::BinInlineFun(std::set
<std::string
>& decls
,
4205 std::set
<std::string
>& funs
)
4207 decls
.insert(nKorrValDecl
); decls
.insert(RoundDecl
);
4208 decls
.insert(IsLeapYearDecl
);decls
.insert(DaysInMonthDecl
);
4209 decls
.insert(DaysToDateDecl
); decls
.insert(DateToDaysDecl
);
4210 decls
.insert(GetYearFracDecl
);
4212 funs
.insert(IsLeapYear
);funs
.insert(DaysInMonth
);
4213 funs
.insert(DaysToDate
);funs
.insert(DateToDays
);
4214 funs
.insert(GetYearFrac
);
4216 void OpAmorlinc::GenSlidingWindowFunction(std::stringstream
&ss
,
4217 const std::string sSymName
, SubArguments
&vSubArguments
)
4219 ss
<< "\ndouble " << sSymName
;
4220 ss
<< "_"<< BinFuncName() <<"(";
4221 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4225 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4228 ss
<< " int gid0 = get_global_id(0);\n";
4229 ss
<< " double tmp = 0;\n";
4230 ss
<< " double fCost,fRestVal,fPer,fRate;\n";
4231 ss
<< " int nDate,nFirstPer,nBase;\n";
4233 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
4234 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
4235 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
4236 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
4237 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
4238 FormulaToken
*tmpCur5
= vSubArguments
[5]->GetFormulaToken();
4239 FormulaToken
*tmpCur6
= vSubArguments
[6]->GetFormulaToken();
4242 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
4244 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
4245 formula::SingleVectorRefToken
*>(tmpCur0
);
4246 ss
<<" if(isNan("<<vSubArguments
[0]->GenSlidingWindowDeclRef();
4247 ss
<<")||(gid0 >="<<tmpCurDVR0
->GetArrayLength()<<"))\n";
4248 ss
<<" fCost = 0;\n else\n";
4252 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
4255 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
4257 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
4258 formula::SingleVectorRefToken
*>(tmpCur1
);
4259 ss
<<" if(isNan("<<vSubArguments
[1]->GenSlidingWindowDeclRef();
4260 ss
<<")||(gid0 >="<<tmpCurDVR1
->GetArrayLength()<<"))\n";
4261 ss
<<" nDate = 0;\n else\n";
4264 ss
<< " nDate=(int)";
4265 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
4268 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
4270 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
4271 formula::SingleVectorRefToken
*>(tmpCur2
);
4272 ss
<<" if(isNan("<<vSubArguments
[2]->GenSlidingWindowDeclRef();
4273 ss
<<")||(gid0 >="<<tmpCurDVR2
->GetArrayLength()<<"))\n";
4274 ss
<<" nFirstPer = 0;\n else\n";
4277 ss
<< " nFirstPer=(int)";
4278 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
4281 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
4283 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
4284 formula::SingleVectorRefToken
*>(tmpCur3
);
4285 ss
<<" if(isNan(" <<vSubArguments
[3]->GenSlidingWindowDeclRef();
4286 ss
<<")||(gid0 >="<<tmpCurDVR3
->GetArrayLength()<<"))\n";
4287 ss
<<" fRestVal = 0;\n else\n";
4291 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
4294 if(tmpCur4
->GetType() == formula::svSingleVectorRef
)
4296 const formula::SingleVectorRefToken
*tmpCurDVR4
= dynamic_cast<const
4297 formula::SingleVectorRefToken
*>(tmpCur4
);
4298 ss
<<" if(isNan(" <<vSubArguments
[4]->GenSlidingWindowDeclRef();
4299 ss
<<")||(gid0 >="<<tmpCurDVR4
->GetArrayLength()<<"))\n";
4300 ss
<<" fPer = 0;\n else\n";
4304 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
4307 if(tmpCur5
->GetType() == formula::svSingleVectorRef
)
4309 const formula::SingleVectorRefToken
*tmpCurDVR5
= dynamic_cast<const
4310 formula::SingleVectorRefToken
*>(tmpCur5
);
4311 ss
<<" if(isNan(" <<vSubArguments
[5]->GenSlidingWindowDeclRef();
4312 ss
<<")||(gid0 >="<<tmpCurDVR5
->GetArrayLength()<<"))\n";
4313 ss
<<" fRate = 0;\n else\n";
4317 ss
<< vSubArguments
[5]->GenSlidingWindowDeclRef();
4320 if(tmpCur6
->GetType() == formula::svSingleVectorRef
)
4322 const formula::SingleVectorRefToken
*tmpCurDVR6
= dynamic_cast<const
4323 formula::SingleVectorRefToken
*>(tmpCur6
);
4324 ss
<<" if(isNan(" <<vSubArguments
[6]->GenSlidingWindowDeclRef();
4325 ss
<<")||(gid0 >="<<tmpCurDVR6
->GetArrayLength()<<"))\n";
4326 ss
<<" nBase = 0;\n else\n";
4329 ss
<< " nBase = (int)";
4330 ss
<< vSubArguments
[6]->GenSlidingWindowDeclRef();
4332 ss
<<" int nPer = convert_int( fPer );\n";
4333 ss
<<" double fOneRate = fCost * fRate;\n";
4334 ss
<<" double fCostDelta = fCost - fRestVal;\n";
4335 ss
<<" double f0Rate = GetYearFrac( 693594,";
4336 ss
<<"nDate, nFirstPer, nBase )* fRate * fCost;\n";
4337 ss
<<" int nNumOfFullPeriods = (int)";
4338 ss
<<"( ( fCost - fRestVal - f0Rate) *pow(fOneRate,-1) );\n";
4339 ss
<<" if( nPer == 0 )\n";
4340 ss
<<" tmp = f0Rate;\n";
4341 ss
<<" else if( nPer <= nNumOfFullPeriods )\n";
4342 ss
<<" tmp = fOneRate;\n";
4343 ss
<<" else if( nPer == nNumOfFullPeriods + 1 )\n";
4344 ss
<<" tmp = fCostDelta - fOneRate * nNumOfFullPeriods - f0Rate;\n";
4346 ss
<<" tmp = 0.0;\n";
4347 ss
<<" return tmp;\n";
4350 void OpReceived::BinInlineFun(std::set
<std::string
>& decls
,
4351 std::set
<std::string
>& funs
)
4353 decls
.insert(GetYearDiffDecl
);decls
.insert(GetDiffDateDecl
);
4354 decls
.insert(DaysToDateDecl
);decls
.insert(DaysInMonthDecl
);
4355 decls
.insert(GetNullDateDecl
);decls
.insert(IsLeapYearDecl
);
4356 decls
.insert(DateToDaysDecl
);
4357 funs
.insert(GetDiffDate
);funs
.insert(DaysToDate
);
4358 funs
.insert(DaysInMonth
);funs
.insert(GetNullDate
);
4359 funs
.insert(DateToDays
);funs
.insert(IsLeapYear
);
4360 funs
.insert(GetYearDiff
);
4363 void OpReceived::GenSlidingWindowFunction(std::stringstream
&ss
,
4364 const std::string sSymName
, SubArguments
&vSubArguments
)
4366 ss
<< "\ndouble " << sSymName
;
4367 ss
<< "_"<< BinFuncName() <<"(";
4368 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4372 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4375 ss
<< " double tmp = " << GetBottom() <<";\n";
4376 ss
<< " int gid0 = get_global_id(0);\n";
4377 ss
<< " int nSettle, nMat;\n";
4378 ss
<< " double fInvest,fDisc;\n";
4379 ss
<< " int rOB;\n";
4381 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
4382 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
4383 formula::SingleVectorRefToken
*>(tmpCur0
);
4384 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
4385 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
4386 formula::SingleVectorRefToken
*>(tmpCur1
);
4387 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
4388 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
4389 formula::SingleVectorRefToken
*>(tmpCur2
);
4390 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
4391 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
4392 formula::SingleVectorRefToken
*>(tmpCur3
);
4393 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
4394 const formula::SingleVectorRefToken
*tmpCurDVR4
= dynamic_cast<const
4395 formula::SingleVectorRefToken
*>(tmpCur4
);
4396 ss
<< " int buffer_settle_len = ";
4397 ss
<< tmpCurDVR0
->GetArrayLength();
4399 ss
<< " int buffer_mat_len = ";
4400 ss
<< tmpCurDVR1
->GetArrayLength();
4402 ss
<< " int buffer_invest_len = ";
4403 ss
<< tmpCurDVR2
->GetArrayLength();
4405 ss
<< " int buffer_disc_len = ";
4406 ss
<< tmpCurDVR3
->GetArrayLength();
4408 ss
<< " int buffer_rob_len = ";
4409 ss
<< tmpCurDVR4
->GetArrayLength();
4413 ss
<<" if(gid0 >= buffer_settle_len || isNan(";
4414 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
4416 ss
<<" nSettle = 0;\n\telse\n";
4418 ss
<<" nSettle = (int)"<<vSubArguments
[0]->GenSlidingWindowDeclRef();
4421 ss
<<" if(gid0 >= buffer_mat_len || isNan(";
4422 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
4424 ss
<<" nMat = 0;\n\telse\n";
4426 ss
<<" nMat = (int)";
4427 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
4430 ss
<<" if(gid0 >= buffer_invest_len || isNan(";
4431 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
4433 ss
<<" fInvest = 0;\n\telse\n";
4435 ss
<<" fInvest = "<<vSubArguments
[2]->GenSlidingWindowDeclRef();
4438 ss
<<" if(gid0 >= buffer_disc_len || isNan(";
4439 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
4441 ss
<<" fDisc = 0;\n\telse\n";
4443 ss
<<" fDisc = "<<vSubArguments
[3]->GenSlidingWindowDeclRef();
4446 ss
<<" if(gid0 >= buffer_rob_len || isNan(";
4447 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
4449 ss
<<" rOB = 0;\n\telse\n";
4451 ss
<<" rOB = (int)"<<vSubArguments
[4]->GenSlidingWindowDeclRef();
4453 ss
<< " double tmpvalue = (1.0-(fDisc";
4454 ss
<<" * GetYearDiff( GetNullDate()";
4455 ss
<<",nSettle,nMat,rOB)));\n";
4456 ss
<< " tmp = fInvest*pow(tmpvalue,-1);\n";
4457 ss
<< " return tmp;\n";
4461 void OpYielddisc::BinInlineFun(std::set
<std::string
>& decls
,
4462 std::set
<std::string
>& funs
)
4464 decls
.insert(GetYearFracDecl
);decls
.insert(GetNullDateDecl
);
4465 decls
.insert(DateToDaysDecl
);decls
.insert(DaysToDateDecl
);
4466 decls
.insert(DaysInMonthDecl
);decls
.insert(IsLeapYearDecl
);
4468 funs
.insert(GetYearFrac
);funs
.insert(GetNullDate
);
4469 funs
.insert(DateToDays
);funs
.insert(DaysToDate
);
4470 funs
.insert(DaysInMonth
);funs
.insert(IsLeapYear
);
4472 void OpYielddisc::GenSlidingWindowFunction(
4473 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
4475 ss
<< "\ndouble " << sSymName
;
4476 ss
<< "_"<< BinFuncName() <<"(";
4477 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4481 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4484 ss
<< "double tmp = " <<"0"<<";\n\t";
4485 ss
<< "int gid0 = get_global_id(0);\n\t";
4486 ss
<< "double tmp000;\n\t";
4487 ss
<< "double tmp001;\n\t";
4488 ss
<< "double tmp002;\n\t";
4489 ss
<< "double tmp003;\n\t";
4490 ss
<< "double tmp004;\n\t";
4494 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
4495 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
4496 formula::SingleVectorRefToken
*>(tmpCur0
);
4498 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
4499 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
4500 formula::SingleVectorRefToken
*>(tmpCur1
);
4502 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
4503 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
4504 formula::SingleVectorRefToken
*>(tmpCur2
);
4506 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
4507 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
4508 formula::SingleVectorRefToken
*>(tmpCur3
);
4510 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
4511 const formula::SingleVectorRefToken
*tmpCurDVR4
= dynamic_cast<const
4512 formula::SingleVectorRefToken
*>(tmpCur4
);
4514 ss
<< "int buffer_tmp000_len = ";
4515 ss
<< tmpCurDVR0
->GetArrayLength();
4518 ss
<< "int buffer_tmp001_len = ";
4519 ss
<< tmpCurDVR1
->GetArrayLength();
4522 ss
<< "int buffer_tmp002_len = ";
4523 ss
<< tmpCurDVR2
->GetArrayLength();
4526 ss
<< "int buffer_tmp003_len = ";
4527 ss
<< tmpCurDVR3
->GetArrayLength();
4530 ss
<< "int buffer_tmp004_len = ";
4531 ss
<< tmpCurDVR4
->GetArrayLength();
4537 ss
<<"if(gid0>=buffer_tmp000_len || isNan(";
4538 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
4540 ss
<<"tmp000 = 0;\n\telse \n\t\t";
4543 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
4547 ss
<<"if(gid0>=buffer_tmp001_len || isNan(";
4548 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
4550 ss
<<"tmp001 = 0;\n\telse \n\t\t";
4553 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
4557 ss
<<"if(gid0>=buffer_tmp002_len || isNan(";
4558 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
4560 ss
<<"tmp002 = 0;\n\telse \n\t\t";
4563 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
4567 ss
<<"if(gid0>=buffer_tmp003_len || isNan(";
4568 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
4570 ss
<<"tmp003 = 0;\n\telse \n\t\t";
4573 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
4577 ss
<<"if(gid0>=buffer_tmp004_len || isNan(";
4578 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
4580 ss
<<"tmp004 = 0;\n\telse \n\t\t";
4583 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
4586 ss
<< "tmp = (tmp003/tmp002)-1;\n\t";
4587 ss
<< "tmp /= GetYearFrac( GetNullDate(),tmp000,tmp001,tmp004);\n\t";
4588 ss
<< "return tmp;\n";
4592 void OpTbillprice::BinInlineFun(std::set
<std::string
>& decls
,
4593 std::set
<std::string
>& funs
)
4595 decls
.insert(GetYearFracDecl
);
4596 decls
.insert(DateToDaysDecl
);decls
.insert(DaysToDateDecl
);
4597 decls
.insert(DaysInMonthDecl
);decls
.insert(IsLeapYearDecl
);
4599 funs
.insert(GetYearFrac
);
4600 funs
.insert(DateToDays
);funs
.insert(DaysToDate
);
4601 funs
.insert(DaysInMonth
);funs
.insert(IsLeapYear
);
4604 void OpTbillprice::GenSlidingWindowFunction(
4605 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
4607 ss
<< "\ndouble " << sSymName
;
4608 ss
<< "_"<< BinFuncName() <<"(";
4609 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4613 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4616 ss
<< " int gid0 = get_global_id(0);\n";
4617 ss
<< " double tmp = 0;\n";
4619 ss
<< " int singleIndex = gid0;\n";
4620 ss
<< " int doubleIndex = gid0;\n";
4621 ss
<< " int i = gid0;\n";
4622 GenTmpVariables(ss
,vSubArguments
);
4623 CheckAllSubArgumentIsNan(ss
,vSubArguments
);
4625 ss
<< " tmp1+=1.0;\n";
4626 ss
<< " double fFraction =GetYearFrac(693594,tmp0,tmp1,0);\n";
4627 ss
<< " tmp = 100.0 * ( 1.0 - tmp2 * fFraction );\n";
4628 ss
<< " return tmp;\n";
4631 void RATE::BinInlineFun(std::set
<std::string
>& decls
,
4632 std::set
<std::string
>& funs
)
4634 decls
.insert(approxEqualDecl
);decls
.insert(nKorrValDecl
);
4635 decls
.insert(SCdEpsilonDecl
);decls
.insert(RoundDecl
);
4636 funs
.insert(approxEqual
);funs
.insert(Round
);
4639 void RATE::GenSlidingWindowFunction(
4640 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
4642 ss
<< "\ndouble " << sSymName
;
4643 ss
<< "_"<< BinFuncName() <<"(";
4644 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4648 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4651 FormulaToken
* pCur
= vSubArguments
[5]->GetFormulaToken();
4653 const formula::SingleVectorRefToken
* pSVR
=
4654 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
4657 ss
<< " double result;\n";
4658 ss
<< " int gid0 = get_global_id(0);\n";
4659 ss
<< " bool bValid = true, bFound = false;\n";
4660 ss
<< " double fX, fXnew, fTerm, fTermDerivation;\n";
4661 ss
<< " double fGeoSeries, fGeoSeriesDerivation;\n";
4662 ss
<< " int nIterationsMax = 150;\n";
4663 ss
<< " int nCount = 0;\n";
4664 ss
<< " double fEpsilonSmall = 1.0E-14;\n";
4665 ss
<< " double arg0, arg1, arg2, arg3, arg4, arg5;\n";
4666 ss
<< " arg0=" << vSubArguments
[0]->GenSlidingWindowDeclRef()<<";\n";
4667 ss
<< " arg1=" << vSubArguments
[1]->GenSlidingWindowDeclRef()<<";\n";
4668 ss
<< " arg2=" << vSubArguments
[2]->GenSlidingWindowDeclRef()<<";\n";
4669 ss
<< " arg3=" << vSubArguments
[3]->GenSlidingWindowDeclRef()<<";\n";
4670 ss
<< " arg4=" << vSubArguments
[4]->GenSlidingWindowDeclRef()<<";\n";
4671 ss
<< " arg5=" << vSubArguments
[5]->GenSlidingWindowDeclRef()<<";\n";
4672 ss
<< " int guessLen = " << pSVR
->GetArrayLength() << ";\n";
4674 ss
<< " if (isNan(arg0) || isNan(arg1) || isNan(arg2)){\n";
4675 ss
<< " result = 523;\n";
4676 ss
<< " return result;\n";
4678 ss
<< " if (isNan(arg3))\n";
4679 ss
<< " arg3 = 0.0;\n";
4680 ss
<< " if (isNan(arg4))\n";
4681 ss
<< " arg4 = 0.0;\n";
4682 ss
<< " if (isNan(arg5))\n";
4683 ss
<< " arg5 = 0.1;\n";
4684 ss
<< " if (gid0 >= guessLen)\n";
4685 ss
<< " arg5 = 0.1;\n";
4687 ss
<< " arg3 = arg3 - arg1 * arg4;\n";
4688 ss
<< " arg2 = arg2 + arg1 * arg4;\n";
4689 ss
<< " if (arg0 == Round(arg0)){\n";
4690 ss
<< " fX = arg5;\n";
4691 ss
<< " double fPowN, fPowNminus1;\n";
4692 ss
<< " while (!bFound && nCount < nIterationsMax)\n";
4694 ss
<< " fPowNminus1 = pow( 1.0+fX, arg0-1.0);\n";
4695 ss
<< " fPowN = fPowNminus1 * (1.0+fX);\n";
4696 ss
<< " if (approxEqual( fabs(fX), 0.0))\n";
4698 ss
<< " fGeoSeries = arg0;\n";
4699 ss
<< " fGeoSeriesDerivation = arg0 * (arg0-1.0)";
4700 ss
<< "*pow(2.0,-1);\n";
4704 ss
<< " fGeoSeries = (fPowN-1.0)*pow(fX,-1);\n";
4705 ss
<< " fGeoSeriesDerivation =";
4706 ss
<< " arg0 * fPowNminus1 * pow( fX , -1) - fGeoSeries * pow(fX, -1);\n";
4708 ss
<< " fTerm = arg3 + arg2 *fPowN+ arg1 * fGeoSeries;\n";
4709 ss
<< " fTermDerivation = arg2 * arg0 * fPowNminus1 +";
4710 ss
<< "arg1 * fGeoSeriesDerivation;\n";
4711 ss
<< " if (fabs(fTerm) < fEpsilonSmall)\n";
4712 ss
<< " bFound = true;\n";
4715 ss
<< " if (approxEqual(fabs(fTermDerivation), 0.0))\n";
4716 ss
<< " fXnew = fX + 1.1 * SCdEpsilon;\n";
4718 ss
<< " fXnew = fX - fTerm ";
4719 ss
<< "*pow( fTermDerivation,-1);\n";
4720 ss
<< " nCount++;\n";
4721 ss
<< " bFound = (fabs(fXnew - fX) < SCdEpsilon);\n";
4722 ss
<< " fX = fXnew;\n";
4728 ss
<< " fX = (arg5 < -1.0) ? -1.0 : arg5;\n";
4729 ss
<< " while (bValid && !bFound && nCount < nIterationsMax)\n";
4731 ss
<< " if (approxEqual(fabs(fX), 0.0)){\n";
4732 ss
<< " fGeoSeries = arg0;\n";
4733 ss
<< " fGeoSeriesDerivation = arg0 * ";
4734 ss
<< "(arg0-1.0)* pow(2.0,-1);\n";
4736 ss
<< " fGeoSeries = (pow( 1.0+fX, arg0) - 1.0)";
4737 ss
<< " *pow( fX,-1);\n";
4738 ss
<< " fGeoSeriesDerivation =";
4739 ss
<< " arg0 * pow(1.0+fX,arg0-1.0) *pow(fX,-1)";
4740 ss
<< " - fGeoSeries *pow( fX,-1);\n";
4742 ss
<< " fTerm = arg3 + arg2 *pow(1.0+fX, arg0)";
4743 ss
<< "+ arg1 * fGeoSeries;\n";
4744 ss
<< " fTermDerivation =";
4745 ss
<< "arg2*arg0*pow(1.0+fX,arg0-1.0)";
4746 ss
<< "+arg1*fGeoSeriesDerivation;\n";
4747 ss
<< " if (fabs(fTerm) < fEpsilonSmall)\n";
4748 ss
<< " bFound = true;\n";
4750 ss
<< " if (approxEqual(fabs(fTermDerivation), 0.0))\n";
4751 ss
<< " fXnew = fX + 1.1 * SCdEpsilon;\n";
4753 ss
<< " fXnew = fX - fTerm ";
4754 ss
<< "*pow( fTermDerivation,-1);\n";
4755 ss
<< " nCount++;\n";
4756 ss
<< " bFound = (fabs(fXnew - fX) < SCdEpsilon);\n";
4757 ss
<< " fX = fXnew;\n";
4758 ss
<< " bValid = (fX >= -1.0);\n";
4762 ss
<< " if (bValid && bFound)\n";
4763 ss
<< " result = fX;\n";
4765 ss
<< " result = 523;\n";
4766 ss
<< " return result;\n";
4770 void OpTbillyield::BinInlineFun(std::set
<std::string
>& decls
,
4771 std::set
<std::string
>& funs
)
4773 decls
.insert(GetDiffDate360Decl
);decls
.insert(IsLeapYearDecl
);
4774 decls
.insert(DateToDaysDecl
);decls
.insert(DaysToDate_LocalBarrierDecl
);
4775 decls
.insert(DaysInMonthDecl
);decls
.insert(GetNullDateDecl
);
4776 decls
.insert(GetDiffDate360_Decl
);
4777 funs
.insert(GetDiffDate360
);funs
.insert(DateToDays
);
4778 funs
.insert(DaysToDate_LocalBarrier
);funs
.insert(IsLeapYear
);
4779 funs
.insert(DaysInMonth
);funs
.insert(GetNullDate
);
4780 funs
.insert(GetDiffDate360_
);
4784 void OpTbillyield::GenSlidingWindowFunction(
4785 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
4787 ss
<< "\ndouble " << sSymName
;
4788 ss
<< "_"<< BinFuncName() <<"(";
4789 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4793 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4796 ss
<< "int gid0 = get_global_id(0);\n\t";
4797 ss
<< "double tmp = 0;\n\t";
4798 ss
<< "double tmp000;\n\t";
4799 ss
<< "double tmp001;\n\t";
4800 ss
<< "double tmp002;\n\t";
4805 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
4806 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
4807 formula::SingleVectorRefToken
*>(tmpCur0
);
4809 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
4810 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
4811 formula::SingleVectorRefToken
*>(tmpCur1
);
4813 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
4814 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
4815 formula::SingleVectorRefToken
*>(tmpCur2
);
4817 ss
<< "int buffer_tmp000_len = ";
4818 ss
<< tmpCurDVR0
->GetArrayLength();
4821 ss
<< "int buffer_tmp001_len = ";
4822 ss
<< tmpCurDVR1
->GetArrayLength();
4825 ss
<< "int buffer_tmp002_len = ";
4826 ss
<< tmpCurDVR2
->GetArrayLength();
4831 ss
<<"if(gid0>=buffer_tmp000_len || isNan(";
4832 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
4834 ss
<<"tmp000 = 0;\n\telse \n\t\t";
4837 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
4841 ss
<<"if(gid0>=buffer_tmp001_len || isNan(";
4842 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
4844 ss
<<"tmp001 = 0;\n\telse \n\t\t";
4847 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
4851 ss
<<"if(gid0>=buffer_tmp002_len || isNan(";
4852 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
4854 ss
<<"tmp002 = 0;\n\telse \n\t\t";
4857 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
4859 ss
<<" int nDiff=GetDiffDate360(GetNullDate(),tmp000,tmp001,true);\n";
4861 ss
<<" tmp=100.0;\n";
4862 ss
<<" tmp = tmp *pow( tmp002,-1);\n";
4863 ss
<<" tmp = tmp - 1.0;\n";
4864 ss
<<" tmp = tmp * pow( nDiff,-1.0 );\n";
4865 ss
<<" tmp = tmp * 360.0;\n";
4866 ss
<<" return tmp;\n";
4869 void OpDDB::GenSlidingWindowFunction(std::stringstream
& ss
,
4870 const std::string sSymName
, SubArguments
& vSubArguments
)
4872 ss
<< "\ndouble " << sSymName
;
4873 ss
<< "_"<< BinFuncName() <<"(";
4874 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4878 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4881 ss
<< " int gid0 = get_global_id(0);\n";
4882 ss
<< " double tmp = 0;\n";
4883 ss
<< " double fWert,fRest,fDauer,fPeriode,fFaktor;\n";
4884 ss
<< " double fZins, fAlterWert, fNeuerWert;\n";
4887 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
4888 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
4889 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
4890 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
4891 FormulaToken
* tmpCur4
= vSubArguments
[4]->GetFormulaToken();
4894 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
4896 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
4897 formula::SingleVectorRefToken
*>(tmpCur0
);
4898 ss
<<" if(gid0 >= "<<tmpCurDVR0
->GetArrayLength()<<" || isNan(";
4899 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
4901 ss
<<" fWert = 0;\n else\n";
4904 ss
<<" fWert = "<<vSubArguments
[0]->GenSlidingWindowDeclRef();
4907 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
4909 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
4910 formula::SingleVectorRefToken
*>(tmpCur1
);
4911 ss
<<" if(gid0 >= "<<tmpCurDVR1
->GetArrayLength()<<" || isNan(";
4912 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
4914 ss
<<" fRest = 0;\n else\n";
4918 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
4921 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
4923 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
4924 formula::SingleVectorRefToken
*>(tmpCur2
);
4925 ss
<<" if(gid0 >= "<<tmpCurDVR2
->GetArrayLength()<<" || isNan(";
4926 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
4928 ss
<<" fDauer = 0;\n else\n";
4932 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
4935 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
4937 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
4938 formula::SingleVectorRefToken
*>(tmpCur3
);
4939 ss
<<" if(gid0 >= "<<tmpCurDVR3
->GetArrayLength()<<" || isNan(";
4940 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
4942 ss
<<" fPeriode = 0;\n else\n";
4945 ss
<<" fPeriode = "<<vSubArguments
[3]->GenSlidingWindowDeclRef();
4948 if(tmpCur4
->GetType() == formula::svSingleVectorRef
)
4950 const formula::SingleVectorRefToken
*tmpCurDVR4
= dynamic_cast<const
4951 formula::SingleVectorRefToken
*>(tmpCur4
);
4952 ss
<<" if(gid0 >= "<<tmpCurDVR4
->GetArrayLength()<<" || isNan(";
4953 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
4955 ss
<<" fFaktor = 0;\n else\n";
4958 ss
<<" fFaktor = "<<vSubArguments
[4]->GenSlidingWindowDeclRef();
4960 ss
<<" fZins = fFaktor * pow(fDauer,-1);\n";
4961 ss
<<" if (fZins >= 1.0)\n";
4963 ss
<<" fZins = 1.0;\n";
4964 ss
<<" if (fPeriode == 1.0)\n";
4965 ss
<<" fAlterWert = fWert;\n";
4967 ss
<<" fAlterWert = 0.0;\n";
4970 ss
<<" fAlterWert = fWert * pow(1.0 - fZins, fPeriode - 1);\n";
4971 ss
<<" fNeuerWert = fWert * pow(1.0 - fZins, fPeriode);\n";
4972 ss
<<" if (fNeuerWert < fRest)\n";
4973 ss
<<" tmp = fAlterWert - fRest;\n";
4975 ss
<<" tmp = fAlterWert - fNeuerWert;\n";
4976 ss
<<" if (tmp < 0.0)\n";
4977 ss
<<" tmp = 0.0;\n";
4978 ss
<<" return tmp;\n";
4981 void OpPV::GenSlidingWindowFunction(
4982 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&
4985 ss
<< "\ndouble " << sSymName
;
4986 ss
<< "_"<< BinFuncName() <<"(";
4987 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4991 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4994 ss
<< " double result = " <<"0"<<";\n";
4995 ss
<< " int gid0 = get_global_id(0);\n";
4996 ss
<< " double zins;\n";
4997 ss
<< " double zzr;\n";
4998 ss
<< " double rmz;\n";
4999 ss
<< " double zw;\n";
5000 ss
<< " double flag;\n";
5003 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
5004 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
5005 formula::SingleVectorRefToken
*>(tmpCur0
);
5007 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
5008 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
5009 formula::SingleVectorRefToken
*>(tmpCur1
);
5011 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
5012 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
5013 formula::SingleVectorRefToken
*>(tmpCur2
);
5015 const formula::SingleVectorRefToken
*tmpCurDVR3
;
5016 const formula::SingleVectorRefToken
*tmpCurDVR4
;
5018 if(vSubArguments
.size()>3)
5020 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
5021 tmpCurDVR3
= dynamic_cast<const formula::SingleVectorRefToken
*>(
5023 ss
<< " int buffer_zw_len = ";
5024 ss
<< tmpCurDVR3
->GetArrayLength();
5028 if(vSubArguments
.size()>4)
5030 FormulaToken
*tmpCur4
= vSubArguments
[4]->GetFormulaToken();
5031 tmpCurDVR4
= dynamic_cast<const formula::SingleVectorRefToken
*>(
5033 ss
<< " int buffer_flag_len = ";
5034 ss
<< tmpCurDVR4
->GetArrayLength();
5038 ss
<< " int buffer_zins_len = ";
5039 ss
<< tmpCurDVR0
->GetArrayLength();
5042 ss
<< " int buffer_zzr_len = ";
5043 ss
<< tmpCurDVR1
->GetArrayLength();
5046 ss
<< " int buffer_rmz_len = ";
5047 ss
<< tmpCurDVR2
->GetArrayLength();
5053 ss
<<" if(gid0>=buffer_zins_len || isNan(";
5054 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
5056 ss
<<" zins = 0;\n else \n";
5059 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
5063 ss
<<" if(gid0>=buffer_zzr_len || isNan(";
5064 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
5066 ss
<<" zzr = 0;\n else \n";
5069 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
5073 ss
<<" if(gid0>=buffer_rmz_len || isNan(";
5074 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
5076 ss
<<" rmz = 0;\n else \n";
5079 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef();
5082 if(vSubArguments
.size()>3)
5085 ss
<<" if(gid0>=buffer_zw_len || isNan(";
5086 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
5088 ss
<<" zw = 0;\n else \n";
5091 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
5098 if(vSubArguments
.size()>4)
5101 ss
<<" if(gid0>=buffer_flag_len || isNan(";
5102 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
5104 ss
<<" flag = 0;\n else \n";
5107 ss
<< vSubArguments
[4]->GenSlidingWindowDeclRef();
5113 ss
<< " if(zins == 0)\n";
5114 ss
<< " result=zw+rmz*zzr;\n";
5115 ss
<< " else if(flag > 0)\n";
5116 ss
<< " result=(zw*pow(1+zins,-zzr))+";
5117 ss
<< "(rmz*(1-pow(1+zins,-zzr+1))*pow(zins,-1))+rmz;\n";
5119 ss
<< " result=(zw*pow(1+zins,-zzr))+";
5120 ss
<< "(rmz*(1-pow(1+zins,-zzr))*pow(zins,-1));\n";
5121 ss
<< " return -result;\n";
5124 void OpVDB::BinInlineFun(std::set
<std::string
>& decls
,
5125 std::set
<std::string
>& funs
)
5127 decls
.insert(ScGetGDADecl
);decls
.insert(DblMinDecl
);
5128 decls
.insert(ScInterVDBDecl
);decls
.insert(VDBImplementDecl
);
5129 funs
.insert(ScGetGDA
);funs
.insert(DblMin
);
5130 funs
.insert(ScInterVDB
);funs
.insert(VDBImplement
);
5133 void OpVDB::GenSlidingWindowFunction(
5134 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
5136 ss
<< "\ndouble " << sSymName
;
5137 ss
<< "_"<< BinFuncName() <<"(";
5138 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
5142 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
5145 ss
<< " int gid0 = get_global_id(0);\n";
5146 ss
<< " int singleIndex = gid0;\n";
5147 ss
<< " double result = 0;\n";
5148 if(vSubArguments
.size()<5)
5150 ss
<< " result = -DBL_MAX;\n";
5151 ss
<< " return result;\n";
5154 GenTmpVariables(ss
,vSubArguments
);
5155 CheckAllSubArgumentIsNan(ss
,vSubArguments
);
5156 if(vSubArguments
.size() <= 6)
5158 ss
<< " int tmp6 = 0;\n";
5160 if(vSubArguments
.size() == 5)
5162 ss
<< " double tmp5= 2.0;\n";
5164 ss
<< " if(tmp3 < 0 || tmp4<tmp3 || tmp4>tmp2 || tmp0<0 ||tmp1>tmp0";
5165 ss
<< "|| tmp5 <=0)\n";
5166 ss
<< " result = -DBL_MAX;\n";
5169 ss
<< "VDBImplement(tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);\n";
5170 ss
<< " return result;\n";
5176 void OpXirr::GenSlidingWindowFunction(std::stringstream
&ss
,
5177 const std::string sSymName
, SubArguments
&vSubArguments
)
5179 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
5180 const formula::DoubleVectorRefToken
*pCurDVR
= dynamic_cast<const
5181 formula::DoubleVectorRefToken
*>(tmpCur
);
5182 size_t nCurWindowSize
= pCurDVR
->GetArrayLength() <
5183 pCurDVR
->GetRefRowSize() ? pCurDVR
->GetArrayLength():
5184 pCurDVR
->GetRefRowSize() ;
5185 ss
<< "\ndouble " << sSymName
;
5186 ss
<< "_"<< BinFuncName() <<"(";
5187 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
5191 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
5194 ss
<< " int gid0 = get_global_id(0);\n";
5195 ss
<< " int doubleIndex = gid0;\n";
5196 ss
<< " int singleIndex = gid0;\n";
5197 ss
<< " double result = 0;\n";
5198 ss
<< " int i=0;\n";
5199 if(vSubArguments
.size()<2)
5201 ss
<< " result = -DBL_MAX;\n";
5202 ss
<< " return result;\n";
5205 GenTmpVariables(ss
,vSubArguments
);
5206 if(vSubArguments
.size() == 2)
5208 ss
<< " double tmp2 = 0.1;\n";
5211 CheckSubArgumentIsNan(ss
,vSubArguments
,2);
5213 ss
<< " if(tmp2<=-1)\n";
5214 ss
<< " result = -DBL_MAX;\n";
5217 ss
<< " double fMaxEps = 1e-10;\n";
5218 ss
<< " int nMaxIter = 50;\n";
5219 ss
<< " double fNewRate, fRateEps, fResultValue, fResultValue2;\n";
5220 ss
<< " int nIter = 0;\n";
5221 ss
<< " int bContLoop;\n";
5222 ss
<< " int windowsSize = ";
5223 ss
<< nCurWindowSize
;
5225 CheckSubArgumentIsNan(ss
,vSubArguments
,0);
5226 CheckSubArgumentIsNan(ss
,vSubArguments
,1);
5227 ss
<< " double D_0 = tmp1;\n";
5228 ss
<< " double V_0 = tmp0;\n";
5229 ss
<< " double fResultRate = tmp2;\n";
5230 ss
<< " double r;\n";
5231 ss
<< " double fResult;\n";
5234 ss
<< " fResultValue = V_0;\n";
5235 ss
<< " r = fResultRate + 1;\n";
5237 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed()) {
5238 ss
<< "gid0+1; i < "<< nCurWindowSize
<<"; i++)\n";
5239 } else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed()) {
5240 ss
<< "1; i < gid0+"<< nCurWindowSize
<<"; i++)\n";
5242 ss
<< "1; i < "<< nCurWindowSize
<<"; i++)\n";
5245 if(!pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
5247 ss
<< " doubleIndex =i+gid0;\n";
5250 ss
<< " doubleIndex =i;\n";
5252 CheckSubArgumentIsNan(ss
,vSubArguments
,0);
5253 CheckSubArgumentIsNan(ss
,vSubArguments
,1);
5254 ss
<< " fResultValue += tmp0/pow(r,(tmp1 - D_0)/365.0);\n";
5256 ss
<< " fResultValue2 = 0;\n";
5259 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed()) {
5260 ss
<< "gid0+1; i < "<< nCurWindowSize
<<"; i++)\n";
5261 } else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed()) {
5262 ss
<< "1; i < gid0+"<< nCurWindowSize
<<"; i++)\n";
5264 ss
<< "1; i < "<< nCurWindowSize
<<"; i++)\n";
5267 if(!pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
5269 ss
<< " doubleIndex =i+gid0;\n";
5272 ss
<< " doubleIndex =i;\n";
5274 CheckSubArgumentIsNan(ss
,vSubArguments
,0);
5275 CheckSubArgumentIsNan(ss
,vSubArguments
,1);
5276 ss
<< " double E_i = (tmp1 - D_0)/365.0;\n";
5277 ss
<< " fResultValue2 -= E_i * tmp0 / pow(r,E_i + 1.0);\n";
5279 ss
<< " fNewRate = fResultRate - fResultValue / fResultValue2;\n";
5280 ss
<< " fRateEps = fabs( fNewRate - fResultRate );\n";
5281 ss
<< " fResultRate = fNewRate;\n";
5282 ss
<< " bContLoop = (fRateEps > fMaxEps) && (fabs( fResultValue ) > fMaxEps);\n";
5284 ss
<< " while( bContLoop && (++nIter < nMaxIter) );\n";
5285 ss
<< " if( bContLoop )\n";
5286 ss
<< " result = -DBL_MAX;\n";
5287 ss
<< " result = fResultRate;\n";
5289 ss
<< " return result;\n";
5294 void OpDB::GenSlidingWindowFunction(std::stringstream
& ss
,
5295 const std::string sSymName
, SubArguments
& vSubArguments
)
5297 ss
<< "\ndouble " << sSymName
;
5298 ss
<< "_"<< BinFuncName() <<"(";
5299 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
5303 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
5306 ss
<< " int gid0 = get_global_id(0);\n";
5307 ss
<< " double nWert,nRest,nDauer,nPeriode;\n";
5308 ss
<< " int nMonate;\n";
5309 ss
<< " double tmp = 0;\n";
5311 FormulaToken
* tmpCur0
= vSubArguments
[0]->GetFormulaToken();
5312 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
5313 formula::SingleVectorRefToken
*>(tmpCur0
);
5314 FormulaToken
* tmpCur1
= vSubArguments
[1]->GetFormulaToken();
5315 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
5316 formula::SingleVectorRefToken
*>(tmpCur1
);
5317 FormulaToken
* tmpCur2
= vSubArguments
[2]->GetFormulaToken();
5318 const formula::SingleVectorRefToken
*tmpCurDVR2
= dynamic_cast<const
5319 formula::SingleVectorRefToken
*>(tmpCur2
);
5320 FormulaToken
* tmpCur3
= vSubArguments
[3]->GetFormulaToken();
5321 const formula::SingleVectorRefToken
*tmpCurDVR3
= dynamic_cast<const
5322 formula::SingleVectorRefToken
*>(tmpCur3
);
5323 FormulaToken
* tmpCur4
= vSubArguments
[4]->GetFormulaToken();
5324 const formula::SingleVectorRefToken
*tmpCurDVR4
= dynamic_cast<const
5325 formula::SingleVectorRefToken
*>(tmpCur4
);
5326 ss
<< " int buffer_wert_len = ";
5327 ss
<< tmpCurDVR0
->GetArrayLength();
5329 ss
<< " int buffer_rest_len = ";
5330 ss
<< tmpCurDVR1
->GetArrayLength();
5332 ss
<< " int buffer_dauer_len = ";
5333 ss
<< tmpCurDVR2
->GetArrayLength();
5335 ss
<< " int buffer_periode_len = ";
5336 ss
<< tmpCurDVR3
->GetArrayLength();
5338 ss
<< " int buffer_nMonate_len = ";
5339 ss
<< tmpCurDVR4
->GetArrayLength();
5343 ss
<<" if(gid0 >= buffer_wert_len || isNan(";
5344 ss
<<vSubArguments
[0]->GenSlidingWindowDeclRef();
5346 ss
<<" nWert = 0;\n else\n";
5348 ss
<<" nWert = "<<vSubArguments
[0]->GenSlidingWindowDeclRef();
5351 ss
<<" if(gid0 >= buffer_rest_len || isNan(";
5352 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
5354 ss
<<" nRest = 0;\n else\n";
5357 ss
<<vSubArguments
[1]->GenSlidingWindowDeclRef();
5360 ss
<<" if(gid0 >= buffer_dauer_len || isNan(";
5361 ss
<<vSubArguments
[2]->GenSlidingWindowDeclRef();
5363 ss
<<" nDauer = 0;\n else\n";
5365 ss
<<" nDauer = "<<vSubArguments
[2]->GenSlidingWindowDeclRef();
5368 ss
<<" if(gid0 >= buffer_periode_len || isNan(";
5369 ss
<<vSubArguments
[3]->GenSlidingWindowDeclRef();
5371 ss
<<" nPeriode = 0;\n else\n";
5373 ss
<<" nPeriode = "<<vSubArguments
[3]->GenSlidingWindowDeclRef();
5376 ss
<<" if(gid0 >= buffer_nMonate_len || isNan(";
5377 ss
<<vSubArguments
[4]->GenSlidingWindowDeclRef();
5379 ss
<<" nMonate = 0;\n else\n";
5381 ss
<<" nMonate = (int)"<<vSubArguments
[4]->GenSlidingWindowDeclRef();
5383 ss
<<" double nAbRate = 1.0 - pow(nRest / nWert, 1.0 / nDauer);\n";
5384 ss
<<" nAbRate = ((int)(nAbRate * 1000.0 + 0.5)) / 1000.0;\n";
5385 ss
<<" double nErsteAbRate = nWert * nAbRate * nMonate / 12.0;\n";
5386 ss
<<" double nGda2 = 0.0;\n";
5387 ss
<<" if ((int)(nPeriode) == 1)\n";
5388 ss
<<" nGda2 = nErsteAbRate;\n";
5391 ss
<<" double nSummAbRate = nErsteAbRate;\n";
5392 ss
<<" double nMin = nDauer;\n";
5393 ss
<<" if (nMin > nPeriode) nMin = nPeriode;\n";
5394 ss
<<" int iMax = (int)nMin;\n";
5395 ss
<<" for (int i = 2; i <= iMax; i++)\n";
5397 ss
<<" nGda2 = (nWert - nSummAbRate) * nAbRate;\n";
5398 ss
<<" nSummAbRate += nGda2;\n";
5400 ss
<<" if (nPeriode > nDauer)\n";
5401 ss
<<" nGda2 = ((nWert - nSummAbRate)";
5402 ss
<<"* nAbRate * (12.0 - nMonate)) / 12.0;\n";
5404 ss
<<" tmp = nGda2;\n";
5405 ss
<<" return tmp;\n";
5410 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */