update emoji autocorrect entries from po-files
[LibreOffice.git] / sc / source / core / opencl / op_financial.cxx
blob2e3c59fb62918860460bb0b1894a58dc225f380d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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>
19 #include <sstream>
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++)
34 if (i)
35 ss << ",";
36 vSubArguments[i]->GenSlidingWindowDecl(ss);
38 ss << ") {\n";
39 ss << " double tmp = " << GetBottom() <<";\n";
40 ss << " int gid0 = get_global_id(0);\n";
41 ss << " double fv;\n";
42 ss << " double pv;\n";
43 ss << " double nper;\n";
44 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
45 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
46 formula::SingleVectorRefToken *>(tmpCur0);
48 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
49 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
50 formula::SingleVectorRefToken *>(tmpCur1);
52 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
53 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
54 formula::SingleVectorRefToken *>(tmpCur2);
56 ss<< " int buffer_nper_len = ";
57 ss<< tmpCurDVR0->GetArrayLength();
58 ss << ";\n";
60 ss<< " int buffer_pv_len = ";
61 ss<< tmpCurDVR1->GetArrayLength();
62 ss << ";\n";
64 ss<< " int buffer_fv_len = ";
65 ss<< tmpCurDVR2->GetArrayLength();
66 ss << ";\n";
68 ss<<" if(gid0>=buffer_nper_len || isNan(";
69 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
70 ss<<"))\n";
71 ss<<" nper = 0;\n\telse \n";
72 ss<<" nper = ";
73 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
74 ss<<";\n";
76 ss<<" if(gid0>=buffer_pv_len || isNan(";
77 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
78 ss<<"))\n";
79 ss<<" pv = 0;\n\telse \n";
80 ss<<" pv = ";
81 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
82 ss<<";\n";
84 ss<<" if(gid0>=buffer_pv_len || isNan(";
85 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
86 ss<<"))\n";
87 ss<<" fv = 0;\n\telse \n";
88 ss<<" fv = ";
89 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
90 ss<<";\n";
91 ss << " tmp = pow(fv*pow(pv,-1),1.0*pow(nper,-1))-1;\n";
92 ss << " return tmp;\n";
93 ss << "}";
96 void OpNominal::GenSlidingWindowFunction(
97 std::stringstream &ss, const std::string &sSymName, SubArguments &
98 vSubArguments)
100 ss << "\ndouble " << sSymName;
101 ss << "_"<< BinFuncName() <<"(";
102 for (unsigned i = 0; i < vSubArguments.size(); i++)
104 if (i)
105 ss << ",";
106 vSubArguments[i]->GenSlidingWindowDecl(ss);
108 ss << ") {\n\t";
109 ss << "double tmp = 0;\n\t";
110 ss << "double temp = 0;\n\t";
111 ss << "int gid0 = get_global_id(0);\n\t";
112 ss << "double tmp0=0,tmp1=0;\n";
113 for (unsigned i = 0; i < vSubArguments.size(); i++)
115 FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
116 assert(pCur);
117 if (pCur->GetType() == formula::svSingleVectorRef)
119 const formula::SingleVectorRefToken* pSVR =
120 static_cast< const formula::SingleVectorRefToken* >(pCur);
121 ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
123 else if (pCur->GetType() == formula::svDouble)
125 ss << "{\n";
127 else
130 if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
132 ss <<" temp="<<vSubArguments[i]->GenSlidingWindowDeclRef();
133 ss <<";\n";
134 ss <<" if (isNan(temp))\n";
135 ss <<" tmp"<<i<<"= 0;\n";
136 ss <<" else\n";
137 ss <<" tmp"<<i<<"=temp;\n";
138 ss <<" }\n";
140 else
142 ss <<" tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(
144 ss <<";\n";
147 ss<<"if(tmp1==0)\n\t";
148 ss<<"\treturn 0;\n\t";
149 ss<<"tmp=pow( tmp1,-1);\n\t";
150 ss<<"tmp=( pow( tmp0+ 1.0, tmp ) - 1.0 ) *";
151 ss<<"tmp1;\n\t";
152 ss << "return tmp;\n";
153 ss << "}";
156 void OpDollarde::GenSlidingWindowFunction(
157 std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
159 ss << "\ndouble " << sSymName;
160 ss << "_"<< BinFuncName() <<"(";
161 for (unsigned i = 0; i < vSubArguments.size(); i++)
163 if (i)
164 ss << ",";
165 vSubArguments[i]->GenSlidingWindowDecl(ss);
167 ss << ") {\n\t";
168 ss << "double tmp = " << GetBottom() <<";\n\t";
169 ss << "int gid0 = get_global_id(0);\n\t";
170 ss << "double fInt = " << GetBottom() <<";\n\t";
171 ss << "double dollar;\n\t";
172 ss << "double fFrac;\n\t";
173 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
174 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
175 formula::SingleVectorRefToken *>(tmpCur0);
176 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
177 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
178 formula::SingleVectorRefToken *>(tmpCur1);
179 ss<< "int buffer_dollar_len = ";
180 ss<< tmpCurDVR0->GetArrayLength();
181 ss << ";\n\t";
182 ss<< "int buffer_frac_len = ";
183 ss<< tmpCurDVR1->GetArrayLength();
184 ss << ";\n\t";
185 ss<<"if((gid0)>=buffer_dollar_len || isNan(";
186 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
187 ss<<"))\n\t\t";
188 ss<<"dollar = 0;\n\telse \n\t\t";
189 ss<<"dollar = ";
190 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
191 ss<<";\n\t";
192 ss<<"if((gid0)>=buffer_frac_len || isNan(";
193 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
194 ss<<"))\n\t\t";
195 ss<<"fFrac = 0;\n\telse \n\t\t";
196 ss<<"fFrac = ";
197 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
198 ss<<";\n\t";
199 ss << "tmp = modf( dollar , &fInt );\n\t";
200 ss << "tmp /= fFrac;\n\t";
201 ss << "tmp *= pow( 10.0 , ceil( log10(fFrac ) ) );\n\t";
202 ss << "tmp += fInt;\t";
203 ss << "\n\treturn tmp;\n";
204 ss << "}";
207 void OpDollarfr::GenSlidingWindowFunction(std::stringstream &ss,
208 const std::string &sSymName, SubArguments &vSubArguments)
210 ss << "\ndouble " << sSymName;
211 ss << "_"<< BinFuncName() <<"(";
212 for (unsigned i = 0; i < vSubArguments.size(); i++)
214 if (i)
215 ss << ",";
216 vSubArguments[i]->GenSlidingWindowDecl(ss);
218 ss << ") {\n\t";
219 ss << "double tmp = " << GetBottom() <<";\n\t";
220 ss << "int gid0 = get_global_id(0);\n\t";
221 ss << "double fInt = " << GetBottom() <<";\n\t";
222 ss << "double dollar;\n\t";
223 ss << "double fFrac;\n\t";
224 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
225 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
226 formula::SingleVectorRefToken *>(tmpCur0);
227 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
228 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
229 formula::SingleVectorRefToken *>(tmpCur1);
230 ss<< "int buffer_dollar_len = ";
231 ss<< tmpCurDVR0->GetArrayLength();
232 ss << ";\n\t";
233 ss<< "int buffer_frac_len = ";
234 ss<< tmpCurDVR1->GetArrayLength();
235 ss << ";\n\t";
236 ss<<"if((gid0)>=buffer_dollar_len || isNan(";
237 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
238 ss<<"))\n\t\t";
239 ss<<"dollar = 0;\n\telse \n\t\t";
240 ss<<"dollar = ";
241 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
242 ss<<";\n\t";
243 ss<<"if((gid0)>=buffer_frac_len || isNan(";
244 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
245 ss<<"))\n\t\t";
246 ss<<"fFrac = 0;\n\telse \n\t\t";
247 ss<<"fFrac = ";
248 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
249 ss<<";\n\t";
250 ss << "tmp = modf( dollar , &fInt );\n\t";
251 ss << "tmp *= fFrac;\n\t";
252 ss << "tmp *= pow( 10.0 , -ceil( log10(fFrac ) ) );\n\t";
253 ss << "tmp += fInt;\t";
254 ss << "\n\treturn tmp;\n";
255 ss << "}";
258 void OpDISC::BinInlineFun(std::set<std::string>& decls,
259 std::set<std::string>& funs)
261 decls.insert(GetYearFrac_newDecl);decls.insert(DaysToDate_newDecl);
262 decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
263 funs.insert(GetYearFrac_new);funs.insert(DaysToDate_new);
264 funs.insert(DaysInMonth);funs.insert(IsLeapYear);
267 void OpDISC::GenSlidingWindowFunction(std::stringstream& ss,
268 const std::string &sSymName, SubArguments& vSubArguments)
270 ss << "\ndouble " << sSymName;
271 ss << "_" << BinFuncName() << "(";
272 for (unsigned i = 0; i < vSubArguments.size(); i++)
274 if (i)
275 ss << ",";
276 vSubArguments[i]->GenSlidingWindowDecl(ss);
278 ss << ") {\n\t";
279 ss << " double tmp = " << GetBottom() << ";\n";
280 ss << " int gid0 = get_global_id(0);\n";
281 ss << " double arg0 = " << GetBottom() << ";\n";
282 ss << " double arg1 = " << GetBottom() << ";\n";
283 ss << " double arg2 = " << GetBottom() << ";\n";
284 ss << " double arg3 = " << GetBottom() << ";\n";
285 ss << " double arg4 = " << GetBottom() << ";\n";
286 for (unsigned i = 0; i < vSubArguments.size(); i++)
288 FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
289 assert(pCur);
290 if (pCur->GetType() == formula::svSingleVectorRef)
292 const formula::SingleVectorRefToken* pSVR =
293 static_cast< const formula::SingleVectorRefToken* >(pCur);
294 ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
296 else if (pCur->GetType() == formula::svDouble)
298 ss << " {\n";
300 if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
302 ss << " if (isNan(";
303 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
304 ss << "))\n";
305 ss << " arg" << i << " = 0;\n";
306 ss << " else\n";
307 ss << " arg" << i << " = ";
308 ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
309 ss << " }\n";
311 else
313 ss << " arg" << i << " = ";
314 ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
317 ss << " int nNullDate = 693594;\n";
318 ss << " tmp = 1.0 - arg2 / arg3;\n";
319 ss << " tmp /=";
320 ss << " GetYearFrac_new(nNullDate, (int)arg0, (int)arg1, (int)arg4);\n";
321 ss << " return tmp;\n";
322 ss << "}";
325 void OpINTRATE::BinInlineFun(std::set<std::string>& decls,
326 std::set<std::string>& funs)
328 decls.insert(GetYearDiff_newDecl);decls.insert(GetDiffDate_newDecl);
329 decls.insert(DaysToDate_newDecl);decls.insert(GetNullDateDecl);
330 decls.insert(DateToDaysDecl);decls.insert(DaysInMonthDecl);
331 decls.insert(IsLeapYearDecl);
332 funs.insert(GetYearDiff_new);funs.insert(GetDiffDate_new);
333 funs.insert(DaysToDate_new);funs.insert(GetNullDate);
334 funs.insert(DateToDays);funs.insert(DaysInMonth);
335 funs.insert(IsLeapYear);
338 void OpINTRATE::GenSlidingWindowFunction(std::stringstream& ss,
339 const std::string &sSymName, SubArguments& vSubArguments)
341 ss << "\ndouble " << sSymName;
342 ss << "_" << BinFuncName() << "(";
343 for (unsigned i = 0; i < vSubArguments.size(); i++)
345 if (i)
346 ss << ",";
347 vSubArguments[i]->GenSlidingWindowDecl(ss);
349 ss << ") {\n";
350 ss << " double tmp = " << GetBottom() << ";\n";
351 ss << " int gid0 = get_global_id(0);\n";
352 ss << " double arg0 = " << GetBottom() << ";\n";
353 ss << " double arg1 = " << GetBottom() << ";\n";
354 ss << " double arg2 = " << GetBottom() << ";\n";
355 ss << " double arg3 = " << GetBottom() << ";\n";
356 ss << " double arg4 = " << GetBottom() << ";\n";
357 for (unsigned i = 0; i < vSubArguments.size(); i++)
359 FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
360 assert(pCur);
361 if (pCur->GetType() == formula::svSingleVectorRef)
363 const formula::SingleVectorRefToken* pSVR =
364 static_cast< const formula::SingleVectorRefToken* >(pCur);
365 ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
367 else if (pCur->GetType() == formula::svDouble)
369 ss << " {\n";
371 if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
373 ss << " if (isNan(";
374 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
375 ss << "))\n";
376 ss << " arg" << i << " = 0;\n";
377 ss << " else\n";
378 ss << " arg" << i << " = ";
379 ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
380 ss << " }\n";
382 else
384 ss << " arg" << i << " = ";
385 ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
388 ss << " int nNullDate = GetNullDate();\n";
389 ss << " tmp = arg3 * pow(arg2,-1) - 1.0;\n";
390 ss << " tmp = tmp * pow(GetYearDiff_new(nNullDate, (int)arg0,";
391 ss << " (int)arg1,(int)arg4),-1);\n";
392 ss << " return tmp;\n";
393 ss << "}";
396 void OpFV::BinInlineFun(std::set<std::string>& decls,
397 std::set<std::string>& funs)
399 decls.insert(GetZwDecl);
400 funs.insert(GetZw);
403 void OpFV::GenSlidingWindowFunction(std::stringstream& ss,
404 const std::string &sSymName, SubArguments& vSubArguments)
406 ss << "\ndouble " << sSymName;
407 ss << "_"<< BinFuncName() <<"(";
408 for (unsigned i = 0; i < vSubArguments.size(); i++)
410 if (i)
411 ss << ",";
412 vSubArguments[i]->GenSlidingWindowDecl(ss);
414 ss << ") {\n";
415 ss << " double tmp = " << GetBottom() << ";\n";
416 ss << " int gid0 = get_global_id(0);\n";
417 ss << " double arg0 = " << GetBottom() << ";\n";
418 ss << " double arg1 = " << GetBottom() << ";\n";
419 ss << " double arg2 = " << GetBottom() << ";\n";
420 ss << " double arg3 = " << GetBottom() << ";\n";
421 ss << " double arg4 = " << GetBottom() << ";\n";
422 unsigned j = vSubArguments.size();
423 while (j--)
425 FormulaToken* pCur = vSubArguments[j]->GetFormulaToken();
426 assert(pCur);
427 if(pCur->GetType() == formula::svSingleVectorRef)
429 const formula::SingleVectorRefToken* pSVR =
430 static_cast< const formula::SingleVectorRefToken* >(pCur);
431 ss << " if(gid0 >= " << pSVR->GetArrayLength() << " || isNan(";
432 ss << vSubArguments[j]->GenSlidingWindowDeclRef();
433 ss << "))\n";
434 ss << " arg" << j << " = " <<GetBottom() << ";\n";
435 ss << " else\n";
436 ss << " arg" << j << " = ";
437 ss << vSubArguments[j]->GenSlidingWindowDeclRef();
438 ss << ";\n";
441 ss << " tmp = GetZw(arg0, arg1, arg2, arg3, arg4);\n";
442 ss << " return tmp;\n";
443 ss << "}";
446 void OpIPMT::BinInlineFun(std::set<std::string>& decls,
447 std::set<std::string>& funs)
449 decls.insert(GetZwDecl);
450 funs.insert(GetZw);
453 void OpIPMT::GenSlidingWindowFunction(std::stringstream& ss,
454 const std::string &sSymName, SubArguments& vSubArguments)
456 ss << "\ndouble " << sSymName;
457 ss << "_"<< BinFuncName() <<"(";
458 for (unsigned i = 0; i < vSubArguments.size(); i++)
460 if (i)
461 ss << ",";
462 vSubArguments[i]->GenSlidingWindowDecl(ss);
464 ss << ") {\n";
465 ss << " double tmp = " << GetBottom() << ";\n";
466 ss << " int gid0 = get_global_id(0);\n";
467 ss << " double arg0 = " << GetBottom() << ";\n";
468 ss << " double arg1 = " << GetBottom() << ";\n";
469 ss << " double arg2 = " << GetBottom() << ";\n";
470 ss << " double arg3 = " << GetBottom() << ";\n";
471 ss << " double arg4 = " << GetBottom() << ";\n";
472 ss << " double arg5 = " << GetBottom() << ";\n";
473 unsigned j = vSubArguments.size();
474 while (j--)
476 FormulaToken* pCur = vSubArguments[j]->GetFormulaToken();
477 assert(pCur);
478 if(pCur->GetType() == formula::svSingleVectorRef)
480 const formula::SingleVectorRefToken* pSVR =
481 static_cast< const formula::SingleVectorRefToken* >(pCur);
482 ss << " if(gid0 >= " << pSVR->GetArrayLength() << " || isNan(";
483 ss << vSubArguments[j]->GenSlidingWindowDeclRef();
484 ss << "))\n";
485 ss << " arg" << j << " = " <<GetBottom() << ";\n";
486 ss << " else\n";
487 ss << " arg" << j << " = ";
488 ss << vSubArguments[j]->GenSlidingWindowDeclRef();
489 ss << ";\n";
492 ss << " double pmt ;\n";
493 ss << " if(arg0 == 0.0)\n";
494 ss << " return 0;\n";
495 ss << " double temp1 = 0;\n";
496 ss << " double abl = pow(1.0 + arg0, arg2);\n";
497 ss << " temp1 -= arg4;\n";
498 ss << " temp1 -= arg3 * abl;\n";
499 ss << " pmt = temp1 / (1.0 + arg0 * arg5) /";
500 ss << " ( (abl - 1.0) / arg0);\n";
501 ss << " double temp = pow( 1 + arg0, arg1 - 2);\n";
502 ss << " if(arg1 == 1.0)\n";
503 ss << " {\n";
504 ss << " if(arg5 > 0.0)\n";
505 ss << " tmp = 0.0;\n";
506 ss << " else\n";
507 ss << " tmp = -arg3;\n";
508 ss << " }\n";
509 ss << " else\n";
510 ss << " {\n";
511 ss << " if(arg5 > 0.0)\n";
512 ss << " tmp = GetZw(arg0, arg1 - 2.0, pmt, arg3, 1.0)";
513 ss << " - pmt;\n";
514 ss << " else\n";
515 ss << " tmp = GetZw(arg0, arg1 - 1.0, pmt, arg3, 0.0);\n";
516 ss << " }\n";
517 ss << " tmp = tmp * arg0;\n";
518 ss << " return tmp;\n";
519 ss << "}";
521 void OpISPMT::GenSlidingWindowFunction(std::stringstream& ss,
522 const std::string &sSymName, SubArguments& vSubArguments)
524 ss << "\ndouble " << sSymName;
525 ss << "_" << BinFuncName() <<"(";
526 for (unsigned i = 0; i < vSubArguments.size(); i++)
528 if (i)
529 ss << ",";
530 vSubArguments[i]->GenSlidingWindowDecl(ss);
532 ss << ") {\n";
533 ss << " double tmp = " << GetBottom() << ";\n";
534 ss << " int gid0 = get_global_id(0);\n";
535 ss << " double arg0 = " << GetBottom() << ";\n";
536 ss << " double arg1 = " << GetBottom() << ";\n";
537 ss << " double arg2 = " << GetBottom() << ";\n";
538 ss << " double arg3 = " << GetBottom() << ";\n";
539 for (unsigned i = 0; i < vSubArguments.size(); i++)
541 FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
542 assert(pCur);
543 if (pCur->GetType() == formula::svSingleVectorRef)
545 const formula::SingleVectorRefToken* pSVR =
546 static_cast< const formula::SingleVectorRefToken* >(pCur);
547 ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
549 else if (pCur->GetType() == formula::svDouble)
551 ss << " {\n";
553 if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
555 ss << " if (isNan(";
556 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
557 ss << "))\n";
558 ss << " arg" << i << " = 0;\n";
559 ss << " else\n";
560 ss << " arg" << i << " = ";
561 ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
562 ss << " }\n";
564 else
566 ss << " arg" << i << " = ";
567 ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
570 ss << " tmp = arg3 * arg0 * ( arg1 - arg2) * pow(arg2, -1);\n";
571 ss << " return tmp;\n";
572 ss << "}";
575 void OpDuration::GenSlidingWindowFunction(std::stringstream& ss,
576 const std::string &sSymName, SubArguments& vSubArguments)
578 ss << "\ndouble " << sSymName;
579 ss << "_" << BinFuncName() <<"(";
580 for (unsigned i = 0; i < vSubArguments.size(); i++)
582 if (i)
583 ss << ",";
584 vSubArguments[i]->GenSlidingWindowDecl(ss);
586 ss << ") {\n";
587 ss << " double tmp = " << GetBottom() << ";\n";
588 ss << " int gid0 = get_global_id(0);\n";
589 ss << " double arg0 = " << GetBottom() << ";\n";
590 ss << " double arg1 = " << GetBottom() << ";\n";
591 ss << " double arg2 = " << GetBottom() << ";\n";
592 for (unsigned i = 0; i < vSubArguments.size(); i++)
594 FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
595 assert(pCur);
596 if (pCur->GetType() == formula::svSingleVectorRef)
598 const formula::SingleVectorRefToken* pSVR =
599 static_cast< const formula::SingleVectorRefToken* >(pCur);
600 ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
602 else if (pCur->GetType() == formula::svDouble)
604 ss << " {\n";
606 if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
608 ss << " if (isNan(";
609 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
610 ss << "))\n";
611 ss << " arg" << i << " = 0;\n";
612 ss << " else\n";
613 ss << " arg" << i << " = ";
614 ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
615 ss << " }\n";
617 else
619 ss << " arg" << i << " = ";
620 ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
623 ss << " tmp = log(arg2 * pow( arg1,-1)) / log(arg0 + 1.0);\n";
624 ss << " return tmp;\n";
625 ss << "}";
628 void OpDuration_ADD::BinInlineFun(std::set<std::string>& decls,
629 std::set<std::string>& funs)
631 decls.insert(GetDurationDecl);decls.insert(lcl_GetcoupnumDecl);
632 decls.insert(GetYearFracDecl);decls.insert(DaysToDateDecl);
633 decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
634 decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
635 funs.insert(GetDuration);funs.insert(lcl_Getcoupnum);
636 funs.insert(GetYearFrac);funs.insert(DaysToDate);
637 funs.insert(GetNullDate);funs.insert(DateToDays);
638 funs.insert(DaysInMonth);funs.insert(IsLeapYear);
641 void OpDuration_ADD::GenSlidingWindowFunction(std::stringstream& ss,
642 const std::string &sSymName, SubArguments& vSubArguments)
644 ss << "\ndouble " << sSymName;
645 ss << "_"<< BinFuncName() <<"(";
646 for (unsigned i = 0; i < vSubArguments.size(); i++)
648 if (i)
649 ss << ",";
650 vSubArguments[i]->GenSlidingWindowDecl(ss);
652 ss << ") {\n";
653 ss << " double tmp = " << GetBottom() << ";\n";
654 ss << " int gid0 = get_global_id(0);\n";
655 ss << " double arg0 = " << GetBottom() << ";\n";
656 ss << " double arg1 = " << GetBottom() << ";\n";
657 ss << " double arg2 = " << GetBottom() << ";\n";
658 ss << " double arg3 = " << GetBottom() << ";\n";
659 ss << " double arg4 = " << GetBottom() << ";\n";
660 ss << " double arg5 = " << GetBottom() << ";\n";
661 unsigned j = vSubArguments.size();
662 while (j--)
664 FormulaToken* pCur = vSubArguments[j]->GetFormulaToken();
665 assert(pCur);
666 if(pCur->GetType() == formula::svSingleVectorRef)
668 const formula::SingleVectorRefToken* pSVR =
669 static_cast< const formula::SingleVectorRefToken* >(pCur);
670 ss << " if(gid0 >= " << pSVR->GetArrayLength() << " || isNan(";
671 ss << vSubArguments[j]->GenSlidingWindowDeclRef();
672 ss << "))\n";
673 ss << " arg" << j << " = " <<GetBottom() << ";\n";
674 ss << " else\n";
675 ss << " arg" << j << " = ";
676 ss << vSubArguments[j]->GenSlidingWindowDeclRef();
677 ss << ";\n";
680 ss << " int nNullDate = GetNullDate();\n";
681 ss << " tmp = GetDuration( nNullDate, (int)arg0, (int)arg1, arg2,";
682 ss << " arg3, (int)arg4, (int)arg5);\n";
683 ss << " return tmp;\n";
684 ss << "}";
686 void OpMDuration::BinInlineFun(std::set<std::string>& decls,
687 std::set<std::string>& funs)
689 decls.insert(GetDuration_newDecl);decls.insert(lcl_Getcoupnum_newDecl);
690 decls.insert(addMonthsDecl);decls.insert(checklessthanDecl);
691 decls.insert(setDayDecl);decls.insert(ScaDateDecl);
692 decls.insert(GetYearFracDecl);decls.insert(DaysToDateDecl);
693 decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
694 funs.insert(GetDuration_new);funs.insert(lcl_Getcoupnum_new);
695 funs.insert(addMonths);funs.insert(checklessthan);
696 funs.insert(setDay);funs.insert(ScaDate);
697 funs.insert(GetYearFrac);funs.insert(DaysToDate);
698 funs.insert(DaysInMonth);funs.insert(IsLeapYear);
701 void OpMDuration::GenSlidingWindowFunction(std::stringstream& ss,
702 const std::string &sSymName, SubArguments& vSubArguments)
704 ss << "\ndouble " << sSymName;
705 ss << "_"<< BinFuncName() <<"(";
706 for (unsigned i = 0; i < vSubArguments.size(); i++)
708 if (i)
709 ss << ",";
710 vSubArguments[i]->GenSlidingWindowDecl(ss);
712 ss << ") {\n";
713 ss << " double tmp = " << GetBottom() << ";\n";
714 ss << " int gid0 = get_global_id(0);\n";
715 ss << " double arg0 = " << GetBottom() << ";\n";
716 ss << " double arg1 = " << GetBottom() << ";\n";
717 ss << " double arg2 = " << GetBottom() << ";\n";
718 ss << " double arg3 = " << GetBottom() << ";\n";
719 ss << " double arg4 = " << GetBottom() << ";\n";
720 ss << " double arg5 = " << GetBottom() << ";\n";
721 for (unsigned i = 0; i < vSubArguments.size(); i++)
723 FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
724 assert(pCur);
725 if (pCur->GetType() == formula::svSingleVectorRef)
727 const formula::SingleVectorRefToken* pSVR =
728 static_cast< const formula::SingleVectorRefToken* >(pCur);
729 ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
731 else if (pCur->GetType() == formula::svDouble)
733 ss << " {\n";
735 if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
737 ss << " if (isNan(";
738 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
739 ss << "))\n";
740 ss << " arg" << i << " = 0;\n";
741 ss << " else\n";
742 ss << " arg" << i << " = ";
743 ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
744 ss << " }\n";
746 else
748 ss << " arg" << i << " = ";
749 ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
752 ss << " int nNullDate = 693594;\n";
753 ss << " tmp = GetDuration_new( nNullDate, (int)arg0, (int)arg1, arg2,";
754 ss << " arg3, (int)arg4, (int)arg5);\n";
755 ss << " tmp = tmp * pow(1.0 + arg3 * pow((int)arg4, -1.0), -1);\n";
756 ss << " return tmp;\n";
757 ss << "}";
759 void Fvschedule::GenSlidingWindowFunction(
760 std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
762 FormulaToken* pCur = vSubArguments[1]->GetFormulaToken();
763 assert(pCur);
764 const formula::DoubleVectorRefToken* pCurDVR =
765 static_cast<const formula::DoubleVectorRefToken *>(pCur);
766 size_t nCurWindowSize = pCurDVR->GetRefRowSize();
767 ss << "\ndouble " << sSymName;
768 ss << "_"<< BinFuncName() <<"(";
769 for (unsigned i = 0; i < vSubArguments.size(); i++)
771 if (i)
772 ss << ",";
773 vSubArguments[i]->GenSlidingWindowDecl(ss);
775 ss << ") {\n\t";
776 ss << "double tmp = 1.0;\n\t";
777 ss << "int gid0 = get_global_id(0);\n\t";
778 ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
779 ss << ";\n\t";
780 ss << "if (isNan(arg0))\n\t\t";
781 ss << "arg0 = 0;\n\t";
782 ss << "double arg1;\n\t";
783 ss << "int arrayLength = " << pCurDVR->GetArrayLength() << ";\n\t";
784 ss << "for (int i = 0; i + gid0 < arrayLength &&";
785 ss << " i < " << nCurWindowSize << "; i++){\n\t\t";
786 ss << "arg1 = ";
787 ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n\t\t\t";
788 ss << "if (isNan(arg1))\n\t\t\t\t";
789 ss << "arg1 = 0;\n\t\t\t";
790 ss << "tmp *= arg1 + 1.0;\n\t\t";
791 ss << "}\n\t";
792 ss << "return (double)tmp * arg0";
793 ss << ";\n}";
795 void Cumipmt::BinInlineFun(std::set<std::string>& decls,
796 std::set<std::string>& funs)
798 decls.insert(GetRmz_newDecl); decls.insert(GetZw_newDecl);
799 funs.insert(GetRmz_new);funs.insert(GetZw_new);
801 void Cumipmt::GenSlidingWindowFunction(
802 std::stringstream &ss, const std::string &sSymName, SubArguments &
803 vSubArguments)
805 ss << "\ndouble " << sSymName;
806 ss << "_"<< BinFuncName() <<"(";
807 for (unsigned i = 0; i < vSubArguments.size(); i++)
809 if (i)
810 ss << ",";
811 vSubArguments[i]->GenSlidingWindowDecl(ss);
813 ss << ") {\n";
814 ss << " int gid0 = get_global_id(0);\n";
815 ss << " double fRate,fVal;\n";
816 ss << " int nStartPer,nEndPer,nNumPeriods,nPayType;\n";
817 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
818 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
819 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
820 FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
821 FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
822 FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
823 if(tmpCur0->GetType() == formula::svSingleVectorRef)
825 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
826 formula::SingleVectorRefToken *>(tmpCur0);
827 ss <<" if(gid0 >= "<<tmpCurDVR0->GetArrayLength()<<" || isNan(";
828 ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
829 ss <<"))\n";
830 ss <<" fRate = 0;\n else\n";
832 ss <<" fRate = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
833 ss <<";\n";
834 if(tmpCur1->GetType() == formula::svSingleVectorRef)
836 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
837 formula::SingleVectorRefToken *>(tmpCur1);
838 ss <<" if(gid0 >= "<<tmpCurDVR1->GetArrayLength()<<" || isNan(";
839 ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
840 ss <<"))\n";
841 ss <<" nNumPeriods = 0;\n else\n";
843 ss <<" nNumPeriods = (int)";
844 ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
845 ss <<";\n";
846 if(tmpCur2->GetType() == formula::svSingleVectorRef)
848 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
849 formula::SingleVectorRefToken *>(tmpCur2);
850 ss <<" if(gid0 >= "<<tmpCurDVR2->GetArrayLength()<<" || isNan(";
851 ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
852 ss <<"))\n";
853 ss <<" fVal = 0;\n else\n";
855 ss <<" fVal = "<<vSubArguments[2]->GenSlidingWindowDeclRef();
856 ss <<";\n";
857 if(tmpCur3->GetType() == formula::svSingleVectorRef)
859 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
860 formula::SingleVectorRefToken *>(tmpCur3);
861 ss <<" if(gid0 >= "<<tmpCurDVR3->GetArrayLength()<<" || isNan(";
862 ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
863 ss <<"))\n";
864 ss <<" nStartPer = 0;\n else\n";
866 ss <<" nStartPer = (int)";
867 ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
868 ss <<";\n";
869 if(tmpCur4->GetType() == formula::svSingleVectorRef)
871 const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
872 formula::SingleVectorRefToken *>(tmpCur4);
873 ss <<" if(gid0 >= "<<tmpCurDVR4->GetArrayLength()<<" || isNan(";
874 ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
875 ss <<"))\n";
876 ss <<" nEndPer = 0;\n else\n";
878 ss <<" nEndPer = (int)";
879 ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
880 ss <<";\n";
882 if(tmpCur5->GetType() == formula::svSingleVectorRef)
884 const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
885 formula::SingleVectorRefToken *>(tmpCur5);
886 ss <<" if(gid0 >= "<<tmpCurDVR5->GetArrayLength()<<" || isNan(";
887 ss <<vSubArguments[5]->GenSlidingWindowDeclRef();
888 ss <<"))\n";
889 ss <<" nPayType = 0;\n else\n";
891 ss <<" nPayType = (int)"<<vSubArguments[5]->GenSlidingWindowDeclRef();
892 ss <<";\n";
893 ss <<" double fRmz;\n";
894 ss <<" fRmz = GetRmz_new( fRate, nNumPeriods, fVal, 0.0, nPayType );\n";
895 ss <<" double tmp = 0.0;\n";
896 ss <<" if( nStartPer == 1 )\n";
897 ss <<" {\n";
898 ss <<" if( nPayType <= 0 )\n";
899 ss <<" tmp = -fVal;\n";
900 ss <<" nStartPer++;\n";
901 ss <<" }\n";
902 ss <<" for( ; nStartPer<= nEndPer ; nStartPer++ )\n";
903 ss <<" {\n";
904 ss <<" if( nPayType > 0 )\n";
905 ss <<" tmp += GetZw_new( fRate, nStartPer - 2 , ";
906 ss <<"fRmz, fVal, 1 ) - fRmz;\n";
907 ss <<" else\n";
908 ss <<" tmp += GetZw_new( fRate, nStartPer - 1 , ";
909 ss <<"fRmz, fVal, 0 );\n";
910 ss <<" }\n";
911 ss <<" tmp *= fRate;\n";
912 ss <<" return tmp;\n";
913 ss <<"}";
916 void IRR::GenSlidingWindowFunction(std::stringstream &ss,
917 const std::string &sSymName, SubArguments &vSubArguments)
919 ss << "\ndouble " << sSymName;
920 ss << "_" << BinFuncName() << "(";
921 for (unsigned i = 0; i < vSubArguments.size(); i++)
923 if (i)
924 ss << ",";
925 vSubArguments[i]->GenSlidingWindowDecl(ss);
927 ss << ") {\n";
928 ss << " #define Epsilon 1.0E-7\n";
929 ss << " int gid0 = get_global_id(0);\n";
930 FormulaToken* pSur = vSubArguments[1]->GetFormulaToken();
931 assert(pSur);
932 ss << " double fSchaetzwert = ";
933 ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
934 ss << " double fEps = 1.0;\n";
935 ss << " double x = 0.0, xNeu = 0.0, fZaehler = 0.0, fNenner = 0.0;\n";
936 ss << " double nCount = 0.0;\n";
937 if (pSur->GetType() == formula::svSingleVectorRef)
939 const formula::SingleVectorRefToken* pSVR =
940 static_cast< const formula::SingleVectorRefToken* >(pSur);
941 ss << " if (gid0 >= " << pSVR->GetArrayLength() << ")\n";
942 ss << " fSchaetzwert = 0.1;\n";
943 ss << " if (isNan(fSchaetzwert))\n";
944 ss << " x = 0.1;\n";
945 ss << " else\n";
947 else if (pSur->GetType() == formula::svDouble)
949 ss << " if (isNan(fSchaetzwert))\n";
950 ss << " x = 0.1;\n";
951 ss << " else\n";
953 ss << " x = fSchaetzwert;\n";
954 ss << " unsigned short nItCount = 0;\n";
955 ss << " while (fEps > Epsilon && nItCount < 20){\n";
956 ss << " nCount = 0.0; fZaehler = 0.0; fNenner = 0.0;\n";
957 ss << " double arg0, arg1;\n";
958 ss << " int i = 0;\n";
959 FormulaToken* pCur = vSubArguments[0]->GetFormulaToken();
960 assert(pCur);
961 const formula::DoubleVectorRefToken* pDVR =
962 static_cast<const formula::DoubleVectorRefToken* >(pCur);
963 size_t nCurWindowSize = pDVR->GetRefRowSize();
964 ss << " for ( ";
965 if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
966 ss << "i = gid0; i < " << pDVR->GetArrayLength();
967 ss << " && i < " << nCurWindowSize << " /2*2; i++){\n";
968 ss << " arg0 = ";
969 ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
970 ss << " i++;;\n";
971 ss << " arg1 = ";
972 ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
973 ss << " if (!isNan(arg0)){\n";
974 ss << " fZaehler += arg0 / pow(1.0 + x, nCount);\n";
975 ss << " fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
976 ss << " nCount += 1;\n";
977 ss << " }\n";
978 ss << " if (!isNan(arg1)){\n";
979 ss << " fZaehler += arg1 / pow(1.0 + x, nCount);\n";
980 ss << " fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
981 ss << " nCount += 1;\n";
982 ss << " }\n";
983 ss << " }\n";
984 ss << "if(i < " << pDVR->GetArrayLength();
985 ss << " && i < " << nCurWindowSize << ") ;{\n";
987 else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
988 ss << "; i < " << pDVR->GetArrayLength();
989 ss << " && i < (gid0+" << nCurWindowSize << " )/2*2; i++){\n";
990 ss << " arg0 = ";
991 ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
992 ss << " if (!isNan(arg0)){\n";
993 ss << " fZaehler += arg0 / pow(1.0 + x, nCount);\n";
994 ss << " fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
995 ss << " nCount += 1;\n";
996 ss << " }\n";
997 ss << " i++;\n";
998 ss << " arg1 = ";
999 ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1000 ss << " if (!isNan(arg1)){\n";
1001 ss << " fZaehler += arg1 / pow(1.0 + x, nCount);\n";
1002 ss << " fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
1003 ss << " nCount+=1;\n";
1004 ss << " }\n";
1005 ss << " }\n";
1006 ss << " if(i < " << pDVR->GetArrayLength();
1007 ss << " && i < gid0+" << nCurWindowSize << "){\n";
1009 else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
1010 ss << " ; i + gid0 < " << pDVR->GetArrayLength();
1011 ss << " && i < " << nCurWindowSize << " /2*2; i++){\n";
1012 ss << " arg0 = ";
1013 ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1014 ss << " i++;;\n";
1015 ss << " arg1 = ";
1016 ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1017 ss << " if (!isNan(arg0)){\n";
1018 ss << " fZaehler += arg0 / pow(1.0 + x, nCount);\n";
1019 ss << " fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
1020 ss << " nCount += 1;\n";
1021 ss << " }\n";
1022 ss << " if (!isNan(arg1)){\n";
1023 ss << " fZaehler += arg1 / pow(1.0 + x, nCount);\n";
1024 ss << " fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
1025 ss << " nCount+=1;\n";
1026 ss << " }\n";
1027 ss << " }\n";
1028 ss << " if(i + gid0 < " << pDVR->GetArrayLength() << " &&";
1029 ss << " i < " << nCurWindowSize << "){\n";
1031 } else {
1032 ss << "; i < " << nCurWindowSize << " /2*2; i++){\n";
1033 ss << " arg0 = ";
1034 ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1035 ss << " i++;;\n";
1036 ss << " arg1 = ";
1037 ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1038 ss << " if (!isNan(arg0)){\n";
1039 ss << " fZaehler += arg0 / pow(1.0 + x, nCount);\n";
1040 ss << " fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
1041 ss << " nCount += 1;\n";
1042 ss << " }\n";
1043 ss << " if (!isNan(arg1)){\n";
1044 ss << " fZaehler += arg1 / pow(1.0 + x, nCount);\n";
1045 ss << " fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
1046 ss << " nCount+=1;\n";
1047 ss << " }\n";
1048 ss << " }\n";
1049 ss << "if(i<" << nCurWindowSize << "){\n";
1052 ss << " arg0 = ";
1053 ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1054 ss << " if (isNan(arg0))\n";
1055 ss << " continue;\n";
1056 ss << " fZaehler += arg0 / pow(1.0+x, nCount);\n";
1057 ss << " fNenner += -nCount * arg0 / pow(1.0+x,nCount+1.0);\n";
1058 ss << " nCount+=1;\n";
1059 ss << " }\n";
1060 ss << " xNeu = x - fZaehler / fNenner;\n";
1061 ss << " fEps = fabs(xNeu - x);\n";
1062 ss << " x = xNeu;\n";
1063 ss << " nItCount++;\n }\n";
1064 ss << " if (fSchaetzwert == 0.0 && fabs(x) < Epsilon)\n";
1065 ss << " x = 0.0;\n";
1066 ss << " if (fEps < Epsilon)\n";
1067 ss << " return x;\n";
1068 ss << " else\n";
1069 ss << " return (double)523;\n";
1070 ss << "}";
1073 void XNPV::GenSlidingWindowFunction(
1074 std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
1076 FormulaToken *pCur = vSubArguments[1]->GetFormulaToken();
1077 assert(pCur);
1078 const formula::DoubleVectorRefToken* pCurDVR =
1079 static_cast<const formula::DoubleVectorRefToken *>(pCur);
1080 size_t nCurWindowSize = pCurDVR->GetRefRowSize();
1081 ss << "\ndouble " << sSymName;
1082 ss << "_"<< BinFuncName() <<"( ";
1083 for (unsigned i = 0; i < vSubArguments.size(); i++)
1085 if (i)
1086 ss << ",";
1087 vSubArguments[i]->GenSlidingWindowDecl(ss);
1090 ss << ") {\n\t";
1091 ss << "double result = 0.0;\n\t";
1092 ss << "int gid0 = get_global_id(0);\n\t";
1093 ss << "int i=0;\n\t";
1094 ss << "double date;\n\t";
1095 ss << "double value;\n\t";
1096 ss << "double rate;\n\t";
1097 ss << "double dateNull;\n\t";
1098 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1099 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
1100 formula::SingleVectorRefToken *>(tmpCur0);
1102 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
1103 const formula::DoubleVectorRefToken*tmpCurDVR1= static_cast<const
1104 formula::DoubleVectorRefToken *>(tmpCur1);
1106 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
1107 const formula::DoubleVectorRefToken*tmpCurDVR2= static_cast<const
1108 formula::DoubleVectorRefToken *>(tmpCur2);
1109 ss<< "int buffer_rate_len = ";
1110 ss<< tmpCurDVR0->GetArrayLength();
1111 ss << ";\n\t";
1112 ss<< "int buffer_value_len = ";
1113 ss<< tmpCurDVR1->GetArrayLength();
1114 ss << ";\n\t";
1115 ss<< "int buffer_date_len = ";
1116 ss<< tmpCurDVR2->GetArrayLength();
1117 ss << ";\n\t";
1118 ss<<"if((gid0)>=buffer_date_len || isNan(";
1119 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
1120 ss<<"))\n\t\t";
1121 ss<<"return NAN;\n\telse \n";
1122 ss<<"dateNull = ";
1123 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
1124 ss<<";\n\t";
1125 ss<<"if((gid0)>=buffer_rate_len || isNan(";
1126 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1127 ss<<"))\n\t\t";
1128 ss<<"return NAN;\n\telse \n";
1129 ss<<"rate = ";
1130 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1131 ss<<";\n\t";
1132 ss<<"if(1 == buffer_date_len )\n";
1133 ss<<"return ";
1134 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
1135 ss<<";\n\t";
1136 ss << "for (int i = ";
1137 if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed())
1139 ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n\t\t";
1141 else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
1143 ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n\t\t";
1145 else
1147 ss << "0; i < "<< nCurWindowSize <<"; i++)\n\t\t";
1149 ss << "{\n\t";
1150 if (!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
1152 ss << "if((i+gid0)>=buffer_value_len || (i+gid0)>=buffer_date_len)\n\t\t";
1153 ss << "return result;\n\telse \n\t\t";
1155 else
1157 ss << "if(i>=buffer_value_len || i>=buffer_date_len)\n\t\t";
1158 ss << "return result;\n\telse \n\t\t";
1161 ss << "value = ";
1162 ss << vSubArguments[1]->GenSlidingWindowDeclRef(true);
1163 ss << ";\n";
1164 ss << " date = ";
1165 ss << vSubArguments[2]->GenSlidingWindowDeclRef(true);
1166 ss << ";\n";
1167 ss << "result += value/(pow((rate+1),(date-dateNull)/365));\n";
1168 ss << "}\n";
1169 ss << "return result;\n";
1170 ss << "}";
1173 void PriceMat::BinInlineFun(std::set<std::string>& decls,
1174 std::set<std::string>& funs)
1176 decls.insert(GetYearFracDecl);decls.insert(GetNullDateDecl);
1177 decls.insert(DateToDaysDecl);decls.insert(DaysToDateDecl);
1178 decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
1180 funs.insert(GetYearFrac);funs.insert(GetNullDate);
1181 funs.insert(DateToDays);funs.insert(DaysToDate);
1182 funs.insert(DaysInMonth);funs.insert(IsLeapYear);
1184 void PriceMat::GenSlidingWindowFunction(
1185 std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
1187 ss << "\ndouble " << sSymName;
1188 ss << "_"<< BinFuncName() <<"(";
1189 for (unsigned i = 0; i < vSubArguments.size(); i++)
1191 if (i)
1192 ss << ",";
1193 vSubArguments[i]->GenSlidingWindowDecl(ss);
1195 ss << ") {\n\t";
1196 ss << "int gid0 = get_global_id(0);\n\t";
1197 ss << "double result=0;\n\t";
1198 ss<< "int nNullDate = GetNullDate( );\n\t";
1199 ss <<"int settle;\n\t";
1200 ss <<"int mat;\n\t";
1201 ss <<"int issue;\n\t";
1202 ss <<"double rate;\n\t";
1203 ss <<"double yield;\n\t";
1204 ss <<"int nBase;\n\t";
1205 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1206 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
1207 formula::SingleVectorRefToken *>(tmpCur0);
1208 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
1209 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
1210 formula::SingleVectorRefToken *>(tmpCur1);
1211 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
1212 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
1213 formula::SingleVectorRefToken *>(tmpCur2);
1214 FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
1215 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
1216 formula::SingleVectorRefToken *>(tmpCur3);
1217 FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
1218 const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
1219 formula::SingleVectorRefToken *>(tmpCur4);
1220 FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
1221 const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
1222 formula::SingleVectorRefToken *>(tmpCur5);
1224 ss<< "int buffer_settle_len = ";
1225 ss<< tmpCurDVR0->GetArrayLength();
1226 ss << ";\n\t";
1227 ss<< "int buffer_mat_len = ";
1228 ss<< tmpCurDVR1->GetArrayLength();
1229 ss << ";\n\t";
1230 ss<< "int buffer_issue_len = ";
1231 ss<< tmpCurDVR2->GetArrayLength();
1232 ss << ";\n\t";
1233 ss<< "int buffer_rate_len = ";
1234 ss<< tmpCurDVR3->GetArrayLength();
1235 ss << ";\n\t";
1236 ss<< "int buffer_yield_len = ";
1237 ss<< tmpCurDVR4->GetArrayLength();
1238 ss << ";\n\t";
1239 ss<< "int buffer_base_len = ";
1240 ss<< tmpCurDVR5->GetArrayLength();
1241 ss << ";\n\t";
1242 ss<<"if(gid0>=buffer_settle_len || isNan(";
1243 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1244 ss<<"))\n\t\t";
1245 ss<<"settle = 0;\n\telse \n\t\t";
1246 ss<<"settle = ";
1247 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1248 ss<<";\n\t";
1249 ss<<"if(gid0>=buffer_mat_len || isNan(";
1250 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
1251 ss<<"))\n\t\t";
1252 ss<<"mat = 0;\n\telse \n\t\t";
1253 ss<<"mat = ";
1254 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
1255 ss<<";\n\t";
1256 ss<<"if(gid0>=buffer_issue_len || isNan(";
1257 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
1258 ss<<"))\n\t\t";
1259 ss<<"issue = 0;\n\telse \n\t\t";
1260 ss<<"issue = ";
1261 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
1262 ss<<";\n\t";
1263 ss<<"if(gid0>=buffer_rate_len || isNan(";
1264 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
1265 ss<<"))\n\t\t";
1266 ss<<"rate = 0;\n\telse \n\t\t";
1267 ss<<"rate = ";
1268 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
1269 ss<<";\n\t";
1270 ss<<"if(gid0>=buffer_yield_len || isNan(";
1271 ss << vSubArguments[4]->GenSlidingWindowDeclRef();
1272 ss<<"))\n\t\t";
1273 ss<<"yield = 0;\n\telse \n\t\t";
1274 ss<<"yield = ";
1275 ss << vSubArguments[4]->GenSlidingWindowDeclRef();
1276 ss<<";\n\t";
1277 ss<<"if(gid0>=buffer_base_len || isNan(";
1278 ss << vSubArguments[5]->GenSlidingWindowDeclRef();
1279 ss<<"))\n\t\t";
1280 ss<<"nBase = 0;\n\telse \n\t\t";
1281 ss<<"nBase = ";
1282 ss << vSubArguments[5]->GenSlidingWindowDeclRef();
1283 ss<<";\n\t";
1284 ss<< "double fIssMat = GetYearFrac( nNullDate, issue, mat, nBase);\n";
1285 ss<<"double fIssSet = GetYearFrac( nNullDate, issue, settle,nBase);\n";
1286 ss<<"double fSetMat = GetYearFrac( nNullDate, settle, mat, nBase);\n";
1287 ss<<"result = 1.0 + fIssMat * rate;\n\t";
1288 ss<<"result /= 1.0 + fSetMat * yield;\n\t";
1289 ss<<"result -= fIssSet * rate;\n\t";
1290 ss<<"result*= 100.0;\n\t";
1291 ss<<"return result;\n\t";
1292 ss<<"}\n";
1295 void OpSYD::GenSlidingWindowFunction(std::stringstream &ss,
1296 const std::string &sSymName, SubArguments &vSubArguments)
1298 ss << "\ndouble " << sSymName;
1299 ss << "_"<< BinFuncName() <<"(";
1300 for (unsigned i = 0; i < vSubArguments.size(); i++)
1302 if (i)
1303 ss << ",";
1304 vSubArguments[i]->GenSlidingWindowDecl(ss);
1306 ss << ") {\n";
1307 ss << " int gid0 = get_global_id(0);\n";
1308 ss << " double result=0;\n";
1309 ss << " double cost;\n";
1310 ss << " double salvage;\n";
1311 ss << " double life;\n";
1312 ss << " double period;\n";
1313 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1314 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
1315 formula::SingleVectorRefToken *>(tmpCur0);
1317 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
1318 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
1319 formula::SingleVectorRefToken *>(tmpCur1);
1321 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
1322 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
1323 formula::SingleVectorRefToken *>(tmpCur2);
1325 FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
1326 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
1327 formula::SingleVectorRefToken *>(tmpCur3);
1329 ss << " int buffer_cost_len = ";
1330 ss << tmpCurDVR0->GetArrayLength();
1331 ss << ";\n";
1333 ss << " int buffer_salvage_len = ";
1334 ss << tmpCurDVR1->GetArrayLength();
1335 ss << ";\n";
1337 ss << " int buffer_life_len = ";
1338 ss << tmpCurDVR2->GetArrayLength();
1339 ss << ";\n";
1340 ss << " int buffer_period_len = ";
1341 ss << tmpCurDVR3->GetArrayLength();
1342 ss << ";\n";
1344 ss <<" if(gid0>=buffer_cost_len || isNan(";
1345 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1346 ss <<"))\n";
1347 ss <<" cost = 0;\n\telse \n";
1348 ss <<" cost = ";
1349 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1350 ss <<";\n";
1351 ss <<" if(gid0>=buffer_salvage_len || isNan(";
1352 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
1353 ss <<"))\n";
1354 ss <<" salvage = 0;\n\telse \n";
1355 ss <<" salvage = ";
1356 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
1357 ss <<";\n";
1358 ss <<" if(gid0>=buffer_life_len || isNan(";
1359 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
1360 ss <<"))\n";
1361 ss <<" life = 0;\n\telse \n";
1362 ss <<" life = ";
1363 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
1364 ss <<";\n";
1365 ss <<" if(gid0>=buffer_period_len || isNan(";
1366 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
1367 ss <<"))\n";
1368 ss <<" period = 0;\n\telse \n";
1369 ss <<" period = ";
1370 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
1371 ss <<";\n";
1372 ss <<" double tmpvalue = ((life*(life+1))*pow(2.0,-1));\n";
1373 ss <<" result = ((cost-salvage)*(life-period+1)";
1374 ss << "*pow(tmpvalue,-1));\n";
1375 ss <<" return result;\n";
1376 ss <<"}\n";
1379 void MIRR::GenSlidingWindowFunction(
1380 std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
1382 FormulaToken* pCur = vSubArguments[0]->GetFormulaToken();
1383 assert(pCur);
1384 const formula::DoubleVectorRefToken* pCurDVR =
1385 static_cast<const formula::DoubleVectorRefToken *>(pCur);
1386 size_t nCurWindowSize = pCurDVR->GetRefRowSize();
1387 FormulaToken* pCur1 = vSubArguments[1]->GetFormulaToken();
1388 assert(pCur1);
1389 const formula::SingleVectorRefToken* pSVR1 =
1390 static_cast< const formula::SingleVectorRefToken* >(pCur1);
1391 assert(pSVR1);
1392 FormulaToken* pCur2 = vSubArguments[2]->GetFormulaToken();
1393 assert(pCur2);
1394 const formula::SingleVectorRefToken* pSVR2 =
1395 static_cast< const formula::SingleVectorRefToken* >(pCur2);
1396 assert(pSVR2);
1398 ss << "\ndouble " << sSymName;
1399 ss << "_"<< BinFuncName() <<"(";
1400 for (unsigned i = 0; i < vSubArguments.size(); i++)
1402 if (i)
1403 ss << ",";
1404 vSubArguments[i]->GenSlidingWindowDecl(ss);
1406 ss << ") {\n\t";
1407 ss << "double tmp = " << GetBottom() <<";\n\t";
1408 ss << "int gid0 = get_global_id(0);\n\t";
1409 ss << "double arg0, arg1, arg2;\n\t";
1410 ss << "arg1 = " << vSubArguments[1]->GenSlidingWindowDeclRef();
1411 ss << ";\n\t";
1412 ss << "arg2 = " << vSubArguments[2]->GenSlidingWindowDeclRef();
1413 ss << ";\n\t";
1414 ss << "int argLen1 = " << pSVR1->GetArrayLength() << ";\n\t";
1415 ss << "int argLen2 = " << pSVR2->GetArrayLength() << ";\n\t";
1416 ss << "if (gid0 >= argLen1)\n\t\t";
1417 ss << "arg1 = 0.0;\n\t";
1418 ss << "if (gid0 >= argLen2)\n\t\t";
1419 ss << "arg2 = 0.0;\n\t";
1420 ss << "if (isNan(arg1))\n\t\t";
1421 ss << "arg1 = 0.0;\n\t";
1422 ss << "if (isNan(arg2))\n\t\t";
1423 ss << "arg2 = 0.0;\n\t";
1424 ss << "double invest = arg1 + 1.0;\n\t";
1425 ss << "double reinvest = arg2 + 1.0;\n\t";
1426 ss << "double NPV_invest = 0.0;\n\t";
1427 ss << "double Pow_invest = 1.0;\n\t";
1428 ss << "double NPV_reinvest = 0.0;\n\t";
1429 ss << "double Pow_reinvest = 1.0;\n\t";
1430 ss << "int nCount = 0;\n\t";
1431 ss << "int arrayLength = " << pCurDVR->GetArrayLength() << ";\n\t";
1432 ss << "for (int i = 0; i + gid0 < arrayLength &&";
1433 ss << " i < " << nCurWindowSize << "; i++){\n\t\t";
1434 ss << "arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
1435 ss << ";\n\t\t";
1436 ss << "if (isNan(arg0))\n\t\t\t";
1437 ss << "continue;\n\t\t";
1438 ss << "if (arg0 > 0.0)\n\t\t\t";
1439 ss << "NPV_reinvest += arg0 * Pow_reinvest;\n\t\t";
1440 ss << "else if (arg0 < 0.0)\n\t\t\t";
1441 ss << "NPV_invest += arg0 * Pow_invest;\n\t\t";
1442 ss << "Pow_reinvest /= reinvest;\n\t\t";
1443 ss << "Pow_invest /= invest;\n\t\t";
1444 ss << "nCount++;\n\t";
1445 ss << "}\n\t";
1446 ss << "tmp = ";
1447 ss << "-NPV_reinvest /NPV_invest * pow(reinvest,(double)nCount-1);\n\t";
1448 ss << "tmp = pow(tmp, 1.0 / (nCount - 1)) - 1.0;\n\t";
1449 ss << "return (double)tmp;\n";
1450 ss << "}";
1453 void OpEffective::GenSlidingWindowFunction(std::stringstream& ss,
1454 const std::string &sSymName, SubArguments& vSubArguments)
1456 ss << "\ndouble " << sSymName;
1457 ss << "_" << BinFuncName() << "(";
1458 for (unsigned i = 0; i < vSubArguments.size(); i++)
1460 if (i)
1461 ss << ",";
1462 vSubArguments[i]->GenSlidingWindowDecl(ss);
1464 ss << ") {\n";
1465 ss << " double tmp = " << GetBottom() <<";\n";
1466 ss << " int gid0 = get_global_id(0);\n\t";
1467 ss << " double arg0 = " << GetBottom() << ";\n";
1468 ss << " double arg1 = " << GetBottom() << ";\n";
1469 for (unsigned i = 0; i < vSubArguments.size(); i++)
1471 FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
1472 assert(pCur);
1473 if (pCur->GetType() == formula::svSingleVectorRef)
1475 const formula::SingleVectorRefToken* pSVR =
1476 static_cast< const formula::SingleVectorRefToken* >(pCur);
1477 ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
1479 else if (pCur->GetType() == formula::svDouble)
1481 ss << " {\n";
1483 if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
1485 ss << " if (isNan(";
1486 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
1487 ss << "))\n";
1488 ss << " arg" << i << " = 0;\n";
1489 ss << " else\n";
1490 ss << " arg" << i << " = ";
1491 ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1492 ss << " }\n";
1494 else
1496 ss << " arg" << i << " = ";
1497 ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1500 ss << " tmp = pow(1.0 + arg0 * pow(arg1, -1), arg1)-1.0;\n";
1501 ss << " return tmp;\n";
1502 ss << "}";
1505 void OpTbilleq::BinInlineFun(std::set<std::string>& decls,
1506 std::set<std::string>& funs)
1508 decls.insert(GetDiffDate360_Decl);decls.insert(GetDiffDate360Decl);
1509 decls.insert(DateToDaysDecl);decls.insert(DaysToDate_LocalBarrierDecl);
1510 decls.insert(DaysInMonthDecl);decls.insert(GetNullDateDecl);
1511 decls.insert(IsLeapYearDecl);
1512 funs.insert(GetDiffDate360_);funs.insert(GetDiffDate360);
1513 funs.insert(DateToDays);funs.insert(DaysToDate_LocalBarrier);
1514 funs.insert(DaysInMonth);funs.insert(GetNullDate);
1515 funs.insert(IsLeapYear);
1517 void OpTbilleq::GenSlidingWindowFunction(
1518 std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
1520 ss << "\ndouble " << sSymName;
1521 ss << "_"<< BinFuncName() <<"(";
1522 for (unsigned i = 0; i < vSubArguments.size(); i++)
1524 if (i)
1525 ss << ",";
1526 vSubArguments[i]->GenSlidingWindowDecl(ss);
1528 ss << ") {\n\t";
1529 ss << " int gid0 = get_global_id(0);\n";
1530 ss << "double tmp = 0;\n\t";
1531 ss << "double tmp000;\n\t";
1532 ss << "double tmp001;\n\t";
1533 ss << "double tmp002;\n\t";
1535 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1536 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
1537 formula::SingleVectorRefToken *>(tmpCur0);
1539 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
1540 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
1541 formula::SingleVectorRefToken *>(tmpCur1);
1543 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
1544 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
1545 formula::SingleVectorRefToken *>(tmpCur2);
1547 ss<< "int buffer_tmp000_len = ";
1548 ss<< tmpCurDVR0->GetArrayLength();
1549 ss << ";\n\t";
1551 ss<< "int buffer_tmp001_len = ";
1552 ss<< tmpCurDVR1->GetArrayLength();
1553 ss << ";\n\t";
1555 ss<< "int buffer_tmp002_len = ";
1556 ss<< tmpCurDVR2->GetArrayLength();
1557 ss << ";\n\t";
1559 ss<<"if(gid0>=buffer_tmp000_len || isNan(";
1560 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1561 ss<<"))\n\t\t";
1562 ss<<"tmp000 = 0;\n\telse \n\t\t";
1563 ss<<"tmp000 = ";
1564 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1565 ss<<";\n\t";
1567 ss<<"if(gid0>=buffer_tmp001_len || isNan(";
1568 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
1569 ss<<"))\n\t\t";
1570 ss<<"tmp001 = 0;\n\telse \n\t\t";
1571 ss<<"tmp001 = ";
1572 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
1573 ss<<";\n\t";
1575 ss<<"if(gid0>=buffer_tmp002_len || isNan(";
1576 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
1577 ss<<"))\n\t\t";
1578 ss<<"tmp002 = 0;\n\telse \n\t\t";
1579 ss<<"tmp002 = ";
1580 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
1581 ss<<";\n\t";
1583 ss<<"tmp001+=1.0;\n";
1584 ss<<"int nDiff =GetDiffDate360(GetNullDate(),tmp000,tmp001,true);\n";
1585 ss<<"tmp =( 365 * tmp002 ) / ( 360 - ( tmp002 * ( nDiff ) ) );\n";
1586 ss << "return tmp;\n";
1587 ss << "}";
1589 void OpCumprinc::BinInlineFun(std::set<std::string>& decls,
1590 std::set<std::string>& funs)
1592 decls.insert(GetRmz_newDecl); decls.insert(GetZw_newDecl);
1593 funs.insert(GetRmz_new);funs.insert(GetZw_new);
1595 void OpCumprinc::GenSlidingWindowFunction(std::stringstream &ss,
1596 const std::string &sSymName, SubArguments &vSubArguments)
1598 ss << "\ndouble " << sSymName;
1599 ss << "_"<< BinFuncName() <<"(";
1600 for (unsigned i = 0; i < vSubArguments.size(); i++)
1602 if (i)
1603 ss << ",";
1604 vSubArguments[i]->GenSlidingWindowDecl(ss);
1606 ss << ") {\n";
1607 ss << " double tmp = " << GetBottom() <<";\n";
1608 ss << " int gid0 = get_global_id(0);\n";
1609 ss << " double fRate,fVal;\n";
1610 ss << " int nStartPer,nEndPer,nNumPeriods,nPayType;\n";
1611 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1612 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
1613 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
1614 FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
1615 FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
1616 FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
1617 if(tmpCur0->GetType() == formula::svSingleVectorRef)
1619 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
1620 formula::SingleVectorRefToken *>(tmpCur0);
1621 ss <<" if(gid0 >= "<<tmpCurDVR0->GetArrayLength()<<" || isNan(";
1622 ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
1623 ss <<"))\n";
1624 ss <<" fRate = 0;\n else\n";
1626 ss <<" fRate = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
1627 ss <<";\n";
1628 if(tmpCur1->GetType() == formula::svSingleVectorRef)
1630 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
1631 formula::SingleVectorRefToken *>(tmpCur1);
1632 ss <<" if(gid0 >= "<<tmpCurDVR1->GetArrayLength()<<" || isNan(";
1633 ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
1634 ss <<"))\n";
1635 ss <<" nNumPeriods = 0;\n else\n";
1637 ss <<" nNumPeriods = (int)";
1638 ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
1639 ss <<";\n";
1640 if(tmpCur2->GetType() == formula::svSingleVectorRef)
1642 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
1643 formula::SingleVectorRefToken *>(tmpCur2);
1644 ss <<" if(gid0 >= "<<tmpCurDVR2->GetArrayLength()<<" || isNan(";
1645 ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
1646 ss <<"))\n";
1647 ss <<" fVal = 0;\n else\n";
1649 ss <<" fVal = "<<vSubArguments[2]->GenSlidingWindowDeclRef();
1650 ss <<";\n";
1651 if(tmpCur3->GetType() == formula::svSingleVectorRef)
1653 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
1654 formula::SingleVectorRefToken *>(tmpCur3);
1655 ss <<" if(gid0 >= "<<tmpCurDVR3->GetArrayLength()<<" || isNan(";
1656 ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
1657 ss <<"))\n";
1658 ss <<" nStartPer = 0;\n else\n";
1660 ss <<" nStartPer = (int)";
1661 ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
1662 ss <<";\n";
1663 if(tmpCur4->GetType() == formula::svSingleVectorRef)
1665 const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
1666 formula::SingleVectorRefToken *>(tmpCur4);
1667 ss <<" if(gid0 >= "<<tmpCurDVR4->GetArrayLength()<<" || isNan(";
1668 ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
1669 ss <<"))\n";
1670 ss <<" nEndPer = 0;\n else\n";
1672 ss <<" nEndPer = (int)";
1673 ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
1674 ss <<";\n";
1676 if(tmpCur5->GetType() == formula::svSingleVectorRef)
1678 const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
1679 formula::SingleVectorRefToken *>(tmpCur5);
1680 ss <<" if(gid0 >= "<<tmpCurDVR5->GetArrayLength()<<" || isNan(";
1681 ss <<vSubArguments[5]->GenSlidingWindowDeclRef();
1682 ss <<"))\n";
1683 ss <<" nPayType = 0;\n else\n";
1685 ss <<" nPayType = (int)";
1686 ss <<vSubArguments[5]->GenSlidingWindowDeclRef();
1687 ss <<";\n";
1688 ss <<" double fRmz;\n";
1689 ss <<" fRmz = GetRmz_new( fRate, nNumPeriods,fVal,0.0,nPayType );\n";
1690 ss <<" if(nStartPer == 1)\n";
1691 ss <<" {\n";
1692 ss <<" if( nPayType <= 0 )\n";
1693 ss <<" tmp = fRmz + fVal * fRate;\n";
1694 ss <<" else\n";
1695 ss <<" tmp = fRmz;\n";
1696 ss <<" nStartPer=nStartPer+1;\n";
1697 ss <<" }\n";
1698 ss <<" for( int i = nStartPer ; i <= nEndPer ; i++ )\n";
1699 ss <<" {\n";
1700 ss <<" if( nPayType > 0 )\n";
1701 ss <<" tmp += fRmz - ( GetZw_new( fRate,i - 2,";
1702 ss <<"fRmz,fVal,1)- fRmz ) * fRate;\n";
1703 ss <<" else\n";
1704 ss <<" tmp += fRmz - GetZw_new( fRate, i - 1,";
1705 ss <<"fRmz,fVal,0 ) * fRate;\n";
1706 ss <<" }\n";
1707 ss <<" return tmp;\n";
1708 ss <<"}";
1710 void OpAccrint::BinInlineFun(std::set<std::string>& decls,
1711 std::set<std::string>& funs)
1713 decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
1714 decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
1715 decls.insert(GetNullDateDecl); decls.insert(GetDiffDateDecl);
1716 funs.insert(IsLeapYear);funs.insert(DaysInMonth);
1717 funs.insert(DaysToDate);funs.insert(DateToDays);
1718 funs.insert(GetNullDate);funs.insert(GetDiffDate);
1720 void OpAccrint::GenSlidingWindowFunction(
1721 std::stringstream &ss, const std::string &sSymName,
1722 SubArguments &vSubArguments)
1724 ss << "\ndouble " << sSymName;
1725 ss << "_"<< BinFuncName() <<"(";
1726 for (unsigned i = 0; i < vSubArguments.size(); i++)
1728 if (i)
1729 ss << ",";
1730 vSubArguments[i]->GenSlidingWindowDecl(ss);
1732 ss << ") {\n";
1733 ss << " int gid0 = get_global_id(0);\n";
1734 ss << " double tmp = 0;\n";
1735 ss << " int nStartDate,nEndDate,mode,freq;\n";
1736 ss << " int nDays1stYear=0;\n";
1737 ss << " double fVal,fRate;\n";
1738 FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
1739 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
1740 formula::SingleVectorRefToken *>(tmpCur0);
1741 FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
1742 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
1743 formula::SingleVectorRefToken *>(tmpCur2);
1744 FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
1745 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
1746 formula::SingleVectorRefToken *>(tmpCur3);
1747 FormulaToken* tmpCur4 = vSubArguments[4]->GetFormulaToken();
1748 const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
1749 formula::SingleVectorRefToken *>(tmpCur4);
1750 FormulaToken* tmpCur5 = vSubArguments[5]->GetFormulaToken();
1751 const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
1752 formula::SingleVectorRefToken *>(tmpCur5);
1753 FormulaToken* tmpCur6 = vSubArguments[6]->GetFormulaToken();
1754 const formula::SingleVectorRefToken*tmpCurDVR6= static_cast<const
1755 formula::SingleVectorRefToken *>(tmpCur6);
1756 ss<< " int buffer_nIssue_len = ";
1757 ss<< tmpCurDVR0->GetArrayLength();
1758 ss<< ";\n";
1759 ss<< " int buffer_nSettle_len = ";
1760 ss<< tmpCurDVR2->GetArrayLength();
1761 ss<< ";\n";
1762 ss<< " int buffer_fRate_len = ";
1763 ss<< tmpCurDVR3->GetArrayLength();
1764 ss<< ";\n";
1765 ss<< " int buffer_fVal_len = ";
1766 ss<< tmpCurDVR4->GetArrayLength();
1767 ss<< ";\n";
1768 ss<< " int buffer_nFreq_len = ";
1769 ss<< tmpCurDVR5->GetArrayLength();
1770 ss<< ";\n";
1771 ss<< " int buffer_nMode_len = ";
1772 ss<< tmpCurDVR6->GetArrayLength();
1773 ss << ";\n";
1774 ss<<" if(gid0 >= buffer_nIssue_len || isNan(";
1775 ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
1776 ss <<"))\n";
1777 ss <<" nStartDate = 0;\n else\n";
1778 ss <<" nStartDate=(int)";
1779 ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
1780 ss <<";\n";
1781 ss <<" if(gid0 >= buffer_nSettle_len || isNan(";
1782 ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
1783 ss <<"))\n";
1784 ss <<" nEndDate = 0;\n else\n";
1785 ss <<" nEndDate=(int)";
1786 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
1787 ss << ";\n";
1788 ss <<" if(gid0 >= buffer_fRate_len || isNan(";
1789 ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
1790 ss <<"))\n";
1791 ss <<" fRate = 0;\n else\n";
1792 ss <<" fRate=";
1793 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
1794 ss <<";\n";
1795 ss <<" if(gid0 >= buffer_fVal_len || isNan(";
1796 ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
1797 ss <<"))\n";
1798 ss <<" fVal = 0;\n else\n";
1799 ss <<" fVal=";
1800 ss << vSubArguments[4]->GenSlidingWindowDeclRef();
1801 ss <<";\n";
1802 ss <<" if(gid0 >= buffer_nFreq_len || isNan(";
1803 ss <<vSubArguments[5]->GenSlidingWindowDeclRef();
1804 ss <<"))\n";
1805 ss <<" freq = 0;\n else\n";
1806 ss <<" freq= (int)";
1807 ss << vSubArguments[5]->GenSlidingWindowDeclRef();
1808 ss <<";\n";
1809 ss <<" if(gid0 >= buffer_nMode_len || isNan(";
1810 ss <<vSubArguments[6]->GenSlidingWindowDeclRef();
1811 ss <<"))\n";
1812 ss <<" mode = 0;\n else\n";
1813 ss <<" mode = (int)";
1814 ss << vSubArguments[6]->GenSlidingWindowDeclRef();
1815 ss <<";\n";
1816 ss <<" int nNullDate=GetNullDate();\n";
1817 ss <<" int nTotalDays = GetDiffDate(nNullDate,nStartDate,";
1818 ss <<"nEndDate, mode,&nDays1stYear);\n";
1819 ss <<" tmp = fVal*fRate*convert_double(nTotalDays)";
1820 ss <<"/convert_double(nDays1stYear);\n";
1821 ss <<" return tmp;\n";
1822 ss <<"}";
1825 void OpAccrintm::BinInlineFun(std::set<std::string>& decls,
1826 std::set<std::string>& funs)
1828 decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
1829 decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
1830 decls.insert(GetNullDateDecl); decls.insert(GetDiffDateDecl);
1831 funs.insert(IsLeapYear);funs.insert(DaysInMonth);
1832 funs.insert(DaysToDate);funs.insert(DateToDays);
1833 funs.insert(GetNullDate);funs.insert(GetDiffDate);
1835 void OpAccrintm::GenSlidingWindowFunction(
1836 std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
1838 ss << "\ndouble " << sSymName;
1839 ss << "_"<< BinFuncName() <<"(";
1840 for (unsigned i = 0; i < vSubArguments.size(); i++)
1842 if (i)
1843 ss << ",";
1844 vSubArguments[i]->GenSlidingWindowDecl(ss);
1846 ss << ") {\n\t";
1847 ss << "int gid0 = get_global_id(0);\n\t";
1848 ss << "double tmp = " << GetBottom() <<";\n\t";
1849 ss << "int nStartDate,nEndDate,mode;\n\t";
1850 ss << "double fRate,fVal;\n\t";
1851 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1852 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
1853 formula::SingleVectorRefToken *>(tmpCur0);
1854 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
1855 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
1856 formula::SingleVectorRefToken *>(tmpCur1);
1858 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
1859 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
1860 formula::SingleVectorRefToken *>(tmpCur2);
1862 FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
1863 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
1864 formula::SingleVectorRefToken *>(tmpCur3);
1866 FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
1867 const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
1868 formula::SingleVectorRefToken *>(tmpCur4);
1869 ss<< "int buffer_nIssue_len = ";
1870 ss<< tmpCurDVR0->GetArrayLength();
1871 ss << ";\n\t";
1873 ss<< "int buffer_nSettle_len = ";
1874 ss<< tmpCurDVR1->GetArrayLength();
1875 ss << ";\n\t";
1877 ss<< "int buffer_fRate_len = ";
1878 ss<< tmpCurDVR2->GetArrayLength();
1879 ss << ";\n\t";
1881 ss<< "int buffer_fVal_len = ";
1882 ss<< tmpCurDVR3->GetArrayLength();
1883 ss << ";\n\t";
1885 ss<< "int buffer_nMode_len = ";
1886 ss<< tmpCurDVR4->GetArrayLength();
1887 ss << ";\n\t";
1888 ss <<"if(gid0 >= buffer_nIssue_len || isNan(";
1889 ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
1890 ss <<"))\n\t\t";
1891 ss <<"nStartDate = 0;\n\telse\n\t\t";
1892 ss << "nStartDate=(int)";
1893 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1894 ss <<";\n\t";
1895 ss <<"if(gid0 >= buffer_nSettle_len || isNan(";
1896 ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
1897 ss <<"))\n\t\t";
1898 ss <<"nEndDate = 0;\n\telse\n\t\t";
1899 ss << "nEndDate=(int)";
1900 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
1901 ss << ";\n\t";
1903 ss <<"if(gid0 >= buffer_fRate_len || isNan(";
1904 ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
1905 ss <<"))\n\t\t";
1906 ss <<"fRate = 0;\n\telse\n\t\t";
1907 ss << "fRate=";
1908 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
1909 ss <<";\n\t";
1910 ss <<"if(gid0 >= buffer_fVal_len || isNan(";
1911 ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
1912 ss <<"))\n\t\t";
1913 ss <<"fVal = 0;\n\telse\n\t\t";
1914 ss << "fVal=";
1915 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
1916 ss << ";\n\t";
1917 ss <<"if(gid0 >= buffer_nMode_len || isNan(";
1918 ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
1919 ss <<"))\n\t\t";
1920 ss <<"mode = 0;\n\telse\n\t\t";
1921 ss << "mode = (int)";
1922 ss << vSubArguments[4]->GenSlidingWindowDeclRef();
1923 ss << ";\n\t";
1924 ss <<"int nDays1stYear=0;\n\t";
1925 ss <<"int nNullDate=GetNullDate();\n\t";
1926 ss <<"int nTotalDays = GetDiffDate(nNullDate,nStartDate,";
1927 ss <<"nEndDate, mode,&nDays1stYear);\n\t";
1928 ss <<"tmp = fVal*fRate*convert_double(nTotalDays)";
1929 ss <<"/convert_double(nDays1stYear);\n\t";
1930 ss << "return tmp;\n";
1931 ss << "}";
1934 void OpYield::BinInlineFun(std::set<std::string>& decls,
1935 std::set<std::string>& funs)
1937 decls.insert(getYield_Decl);decls.insert(getPrice_Decl);
1938 decls.insert(coupnumDecl);decls.insert(coupdaysncDecl);
1939 decls.insert(coupdaybsDecl);decls.insert(coupdaysDecl);
1940 decls.insert(lcl_GetcoupnumDecl);decls.insert(lcl_GetcoupdaysDecl);
1941 decls.insert(lcl_GetcoupdaybsDecl);decls.insert(getDiffDecl);
1942 decls.insert(getDaysInYearRangeDecl);decls.insert(GetDaysInYearDecl);
1943 decls.insert(GetDaysInYearsDecl);decls.insert(getDaysInMonthRangeDecl);
1944 decls.insert(addMonthsDecl);decls.insert(ScaDateDecl);
1945 decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
1946 decls.insert(DaysToDateDecl);decls.insert(DaysInMonthDecl);
1947 decls.insert(IsLeapYearDecl);
1949 funs.insert(getYield_);funs.insert(getPrice_);
1950 funs.insert(coupnum);funs.insert(coupdaysnc);
1951 funs.insert(coupdaybs);funs.insert(coupdays);
1952 funs.insert(lcl_Getcoupnum);funs.insert(lcl_Getcoupdays);
1953 funs.insert(lcl_Getcoupdaybs);funs.insert(getDiff);
1954 funs.insert(getDaysInYearRange);funs.insert(GetDaysInYear);
1955 funs.insert(GetDaysInYears);funs.insert(getDaysInMonthRange);
1956 funs.insert(addMonths);funs.insert(ScaDate);
1957 funs.insert(GetNullDate);funs.insert(DateToDays);
1958 funs.insert(DaysToDate);funs.insert(DaysInMonth);
1959 funs.insert(IsLeapYear);
1962 void OpYield::GenSlidingWindowFunction(
1963 std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
1965 ss << "\ndouble " << sSymName;
1966 ss << "_"<< BinFuncName() <<"(";
1967 for (unsigned i = 0; i < vSubArguments.size(); i++)
1969 if (i)
1970 ss << ",";
1971 vSubArguments[i]->GenSlidingWindowDecl(ss);
1973 ss << ") {\n\t";
1974 ss << "double tmp = 0;\n\t";
1975 ss << "int gid0 = get_global_id(0);\n\t";
1976 ss << "double tmp000;\n\t";
1977 ss << "double tmp001;\n\t";
1978 ss << "double tmp002;\n\t";
1979 ss << "double tmp003;\n\t";
1980 ss << "double tmp004;\n\t";
1981 ss << "double tmp005;\n\t";
1982 ss << "double tmp006;\n\t";
1984 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1985 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
1986 formula::SingleVectorRefToken *>(tmpCur0);
1988 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
1989 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
1990 formula::SingleVectorRefToken *>(tmpCur1);
1992 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
1993 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
1994 formula::SingleVectorRefToken *>(tmpCur2);
1996 FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
1997 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
1998 formula::SingleVectorRefToken *>(tmpCur3);
2000 FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
2001 const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
2002 formula::SingleVectorRefToken *>(tmpCur4);
2004 FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
2005 const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
2006 formula::SingleVectorRefToken *>(tmpCur5);
2008 FormulaToken *tmpCur6 = vSubArguments[6]->GetFormulaToken();
2009 const formula::SingleVectorRefToken*tmpCurDVR6= static_cast<const
2010 formula::SingleVectorRefToken *>(tmpCur6);
2012 ss<< "int buffer_tmp000_len = ";
2013 ss<< tmpCurDVR0->GetArrayLength();
2014 ss << ";\n\t";
2016 ss<< "int buffer_tmp001_len = ";
2017 ss<< tmpCurDVR1->GetArrayLength();
2018 ss << ";\n\t";
2020 ss<< "int buffer_tmp002_len = ";
2021 ss<< tmpCurDVR2->GetArrayLength();
2022 ss << ";\n\t";
2024 ss<< "int buffer_tmp003_len = ";
2025 ss<< tmpCurDVR3->GetArrayLength();
2026 ss << ";\n\t";
2028 ss<< "int buffer_tmp004_len = ";
2029 ss<< tmpCurDVR4->GetArrayLength();
2030 ss << ";\n\t";
2032 ss<< "int buffer_tmp005_len = ";
2033 ss<< tmpCurDVR5->GetArrayLength();
2034 ss << ";\n\t";
2036 ss<< "int buffer_tmp006_len = ";
2037 ss<< tmpCurDVR6->GetArrayLength();
2038 ss << ";\n\t";
2040 ss<<"if(gid0>=buffer_tmp000_len || isNan(";
2041 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
2042 ss<<"))\n\t\t";
2043 ss<<"tmp000 = 0;\n\telse \n\t\t";
2044 ss<<"tmp000 = ";
2045 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
2046 ss<<";\n\t";
2048 ss<<"if(gid0>=buffer_tmp001_len || isNan(";
2049 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
2050 ss<<"))\n\t\t";
2051 ss<<"tmp001 = 0;\n\telse \n\t\t";
2052 ss<<"tmp001 = ";
2053 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
2054 ss<<";\n\t";
2056 ss<<"if(gid0>=buffer_tmp002_len || isNan(";
2057 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
2058 ss<<"))\n\t\t";
2059 ss<<"tmp002 = 0;\n\telse \n\t\t";
2060 ss<<"tmp002 = ";
2061 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
2062 ss<<";\n\t";
2064 ss<<"if(gid0>=buffer_tmp003_len || isNan(";
2065 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
2066 ss<<"))\n\t\t";
2067 ss<<"tmp003 = 0;\n\telse \n\t\t";
2068 ss<<"tmp003 = ";
2069 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
2070 ss<<";\n\t";
2072 ss<<"if(gid0>=buffer_tmp004_len || isNan(";
2073 ss << vSubArguments[4]->GenSlidingWindowDeclRef();
2074 ss<<"))\n\t\t";
2075 ss<<"tmp004 = 0;\n\telse \n\t\t";
2076 ss<<"tmp004 = ";
2077 ss << vSubArguments[4]->GenSlidingWindowDeclRef();
2078 ss<<";\n\t";
2080 ss<<"if(gid0>=buffer_tmp005_len || isNan(";
2081 ss << vSubArguments[5]->GenSlidingWindowDeclRef();
2082 ss<<"))\n\t\t";
2083 ss<<"tmp005 = 0;\n\telse \n\t\t";
2084 ss<<"tmp005 = ";
2085 ss << vSubArguments[5]->GenSlidingWindowDeclRef();
2086 ss<<";\n\t";
2088 ss<<"if(gid0>=buffer_tmp006_len || isNan(";
2089 ss << vSubArguments[6]->GenSlidingWindowDeclRef();
2090 ss<<"))\n\t\t";
2091 ss<<"tmp006 = 0;\n\telse \n\t\t";
2092 ss<<"tmp006 = ";
2093 ss << vSubArguments[6]->GenSlidingWindowDeclRef();
2094 ss<<";\n\t";
2096 ss << "tmp = getYield_(";
2097 ss << "GetNullDate(),tmp000,tmp001,tmp002,tmp003,tmp004,tmp005,tmp006);\n\t ";
2098 ss << "return tmp;\n";
2099 ss << "}";
2102 void OpSLN::GenSlidingWindowFunction(std::stringstream &ss,
2103 const std::string &sSymName, SubArguments &vSubArguments)
2105 ss << "\ndouble " << sSymName;
2106 ss << "_"<< BinFuncName() <<"(";
2107 for (unsigned i = 0; i < vSubArguments.size(); i++)
2109 if (i)
2110 ss << ",";
2111 vSubArguments[i]->GenSlidingWindowDecl(ss);
2113 ss << ") {\n";
2114 ss << " double tmp = 0;\n";
2115 ss << " int gid0 = get_global_id(0);\n";
2116 ss << " double wert;\n";
2117 ss << " double rest;\n";
2118 ss << " double dauer;\n";
2120 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
2121 const formula::SingleVectorRefToken*tmpCurDVR0=
2122 static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
2123 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
2124 const formula::SingleVectorRefToken*tmpCurDVR1=
2125 static_cast<const formula::SingleVectorRefToken *>(tmpCur1);
2126 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
2127 const formula::SingleVectorRefToken*tmpCurDVR2=
2128 static_cast<const formula::SingleVectorRefToken *>(tmpCur2);
2129 ss<< " int buffer_wert_len = ";
2130 ss<< tmpCurDVR0->GetArrayLength();
2131 ss << ";\n";
2132 ss<< " int buffer_rest_len = ";
2133 ss<< tmpCurDVR1->GetArrayLength();
2134 ss << ";\n";
2135 ss<< " int buffer_dauer_len = ";
2136 ss<< tmpCurDVR2->GetArrayLength();
2137 ss << ";\n";
2138 ss<<" if(gid0>=buffer_wert_len || isNan(";
2139 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
2140 ss<<"))\n";
2141 ss<<" wert = 0;\n\telse \n";
2142 ss<<" wert = ";
2143 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
2144 ss<<";\n";
2145 ss<<" if(gid0>=buffer_rest_len || isNan(";
2146 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
2147 ss<<"))\n";
2148 ss<<" rest = 0;\n\telse \n";
2149 ss<<" rest = ";
2150 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
2151 ss<<";\n";
2152 ss<<" if(gid0>=buffer_dauer_len || isNan(";
2153 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
2154 ss<<"))\n";
2155 ss<<" dauer = 0;\n\telse \n";
2156 ss<<" dauer = ";
2157 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
2158 ss<<";\n";
2159 ss << " tmp = (wert-rest)*pow(dauer,-1);\n";
2160 ss << " return tmp;\n";
2161 ss << "}";
2164 void OpYieldmat::BinInlineFun(std::set<std::string>& decls,
2165 std::set<std::string>& funs)
2167 decls.insert(GetYearFrac_newDecl);decls.insert(GetNullDateDecl);
2168 decls.insert(DateToDaysDecl);decls.insert(DaysToDate_newDecl);
2169 decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
2170 decls.insert(GetYieldmatDecl);
2172 funs.insert(GetYearFrac_new);funs.insert(GetNullDate);
2173 funs.insert(DateToDays);funs.insert(DaysToDate_new);
2174 funs.insert(DaysInMonth);funs.insert(IsLeapYear);
2175 funs.insert(GetYieldmat);
2178 void OpYieldmat::GenSlidingWindowFunction(
2179 std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
2181 ss << "\ndouble " << sSymName;
2182 ss << "_"<< BinFuncName() <<"(";
2183 for (unsigned i = 0; i < vSubArguments.size(); i++)
2185 if (i)
2186 ss << ",";
2187 vSubArguments[i]->GenSlidingWindowDecl(ss);
2189 ss << ") {\n\t";
2190 ss << "double tmp = 0;\n\t";
2191 ss << "int gid0 = get_global_id(0);\n\t";
2192 ss << "double tmp000;\n\t";
2193 ss << "double tmp001;\n\t";
2194 ss << "double tmp002;\n\t";
2195 ss << "double tmp003;\n\t";
2196 ss << "double tmp004;\n\t";
2197 ss << "double tmp005;\n\t";
2199 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
2200 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
2201 formula::SingleVectorRefToken *>(tmpCur0);
2203 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
2204 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
2205 formula::SingleVectorRefToken *>(tmpCur1);
2207 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
2208 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
2209 formula::SingleVectorRefToken *>(tmpCur2);
2211 FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
2212 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
2213 formula::SingleVectorRefToken *>(tmpCur3);
2215 FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
2216 const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
2217 formula::SingleVectorRefToken *>(tmpCur4);
2219 FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
2220 const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
2221 formula::SingleVectorRefToken *>(tmpCur5);
2223 ss<< "int buffer_tmp000_len = ";
2224 ss<< tmpCurDVR0->GetArrayLength();
2225 ss << ";\n\t";
2227 ss<< "int buffer_tmp001_len = ";
2228 ss<< tmpCurDVR1->GetArrayLength();
2229 ss << ";\n\t";
2231 ss<< "int buffer_tmp002_len = ";
2232 ss<< tmpCurDVR2->GetArrayLength();
2233 ss << ";\n\t";
2235 ss<< "int buffer_tmp003_len = ";
2236 ss<< tmpCurDVR3->GetArrayLength();
2237 ss << ";\n\t";
2239 ss<< "int buffer_tmp004_len = ";
2240 ss<< tmpCurDVR4->GetArrayLength();
2241 ss << ";\n\t";
2243 ss<< "int buffer_tmp005_len = ";
2244 ss<< tmpCurDVR5->GetArrayLength();
2245 ss << ";\n\t";
2247 ss<<"if(gid0>=buffer_tmp000_len || isNan(";
2248 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
2249 ss<<"))\n\t\t";
2250 ss<<"tmp000 = 0;\n\telse \n\t\t";
2251 ss<<"tmp000 = ";
2252 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
2253 ss<<";\n\t";
2255 ss<<"if(gid0>=buffer_tmp001_len || isNan(";
2256 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
2257 ss<<"))\n\t\t";
2258 ss<<"tmp001 = 0;\n\telse \n\t\t";
2259 ss<<"tmp001 = ";
2260 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
2261 ss<<";\n\t";
2263 ss<<"if(gid0>=buffer_tmp002_len || isNan(";
2264 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
2265 ss<<"))\n\t\t";
2266 ss<<"tmp002 = 0;\n\telse \n\t\t";
2267 ss<<"tmp002 = ";
2268 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
2269 ss<<";\n\t";
2271 ss<<"if(gid0>=buffer_tmp003_len || isNan(";
2272 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
2273 ss<<"))\n\t\t";
2274 ss<<"tmp003 = 0;\n\telse \n\t\t";
2275 ss<<"tmp003 = ";
2276 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
2277 ss<<";\n\t";
2279 ss<<"if(gid0>=buffer_tmp004_len || isNan(";
2280 ss << vSubArguments[4]->GenSlidingWindowDeclRef();
2281 ss<<"))\n\t\t";
2282 ss<<"tmp004 = 0;\n\telse \n\t\t";
2283 ss<<"tmp004 = ";
2284 ss << vSubArguments[4]->GenSlidingWindowDeclRef();
2285 ss<<";\n\t";
2287 ss<<"if(gid0>=buffer_tmp005_len || isNan(";
2288 ss << vSubArguments[5]->GenSlidingWindowDeclRef();
2289 ss<<"))\n\t\t";
2290 ss<<"tmp005 = 0;\n\telse \n\t\t";
2291 ss<<"tmp005 = ";
2292 ss << vSubArguments[5]->GenSlidingWindowDeclRef();
2293 ss<<";\n\t";
2295 ss << "tmp = GetYieldmat(";
2296 ss<<"GetNullDate(),tmp000,tmp001,tmp002,tmp003,tmp004,tmp005);\n\t";
2297 ss << "return tmp;\n";
2298 ss << "}";
2301 void OpPMT::GenSlidingWindowFunction(std::stringstream &ss,
2302 const std::string &sSymName, SubArguments &vSubArguments)
2304 ss << "\ndouble " << sSymName;
2305 ss << "_"<< BinFuncName() <<"(";
2306 for (unsigned i = 0; i < vSubArguments.size(); i++)
2308 if (i)
2309 ss << ", ";
2310 vSubArguments[i]->GenSlidingWindowDecl(ss);
2312 ss<<") {\n";
2313 ss<<" double tmp = 0;\n";
2314 ss<<" double temp=0.0;\n";
2315 ss<<" int gid0 = get_global_id(0);\n";
2316 ss<<" double tmp0=0,tmp1=0,tmp2=0;\n";
2317 ss<<" double tmp3=0,tmp4=0;\n";
2318 size_t i = vSubArguments.size();
2319 ss <<"\n ";
2320 //while (i-- > 1)
2321 for (i = 0; i < vSubArguments.size(); i++)
2323 FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
2324 assert(pCur);
2325 if (pCur->GetType() == formula::svSingleVectorRef)
2327 const formula::SingleVectorRefToken* pSVR =
2328 static_cast< const formula::SingleVectorRefToken* >(pCur);
2329 ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
2331 else if (pCur->GetType() == formula::svDouble)
2333 ss << "{\n";
2335 else
2338 if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
2340 ss <<" temp="<<vSubArguments[i]->GenSlidingWindowDeclRef();
2341 ss <<";\n";
2342 ss <<" if (isNan(temp))\n";
2343 ss <<" tmp"<<i<<"= 0;\n";
2344 ss <<" else\n";
2345 ss <<" tmp"<<i<<"=temp;\n";
2346 ss <<" }\n";
2348 else
2350 ss <<" tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(
2352 ss <<";\n";
2355 ss<<" if(tmp0==0.0)\n";
2356 ss<<" return -(tmp2+tmp3)/tmp1;\n";
2357 ss<<" tmp-=tmp3;\n";
2358 ss<<" tmp=tmp-tmp2*pow(1.0+tmp0,tmp1);\n";
2359 ss<<" tmp=tmp*pow(( (1.0+tmp0*tmp4)* ";
2360 ss<<"( (pow(1.0+tmp0,tmp1)-1.0)/tmp0)),-1);\n";
2361 ss<<" return tmp;\n";
2362 ss<<"}";
2365 void OpNPV::GenSlidingWindowFunction(std::stringstream &ss,
2366 const std::string &sSymName, SubArguments &vSubArguments)
2368 ss << "\ndouble " << sSymName;
2369 ss << "_"<< BinFuncName() <<"(";
2370 for (unsigned i = 0; i < vSubArguments.size(); i++)
2372 if (i)
2373 ss << ", ";
2374 vSubArguments[i]->GenSlidingWindowDecl(ss);
2376 ss << ") {\n";
2377 ss << " double tmp = 0.0;\n";
2378 ss << " int gid0 = get_global_id(0);\n";
2379 ss << " int nCount = 1;\n";
2380 ss << " double arg0=";
2381 ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
2382 ss <<";\n";
2383 //while (i-- > 1)
2384 for (size_t i = 1; i < vSubArguments.size(); i++)
2386 FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
2387 assert(pCur);
2388 if (pCur->GetType() == formula::svDoubleVectorRef)
2390 const formula::DoubleVectorRefToken* pDVR =
2391 static_cast<const formula::DoubleVectorRefToken *>(pCur);
2392 size_t nCurWindowSize = pDVR->GetRefRowSize();
2393 ss << " for (int i = ";
2394 if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
2395 ss << "gid0; i < " << pDVR->GetArrayLength();
2396 ss << " && i < " << nCurWindowSize << "; i++){\n";
2397 } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
2398 ss << "0; i < " << pDVR->GetArrayLength();
2399 ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
2400 } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
2401 ss << "0; i + gid0 < " << pDVR->GetArrayLength();
2402 ss << " && i < "<< nCurWindowSize << "; i++){\n";
2404 else {
2405 ss << "0; i < "<< nCurWindowSize << "; i++){\n";
2408 else if (pCur->GetType() == formula::svSingleVectorRef)
2410 const formula::SingleVectorRefToken* pSVR =
2411 static_cast< const formula::SingleVectorRefToken* >(pCur);
2412 ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
2414 else if (pCur->GetType() == formula::svDouble)
2416 ss << "{\n";
2418 else
2420 ss << "nCount += 1;\n";
2422 if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
2424 ss << " double temp=";
2425 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2426 ss << ";\n";
2427 ss << " double temp1=1.0;";
2428 ss << " if (isNan(temp)){\n";
2429 ss << " tmp += 0;}\n";
2430 ss << " else{\n";
2431 ss << " for(int i=1;i<nCount;i+=2)\n";
2432 ss << " temp1*=pow(1.0f+ arg0 ,2);\n";
2433 ss << " if(nCount%2)\n";
2434 ss << " temp1*=1.0f+ arg0;\n";
2435 ss << " tmp +=temp/ temp1;\n";
2436 ss << " nCount += 1;\n";
2437 ss << " }\n";
2438 ss << " }\n";
2440 else
2442 ss << " double temp=";
2443 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2444 ss << ";\n";
2445 ss << " double temp1=1.0;";
2446 ss << " for(int i=1;i<nCount;i+=2)";
2447 ss << " temp1*=pow(1.0f+ arg0 ,2);\n";
2448 ss << " if(nCount%2)";
2449 ss << " temp1*=1.0f+ arg0;\n";
2450 ss << " tmp +=temp/ temp1;\n";
2451 ss << " nCount += 1;\n";
2454 ss << " return tmp;\n";
2455 ss << "}";
2458 void OpPrice::BinInlineFun(std::set<std::string>& decls,
2459 std::set<std::string>& funs)
2461 decls.insert(getPrice_new_Decl);
2462 decls.insert(IsLeapYearDecl);decls.insert(DaysInMonthDecl);
2463 decls.insert(DaysToDateDecl);
2464 decls.insert(DateToDaysDecl);
2465 decls.insert(ScaDateDecl);
2466 decls.insert(setDayDecl);decls.insert(checklessthanDecl);
2467 decls.insert(addMonthsDecl);decls.insert(lcl_Getcoupnum_newDecl);
2468 decls.insert(coupnum_newDecl);
2469 decls.insert(DateToDays_newDecl);
2470 decls.insert(getDaysInMonthRangeDecl);
2471 decls.insert(GetDaysInYearsDecl); decls.insert(GetDaysInYearDecl);
2472 decls.insert(getDaysInYearRangeDecl); decls.insert(getDiffDecl);
2473 decls.insert(coupdaybs_newDecl);
2474 decls.insert(lcl_Getcoupdays_newDecl);
2475 decls.insert(lcl_Getcoupdaybs_newDecl);
2476 decls.insert(coupdays_newDecl);
2477 decls.insert(coupdaysnc_newDecl);
2478 funs.insert(IsLeapYear);funs.insert(DaysInMonth_new);
2479 funs.insert(DaysToDate);funs.insert(DateToDays_new);
2480 funs.insert(DateToDays);
2481 funs.insert(ScaDate);
2482 funs.insert(addMonths);funs.insert(getDaysInMonthRange);
2483 funs.insert(GetDaysInYears);funs.insert(GetDaysInYear);
2484 funs.insert(getDaysInYearRange);funs.insert(getDiff);
2485 funs.insert(setDay);funs.insert(checklessthan);
2486 funs.insert(lcl_Getcoupdaybs_new);
2487 funs.insert(coupdaybs_new);
2488 funs.insert(lcl_Getcoupdays_new);
2489 funs.insert(coupdaysnc_new);
2490 funs.insert(coupdays_new);
2491 funs.insert(setDay);funs.insert(checklessthan);
2492 funs.insert(lcl_Getcoupnum_new);
2493 funs.insert(coupnum_new);funs.insert(getPrice_new);
2495 void OpPrice::GenSlidingWindowFunction(std::stringstream &ss,
2496 const std::string &sSymName, SubArguments &vSubArguments)
2498 ss << "\ndouble " << sSymName;
2499 ss << "_"<< BinFuncName() <<"(";
2500 for (unsigned i = 0; i < vSubArguments.size(); i++)
2502 if (i)
2503 ss << ", ";
2504 vSubArguments[i]->GenSlidingWindowDecl(ss);
2506 ss<<") {\n";
2507 ss<<" double tmp = 0;\n";
2508 ss<<" int gid0 = get_global_id(0);\n";
2509 ss<<" double tmp0=0;\n";
2510 ss<<" double tmp1=0;\n";
2511 ss<<" double tmp2=0;\n";
2512 ss<<" double tmp3=0;\n";
2513 ss<<" double tmp4=0,tmp5=0;\n";
2514 ss<<" double tmp6=0;\n";
2515 ss<<"\n";
2516 for (size_t i = 0; i < vSubArguments.size(); i++)
2518 FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
2519 assert(pCur);
2520 if (pCur->GetType() == formula::svSingleVectorRef)
2522 const formula::SingleVectorRefToken* pSVR =
2523 static_cast< const formula::SingleVectorRefToken* >(pCur);
2524 ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
2526 else if (pCur->GetType() == formula::svDouble)
2528 ss << "{\n";
2530 else
2533 if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
2535 ss << " if (isNan(";
2536 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2537 ss << "))\n";
2538 ss << " tmp"<<i<<"= 0;\n";
2539 ss << " else\n";
2540 ss << " tmp"<<i<<"=";
2541 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2542 ss << ";\n }\n";
2544 else
2546 ss << " tmp"<<i<<"=";
2547 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2548 ss <<";\n";
2551 ss << " if(tmp4*tmp5 == 0) return NAN;\n";
2552 ss << " tmp = getPrice_(tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);\n";
2553 ss << " return tmp;\n";
2554 ss << "}";
2557 void OpOddlprice::BinInlineFun(std::set<std::string>& decls,
2558 std::set<std::string>& funs)
2560 decls.insert(GetOddlpriceDecl);decls.insert(GetDiffDateDecl);
2561 decls.insert(GetYearDiffDecl);decls.insert(IsLeapYearDecl);
2562 decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
2563 decls.insert(DaysToDateDecl);decls.insert(DaysInMonthDecl);
2564 decls.insert(GetYearFracDecl);
2565 funs.insert(GetOddlprice);funs.insert(GetDiffDate);
2566 funs.insert(GetYearDiff);funs.insert(IsLeapYear);
2567 funs.insert(GetNullDate);funs.insert(DaysInMonth);
2568 funs.insert(DaysToDate);funs.insert(DateToDays);
2569 funs.insert(GetYearFrac);
2571 void OpOddlprice::GenSlidingWindowFunction(std::stringstream &ss,
2572 const std::string &sSymName, SubArguments &vSubArguments)
2574 ss << "\ndouble " << sSymName;
2575 ss << "_"<< BinFuncName() <<"(";
2576 for (unsigned i = 0; i < vSubArguments.size(); i++)
2578 if (i)
2579 ss << ", ";
2580 vSubArguments[i]->GenSlidingWindowDecl(ss);
2582 ss <<") {\n";
2583 ss <<" double tmp = 0;\n";
2584 ss <<" int gid0 = get_global_id(0);\n";
2585 ss <<" double tmp0=0;\n";
2586 ss <<" double tmp1=0;\n";
2587 ss <<" double tmp2=0;\n";
2588 ss <<" double tmp3=0;\n";
2589 ss <<" double tmp4=0;\n";
2590 ss <<" double tmp5=0;\n";
2591 ss <<" double tmp6=0;\n";
2592 ss <<" double tmp7=0;\n";
2593 ss <<" \n";
2594 for (size_t i = 0; i < vSubArguments.size(); i++)
2596 FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
2597 assert(pCur);
2598 if (pCur->GetType() == formula::svDoubleVectorRef)
2600 const formula::DoubleVectorRefToken* pDVR =
2601 static_cast<const formula::DoubleVectorRefToken *>(pCur);
2602 size_t nCurWindowSize = pDVR->GetRefRowSize();
2603 ss << " for (int i = ";
2604 if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
2605 ss << "gid0; i < " << pDVR->GetArrayLength();
2606 ss << " && i < " << nCurWindowSize << "; i++){\n";
2607 } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
2608 ss << "0; i < " << pDVR->GetArrayLength();
2609 ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
2610 } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
2611 ss << "0; i + gid0 < " << pDVR->GetArrayLength();
2612 ss << " && i < "<< nCurWindowSize << "; i++){\n";
2614 else {
2615 ss << "0; i < "<< nCurWindowSize << "; i++){\n";
2618 else if (pCur->GetType() == formula::svSingleVectorRef)
2620 const formula::SingleVectorRefToken* pSVR =
2621 static_cast< const formula::SingleVectorRefToken* >(pCur);
2622 ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
2624 else if (pCur->GetType() == formula::svDouble)
2626 ss << "{\n";
2628 else
2631 if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
2633 ss << " if (isNan(";
2634 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2635 ss << "))\n";
2636 ss << " tmp"<<i<<"= 0;\n";
2637 ss << " else\n";
2638 ss << " tmp"<<i<<"=";
2639 ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
2640 ss << ";\n";
2641 ss <<" }\n";
2643 else
2645 ss << " tmp"<<i<<"=";
2646 ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
2647 ss <<";\n";
2650 ss <<" int nNullDate = GetNullDate();\n";
2651 ss <<" tmp = GetOddlprice(nNullDate,tmp0,tmp1,";
2652 ss <<"tmp2,tmp3,tmp4,tmp5,tmp6,tmp7);\n";
2653 ss <<" return tmp;\n";
2654 ss <<"}";
2656 void OpOddlyield::BinInlineFun(std::set<std::string>& decls,
2657 std::set<std::string>& funs)
2659 decls.insert(GetDiffDateDecl);decls.insert(DaysToDateDecl);
2660 decls.insert(GetYearDiffDecl);decls.insert(IsLeapYearDecl);
2661 decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
2662 decls.insert(DaysInMonthDecl);
2663 decls.insert(GetYearFracDecl);decls.insert(GetOddlyieldDecl);
2664 funs.insert(GetDiffDate);funs.insert(DaysToDate);
2665 funs.insert(GetYearDiff);funs.insert(IsLeapYear);
2666 funs.insert(GetNullDate);funs.insert(DaysInMonth);
2667 funs.insert(DateToDays);
2668 funs.insert(GetYearFrac);funs.insert(GetOddlyield);
2670 void OpOddlyield::GenSlidingWindowFunction(std::stringstream &ss,
2671 const std::string &sSymName, SubArguments &vSubArguments)
2673 ss << "\ndouble " << sSymName;
2674 ss << "_"<< BinFuncName() <<"(";
2675 for (unsigned i = 0; i < vSubArguments.size(); i++)
2677 if (i)
2678 ss << ", ";
2679 vSubArguments[i]->GenSlidingWindowDecl(ss);
2681 ss <<") {\n";
2682 ss <<" double tmp = 0;\n";
2683 ss <<" int gid0 = get_global_id(0);\n";
2684 ss <<" double tmp0=0;\n";
2685 ss <<" double tmp1=0;\n";
2686 ss <<" double tmp2=0;\n";
2687 ss <<" double tmp3=0;\n";
2688 ss <<" double tmp4=0;\n";
2689 ss <<" double tmp5=0;\n";
2690 ss <<" double tmp6=0;\n";
2691 ss <<" double tmp7=0;\n";
2692 ss <<" \n";
2693 for (size_t i = 0; i < vSubArguments.size(); i++)
2695 FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
2696 assert(pCur);
2697 if (pCur->GetType() == formula::svDoubleVectorRef)
2699 const formula::DoubleVectorRefToken* pDVR =
2700 static_cast<const formula::DoubleVectorRefToken *>(pCur);
2701 size_t nCurWindowSize = pDVR->GetRefRowSize();
2702 ss << " for (int i = ";
2703 if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
2704 ss << "gid0; i < " << pDVR->GetArrayLength();
2705 ss << " && i < " << nCurWindowSize << "; i++){\n";
2706 } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
2707 ss << "0; i < " << pDVR->GetArrayLength();
2708 ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
2709 } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
2710 ss << "0; i + gid0 < " << pDVR->GetArrayLength();
2711 ss << " && i < "<< nCurWindowSize << "; i++){\n";
2713 else {
2714 ss << "0; i < "<< nCurWindowSize << "; i++){\n";
2717 else if (pCur->GetType() == formula::svSingleVectorRef)
2719 const formula::SingleVectorRefToken* pSVR =
2720 static_cast< const formula::SingleVectorRefToken* >(pCur);
2721 ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
2723 else if (pCur->GetType() == formula::svDouble)
2725 ss << "{\n";
2727 else
2730 if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
2732 ss << " if (isNan(";
2733 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2734 ss << "))\n";
2735 ss << " tmp"<<i<<"= 0;\n";
2736 ss << " else\n";
2737 ss << " tmp"<<i<<"=";
2738 ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
2739 ss << ";\n";
2740 ss <<" }\n";
2742 else
2744 ss << " tmp"<<i<<"=";
2745 ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
2746 ss <<";\n";
2749 ss <<" int nNullDate = GetNullDate();\n";
2750 ss <<" tmp = GetOddlyield(nNullDate,tmp0,tmp1";
2751 ss <<",tmp2,tmp3,tmp4,tmp5,tmp6,tmp7);\n";
2752 ss <<" return tmp;\n";
2753 ss <<"}";
2755 void OpPriceDisc::BinInlineFun(std::set<std::string>& decls,
2756 std::set<std::string>& funs)
2758 decls.insert(GetYearDiffDecl);decls.insert(getDiffDecl);
2759 decls.insert(getDaysInYearRangeDecl);decls.insert(GetDaysInYearDecl);
2760 decls.insert(GetDaysInYearsDecl);decls.insert(getDaysInMonthRangeDecl);
2761 decls.insert(addMonthsDecl);decls.insert(ScaDateDecl);
2762 decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
2763 decls.insert(DaysToDateDecl);decls.insert(DaysInMonthDecl);
2764 decls.insert(IsLeapYearDecl);decls.insert(GetDiffDateDecl);
2765 funs.insert(GetYearDiff);funs.insert(getDiff);
2766 funs.insert(getDaysInYearRange);funs.insert(GetDaysInYear);
2767 funs.insert(GetDaysInYears);funs.insert(getDaysInMonthRange);
2768 funs.insert(addMonths);funs.insert(ScaDate);
2769 funs.insert(GetNullDate);funs.insert(DateToDays);
2770 funs.insert(DaysToDate);funs.insert(DaysInMonth);
2771 funs.insert(IsLeapYear);funs.insert(GetDiffDate);
2773 void OpPriceDisc::GenSlidingWindowFunction(std::stringstream &ss,
2774 const std::string &sSymName, SubArguments &vSubArguments)
2776 ss << "\ndouble " << sSymName;
2777 ss << "_"<< BinFuncName() <<"(";
2778 for (unsigned i = 0; i < vSubArguments.size(); i++)
2780 if (i)
2781 ss << ", ";
2782 vSubArguments[i]->GenSlidingWindowDecl(ss);
2784 ss << ") {\n";
2785 ss << " double tmp = 0;\n";
2786 ss << " int gid0 = get_global_id(0);\n";
2787 ss<<" double tmp0=0;\n";
2788 ss<<" double tmp1=0;\n";
2789 ss<<" double tmp2=0;\n";
2790 ss<<" double tmp3=0;\n";
2791 ss<<" double tmp4=0;\n";
2792 ss <<" \n";
2793 for (size_t i = 0; i < vSubArguments.size(); i++)
2795 FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
2796 assert(pCur);
2797 if (pCur->GetType() == formula::svSingleVectorRef)
2799 const formula::SingleVectorRefToken* pSVR =
2800 static_cast< const formula::SingleVectorRefToken* >(pCur);
2801 ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
2803 else if (pCur->GetType() == formula::svDouble)
2805 ss << "{\n";
2807 else
2810 if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
2812 ss << " if (isNan(";
2813 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2814 ss << "))\n";
2815 ss << " tmp"<<i<<"= 0;\n";
2816 ss << " else\n";
2817 ss << " tmp"<<i<<"=";
2818 ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
2819 ss << ";\n";
2820 ss <<" }\n";
2822 else
2824 ss << " tmp"<<i<<"=";
2825 ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
2826 ss <<";\n";
2829 ss <<" int nNullDate = GetNullDate();\n";
2830 ss <<" tmp=tmp3* ( 1.0 -tmp2*GetYearDiff( nNullDate, ";
2831 ss <<"tmp0,tmp1,tmp4));\n";
2832 ss <<" return tmp;\n";
2833 ss <<"}";
2835 void OpNper::GenSlidingWindowFunction(std::stringstream &ss,
2836 const std::string &sSymName, SubArguments &vSubArguments)
2838 ss << "\ndouble " << sSymName;
2839 ss << "_"<< BinFuncName() <<"(";
2840 for (unsigned i = 0; i < vSubArguments.size(); i++)
2842 if (i)
2843 ss << ", ";
2844 vSubArguments[i]->GenSlidingWindowDecl(ss);
2846 ss << ") {\n";
2847 ss << " double tmp = 0;\n";
2848 ss << " int gid0 = get_global_id(0);\n";
2849 ss <<" double tmp0=0;\n";
2850 ss <<" double tmp1=0;\n";
2851 ss <<" double tmp2=0;\n";
2852 ss <<" double tmp3=0;\n";
2853 ss <<" double tmp4=0;\n";
2855 for (size_t i = 0; i < vSubArguments.size(); i++)
2857 FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
2858 assert(pCur);
2859 if (pCur->GetType() == formula::svSingleVectorRef)
2861 const formula::SingleVectorRefToken* pSVR =
2862 static_cast< const formula::SingleVectorRefToken* >(pCur);
2863 ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
2865 else if (pCur->GetType() == formula::svDouble)
2867 ss << "{\n";
2869 else
2872 if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
2874 ss << " if (isNan(";
2875 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2876 ss << "))\n";
2877 ss << " tmp"<<i<<"= 0;\n";
2878 ss << " else\n";
2879 ss << " tmp"<<i<<"=";
2880 ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
2881 ss << ";\n";
2882 ss <<" }\n";
2884 else
2886 ss << " tmp"<<i<<"=";
2887 ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
2888 ss <<";\n";
2891 ss <<" if (tmp0 == 0.0)\n";
2892 ss <<" tmp=(-1*(tmp2 + tmp3)/tmp1);\n";
2893 ss <<" else if (tmp4 > 0.0)\n";
2894 ss <<" tmp=log(-1*(tmp0*tmp3-tmp1*(1.0+tmp0))*";
2895 ss <<"pow((tmp0*tmp2+tmp1*(1.0+tmp0)),-1))/log(1.0+tmp0);\n";
2896 ss <<" else\n";
2897 ss <<" tmp=log(-1*(tmp0*tmp3-tmp1)*pow(tmp0*tmp2+tmp1,-1))";
2898 ss <<"/log(1.0+tmp0);\n";
2899 ss <<" return tmp;\n";
2900 ss <<"}";
2903 void OpPPMT::BinInlineFun(std::set<std::string>& decls,
2904 std::set<std::string>& funs)
2906 decls.insert(GetZwDecl);
2907 funs.insert(GetZw);
2910 void OpPPMT::GenSlidingWindowFunction(std::stringstream &ss,
2911 const std::string &sSymName, SubArguments &vSubArguments)
2913 ss << "\ndouble " << sSymName;
2914 ss << "_"<< BinFuncName() <<"(";
2915 for (unsigned i = 0; i < vSubArguments.size(); i++)
2917 if (i)
2918 ss << ", ";
2919 vSubArguments[i]->GenSlidingWindowDecl(ss);
2921 ss<<") {\n";
2922 ss<<" double tmp = 0;\n";
2923 ss<<" int gid0 = get_global_id(0);\n";
2924 ss<<" double arg=0;\n";
2925 ss<<" double tmp0=0;\n";
2926 ss<<" double tmp1=0;\n";
2927 ss<<" double tmp2=0;\n";
2928 ss<<" double tmp3=0;\n";
2929 ss<<" double tmp4=0,tmp5=0;\n";
2930 ss <<"\n ";
2931 //while (i-- > 1)
2932 for (size_t i = 0; i < vSubArguments.size(); i++)
2934 FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
2935 assert(pCur);
2936 if (pCur->GetType() == formula::svSingleVectorRef)
2938 const formula::SingleVectorRefToken* pSVR =
2939 static_cast< const formula::SingleVectorRefToken* >(pCur);
2940 ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
2942 else if (pCur->GetType() == formula::svDouble)
2944 ss << "{\n";
2946 else
2949 if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
2951 ss << " arg=";
2952 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2953 ss << ";\n";
2954 ss << " if (isNan(arg))\n";
2955 ss << " tmp"<<i<<"= 0;\n";
2956 ss << " else\n";
2957 ss << " tmp"<<i<<"=arg;\n";
2958 ss << " }\n";
2960 else
2962 ss<<" tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
2963 ss<<";\n";
2966 ss<<" double pmt=0 ;\n";
2967 ss<<" if(tmp0==0.0)\n";
2968 ss<<" return -(tmp3+tmp4)/tmp2;\n";
2969 ss<<" pmt=pmt-tmp4-tmp3*pow(1.0+tmp0,tmp2);\n";
2970 ss<<" pmt=pmt*pow(( (1.0+tmp0*tmp5)* ";
2971 ss<<"( (pow(1.0+tmp0,tmp2)-1.0)/tmp0)),-1);\n";
2972 ss<<" double temp = pow( 1+tmp0,tmp1-2);\n";
2973 ss<<" double re;\n";
2974 ss<<" if(tmp1==1.0){\n";
2975 ss<<" if(tmp5>0.0)\n";
2976 ss<<" re=0.0;\n";
2977 ss<<" else\n";
2978 ss<<" re=-tmp3;\n";
2979 ss<<" }\n";
2980 ss<<" else\n";
2981 ss<<" {\n";
2982 ss<<" if(tmp5>0.0)\n ";
2983 ss<<" re=GetZw(tmp0, tmp1-2.0, pmt, tmp3, 1.0) - pmt;\n";
2984 ss<<" else\n";
2985 ss<<" re=GetZw(tmp0, tmp1-1.0, pmt, tmp3, 0.0);\n";
2986 ss<<" }\n ";
2987 ss<<" re = re * tmp0;\n";
2988 ss<<" tmp = pmt - re;\n";
2989 ss<<" return tmp;\n";
2990 ss<<"}";
2993 void OpCoupdaybs::BinInlineFun(std::set<std::string>& decls,
2994 std::set<std::string>& funs)
2996 decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
2997 decls.insert(DaysToDateDecl); decls.insert(DateToDays_newDecl);
2998 decls.insert(GetNullDate_newDecl); decls.insert(ScaDateDecl);
2999 decls.insert(addMonthsDecl); decls.insert(getDaysInMonthRangeDecl);
3000 decls.insert(GetDaysInYearsDecl);
3001 decls.insert(getDaysInYearRangeDecl); decls.insert(getDiffDecl);
3002 decls.insert(setDayDecl);decls.insert(checklessthanDecl);
3003 decls.insert(lcl_Getcoupdaybs_newDecl);
3004 decls.insert(coupdaybs_newDecl);
3005 funs.insert(IsLeapYear);funs.insert(DaysInMonth);
3006 funs.insert(DaysToDate);funs.insert(DateToDays_new);
3007 funs.insert(GetNullDate_new);funs.insert(ScaDate);
3008 funs.insert(addMonths);funs.insert(getDaysInMonthRange);
3009 funs.insert(GetDaysInYears);
3010 funs.insert(getDaysInYearRange);funs.insert(getDiff);
3011 funs.insert(setDay);funs.insert(checklessthan);
3012 funs.insert(lcl_Getcoupdaybs_new);
3013 funs.insert(coupdaybs_new);
3015 void OpCoupdaybs::GenSlidingWindowFunction(
3016 std::stringstream &ss, const std::string &sSymName, SubArguments &
3017 vSubArguments)
3019 ss << "\ndouble " << sSymName;
3020 ss << "_"<< BinFuncName() <<"(";
3021 for (unsigned i = 0; i < vSubArguments.size(); i++)
3023 if (i)
3024 ss << ",";
3025 vSubArguments[i]->GenSlidingWindowDecl(ss);
3027 ss << ") {\n";
3028 ss << " double tmp = 0;\n";
3029 ss << " int gid0 = get_global_id(0);\n";
3030 ss << " int nSettle,nMat,nFreq,nBase;\n";
3031 FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
3032 FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
3033 FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
3034 FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
3035 if(tmpCur0->GetType() == formula::svSingleVectorRef)
3037 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
3038 formula::SingleVectorRefToken *>(tmpCur0);
3039 ss <<" if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
3040 ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
3041 ss <<" nSettle = 0;\n else\n";
3043 ss <<" nSettle=(int)";
3044 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
3045 ss <<";\n";
3046 if(tmpCur1->GetType() == formula::svSingleVectorRef)
3048 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
3049 formula::SingleVectorRefToken *>(tmpCur1);
3050 ss <<" if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
3051 ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
3052 ss <<" nMat = 0;\n else\n";
3054 ss <<" nMat=(int)";
3055 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
3056 ss <<";\n";
3057 if(tmpCur2->GetType() == formula::svSingleVectorRef)
3059 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
3060 formula::SingleVectorRefToken *>(tmpCur2);
3061 ss <<" if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
3062 ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
3063 ss <<" nFreq = 0;\n else\n";
3065 ss << " nFreq=(int)";
3066 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
3067 ss <<";\n";
3068 if(tmpCur3->GetType() == formula::svSingleVectorRef)
3070 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
3071 formula::SingleVectorRefToken *>(tmpCur3);
3072 ss <<" if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
3073 ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
3074 ss <<" nBase = 0;\n else\n";
3076 ss << " nBase=(int)";
3077 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
3078 ss << ";\n";
3079 ss <<" tmp = coupdaybs_new(nSettle,nMat,nFreq,nBase);\n";
3080 ss <<" return tmp;\n";
3081 ss <<"}";
3084 void OpCoupdays::BinInlineFun(std::set<std::string>& decls,
3085 std::set<std::string>& funs)
3087 decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
3088 decls.insert(DaysToDateDecl); decls.insert(DateToDays_newDecl);
3089 decls.insert(GetNullDate_newDecl); decls.insert(ScaDateDecl);
3090 decls.insert(addMonthsDecl); decls.insert(getDaysInMonthRangeDecl);
3091 decls.insert(GetDaysInYearsDecl); decls.insert(GetDaysInYearDecl);
3092 decls.insert(getDaysInYearRangeDecl); decls.insert(getDiffDecl);
3093 decls.insert(setDayDecl);decls.insert(checklessthanDecl);
3094 decls.insert(lcl_Getcoupdays_newDecl);
3095 decls.insert(coupdays_newDecl);
3096 funs.insert(IsLeapYear);funs.insert(DaysInMonth);
3097 funs.insert(DaysToDate);funs.insert(DateToDays_new);
3098 funs.insert(GetNullDate_new);funs.insert(ScaDate);
3099 funs.insert(addMonths);funs.insert(getDaysInMonthRange);
3100 funs.insert(GetDaysInYears);funs.insert(GetDaysInYear);
3101 funs.insert(getDaysInYearRange);funs.insert(getDiff);
3102 funs.insert(lcl_Getcoupdays_new);
3103 funs.insert(setDay);funs.insert(checklessthan);
3104 funs.insert(coupdays_new);
3106 void OpCoupdays::GenSlidingWindowFunction(
3107 std::stringstream &ss, const std::string &sSymName, SubArguments &
3108 vSubArguments)
3110 ss << "\ndouble " << sSymName;
3111 ss << "_"<< BinFuncName() <<"(";
3112 for (unsigned i = 0; i < vSubArguments.size(); i++)
3114 if (i)
3115 ss << ",";
3116 vSubArguments[i]->GenSlidingWindowDecl(ss);
3118 ss << ") {\n";
3119 ss << " double tmp = 0;\n";
3120 ss << " int gid0 = get_global_id(0);\n";
3121 ss << " int nSettle,nMat,nFreq,nBase;\n";
3122 FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
3123 FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
3124 FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
3125 FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
3126 if(tmpCur0->GetType() == formula::svSingleVectorRef)
3128 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
3129 formula::SingleVectorRefToken *>(tmpCur0);
3130 ss <<" if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
3131 ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
3132 ss <<" nSettle = 0;\n else\n";
3134 ss <<" nSettle=(int)";
3135 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
3136 ss <<";\n";
3137 if(tmpCur1->GetType() == formula::svSingleVectorRef)
3139 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
3140 formula::SingleVectorRefToken *>(tmpCur1);
3141 ss <<" if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
3142 ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
3143 ss <<" nMat = 0;\n else\n";
3145 ss <<" nMat=(int)";
3146 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
3147 ss <<";\n";
3148 if(tmpCur2->GetType() == formula::svSingleVectorRef)
3150 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
3151 formula::SingleVectorRefToken *>(tmpCur2);
3152 ss <<" if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
3153 ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
3154 ss <<" nFreq = 0;\n else\n";
3156 ss << " nFreq=(int)";
3157 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
3158 ss <<";\n";
3159 if(tmpCur3->GetType() == formula::svSingleVectorRef)
3161 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
3162 formula::SingleVectorRefToken *>(tmpCur3);
3163 ss <<" if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
3164 ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
3165 ss <<" nBase = 0;\n else\n";
3167 ss << " nBase=(int)";
3168 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
3169 ss << ";\n";
3170 ss <<" tmp = coupdays_new(nSettle,nMat,nFreq,nBase);\n";
3171 ss <<" return tmp;\n";
3172 ss << "}";
3174 void OpCouppcd::BinInlineFun(std::set<std::string>& decls,
3175 std::set<std::string>& funs)
3177 decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
3178 decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
3179 decls.insert(GetNullDateDecl);
3180 decls.insert(ScaDateDecl);
3181 decls.insert(addMonthsDecl);
3182 decls.insert(setDayDecl);decls.insert(checklessthanDecl);
3183 decls.insert(lcl_GetCouppcdDecl);
3184 funs.insert(IsLeapYear);funs.insert(DaysInMonth);
3185 funs.insert(DaysToDate);funs.insert(DateToDays);
3186 funs.insert(GetNullDate);
3187 funs.insert(ScaDate);
3188 funs.insert(addMonths);
3189 funs.insert(setDay);funs.insert(checklessthan);
3190 funs.insert(lcl_GetCouppcd);
3192 void OpCouppcd::GenSlidingWindowFunction(
3193 std::stringstream &ss, const std::string &sSymName,
3194 SubArguments &vSubArguments)
3196 ss << "\ndouble " << sSymName;
3197 ss << "_"<< BinFuncName() <<"(";
3198 for (unsigned i = 0; i < vSubArguments.size(); i++)
3200 if (i)
3201 ss << ",";
3202 vSubArguments[i]->GenSlidingWindowDecl(ss);
3204 ss << ") {\n";
3205 ss << " double tmp = 0;\n";
3206 ss << " int gid0 = get_global_id(0);\n";
3207 ss << " int nSettle,nMat,nFreq,nBase;\n";
3208 FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
3209 FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
3210 FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
3211 FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
3212 if(tmpCur0->GetType() == formula::svSingleVectorRef)
3214 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
3215 formula::SingleVectorRefToken *>(tmpCur0);
3216 ss <<" if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
3217 ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
3218 ss <<" nSettle = 0;\n else\n";
3220 ss <<" nSettle=(int)";
3221 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
3222 ss <<";\n";
3223 if(tmpCur1->GetType() == formula::svSingleVectorRef)
3225 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
3226 formula::SingleVectorRefToken *>(tmpCur1);
3227 ss <<" if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
3228 ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
3229 ss <<" nMat = 0;\n else\n";
3231 ss <<" nMat=(int)";
3232 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
3233 ss <<";\n";
3234 if(tmpCur2->GetType() == formula::svSingleVectorRef)
3236 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
3237 formula::SingleVectorRefToken *>(tmpCur2);
3238 ss <<" if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
3239 ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
3240 ss <<" nFreq = 0;\n else\n";
3242 ss << " nFreq=(int)";
3243 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
3244 ss <<";\n";
3245 if(tmpCur3->GetType() == formula::svSingleVectorRef)
3247 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
3248 formula::SingleVectorRefToken *>(tmpCur3);
3249 ss <<" if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
3250 ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
3251 ss <<" nBase = 0;\n else\n";
3253 ss << " nBase=(int)";
3254 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
3255 ss << ";\n";
3256 ss <<" int nNullDate=693594;\n";
3257 ss <<" tmp = lcl_GetCouppcd(nNullDate,nSettle,nMat,nFreq,nBase);\n";
3258 ss <<" return tmp;\n";
3259 ss <<"}";
3261 void OpCoupncd::BinInlineFun(std::set<std::string>& decls,
3262 std::set<std::string>& funs)
3264 decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
3265 decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
3266 decls.insert(GetNullDateDecl);
3267 decls.insert(ScaDateDecl);
3268 decls.insert(addMonthsDecl);
3269 decls.insert(setDayDecl);decls.insert(checklessthanDecl);
3270 decls.insert(lcl_GetCoupncdDecl);
3271 funs.insert(IsLeapYear);funs.insert(DaysInMonth);
3272 funs.insert(DaysToDate);funs.insert(DateToDays);
3273 funs.insert(GetNullDate);
3274 funs.insert(ScaDate);
3275 funs.insert(addMonths);
3276 funs.insert(setDay);funs.insert(checklessthan);
3277 funs.insert(lcl_GetCoupncd);
3279 void OpCoupncd::GenSlidingWindowFunction(
3280 std::stringstream &ss, const std::string &sSymName, SubArguments &
3281 vSubArguments)
3283 ss << "\ndouble " << sSymName;
3284 ss << "_"<< BinFuncName() <<"(";
3285 for (unsigned i = 0; i < vSubArguments.size(); i++)
3287 if (i)
3288 ss << ",";
3289 vSubArguments[i]->GenSlidingWindowDecl(ss);
3291 ss << ") {\n";
3292 ss << " double tmp = 0;\n";
3293 ss << " int gid0 = get_global_id(0);\n";
3294 ss << " int nSettle,nMat,nFreq,nBase;\n";
3295 FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
3296 FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
3297 FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
3298 FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
3299 if(tmpCur0->GetType() == formula::svSingleVectorRef)
3301 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
3302 formula::SingleVectorRefToken *>(tmpCur0);
3303 ss <<" if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
3304 ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
3305 ss <<" nSettle = 0;\n else\n";
3307 ss <<" nSettle=(int)";
3308 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
3309 ss <<";\n";
3310 if(tmpCur1->GetType() == formula::svSingleVectorRef)
3312 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
3313 formula::SingleVectorRefToken *>(tmpCur1);
3314 ss <<" if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
3315 ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
3316 ss <<" nMat = 0;\n else\n";
3318 ss <<" nMat=(int)";
3319 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
3320 ss <<";\n";
3321 if(tmpCur2->GetType() == formula::svSingleVectorRef)
3323 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
3324 formula::SingleVectorRefToken *>(tmpCur2);
3325 ss <<" if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
3326 ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
3327 ss <<" nFreq = 0;\n else\n";
3329 ss << " nFreq=(int)";
3330 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
3331 ss <<";\n";
3332 if(tmpCur3->GetType() == formula::svSingleVectorRef)
3334 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
3335 formula::SingleVectorRefToken *>(tmpCur3);
3336 ss <<" if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
3337 ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
3338 ss <<" nBase = 0;\n else\n";
3340 ss << " nBase=(int)";
3341 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
3342 ss << ";\n";
3343 ss <<" int nNullDate=693594;\n";
3344 ss <<" tmp = lcl_GetCoupncd(nNullDate,nSettle,nMat,nFreq,nBase);\n";
3345 ss <<" return tmp;\n";
3346 ss <<"}";
3349 void OpCoupdaysnc::BinInlineFun(std::set<std::string>& decls,
3350 std::set<std::string>& funs)
3352 decls.insert(IsLeapYearDecl); decls.insert(DaysInMonth_newDecl);
3353 decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
3354 decls.insert(DateToDays_newDecl);
3355 decls.insert(ScaDateDecl);
3356 decls.insert(addMonthsDecl); decls.insert(getDaysInMonthRangeDecl);
3357 decls.insert(GetDaysInYearsDecl); decls.insert(GetDaysInYearDecl);
3358 decls.insert(getDaysInYearRangeDecl); decls.insert(getDiffDecl);
3359 decls.insert(setDayDecl);decls.insert(checklessthanDecl);
3360 decls.insert(coupdaybs_newDecl);
3361 decls.insert(lcl_Getcoupdays_newDecl);
3362 decls.insert(lcl_Getcoupdaybs_newDecl);
3363 decls.insert(coupdays_newDecl);
3364 decls.insert(coupdaysnc_newDecl);
3365 funs.insert(IsLeapYear);funs.insert(DaysInMonth_new);
3366 funs.insert(DaysToDate);funs.insert(DateToDays_new);
3367 funs.insert(DateToDays);
3368 funs.insert(ScaDate);
3369 funs.insert(addMonths);funs.insert(getDaysInMonthRange);
3370 funs.insert(GetDaysInYears);funs.insert(GetDaysInYear);
3371 funs.insert(getDaysInYearRange);funs.insert(getDiff);
3372 funs.insert(setDay);funs.insert(checklessthan);
3373 funs.insert(lcl_Getcoupdaybs_new);
3374 funs.insert(coupdaybs_new);
3375 funs.insert(lcl_Getcoupdays_new);
3376 funs.insert(coupdaysnc_new);
3377 funs.insert(coupdays_new);
3379 void OpCoupdaysnc::GenSlidingWindowFunction(
3380 std::stringstream &ss, const std::string &sSymName,
3381 SubArguments &vSubArguments)
3383 ss << "\ndouble " << sSymName;
3384 ss << "_"<< BinFuncName() <<"(";
3385 for (unsigned i = 0; i < vSubArguments.size(); i++)
3387 if (i)
3388 ss << ",";
3389 vSubArguments[i]->GenSlidingWindowDecl(ss);
3391 ss << ") {\n";
3392 ss << " double tmp = 0;\n";
3393 ss << " int gid0 = get_global_id(0);\n";
3394 ss << " int nSettle,nMat,nFreq,nBase;\n";
3395 FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
3396 FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
3397 FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
3398 FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
3399 if(tmpCur0->GetType() == formula::svSingleVectorRef)
3401 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
3402 formula::SingleVectorRefToken *>(tmpCur0);
3403 ss <<" if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
3404 ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
3405 ss <<" nSettle = 0;\n else\n";
3407 ss <<" nSettle=(int)";
3408 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
3409 ss <<";\n";
3410 if(tmpCur1->GetType() == formula::svSingleVectorRef)
3412 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
3413 formula::SingleVectorRefToken *>(tmpCur1);
3414 ss <<" if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
3415 ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
3416 ss <<" nMat = 0;\n else\n";
3418 ss <<" nMat=(int)";
3419 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
3420 ss <<";\n";
3421 if(tmpCur2->GetType() == formula::svSingleVectorRef)
3423 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
3424 formula::SingleVectorRefToken *>(tmpCur2);
3425 ss <<" if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
3426 ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
3427 ss <<" nFreq = 0;\n else\n";
3429 ss << " nFreq=(int)";
3430 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
3431 ss <<";\n";
3432 if(tmpCur3->GetType() == formula::svSingleVectorRef)
3434 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
3435 formula::SingleVectorRefToken *>(tmpCur3);
3436 ss <<" if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
3437 ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
3438 ss <<" nBase = 0;\n else\n";
3440 ss << " nBase=(int)";
3441 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
3442 ss << ";\n";
3443 ss <<" tmp = coupdaysnc_new(nSettle,nMat,nFreq,nBase);\n";
3444 ss <<" return tmp;\n";
3445 ss << "}";
3448 void OpCoupnum::BinInlineFun(std::set<std::string>& decls,
3449 std::set<std::string>& funs)
3451 decls.insert(IsLeapYearDecl);decls.insert(DaysInMonthDecl);
3452 decls.insert(DaysToDateDecl);
3453 decls.insert(DateToDaysDecl);
3454 decls.insert(ScaDateDecl);
3455 decls.insert(setDayDecl);decls.insert(checklessthanDecl);
3456 decls.insert(addMonthsDecl);decls.insert(lcl_Getcoupnum_newDecl);
3457 decls.insert(coupnum_newDecl);
3458 funs.insert(IsLeapYear);funs.insert(DaysInMonth_new);
3459 funs.insert(DaysToDate);
3460 funs.insert(DateToDays);
3461 funs.insert(ScaDate);
3462 funs.insert(setDay);funs.insert(checklessthan);
3463 funs.insert(addMonths);funs.insert(lcl_Getcoupnum_new);
3464 funs.insert(coupnum_new);
3466 void OpCoupnum::GenSlidingWindowFunction(std::stringstream &ss,
3467 const std::string &sSymName, SubArguments &vSubArguments)
3469 ss << "\ndouble " << sSymName;
3470 ss << "_"<< BinFuncName() <<"(";
3471 for (unsigned i = 0; i < vSubArguments.size(); i++)
3473 if (i)
3474 ss << ",";
3475 vSubArguments[i]->GenSlidingWindowDecl(ss);
3477 ss << ") {\n";
3478 ss << " double tmp = 0;\n";
3479 ss << " int gid0 = get_global_id(0);\n";
3480 ss << " int nSettle,nMat,nFreq,nBase;\n";
3481 FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
3482 FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
3483 FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
3484 FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
3485 if(tmpCur0->GetType() == formula::svSingleVectorRef)
3487 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
3488 formula::SingleVectorRefToken *>(tmpCur0);
3489 ss <<" if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
3490 ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
3491 ss <<" nSettle = 0;\n else\n";
3493 ss <<" nSettle=(int)";
3494 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
3495 ss <<";\n";
3496 if(tmpCur1->GetType() == formula::svSingleVectorRef)
3498 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
3499 formula::SingleVectorRefToken *>(tmpCur1);
3500 ss <<" if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
3501 ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
3502 ss <<" nMat = 0;\n else\n";
3504 ss <<" nMat=(int)";
3505 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
3506 ss <<";\n";
3507 if(tmpCur2->GetType() == formula::svSingleVectorRef)
3509 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
3510 formula::SingleVectorRefToken *>(tmpCur2);
3511 ss <<" if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
3512 ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
3513 ss <<" nFreq = 0;\n else\n";
3515 ss << " nFreq=(int)";
3516 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
3517 ss <<";\n";
3518 if(tmpCur3->GetType() == formula::svSingleVectorRef)
3520 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
3521 formula::SingleVectorRefToken *>(tmpCur3);
3522 ss <<" if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
3523 ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
3524 ss <<" nBase = 0;\n else\n";
3526 ss << " nBase=(int)";
3527 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
3528 ss << ";\n";
3529 ss <<" tmp = coupnum_new(nSettle,nMat,nFreq,nBase);\n";
3530 ss <<" return tmp;\n";
3531 ss << "}";
3533 void OpAmordegrc::BinInlineFun(std::set<std::string>& decls,
3534 std::set<std::string>& funs)
3536 decls.insert(nKorrValDecl); decls.insert(RoundDecl);
3537 decls.insert(IsLeapYearDecl);decls.insert(DaysInMonthDecl);
3538 decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
3539 decls.insert(GetNullDateDecl); decls.insert(GetYearFracDecl);
3540 funs.insert(Round);
3541 funs.insert(IsLeapYear);funs.insert(DaysInMonth);
3542 funs.insert(DaysToDate);funs.insert(DateToDays);
3543 funs.insert(GetNullDate);funs.insert(GetYearFrac);
3545 void OpAmordegrc::GenSlidingWindowFunction(std::stringstream &ss,
3546 const std::string &sSymName, SubArguments &vSubArguments)
3548 ss << "\ndouble " << sSymName;
3549 ss << "_"<< BinFuncName() <<"(";
3550 for (unsigned i = 0; i < vSubArguments.size(); i++)
3552 if (i)
3553 ss << ",";
3554 vSubArguments[i]->GenSlidingWindowDecl(ss);
3556 ss << ") {\n ";
3557 ss << "int gid0 = get_global_id(0);\n";
3558 ss << " double tmp = " << GetBottom() <<";\n";
3559 ss << " double fCost,fRestVal,fPer,fRate;\n";
3560 ss << " int nDate,nFirstPer,nBase;\n";
3561 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
3562 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
3563 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
3564 FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
3565 FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
3566 FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
3567 FormulaToken *tmpCur6 = vSubArguments[6]->GetFormulaToken();
3568 if(tmpCur0->GetType() == formula::svSingleVectorRef)
3570 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
3571 formula::SingleVectorRefToken *>(tmpCur0);
3572 ss <<" if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
3573 ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
3574 ss <<" fCost = 0;\n else\n";
3576 ss << " fCost=";
3577 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
3578 ss <<";\n";
3579 if(tmpCur1->GetType() == formula::svSingleVectorRef)
3581 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
3582 formula::SingleVectorRefToken *>(tmpCur1);
3583 ss <<" if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
3584 ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
3585 ss <<" nDate = 0;\n else\n";
3587 ss << " nDate=(int)";
3588 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
3589 ss << ";\n";
3590 if(tmpCur2->GetType() == formula::svSingleVectorRef)
3592 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
3593 formula::SingleVectorRefToken *>(tmpCur2);
3594 ss <<" if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
3595 ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
3596 ss <<" nFirstPer = 0;\n else\n";
3598 ss << " nFirstPer=(int)";
3599 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
3600 ss <<";\n";
3601 if(tmpCur3->GetType() == formula::svSingleVectorRef)
3603 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
3604 formula::SingleVectorRefToken *>(tmpCur3);
3605 ss <<" if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
3606 ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
3607 ss <<" fRestVal = 0;\n else\n";
3609 ss << " fRestVal=";
3610 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
3611 ss << ";\n";
3612 if(tmpCur4->GetType() == formula::svSingleVectorRef)
3614 const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
3615 formula::SingleVectorRefToken *>(tmpCur4);
3616 ss <<" if(isNan(" <<vSubArguments[4]->GenSlidingWindowDeclRef();
3617 ss <<")||(gid0 >="<<tmpCurDVR4->GetArrayLength()<<"))\n";
3618 ss <<" fPer = 0;\n else\n";
3620 ss << " fPer = ";
3621 ss << vSubArguments[4]->GenSlidingWindowDeclRef();
3622 ss <<";\n";
3623 if(tmpCur5->GetType() == formula::svSingleVectorRef)
3625 const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
3626 formula::SingleVectorRefToken *>(tmpCur5);
3627 ss <<" if(isNan(" <<vSubArguments[5]->GenSlidingWindowDeclRef();
3628 ss <<")||(gid0 >="<<tmpCurDVR5->GetArrayLength()<<"))\n";
3629 ss <<" fRate = 0;\n else\n";
3631 ss << " fRate=";
3632 ss << vSubArguments[5]->GenSlidingWindowDeclRef();
3633 ss << ";\n";
3634 if(tmpCur6->GetType() == formula::svSingleVectorRef)
3636 const formula::SingleVectorRefToken*tmpCurDVR6= static_cast<const
3637 formula::SingleVectorRefToken *>(tmpCur6);
3638 ss <<" if(isNan(" <<vSubArguments[6]->GenSlidingWindowDeclRef();
3639 ss <<")||(gid0 >="<<tmpCurDVR6->GetArrayLength()<<"))\n";
3640 ss <<" nBase = 0;\n else\n";
3642 ss << " nBase = (int)";
3643 ss << vSubArguments[6]->GenSlidingWindowDeclRef();
3644 ss << ";\n";
3645 ss <<" uint nPer = convert_int( fPer );\n";
3646 ss <<" double fUsePer = 1.0 *pow( fRate,-1);\n";
3647 ss <<" double fAmorCoeff;\n";
3648 ss <<" if( fUsePer < 3.0 )\n";
3649 ss <<" fAmorCoeff = 1.0;\n";
3650 ss <<" else if( fUsePer < 5.0 )\n";
3651 ss <<" fAmorCoeff = 1.5;\n";
3652 ss <<" else if( fUsePer <= 6.0 )\n";
3653 ss <<" fAmorCoeff = 2.0;\n";
3654 ss <<" else\n";
3655 ss <<" fAmorCoeff = 2.5;\n";
3656 ss <<" fRate *= fAmorCoeff;\n";
3657 ss <<" tmp = Round( GetYearFrac( 693594,";
3658 ss <<"nDate, nFirstPer, nBase ) * fRate * fCost);\n";
3659 ss <<" fCost = fCost-tmp;\n";
3660 ss <<" double fRest = fCost - fRestVal;\n";
3661 ss <<" for( uint n = 0 ; n < nPer ; n++ )\n";
3662 ss <<" {\n";
3663 ss <<" tmp = Round( fRate * fCost);\n";
3664 ss <<" fRest -= tmp;\n";
3665 ss <<" if( fRest < 0.0 )\n";
3666 ss <<" {\n";
3667 ss <<" switch( nPer - n )\n";
3668 ss <<" {\n";
3669 ss <<" case 0:\n";
3670 ss <<" case 1:\n";
3671 ss <<" tmp = Round( fCost * 0.5);\n";
3672 ss <<" default:\n";
3673 ss <<" tmp = 0.0;\n";
3674 ss <<" }\n";
3675 ss <<" }\n";
3676 ss <<" fCost -= tmp;\n";
3677 ss <<" }\n";
3678 ss <<" return tmp;\n";
3679 ss <<"}";
3681 void OpAmorlinc::BinInlineFun(std::set<std::string>& decls,
3682 std::set<std::string>& funs)
3684 decls.insert(nKorrValDecl); decls.insert(RoundDecl);
3685 decls.insert(IsLeapYearDecl);decls.insert(DaysInMonthDecl);
3686 decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
3687 decls.insert(GetYearFracDecl);
3688 funs.insert(Round);
3689 funs.insert(IsLeapYear);funs.insert(DaysInMonth);
3690 funs.insert(DaysToDate);funs.insert(DateToDays);
3691 funs.insert(GetYearFrac);
3693 void OpAmorlinc::GenSlidingWindowFunction(std::stringstream &ss,
3694 const std::string &sSymName, SubArguments &vSubArguments)
3696 ss << "\ndouble " << sSymName;
3697 ss << "_"<< BinFuncName() <<"(";
3698 for (unsigned i = 0; i < vSubArguments.size(); i++)
3700 if (i)
3701 ss << ",";
3702 vSubArguments[i]->GenSlidingWindowDecl(ss);
3704 ss << ") {\n";
3705 ss << " int gid0 = get_global_id(0);\n";
3706 ss << " double tmp = 0;\n";
3707 ss << " double fCost,fRestVal,fPer,fRate;\n";
3708 ss << " int nDate,nFirstPer,nBase;\n";
3709 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
3710 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
3711 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
3712 FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
3713 FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
3714 FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
3715 FormulaToken *tmpCur6 = vSubArguments[6]->GetFormulaToken();
3716 if(tmpCur0->GetType() == formula::svSingleVectorRef)
3718 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
3719 formula::SingleVectorRefToken *>(tmpCur0);
3720 ss <<" if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
3721 ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
3722 ss <<" fCost = 0;\n else\n";
3724 ss << " fCost=";
3725 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
3726 ss <<";\n";
3727 if(tmpCur1->GetType() == formula::svSingleVectorRef)
3729 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
3730 formula::SingleVectorRefToken *>(tmpCur1);
3731 ss <<" if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
3732 ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
3733 ss <<" nDate = 0;\n else\n";
3735 ss << " nDate=(int)";
3736 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
3737 ss << ";\n";
3738 if(tmpCur2->GetType() == formula::svSingleVectorRef)
3740 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
3741 formula::SingleVectorRefToken *>(tmpCur2);
3742 ss <<" if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
3743 ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
3744 ss <<" nFirstPer = 0;\n else\n";
3746 ss << " nFirstPer=(int)";
3747 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
3748 ss <<";\n";
3749 if(tmpCur3->GetType() == formula::svSingleVectorRef)
3751 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
3752 formula::SingleVectorRefToken *>(tmpCur3);
3753 ss <<" if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
3754 ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
3755 ss <<" fRestVal = 0;\n else\n";
3757 ss << " fRestVal=";
3758 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
3759 ss << ";\n";
3760 if(tmpCur4->GetType() == formula::svSingleVectorRef)
3762 const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
3763 formula::SingleVectorRefToken *>(tmpCur4);
3764 ss <<" if(isNan(" <<vSubArguments[4]->GenSlidingWindowDeclRef();
3765 ss <<")||(gid0 >="<<tmpCurDVR4->GetArrayLength()<<"))\n";
3766 ss <<" fPer = 0;\n else\n";
3768 ss << " fPer = ";
3769 ss << vSubArguments[4]->GenSlidingWindowDeclRef();
3770 ss <<";\n";
3771 if(tmpCur5->GetType() == formula::svSingleVectorRef)
3773 const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
3774 formula::SingleVectorRefToken *>(tmpCur5);
3775 ss <<" if(isNan(" <<vSubArguments[5]->GenSlidingWindowDeclRef();
3776 ss <<")||(gid0 >="<<tmpCurDVR5->GetArrayLength()<<"))\n";
3777 ss <<" fRate = 0;\n else\n";
3779 ss << " fRate=";
3780 ss << vSubArguments[5]->GenSlidingWindowDeclRef();
3781 ss << ";\n";
3782 if(tmpCur6->GetType() == formula::svSingleVectorRef)
3784 const formula::SingleVectorRefToken*tmpCurDVR6= static_cast<const
3785 formula::SingleVectorRefToken *>(tmpCur6);
3786 ss <<" if(isNan(" <<vSubArguments[6]->GenSlidingWindowDeclRef();
3787 ss <<")||(gid0 >="<<tmpCurDVR6->GetArrayLength()<<"))\n";
3788 ss <<" nBase = 0;\n else\n";
3790 ss << " nBase = (int)";
3791 ss << vSubArguments[6]->GenSlidingWindowDeclRef();
3792 ss << ";\n";
3793 ss <<" int nPer = convert_int( fPer );\n";
3794 ss <<" double fOneRate = fCost * fRate;\n";
3795 ss <<" double fCostDelta = fCost - fRestVal;\n";
3796 ss <<" double f0Rate = GetYearFrac( 693594,";
3797 ss <<"nDate, nFirstPer, nBase )* fRate * fCost;\n";
3798 ss <<" int nNumOfFullPeriods = (int)";
3799 ss <<"( ( fCost - fRestVal - f0Rate) *pow(fOneRate,-1) );\n";
3800 ss <<" if( nPer == 0 )\n";
3801 ss <<" tmp = f0Rate;\n";
3802 ss <<" else if( nPer <= nNumOfFullPeriods )\n";
3803 ss <<" tmp = fOneRate;\n";
3804 ss <<" else if( nPer == nNumOfFullPeriods + 1 )\n";
3805 ss <<" tmp = fCostDelta - fOneRate * nNumOfFullPeriods - f0Rate;\n";
3806 ss <<" else\n";
3807 ss <<" tmp = 0.0;\n";
3808 ss <<" return tmp;\n";
3809 ss <<"}";
3811 void OpReceived::BinInlineFun(std::set<std::string>& decls,
3812 std::set<std::string>& funs)
3814 decls.insert(GetYearDiffDecl);decls.insert(GetDiffDateDecl);
3815 decls.insert(DaysToDateDecl);decls.insert(DaysInMonthDecl);
3816 decls.insert(GetNullDateDecl);decls.insert(IsLeapYearDecl);
3817 decls.insert(DateToDaysDecl);
3818 funs.insert(GetDiffDate);funs.insert(DaysToDate);
3819 funs.insert(DaysInMonth);funs.insert(GetNullDate);
3820 funs.insert(DateToDays);funs.insert(IsLeapYear);
3821 funs.insert(GetYearDiff);
3824 void OpReceived::GenSlidingWindowFunction(std::stringstream &ss,
3825 const std::string &sSymName, SubArguments &vSubArguments)
3827 ss << "\ndouble " << sSymName;
3828 ss << "_"<< BinFuncName() <<"(";
3829 for (unsigned i = 0; i < vSubArguments.size(); i++)
3831 if (i)
3832 ss << ",";
3833 vSubArguments[i]->GenSlidingWindowDecl(ss);
3835 ss << ") {\n";
3836 ss << " double tmp = " << GetBottom() <<";\n";
3837 ss << " int gid0 = get_global_id(0);\n";
3838 ss << " int nSettle, nMat;\n";
3839 ss << " double fInvest,fDisc;\n";
3840 ss << " int rOB;\n";
3841 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
3842 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
3843 formula::SingleVectorRefToken *>(tmpCur0);
3844 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
3845 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
3846 formula::SingleVectorRefToken *>(tmpCur1);
3847 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
3848 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
3849 formula::SingleVectorRefToken *>(tmpCur2);
3850 FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
3851 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
3852 formula::SingleVectorRefToken *>(tmpCur3);
3853 FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
3854 const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
3855 formula::SingleVectorRefToken *>(tmpCur4);
3856 ss<< " int buffer_settle_len = ";
3857 ss<< tmpCurDVR0->GetArrayLength();
3858 ss << ";\n";
3859 ss<< " int buffer_mat_len = ";
3860 ss<< tmpCurDVR1->GetArrayLength();
3861 ss << ";\n";
3862 ss<< " int buffer_invest_len = ";
3863 ss<< tmpCurDVR2->GetArrayLength();
3864 ss << ";\n";
3865 ss<< " int buffer_disc_len = ";
3866 ss<< tmpCurDVR3->GetArrayLength();
3867 ss << ";\n";
3868 ss<< " int buffer_rob_len = ";
3869 ss<< tmpCurDVR4->GetArrayLength();
3870 ss << ";\n";
3871 ss <<" if(gid0 >= buffer_settle_len || isNan(";
3872 ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
3873 ss <<"))\n";
3874 ss <<" nSettle = 0;\n\telse\n";
3875 ss <<" nSettle = (int)"<<vSubArguments[0]->GenSlidingWindowDeclRef();
3876 ss <<";\n";
3877 ss <<" if(gid0 >= buffer_mat_len || isNan(";
3878 ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
3879 ss <<"))\n";
3880 ss <<" nMat = 0;\n\telse\n";
3881 ss <<" nMat = (int)";
3882 ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
3883 ss <<";\n";
3884 ss <<" if(gid0 >= buffer_invest_len || isNan(";
3885 ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
3886 ss <<"))\n";
3887 ss <<" fInvest = 0;\n\telse\n";
3888 ss <<" fInvest = "<<vSubArguments[2]->GenSlidingWindowDeclRef();
3889 ss <<";\n";
3890 ss <<" if(gid0 >= buffer_disc_len || isNan(";
3891 ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
3892 ss <<"))\n";
3893 ss <<" fDisc = 0;\n\telse\n";
3894 ss <<" fDisc = "<<vSubArguments[3]->GenSlidingWindowDeclRef();
3895 ss <<";\n";
3896 ss <<" if(gid0 >= buffer_rob_len || isNan(";
3897 ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
3898 ss <<"))\n";
3899 ss <<" rOB = 0;\n\telse\n";
3900 ss <<" rOB = (int)"<<vSubArguments[4]->GenSlidingWindowDeclRef();
3901 ss <<";\n";
3902 ss << " double tmpvalue = (1.0-(fDisc";
3903 ss <<" * GetYearDiff( GetNullDate()";
3904 ss <<",nSettle,nMat,rOB)));\n";
3905 ss << " tmp = fInvest*pow(tmpvalue,-1);\n";
3906 ss << " return tmp;\n";
3907 ss << "}";
3910 void OpYielddisc::BinInlineFun(std::set<std::string>& decls,
3911 std::set<std::string>& funs)
3913 decls.insert(GetYearFracDecl);decls.insert(GetNullDateDecl);
3914 decls.insert(DateToDaysDecl);decls.insert(DaysToDateDecl);
3915 decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
3917 funs.insert(GetYearFrac);funs.insert(GetNullDate);
3918 funs.insert(DateToDays);funs.insert(DaysToDate);
3919 funs.insert(DaysInMonth);funs.insert(IsLeapYear);
3921 void OpYielddisc::GenSlidingWindowFunction(
3922 std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
3924 ss << "\ndouble " << sSymName;
3925 ss << "_"<< BinFuncName() <<"(";
3926 for (unsigned i = 0; i < vSubArguments.size(); i++)
3928 if (i)
3929 ss << ",";
3930 vSubArguments[i]->GenSlidingWindowDecl(ss);
3932 ss << ") {\n\t";
3933 ss << "double tmp = 0;\n\t";
3934 ss << "int gid0 = get_global_id(0);\n\t";
3935 ss << "double tmp000;\n\t";
3936 ss << "double tmp001;\n\t";
3937 ss << "double tmp002;\n\t";
3938 ss << "double tmp003;\n\t";
3939 ss << "double tmp004;\n\t";
3941 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
3942 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
3943 formula::SingleVectorRefToken *>(tmpCur0);
3945 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
3946 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
3947 formula::SingleVectorRefToken *>(tmpCur1);
3949 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
3950 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
3951 formula::SingleVectorRefToken *>(tmpCur2);
3953 FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
3954 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
3955 formula::SingleVectorRefToken *>(tmpCur3);
3957 FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
3958 const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
3959 formula::SingleVectorRefToken *>(tmpCur4);
3961 ss<< "int buffer_tmp000_len = ";
3962 ss<< tmpCurDVR0->GetArrayLength();
3963 ss << ";\n\t";
3965 ss<< "int buffer_tmp001_len = ";
3966 ss<< tmpCurDVR1->GetArrayLength();
3967 ss << ";\n\t";
3969 ss<< "int buffer_tmp002_len = ";
3970 ss<< tmpCurDVR2->GetArrayLength();
3971 ss << ";\n\t";
3973 ss<< "int buffer_tmp003_len = ";
3974 ss<< tmpCurDVR3->GetArrayLength();
3975 ss << ";\n\t";
3977 ss<< "int buffer_tmp004_len = ";
3978 ss<< tmpCurDVR4->GetArrayLength();
3979 ss << ";\n\t";
3981 ss<<"if(gid0>=buffer_tmp000_len || isNan(";
3982 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
3983 ss<<"))\n\t\t";
3984 ss<<"tmp000 = 0;\n\telse \n\t\t";
3985 ss<<"tmp000 = ";
3986 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
3987 ss<<";\n\t";
3989 ss<<"if(gid0>=buffer_tmp001_len || isNan(";
3990 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
3991 ss<<"))\n\t\t";
3992 ss<<"tmp001 = 0;\n\telse \n\t\t";
3993 ss<<"tmp001 = ";
3994 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
3995 ss<<";\n\t";
3997 ss<<"if(gid0>=buffer_tmp002_len || isNan(";
3998 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
3999 ss<<"))\n\t\t";
4000 ss<<"tmp002 = 0;\n\telse \n\t\t";
4001 ss<<"tmp002 = ";
4002 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
4003 ss<<";\n\t";
4005 ss<<"if(gid0>=buffer_tmp003_len || isNan(";
4006 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
4007 ss<<"))\n\t\t";
4008 ss<<"tmp003 = 0;\n\telse \n\t\t";
4009 ss<<"tmp003 = ";
4010 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
4011 ss<<";\n\t";
4013 ss<<"if(gid0>=buffer_tmp004_len || isNan(";
4014 ss << vSubArguments[4]->GenSlidingWindowDeclRef();
4015 ss<<"))\n\t\t";
4016 ss<<"tmp004 = 0;\n\telse \n\t\t";
4017 ss<<"tmp004 = ";
4018 ss << vSubArguments[4]->GenSlidingWindowDeclRef();
4019 ss<<";\n\t";
4021 ss<< "tmp = (tmp003/tmp002)-1;\n\t";
4022 ss << "tmp /= GetYearFrac( GetNullDate(),tmp000,tmp001,tmp004);\n\t";
4023 ss << "return tmp;\n";
4024 ss << "}";
4027 void OpTbillprice::BinInlineFun(std::set<std::string>& decls,
4028 std::set<std::string>& funs)
4030 decls.insert(GetYearFracDecl);
4031 decls.insert(DateToDaysDecl);decls.insert(DaysToDateDecl);
4032 decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
4034 funs.insert(GetYearFrac);
4035 funs.insert(DateToDays);funs.insert(DaysToDate);
4036 funs.insert(DaysInMonth);funs.insert(IsLeapYear);
4039 void OpTbillprice::GenSlidingWindowFunction(
4040 std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
4042 ss << "\ndouble " << sSymName;
4043 ss << "_"<< BinFuncName() <<"(";
4044 for (unsigned i = 0; i < vSubArguments.size(); i++)
4046 if (i)
4047 ss << ",";
4048 vSubArguments[i]->GenSlidingWindowDecl(ss);
4050 ss << ") {\n";
4051 ss << " int gid0 = get_global_id(0);\n";
4052 ss << " double tmp = 0;\n";
4054 ss << " int singleIndex = gid0;\n";
4055 ss << " int doubleIndex = gid0;\n";
4056 ss << " int i = gid0;\n";
4057 GenTmpVariables(ss,vSubArguments);
4058 CheckAllSubArgumentIsNan(ss,vSubArguments);
4060 ss << " tmp1+=1.0;\n";
4061 ss << " double fFraction =GetYearFrac(693594,tmp0,tmp1,0);\n";
4062 ss << " tmp = 100.0 * ( 1.0 - tmp2 * fFraction );\n";
4063 ss << " return tmp;\n";
4064 ss << "}\n";
4066 void RATE::BinInlineFun(std::set<std::string>& decls,
4067 std::set<std::string>& funs)
4069 decls.insert(approxEqualDecl);decls.insert(nKorrValDecl);
4070 decls.insert(SCdEpsilonDecl);decls.insert(RoundDecl);
4071 funs.insert(approxEqual);funs.insert(Round);
4074 void RATE::GenSlidingWindowFunction(
4075 std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
4077 ss << "\ndouble " << sSymName;
4078 ss << "_"<< BinFuncName() <<"(";
4079 for (unsigned i = 0; i < vSubArguments.size(); i++)
4081 if (i)
4082 ss << ",";
4083 vSubArguments[i]->GenSlidingWindowDecl(ss);
4086 FormulaToken* pCur = vSubArguments[5]->GetFormulaToken();
4087 assert(pCur);
4088 const formula::SingleVectorRefToken* pSVR =
4089 static_cast< const formula::SingleVectorRefToken* >(pCur);
4090 assert(pSVR);
4091 ss << ") {\n";
4092 ss << " double result;\n";
4093 ss << " int gid0 = get_global_id(0);\n";
4094 ss << " bool bValid = true, bFound = false;\n";
4095 ss << " double fX, fXnew, fTerm, fTermDerivation;\n";
4096 ss << " double fGeoSeries, fGeoSeriesDerivation;\n";
4097 ss << " int nIterationsMax = 150;\n";
4098 ss << " int nCount = 0;\n";
4099 ss << " double fEpsilonSmall = 1.0E-14;\n";
4100 ss << " double arg0, arg1, arg2, arg3, arg4, arg5;\n";
4101 ss << " arg0=" << vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n";
4102 ss << " arg1=" << vSubArguments[1]->GenSlidingWindowDeclRef()<<";\n";
4103 ss << " arg2=" << vSubArguments[2]->GenSlidingWindowDeclRef()<<";\n";
4104 ss << " arg3=" << vSubArguments[3]->GenSlidingWindowDeclRef()<<";\n";
4105 ss << " arg4=" << vSubArguments[4]->GenSlidingWindowDeclRef()<<";\n";
4106 ss << " arg5=" << vSubArguments[5]->GenSlidingWindowDeclRef()<<";\n";
4107 ss << " int guessLen = " << pSVR->GetArrayLength() << ";\n";
4108 ss << " if (isNan(arg0) || isNan(arg1) || isNan(arg2)){\n";
4109 ss << " result = 523;\n";
4110 ss << " return result;\n";
4111 ss << " }\n";
4112 ss << " if (isNan(arg3))\n";
4113 ss << " arg3 = 0.0;\n";
4114 ss << " if (isNan(arg4))\n";
4115 ss << " arg4 = 0.0;\n";
4116 ss << " if (isNan(arg5))\n";
4117 ss << " arg5 = 0.1;\n";
4118 ss << " if (gid0 >= guessLen)\n";
4119 ss << " arg5 = 0.1;\n";
4120 ss << " arg3 = arg3 - arg1 * arg4;\n";
4121 ss << " arg2 = arg2 + arg1 * arg4;\n";
4122 ss << " if (arg0 == Round(arg0)){\n";
4123 ss << " fX = arg5;\n";
4124 ss << " double fPowN, fPowNminus1;\n";
4125 ss << " while (!bFound && nCount < nIterationsMax)\n";
4126 ss << " {\n";
4127 ss << " fPowNminus1 = pow( 1.0+fX, arg0-1.0);\n";
4128 ss << " fPowN = fPowNminus1 * (1.0+fX);\n";
4129 ss << " if (approxEqual( fabs(fX), 0.0))\n";
4130 ss << " {\n";
4131 ss << " fGeoSeries = arg0;\n";
4132 ss << " fGeoSeriesDerivation = arg0 * (arg0-1.0)";
4133 ss << "*pow(2.0,-1);\n";
4134 ss << " }\n";
4135 ss << " else\n";
4136 ss << " {";
4137 ss << " fGeoSeries = (fPowN-1.0)*pow(fX,-1);\n";
4138 ss << " fGeoSeriesDerivation =";
4139 ss << " arg0 * fPowNminus1 * pow( fX , -1) - fGeoSeries * pow(fX, -1);\n";
4140 ss << " }\n";
4141 ss << " fTerm = arg3 + arg2 *fPowN+ arg1 * fGeoSeries;\n";
4142 ss << " fTermDerivation = arg2 * arg0 * fPowNminus1 +";
4143 ss << "arg1 * fGeoSeriesDerivation;\n";
4144 ss << " if (fabs(fTerm) < fEpsilonSmall)\n";
4145 ss << " bFound = true;\n";
4146 ss << " else\n";
4147 ss << " {\n";
4148 ss << " if (approxEqual(fabs(fTermDerivation), 0.0))\n";
4149 ss << " fXnew = fX + 1.1 * SCdEpsilon;\n";
4150 ss << " else\n";
4151 ss << " fXnew = fX - fTerm ";
4152 ss << "*pow( fTermDerivation,-1);\n";
4153 ss << " nCount++;\n";
4154 ss << " bFound = (fabs(fXnew - fX) < SCdEpsilon);\n";
4155 ss << " fX = fXnew;\n";
4156 ss << " }\n";
4157 ss << " }\n";
4158 ss << " }\n";
4159 ss << " else\n";
4160 ss << " {";
4161 ss << " fX = (arg5 < -1.0) ? -1.0 : arg5;\n";
4162 ss << " while (bValid && !bFound && nCount < nIterationsMax)\n";
4163 ss << " {\n";
4164 ss << " if (approxEqual(fabs(fX), 0.0)){\n";
4165 ss << " fGeoSeries = arg0;\n";
4166 ss << " fGeoSeriesDerivation = arg0 * ";
4167 ss << "(arg0-1.0)* pow(2.0,-1);\n";
4168 ss << " }else{\n";
4169 ss << " fGeoSeries = (pow( 1.0+fX, arg0) - 1.0)";
4170 ss << " *pow( fX,-1);\n";
4171 ss << " fGeoSeriesDerivation =";
4172 ss << " arg0 * pow(1.0+fX,arg0-1.0) *pow(fX,-1)";
4173 ss << " - fGeoSeries *pow( fX,-1);\n";
4174 ss << " }\n";
4175 ss << " fTerm = arg3 + arg2 *pow(1.0+fX, arg0)";
4176 ss << "+ arg1 * fGeoSeries;\n";
4177 ss << " fTermDerivation =";
4178 ss << "arg2*arg0*pow(1.0+fX,arg0-1.0)";
4179 ss << "+arg1*fGeoSeriesDerivation;\n";
4180 ss << " if (fabs(fTerm) < fEpsilonSmall)\n";
4181 ss << " bFound = true;\n";
4182 ss << " else{\n";
4183 ss << " if (approxEqual(fabs(fTermDerivation), 0.0))\n";
4184 ss << " fXnew = fX + 1.1 * SCdEpsilon;\n";
4185 ss << " else\n";
4186 ss << " fXnew = fX - fTerm ";
4187 ss << "*pow( fTermDerivation,-1);\n";
4188 ss << " nCount++;\n";
4189 ss << " bFound = (fabs(fXnew - fX) < SCdEpsilon);\n";
4190 ss << " fX = fXnew;\n";
4191 ss << " bValid = (fX >= -1.0);\n";
4192 ss << " }\n";
4193 ss << " }\n";
4194 ss << " }\n";
4195 ss << " if (bValid && bFound)\n";
4196 ss << " result = fX;\n";
4197 ss << " else\n";
4198 ss << " result = 523;\n";
4199 ss << " return result;\n";
4200 ss << "}";
4203 void OpTbillyield::BinInlineFun(std::set<std::string>& decls,
4204 std::set<std::string>& funs)
4206 decls.insert(GetDiffDate360Decl);decls.insert(IsLeapYearDecl);
4207 decls.insert(DateToDaysDecl);decls.insert(DaysToDate_LocalBarrierDecl);
4208 decls.insert(DaysInMonthDecl);decls.insert(GetNullDateDecl);
4209 decls.insert(GetDiffDate360_Decl);
4210 funs.insert(GetDiffDate360);funs.insert(DateToDays);
4211 funs.insert(DaysToDate_LocalBarrier);funs.insert(IsLeapYear);
4212 funs.insert(DaysInMonth);funs.insert(GetNullDate);
4213 funs.insert(GetDiffDate360_);
4217 void OpTbillyield::GenSlidingWindowFunction(
4218 std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
4220 ss << "\ndouble " << sSymName;
4221 ss << "_"<< BinFuncName() <<"(";
4222 for (unsigned i = 0; i < vSubArguments.size(); i++)
4224 if (i)
4225 ss << ",";
4226 vSubArguments[i]->GenSlidingWindowDecl(ss);
4228 ss << ") {\n\t";
4229 ss << "int gid0 = get_global_id(0);\n\t";
4230 ss << "double tmp = 0;\n\t";
4231 ss << "double tmp000;\n\t";
4232 ss << "double tmp001;\n\t";
4233 ss << "double tmp002;\n\t";
4235 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
4236 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
4237 formula::SingleVectorRefToken *>(tmpCur0);
4239 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
4240 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
4241 formula::SingleVectorRefToken *>(tmpCur1);
4243 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
4244 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
4245 formula::SingleVectorRefToken *>(tmpCur2);
4247 ss<< "int buffer_tmp000_len = ";
4248 ss<< tmpCurDVR0->GetArrayLength();
4249 ss << ";\n\t";
4251 ss<< "int buffer_tmp001_len = ";
4252 ss<< tmpCurDVR1->GetArrayLength();
4253 ss << ";\n\t";
4255 ss<< "int buffer_tmp002_len = ";
4256 ss<< tmpCurDVR2->GetArrayLength();
4257 ss << ";\n\t";
4259 ss<<"if(gid0>=buffer_tmp000_len || isNan(";
4260 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
4261 ss<<"))\n\t\t";
4262 ss<<"tmp000 = 0;\n\telse \n\t\t";
4263 ss<<"tmp000 = ";
4264 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
4265 ss<<";\n\t";
4267 ss<<"if(gid0>=buffer_tmp001_len || isNan(";
4268 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
4269 ss<<"))\n\t\t";
4270 ss<<"tmp001 = 0;\n\telse \n\t\t";
4271 ss<<"tmp001 = ";
4272 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
4273 ss<<";\n\t";
4275 ss<<"if(gid0>=buffer_tmp002_len || isNan(";
4276 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
4277 ss<<"))\n\t\t";
4278 ss<<"tmp002 = 0;\n\telse \n\t\t";
4279 ss<<"tmp002 = ";
4280 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
4281 ss<<";\n\t";
4282 ss <<" int nDiff=GetDiffDate360(GetNullDate(),tmp000,tmp001,true);\n";
4283 ss <<" nDiff++;\n";
4284 ss <<" tmp=100.0;\n";
4285 ss <<" tmp = tmp *pow( tmp002,-1);\n";
4286 ss <<" tmp = tmp - 1.0;\n";
4287 ss <<" tmp = tmp * pow( nDiff,-1.0 );\n";
4288 ss <<" tmp = tmp * 360.0;\n";
4289 ss <<" return tmp;\n";
4290 ss << "}\n";
4292 void OpDDB::GenSlidingWindowFunction(std::stringstream& ss,
4293 const std::string &sSymName, SubArguments& vSubArguments)
4295 ss << "\ndouble " << sSymName;
4296 ss << "_"<< BinFuncName() <<"(";
4297 for (unsigned i = 0; i < vSubArguments.size(); i++)
4299 if (i)
4300 ss << ",";
4301 vSubArguments[i]->GenSlidingWindowDecl(ss);
4303 ss << ") {\n";
4304 ss << " int gid0 = get_global_id(0);\n";
4305 ss << " double tmp = 0;\n";
4306 ss << " double fWert,fRest,fDauer,fPeriode,fFaktor;\n";
4307 ss << " double fZins, fAlterWert, fNeuerWert;\n";
4309 FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
4310 FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
4311 FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
4312 FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
4313 FormulaToken* tmpCur4 = vSubArguments[4]->GetFormulaToken();
4314 if(tmpCur0->GetType() == formula::svSingleVectorRef)
4316 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
4317 formula::SingleVectorRefToken *>(tmpCur0);
4318 ss <<" if(gid0 >= "<<tmpCurDVR0->GetArrayLength()<<" || isNan(";
4319 ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
4320 ss <<"))\n";
4321 ss <<" fWert = 0;\n else\n";
4323 ss <<" fWert = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
4324 ss <<";\n";
4325 if(tmpCur1->GetType() == formula::svSingleVectorRef)
4327 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
4328 formula::SingleVectorRefToken *>(tmpCur1);
4329 ss <<" if(gid0 >= "<<tmpCurDVR1->GetArrayLength()<<" || isNan(";
4330 ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
4331 ss <<"))\n";
4332 ss <<" fRest = 0;\n else\n";
4334 ss <<" fRest = ";
4335 ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
4336 ss <<";\n";
4337 if(tmpCur2->GetType() == formula::svSingleVectorRef)
4339 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
4340 formula::SingleVectorRefToken *>(tmpCur2);
4341 ss <<" if(gid0 >= "<<tmpCurDVR2->GetArrayLength()<<" || isNan(";
4342 ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
4343 ss <<"))\n";
4344 ss <<" fDauer = 0;\n else\n";
4346 ss <<" fDauer = ";
4347 ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
4348 ss <<";\n";
4349 if(tmpCur3->GetType() == formula::svSingleVectorRef)
4351 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
4352 formula::SingleVectorRefToken *>(tmpCur3);
4353 ss <<" if(gid0 >= "<<tmpCurDVR3->GetArrayLength()<<" || isNan(";
4354 ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
4355 ss <<"))\n";
4356 ss <<" fPeriode = 0;\n else\n";
4358 ss <<" fPeriode = "<<vSubArguments[3]->GenSlidingWindowDeclRef();
4359 ss <<";\n";
4360 if(tmpCur4->GetType() == formula::svSingleVectorRef)
4362 const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
4363 formula::SingleVectorRefToken *>(tmpCur4);
4364 ss <<" if(gid0 >= "<<tmpCurDVR4->GetArrayLength()<<" || isNan(";
4365 ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
4366 ss <<"))\n";
4367 ss <<" fFaktor = 0;\n else\n";
4369 ss <<" fFaktor = "<<vSubArguments[4]->GenSlidingWindowDeclRef();
4370 ss <<";\n";
4371 ss <<" fZins = fFaktor * pow(fDauer,-1);\n";
4372 ss <<" if (fZins >= 1.0)\n";
4373 ss <<" {\n";
4374 ss <<" fZins = 1.0;\n";
4375 ss <<" if (fPeriode == 1.0)\n";
4376 ss <<" fAlterWert = fWert;\n";
4377 ss <<" else\n";
4378 ss <<" fAlterWert = 0.0;\n";
4379 ss <<" }\n";
4380 ss <<" else\n";
4381 ss <<" fAlterWert = fWert * pow(1.0 - fZins, fPeriode - 1);\n";
4382 ss <<" fNeuerWert = fWert * pow(1.0 - fZins, fPeriode);\n";
4383 ss <<" if (fNeuerWert < fRest)\n";
4384 ss <<" tmp = fAlterWert - fRest;\n";
4385 ss <<" else\n";
4386 ss <<" tmp = fAlterWert - fNeuerWert;\n";
4387 ss <<" if (tmp < 0.0)\n";
4388 ss <<" tmp = 0.0;\n";
4389 ss <<" return tmp;\n";
4390 ss <<"}";
4392 void OpPV::GenSlidingWindowFunction(
4393 std::stringstream &ss, const std::string &sSymName, SubArguments &
4394 vSubArguments)
4396 ss << "\ndouble " << sSymName;
4397 ss << "_"<< BinFuncName() <<"(";
4398 for (unsigned i = 0; i < vSubArguments.size(); i++)
4400 if (i)
4401 ss << ",";
4402 vSubArguments[i]->GenSlidingWindowDecl(ss);
4404 ss << ") {\n";
4405 ss << " double result = 0;\n";
4406 ss << " int gid0 = get_global_id(0);\n";
4407 ss << " double zins;\n";
4408 ss << " double zzr;\n";
4409 ss << " double rmz;\n";
4410 ss << " double zw;\n";
4411 ss << " double flag;\n";
4413 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
4414 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
4415 formula::SingleVectorRefToken *>(tmpCur0);
4417 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
4418 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
4419 formula::SingleVectorRefToken *>(tmpCur1);
4421 FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
4422 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
4423 formula::SingleVectorRefToken *>(tmpCur2);
4425 if(vSubArguments.size()>3)
4427 FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
4428 const formula::SingleVectorRefToken* tmpCurDVR3= static_cast<const formula::SingleVectorRefToken *>(
4429 tmpCur3);
4430 ss<< " int buffer_zw_len = ";
4431 ss<< tmpCurDVR3->GetArrayLength();
4432 ss << ";\n";
4435 if(vSubArguments.size()>4)
4437 FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
4438 const formula::SingleVectorRefToken* tmpCurDVR4= static_cast<const formula::SingleVectorRefToken *>(
4439 tmpCur4);
4440 ss<< " int buffer_flag_len = ";
4441 ss<< tmpCurDVR4->GetArrayLength();
4442 ss << ";\n";
4445 ss<< " int buffer_zins_len = ";
4446 ss<< tmpCurDVR0->GetArrayLength();
4447 ss << ";\n";
4449 ss<< " int buffer_zzr_len = ";
4450 ss<< tmpCurDVR1->GetArrayLength();
4451 ss << ";\n";
4453 ss<< " int buffer_rmz_len = ";
4454 ss<< tmpCurDVR2->GetArrayLength();
4455 ss << ";\n";
4457 ss<<" if(gid0>=buffer_zins_len || isNan(";
4458 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
4459 ss<<"))\n";
4460 ss<<" zins = 0;\n else \n";
4461 ss<<" zins = ";
4462 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
4463 ss<<";\n";
4465 ss<<" if(gid0>=buffer_zzr_len || isNan(";
4466 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
4467 ss<<"))\n";
4468 ss<<" zzr = 0;\n else \n";
4469 ss<<" zzr = ";
4470 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
4471 ss<<";\n";
4473 ss<<" if(gid0>=buffer_rmz_len || isNan(";
4474 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
4475 ss<<"))\n";
4476 ss<<" rmz = 0;\n else \n";
4477 ss<<" rmz = ";
4478 ss << vSubArguments[2]->GenSlidingWindowDeclRef();
4479 ss<<";\n";
4481 if(vSubArguments.size()>3)
4483 ss<<" if(gid0>=buffer_zw_len || isNan(";
4484 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
4485 ss<<"))\n";
4486 ss<<" zw = 0;\n else \n";
4487 ss<<" zw = ";
4488 ss << vSubArguments[3]->GenSlidingWindowDeclRef();
4489 ss<<";\n";
4490 }else
4492 ss<<" zw = 0;\n";
4495 if(vSubArguments.size()>4)
4497 ss<<" if(gid0>=buffer_flag_len || isNan(";
4498 ss << vSubArguments[4]->GenSlidingWindowDeclRef();
4499 ss<<"))\n";
4500 ss<<" flag = 0;\n else \n";
4501 ss<<" flag = ";
4502 ss << vSubArguments[4]->GenSlidingWindowDeclRef();
4503 ss<<";\n";
4504 }else
4506 ss<<" flag = 0;\n";
4508 ss << " if(zins == 0)\n";
4509 ss << " result=zw+rmz*zzr;\n";
4510 ss << " else if(flag > 0)\n";
4511 ss << " result=(zw*pow(1+zins,-zzr))+";
4512 ss << "(rmz*(1-pow(1+zins,-zzr+1))*pow(zins,-1))+rmz;\n";
4513 ss << " else\n";
4514 ss << " result=(zw*pow(1+zins,-zzr))+";
4515 ss << "(rmz*(1-pow(1+zins,-zzr))*pow(zins,-1));\n";
4516 ss << " return -result;\n";
4517 ss << "}";
4519 void OpVDB::BinInlineFun(std::set<std::string>& decls,
4520 std::set<std::string>& funs)
4522 decls.insert(ScGetGDADecl);decls.insert(DblMinDecl);
4523 decls.insert(ScInterVDBDecl);decls.insert(VDBImplementDecl);
4524 funs.insert(ScGetGDA);funs.insert(DblMin);
4525 funs.insert(ScInterVDB);funs.insert(VDBImplement);
4528 void OpVDB::GenSlidingWindowFunction(
4529 std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
4531 ss << "\ndouble " << sSymName;
4532 ss << "_"<< BinFuncName() <<"(";
4533 for (unsigned i = 0; i < vSubArguments.size(); i++)
4535 if (i)
4536 ss << ",";
4537 vSubArguments[i]->GenSlidingWindowDecl(ss);
4539 ss << ") {\n";
4540 ss << " int gid0 = get_global_id(0);\n";
4541 ss << " int singleIndex = gid0;\n";
4542 ss << " double result = 0;\n";
4543 if(vSubArguments.size()<5)
4545 ss << " result = -DBL_MAX;\n";
4546 ss << " return result;\n";
4547 }else
4549 GenTmpVariables(ss,vSubArguments);
4550 CheckAllSubArgumentIsNan(ss,vSubArguments);
4551 if(vSubArguments.size() <= 6)
4553 ss << " int tmp6 = 0;\n";
4555 if(vSubArguments.size() == 5)
4557 ss << " double tmp5= 2.0;\n";
4559 ss << " if(tmp3 < 0 || tmp4<tmp3 || tmp4>tmp2 || tmp0<0 ||tmp1>tmp0";
4560 ss << "|| tmp5 <=0)\n";
4561 ss << " result = -DBL_MAX;\n";
4562 ss << " else\n";
4563 ss << " result =";
4564 ss << "VDBImplement(tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);\n";
4565 ss << " return result;\n";
4566 ss << "}";
4571 void OpXirr::GenSlidingWindowFunction(std::stringstream &ss,
4572 const std::string &sSymName, SubArguments &vSubArguments)
4574 FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
4575 const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
4576 formula::DoubleVectorRefToken *>(tmpCur);
4577 size_t nCurWindowSize = pCurDVR->GetArrayLength() <
4578 pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
4579 pCurDVR->GetRefRowSize() ;
4580 ss << "\ndouble " << sSymName;
4581 ss << "_"<< BinFuncName() <<"(";
4582 for (unsigned i = 0; i < vSubArguments.size(); i++)
4584 if (i)
4585 ss << ",";
4586 vSubArguments[i]->GenSlidingWindowDecl(ss);
4588 ss << ") {\n";
4589 ss << " int gid0 = get_global_id(0);\n";
4590 ss << " int doubleIndex = gid0;\n";
4591 ss << " int singleIndex = gid0;\n";
4592 ss << " double result = 0;\n";
4593 ss << " int i=0;\n";
4594 if(vSubArguments.size()<2)
4596 ss << " result = -DBL_MAX;\n";
4597 ss << " return result;\n";
4598 }else
4600 GenTmpVariables(ss,vSubArguments);
4601 if(vSubArguments.size() == 2)
4603 ss << " double tmp2 = 0.1;\n";
4604 }else
4606 CheckSubArgumentIsNan(ss,vSubArguments,2);
4608 ss << " if(tmp2<=-1)\n";
4609 ss << " result = -DBL_MAX;\n";
4610 ss << " else\n";
4611 ss << " {\n";
4612 ss << " double fMaxEps = 1e-10;\n";
4613 ss << " int nMaxIter = 50;\n";
4614 ss << " double fNewRate, fRateEps, fResultValue, fResultValue2;\n";
4615 ss << " int nIter = 0;\n";
4616 ss << " int bContLoop;\n";
4617 ss << " int windowsSize = ";
4618 ss << nCurWindowSize;
4619 ss << ";\n";
4620 CheckSubArgumentIsNan(ss,vSubArguments,0);
4621 CheckSubArgumentIsNan(ss,vSubArguments,1);
4622 ss << " double D_0 = tmp1;\n";
4623 ss << " double V_0 = tmp0;\n";
4624 ss << " double fResultRate = tmp2;\n";
4625 ss << " double r;\n";
4626 ss << " double fResult;\n";
4627 ss << " do\n";
4628 ss << " {\n";
4629 ss << " fResultValue = V_0;\n";
4630 ss << " r = fResultRate + 1;\n";
4631 ss << " for (i = ";
4632 if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
4633 ss << "gid0+1; i < "<< nCurWindowSize <<"; i++)\n";
4634 } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
4635 ss << "1; i < gid0+"<< nCurWindowSize <<"; i++)\n";
4636 } else {
4637 ss << "1; i < "<< nCurWindowSize <<"; i++)\n";
4639 ss << " {\n";
4640 if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
4642 ss<< " doubleIndex =i+gid0;\n";
4643 }else
4645 ss<< " doubleIndex =i;\n";
4647 CheckSubArgumentIsNan(ss,vSubArguments,0);
4648 CheckSubArgumentIsNan(ss,vSubArguments,1);
4649 ss << " fResultValue += tmp0/pow(r,(tmp1 - D_0)/365.0);\n";
4650 ss << " }\n";
4651 ss << " fResultValue2 = 0;\n";
4653 ss << " for (i = ";
4654 if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
4655 ss << "gid0+1; i < "<< nCurWindowSize <<"; i++)\n";
4656 } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
4657 ss << "1; i < gid0+"<< nCurWindowSize <<"; i++)\n";
4658 } else {
4659 ss << "1; i < "<< nCurWindowSize <<"; i++)\n";
4661 ss << " {\n";
4662 if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
4664 ss<< " doubleIndex =i+gid0;\n";
4665 }else
4667 ss<< " doubleIndex =i;\n";
4669 CheckSubArgumentIsNan(ss,vSubArguments,0);
4670 CheckSubArgumentIsNan(ss,vSubArguments,1);
4671 ss << " double E_i = (tmp1 - D_0)/365.0;\n";
4672 ss << " fResultValue2 -= E_i * tmp0 / pow(r,E_i + 1.0);\n";
4673 ss << " }\n";
4674 ss << " fNewRate = fResultRate - fResultValue / fResultValue2;\n";
4675 ss << " fRateEps = fabs( fNewRate - fResultRate );\n";
4676 ss << " fResultRate = fNewRate;\n";
4677 ss << " bContLoop = (fRateEps > fMaxEps) && (fabs( fResultValue ) > fMaxEps);\n";
4678 ss << " }\n";
4679 ss << " while( bContLoop && (++nIter < nMaxIter) );\n";
4680 ss << " if( bContLoop )\n";
4681 ss << " result = -DBL_MAX;\n";
4682 ss << " result = fResultRate;\n";
4683 ss << " }\n";
4684 ss << " return result;\n";
4685 ss << "}";
4689 void OpDB::GenSlidingWindowFunction(std::stringstream& ss,
4690 const std::string &sSymName, SubArguments& vSubArguments)
4692 ss << "\ndouble " << sSymName;
4693 ss << "_"<< BinFuncName() <<"(";
4694 for (unsigned i = 0; i < vSubArguments.size(); i++)
4696 if (i)
4697 ss << ",";
4698 vSubArguments[i]->GenSlidingWindowDecl(ss);
4700 ss << ") {\n";
4701 ss << " int gid0 = get_global_id(0);\n";
4702 ss << " double nWert,nRest,nDauer,nPeriode;\n";
4703 ss << " int nMonate;\n";
4704 ss << " double tmp = 0;\n";
4705 FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
4706 const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
4707 formula::SingleVectorRefToken *>(tmpCur0);
4708 FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
4709 const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
4710 formula::SingleVectorRefToken *>(tmpCur1);
4711 FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
4712 const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
4713 formula::SingleVectorRefToken *>(tmpCur2);
4714 FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
4715 const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
4716 formula::SingleVectorRefToken *>(tmpCur3);
4717 FormulaToken* tmpCur4 = vSubArguments[4]->GetFormulaToken();
4718 const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
4719 formula::SingleVectorRefToken *>(tmpCur4);
4720 ss<< " int buffer_wert_len = ";
4721 ss<< tmpCurDVR0->GetArrayLength();
4722 ss << ";\n";
4723 ss<< " int buffer_rest_len = ";
4724 ss<< tmpCurDVR1->GetArrayLength();
4725 ss << ";\n";
4726 ss<< " int buffer_dauer_len = ";
4727 ss<< tmpCurDVR2->GetArrayLength();
4728 ss << ";\n";
4729 ss<< " int buffer_periode_len = ";
4730 ss<< tmpCurDVR3->GetArrayLength();
4731 ss << ";\n";
4732 ss<< " int buffer_nMonate_len = ";
4733 ss<< tmpCurDVR4->GetArrayLength();
4734 ss << ";\n";
4735 ss <<" if(gid0 >= buffer_wert_len || isNan(";
4736 ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
4737 ss <<"))\n";
4738 ss <<" nWert = 0;\n else\n";
4739 ss <<" nWert = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
4740 ss <<";\n";
4741 ss <<" if(gid0 >= buffer_rest_len || isNan(";
4742 ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
4743 ss <<"))\n";
4744 ss <<" nRest = 0;\n else\n";
4745 ss <<" nRest = ";
4746 ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
4747 ss <<";\n";
4748 ss <<" if(gid0 >= buffer_dauer_len || isNan(";
4749 ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
4750 ss <<"))\n";
4751 ss <<" nDauer = 0;\n else\n";
4752 ss <<" nDauer = "<<vSubArguments[2]->GenSlidingWindowDeclRef();
4753 ss <<";\n";
4754 ss <<" if(gid0 >= buffer_periode_len || isNan(";
4755 ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
4756 ss <<"))\n";
4757 ss <<" nPeriode = 0;\n else\n";
4758 ss <<" nPeriode = "<<vSubArguments[3]->GenSlidingWindowDeclRef();
4759 ss <<";\n";
4760 ss <<" if(gid0 >= buffer_nMonate_len || isNan(";
4761 ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
4762 ss <<"))\n";
4763 ss <<" nMonate = 0;\n else\n";
4764 ss <<" nMonate = (int)"<<vSubArguments[4]->GenSlidingWindowDeclRef();
4765 ss <<";\n";
4766 ss <<" double nAbRate = 1.0 - pow(nRest / nWert, 1.0 / nDauer);\n";
4767 ss <<" nAbRate = ((int)(nAbRate * 1000.0 + 0.5)) / 1000.0;\n";
4768 ss <<" double nErsteAbRate = nWert * nAbRate * nMonate / 12.0;\n";
4769 ss <<" double nGda2 = 0.0;\n";
4770 ss <<" if ((int)(nPeriode) == 1)\n";
4771 ss <<" nGda2 = nErsteAbRate;\n";
4772 ss <<" else\n";
4773 ss <<" {\n";
4774 ss <<" double nSummAbRate = nErsteAbRate;\n";
4775 ss <<" double nMin = nDauer;\n";
4776 ss <<" if (nMin > nPeriode) nMin = nPeriode;\n";
4777 ss <<" int iMax = (int)nMin;\n";
4778 ss <<" for (int i = 2; i <= iMax; i++)\n";
4779 ss <<" {\n";
4780 ss <<" nGda2 = (nWert - nSummAbRate) * nAbRate;\n";
4781 ss <<" nSummAbRate += nGda2;\n";
4782 ss <<" }\n";
4783 ss <<" if (nPeriode > nDauer)\n";
4784 ss <<" nGda2 = ((nWert - nSummAbRate)";
4785 ss <<"* nAbRate * (12.0 - nMonate)) / 12.0;\n";
4786 ss <<" }\n";
4787 ss <<" tmp = nGda2;\n";
4788 ss <<" return tmp;\n";
4789 ss <<"}";
4793 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */