LCOV - code coverage report
Current view: top level - sc/source/core/opencl - op_financial.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 3718 0.0 %
Date: 2014-04-14 Functions: 0 88 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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             :  */
       9             : 
      10             : #include "op_financial.hxx"
      11             : 
      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>
      20             : 
      21             : using namespace formula;
      22             : 
      23             : namespace sc { namespace opencl {
      24             : // Definitions of inline functions
      25             : #include "opinlinefun_finacial.cxx"
      26             : 
      27           0 : void RRI::GenSlidingWindowFunction(
      28             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
      29             : {
      30           0 :     ss << "\ndouble " << sSymName;
      31           0 :     ss << "_"<< BinFuncName() <<"(";
      32           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
      33             :     {
      34           0 :         if (i)
      35           0 :             ss << ",";
      36           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
      37             :     }
      38           0 :     ss << ") {\n";
      39           0 :     ss << "    double tmp = " << GetBottom() <<";\n";
      40           0 :     ss << "    int gid0 = get_global_id(0);\n";
      41           0 :     ss << "    double fv;\n";
      42           0 :     ss << "    double pv;\n";
      43           0 :     ss << "    double nper;\n";
      44             : #ifdef ISNAN
      45           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
      46             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
      47           0 :     formula::SingleVectorRefToken *>(tmpCur0);
      48             : 
      49           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
      50             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
      51           0 :     formula::SingleVectorRefToken *>(tmpCur1);
      52             : 
      53           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
      54             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
      55           0 :     formula::SingleVectorRefToken *>(tmpCur2);
      56             : 
      57           0 :     ss<< "    int buffer_nper_len = ";
      58           0 :     ss<< tmpCurDVR0->GetArrayLength();
      59           0 :     ss << ";\n";
      60             : 
      61           0 :     ss<< "    int buffer_pv_len = ";
      62           0 :     ss<< tmpCurDVR1->GetArrayLength();
      63           0 :     ss << ";\n";
      64             : 
      65           0 :     ss<< "    int buffer_fv_len = ";
      66           0 :     ss<< tmpCurDVR2->GetArrayLength();
      67           0 :     ss << ";\n";
      68             : #endif
      69             : 
      70             : #ifdef ISNAN
      71           0 :     ss<<"    if(gid0>=buffer_nper_len || isNan(";
      72           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
      73           0 :     ss<<"))\n";
      74           0 :     ss<<"        nper = 0;\n\telse \n";
      75             : #endif
      76           0 :     ss<<"        nper = ";
      77           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
      78           0 :     ss<<";\n";
      79             : 
      80             : #ifdef ISNAN
      81           0 :     ss<<"    if(gid0>=buffer_pv_len || isNan(";
      82           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
      83           0 :     ss<<"))\n";
      84           0 :     ss<<"        pv = 0;\n\telse \n";
      85             : #endif
      86           0 :     ss<<"        pv = ";
      87           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
      88           0 :     ss<<";\n";
      89             : 
      90             : #ifdef ISNAN
      91           0 :     ss<<"    if(gid0>=buffer_pv_len || isNan(";
      92           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
      93           0 :     ss<<"))\n";
      94           0 :     ss<<"        fv = 0;\n\telse \n";
      95             : #endif
      96           0 :     ss<<"        fv = ";
      97           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
      98           0 :     ss<<";\n";
      99           0 :     ss << "    tmp = pow(fv*pow(pv,-1),1.0*pow(nper,-1))-1;\n";
     100           0 :     ss << "    return tmp;\n";
     101           0 :     ss << "}";
     102           0 : }
     103             : 
     104           0 : void OpNominal::GenSlidingWindowFunction(
     105             :     std::stringstream &ss, const std::string &sSymName, SubArguments &
     106             : vSubArguments)
     107             : {
     108           0 :     ss << "\ndouble " << sSymName;
     109           0 :     ss << "_"<< BinFuncName() <<"(";
     110           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     111             :     {
     112           0 :         if (i)
     113           0 :             ss << ",";
     114           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     115             :     }
     116           0 :     ss << ") {\n\t";
     117           0 :     ss << "double tmp = 0;\n\t";
     118           0 :     ss << "double temp = 0;\n\t";
     119           0 :     ss << "int gid0 = get_global_id(0);\n\t";
     120           0 :     ss << "double tmp0=0,tmp1=0;\n";
     121           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     122             :     {
     123           0 :         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
     124             :         assert(pCur);
     125           0 :         if (pCur->GetType() == formula::svSingleVectorRef)
     126             :         {
     127             : #ifdef  ISNAN
     128             :                 const formula::SingleVectorRefToken* pSVR =
     129           0 :                 static_cast< const formula::SingleVectorRefToken* >(pCur);
     130           0 :             ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
     131             : #else
     132             : #endif
     133             :         }
     134           0 :         else if (pCur->GetType() == formula::svDouble)
     135             :         {
     136             : #ifdef  ISNAN
     137           0 :             ss << "{\n";
     138             : #endif
     139             :         }
     140             :         else
     141             :         {
     142             : #ifdef  ISNAN
     143             : #endif
     144             :         }
     145             : #ifdef  ISNAN
     146           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
     147             :         {
     148           0 :             ss <<"    temp="<<vSubArguments[i]->GenSlidingWindowDeclRef();
     149           0 :             ss <<";\n";
     150           0 :             ss <<"    if (isNan(temp))\n";
     151           0 :             ss <<"        tmp"<<i<<"= 0;\n";
     152           0 :             ss <<"    else\n";
     153           0 :             ss <<"        tmp"<<i<<"=temp;\n";
     154           0 :             ss <<"    }\n";
     155             :         }
     156             :         else
     157             :         {
     158           0 :             ss <<"    tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(
     159           0 : );
     160           0 :             ss <<";\n";
     161             :         }
     162             : #else
     163             :     ss <<"    tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
     164             :     ss <<";\n";
     165             : #endif
     166             :     }
     167           0 :     ss<<"if(tmp1==0)\n\t";
     168           0 :     ss<<"\treturn 0;\n\t";
     169           0 :     ss<<"tmp=pow( tmp1,-1);\n\t";
     170           0 :     ss<<"tmp=( pow( tmp0+ 1.0, tmp ) - 1.0 ) *";
     171           0 :     ss<<"tmp1;\n\t";
     172           0 :     ss << "return tmp;\n";
     173           0 :     ss << "}";
     174           0 : }
     175             : 
     176           0 : void OpDollarde::GenSlidingWindowFunction(
     177             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
     178             : {
     179           0 :     ss << "\ndouble " << sSymName;
     180           0 :     ss << "_"<< BinFuncName() <<"(";
     181           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     182             :     {
     183           0 :         if (i)
     184           0 :             ss << ",";
     185           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     186             :     }
     187           0 :     ss << ") {\n\t";
     188           0 :     ss << "double tmp = " << GetBottom() <<";\n\t";
     189           0 :     ss << "int gid0 = get_global_id(0);\n\t";
     190           0 :     ss << "double fInt = " << GetBottom() <<";\n\t";
     191           0 :     ss << "double dollar;\n\t";
     192           0 :     ss << "double fFrac;\n\t";
     193             : #ifdef ISNAN
     194           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
     195             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
     196           0 :     formula::SingleVectorRefToken *>(tmpCur0);
     197           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
     198             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
     199           0 :     formula::SingleVectorRefToken *>(tmpCur1);
     200           0 :     ss<< "int buffer_dollar_len = ";
     201           0 :     ss<< tmpCurDVR0->GetArrayLength();
     202           0 :     ss << ";\n\t";
     203           0 :     ss<< "int buffer_frac_len = ";
     204           0 :     ss<< tmpCurDVR1->GetArrayLength();
     205           0 :     ss << ";\n\t";
     206             : #endif
     207             : #ifdef ISNAN
     208           0 :     ss<<"if((gid0)>=buffer_dollar_len || isNan(";
     209           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     210           0 :     ss<<"))\n\t\t";
     211           0 :     ss<<"dollar = 0;\n\telse \n\t\t";
     212             : #endif
     213           0 :     ss<<"dollar = ";
     214           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     215           0 :     ss<<";\n\t";
     216             : #ifdef ISNAN
     217           0 :     ss<<"if((gid0)>=buffer_frac_len || isNan(";
     218           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
     219           0 :     ss<<"))\n\t\t";
     220           0 :     ss<<"fFrac = 0;\n\telse \n\t\t";
     221             : #endif
     222           0 :     ss<<"fFrac = ";
     223           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
     224           0 :     ss<<";\n\t";
     225           0 :     ss << "tmp = modf( dollar , &fInt );\n\t";
     226           0 :     ss << "tmp /= fFrac;\n\t";
     227           0 :     ss << "tmp *= pow( 10.0 , ceil( log10(fFrac ) ) );\n\t";
     228           0 :     ss << "tmp += fInt;\t";
     229           0 :     ss << "\n\treturn tmp;\n";
     230           0 :     ss << "}";
     231           0 : }
     232             : 
     233           0 : void OpDollarfr::GenSlidingWindowFunction(std::stringstream &ss,
     234             :         const std::string &sSymName, SubArguments &vSubArguments)
     235             : {
     236           0 :     ss << "\ndouble " << sSymName;
     237           0 :     ss << "_"<< BinFuncName() <<"(";
     238           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     239             :     {
     240           0 :         if (i)
     241           0 :             ss << ",";
     242           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     243             :     }
     244           0 :     ss << ") {\n\t";
     245           0 :     ss << "double tmp = " << GetBottom() <<";\n\t";
     246           0 :     ss << "int gid0 = get_global_id(0);\n\t";
     247           0 :     ss << "double fInt = " << GetBottom() <<";\n\t";
     248           0 :     ss << "double dollar;\n\t";
     249           0 :     ss << "double fFrac;\n\t";
     250             : #ifdef  ISNAN
     251           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
     252             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
     253           0 :     formula::SingleVectorRefToken *>(tmpCur0);
     254           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
     255             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
     256           0 :     formula::SingleVectorRefToken *>(tmpCur1);
     257           0 :     ss<< "int buffer_dollar_len = ";
     258           0 :     ss<< tmpCurDVR0->GetArrayLength();
     259           0 :     ss << ";\n\t";
     260           0 :     ss<< "int buffer_frac_len = ";
     261           0 :     ss<< tmpCurDVR1->GetArrayLength();
     262           0 :     ss << ";\n\t";
     263             : #endif
     264             : #ifdef  ISNAN
     265           0 :     ss<<"if((gid0)>=buffer_dollar_len || isNan(";
     266           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     267           0 :     ss<<"))\n\t\t";
     268           0 :     ss<<"dollar = 0;\n\telse \n\t\t";
     269             : #endif
     270           0 :     ss<<"dollar = ";
     271           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     272           0 :     ss<<";\n\t";
     273             : #ifdef  ISNAN
     274           0 :     ss<<"if((gid0)>=buffer_frac_len || isNan(";
     275           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
     276           0 :     ss<<"))\n\t\t";
     277           0 :     ss<<"fFrac = 0;\n\telse \n\t\t";
     278             : #endif
     279           0 :     ss<<"fFrac = ";
     280           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
     281           0 :     ss<<";\n\t";
     282           0 :     ss << "tmp = modf( dollar , &fInt );\n\t";
     283           0 :     ss << "tmp *= fFrac;\n\t";
     284           0 :     ss << "tmp *= pow( 10.0 , -ceil( log10(fFrac ) ) );\n\t";
     285           0 :     ss << "tmp += fInt;\t";
     286           0 :     ss << "\n\treturn tmp;\n";
     287           0 :     ss << "}";
     288           0 : }
     289             : 
     290           0 : void OpDISC::BinInlineFun(std::set<std::string>& decls,
     291             :     std::set<std::string>& funs)
     292             : {
     293           0 :     decls.insert(GetYearFrac_newDecl);decls.insert(DaysToDate_newDecl);
     294           0 :     decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
     295           0 :     funs.insert(GetYearFrac_new);funs.insert(DaysToDate_new);
     296           0 :     funs.insert(DaysInMonth);funs.insert(IsLeapYear);
     297           0 : }
     298             : 
     299           0 : void OpDISC::GenSlidingWindowFunction(std::stringstream& ss,
     300             :     const std::string &sSymName, SubArguments& vSubArguments)
     301             : {
     302           0 :     ss << "\ndouble " << sSymName;
     303           0 :     ss << "_" << BinFuncName() << "(";
     304           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     305             :     {
     306           0 :         if (i)
     307           0 :             ss << ",";
     308           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     309             :     }
     310           0 :     ss << ") {\n\t";
     311           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
     312           0 :     ss << "    int gid0 = get_global_id(0);\n";
     313           0 :     ss << "    double arg0 = " << GetBottom() << ";\n";
     314           0 :     ss << "    double arg1 = " << GetBottom() << ";\n";
     315           0 :     ss << "    double arg2 = " << GetBottom() << ";\n";
     316           0 :     ss << "    double arg3 = " << GetBottom() << ";\n";
     317           0 :     ss << "    double arg4 = " << GetBottom() << ";\n";
     318           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     319             :     {
     320           0 :         FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
     321             :         assert(pCur);
     322           0 :         if (pCur->GetType() == formula::svSingleVectorRef)
     323             :         {
     324             : #ifdef  ISNAN
     325             :             const formula::SingleVectorRefToken* pSVR =
     326           0 :                 static_cast< const formula::SingleVectorRefToken* >(pCur);
     327           0 :             ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
     328             : #endif
     329             :         }
     330           0 :         else if (pCur->GetType() == formula::svDouble)
     331             :         {
     332             : #ifdef  ISNAN
     333           0 :             ss << "    {\n";
     334             : #endif
     335             :         }
     336             : #ifdef  ISNAN
     337           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
     338             :         {
     339           0 :             ss << "        if (isNan(";
     340           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
     341           0 :             ss << "))\n";
     342           0 :             ss << "            arg" << i << " = 0;\n";
     343           0 :             ss << "        else\n";
     344           0 :             ss << "            arg" << i << " = ";
     345           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
     346           0 :             ss << "    }\n";
     347             :         }
     348             :         else
     349             :         {
     350           0 :             ss << "    arg" << i << " = ";
     351           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
     352             :         }
     353             : #else
     354             :         ss << "    arg" << i;
     355             :         ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
     356             : #endif
     357             :     }
     358           0 :     ss << "    int nNullDate = 693594;\n";
     359           0 :     ss << "    tmp = 1.0 - arg2 / arg3;\n";
     360           0 :     ss << "    tmp /=";
     361           0 :     ss << " GetYearFrac_new(nNullDate, (int)arg0, (int)arg1, (int)arg4);\n";
     362           0 :     ss << "    return tmp;\n";
     363           0 :     ss << "}";
     364           0 : }
     365             : 
     366             : 
     367           0 : void OpINTRATE::BinInlineFun(std::set<std::string>& decls,
     368             :     std::set<std::string>& funs)
     369             : {
     370           0 :     decls.insert(GetYearDiff_newDecl);decls.insert(GetDiffDate_newDecl);
     371           0 :     decls.insert(DaysToDate_newDecl);decls.insert(GetNullDateDecl);
     372           0 :     decls.insert(DateToDaysDecl);decls.insert(DaysInMonthDecl);
     373           0 :     decls.insert(IsLeapYearDecl);
     374           0 :     funs.insert(GetYearDiff_new);funs.insert(GetDiffDate_new);
     375           0 :     funs.insert(DaysToDate_new);funs.insert(GetNullDate);
     376           0 :     funs.insert(DateToDays);funs.insert(DaysInMonth);
     377           0 :     funs.insert(IsLeapYear);
     378           0 : }
     379             : 
     380           0 : void OpINTRATE::GenSlidingWindowFunction(std::stringstream& ss,
     381             :     const std::string &sSymName, SubArguments& vSubArguments)
     382             : {
     383           0 :     ss << "\ndouble " << sSymName;
     384           0 :     ss << "_" << BinFuncName() << "(";
     385           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     386             :     {
     387           0 :         if (i)
     388           0 :             ss << ",";
     389           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     390             :     }
     391           0 :     ss << ") {\n";
     392           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
     393           0 :     ss << "    int gid0 = get_global_id(0);\n";
     394           0 :     ss << "    double arg0 = " << GetBottom() << ";\n";
     395           0 :     ss << "    double arg1 = " << GetBottom() << ";\n";
     396           0 :     ss << "    double arg2 = " << GetBottom() << ";\n";
     397           0 :     ss << "    double arg3 = " << GetBottom() << ";\n";
     398           0 :     ss << "    double arg4 = " << GetBottom() << ";\n";
     399           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     400             :     {
     401           0 :         FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
     402             :         assert(pCur);
     403           0 :         if (pCur->GetType() == formula::svSingleVectorRef)
     404             :         {
     405             : #ifdef  ISNAN
     406             :             const formula::SingleVectorRefToken* pSVR =
     407           0 :                 static_cast< const formula::SingleVectorRefToken* >(pCur);
     408           0 :             ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
     409             : #endif
     410             :         }
     411           0 :         else if (pCur->GetType() == formula::svDouble)
     412             :         {
     413             : #ifdef  ISNAN
     414           0 :             ss << "    {\n";
     415             : #endif
     416             :         }
     417             : #ifdef  ISNAN
     418           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
     419             :         {
     420           0 :             ss << "        if (isNan(";
     421           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
     422           0 :             ss << "))\n";
     423           0 :             ss << "            arg" << i << " = 0;\n";
     424           0 :             ss << "        else\n";
     425           0 :             ss << "            arg" << i << " = ";
     426           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
     427           0 :             ss << "    }\n";
     428             :         }
     429             :         else
     430             :         {
     431           0 :             ss << "    arg" << i << " = ";
     432           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
     433             :         }
     434             : #else
     435             :         ss << "    arg" << i;
     436             :         ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
     437             : #endif
     438             :     }
     439           0 :     ss << "    int nNullDate = GetNullDate();\n";
     440           0 :     ss << "    tmp = arg3 * pow(arg2,-1) - 1.0;\n";
     441           0 :     ss << "    tmp = tmp * pow(GetYearDiff_new(nNullDate, (int)arg0,";
     442           0 :     ss << " (int)arg1,(int)arg4),-1);\n";
     443           0 :     ss << "    return tmp;\n";
     444           0 :     ss << "}";
     445           0 : }
     446             : 
     447           0 : void OpFV::BinInlineFun(std::set<std::string>& decls,
     448             :     std::set<std::string>& funs)
     449             : {
     450           0 :     decls.insert(GetZwDecl);
     451           0 :     funs.insert(GetZw);
     452           0 : }
     453             : 
     454           0 : void OpFV::GenSlidingWindowFunction(std::stringstream& ss,
     455             :     const std::string &sSymName, SubArguments& vSubArguments)
     456             : {
     457           0 :     ss << "\ndouble " << sSymName;
     458           0 :     ss << "_"<< BinFuncName() <<"(";
     459           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     460             :     {
     461           0 :         if (i)
     462           0 :             ss << ",";
     463           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     464             :     }
     465           0 :     ss << ") {\n";
     466           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
     467           0 :     ss << "    int gid0 = get_global_id(0);\n";
     468           0 :     ss << "    double arg0 = " << GetBottom() << ";\n";
     469           0 :     ss << "    double arg1 = " << GetBottom() << ";\n";
     470           0 :     ss << "    double arg2 = " << GetBottom() << ";\n";
     471           0 :     ss << "    double arg3 = " << GetBottom() << ";\n";
     472           0 :     ss << "    double arg4 = " << GetBottom() << ";\n";
     473           0 :     unsigned j = vSubArguments.size();
     474           0 :     while (j--)
     475             :         {
     476           0 :         FormulaToken* pCur = vSubArguments[j]->GetFormulaToken();
     477             :         assert(pCur);
     478           0 :         if(pCur->GetType() == formula::svSingleVectorRef)
     479             :             {
     480             : #ifdef  ISNAN
     481             :             const formula::SingleVectorRefToken* pSVR =
     482           0 :             static_cast< const formula::SingleVectorRefToken* >(pCur);
     483           0 :             ss << "    if(gid0 >= " << pSVR->GetArrayLength() << " || isNan(";
     484           0 :             ss << vSubArguments[j]->GenSlidingWindowDeclRef();
     485           0 :             ss << "))\n";
     486           0 :             ss << "        arg" << j << " = " <<GetBottom() << ";\n";
     487           0 :             ss << "    else\n";
     488             : #endif
     489           0 :             ss << "        arg" << j << " = ";
     490           0 :             ss << vSubArguments[j]->GenSlidingWindowDeclRef();
     491           0 :             ss << ";\n";
     492             :             }
     493             :         }
     494           0 :     ss << "    tmp = GetZw(arg0, arg1, arg2, arg3, arg4);\n";
     495           0 :     ss << "    return tmp;\n";
     496           0 :     ss << "}";
     497           0 : }
     498             : 
     499           0 : void OpIPMT::BinInlineFun(std::set<std::string>& decls,
     500             :     std::set<std::string>& funs)
     501             : {
     502           0 :     decls.insert(GetZwDecl);
     503           0 :     funs.insert(GetZw);
     504           0 : }
     505             : 
     506           0 : void OpIPMT::GenSlidingWindowFunction(std::stringstream& ss,
     507             :     const std::string &sSymName, SubArguments& vSubArguments)
     508             : {
     509           0 :     ss << "\ndouble " << sSymName;
     510           0 :     ss << "_"<< BinFuncName() <<"(";
     511           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     512             :     {
     513           0 :         if (i)
     514           0 :             ss << ",";
     515           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     516             :     }
     517           0 :     ss << ") {\n";
     518           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
     519           0 :     ss << "    int gid0 = get_global_id(0);\n";
     520           0 :     ss << "    double arg0 = " << GetBottom() << ";\n";
     521           0 :     ss << "    double arg1 = " << GetBottom() << ";\n";
     522           0 :     ss << "    double arg2 = " << GetBottom() << ";\n";
     523           0 :     ss << "    double arg3 = " << GetBottom() << ";\n";
     524           0 :     ss << "    double arg4 = " << GetBottom() << ";\n";
     525           0 :     ss << "    double arg5 = " << GetBottom() << ";\n";
     526           0 :     unsigned j = vSubArguments.size();
     527           0 :     while (j--)
     528             :         {
     529           0 :         FormulaToken* pCur = vSubArguments[j]->GetFormulaToken();
     530             :         assert(pCur);
     531           0 :         if(pCur->GetType() == formula::svSingleVectorRef)
     532             :             {
     533             : #ifdef  ISNAN
     534             :             const formula::SingleVectorRefToken* pSVR =
     535           0 :             static_cast< const formula::SingleVectorRefToken* >(pCur);
     536           0 :             ss << "    if(gid0 >= " << pSVR->GetArrayLength() << " || isNan(";
     537           0 :             ss << vSubArguments[j]->GenSlidingWindowDeclRef();
     538           0 :             ss << "))\n";
     539           0 :             ss << "        arg" << j << " = " <<GetBottom() << ";\n";
     540           0 :             ss << "    else\n";
     541             : #endif
     542           0 :             ss << "        arg" << j << " = ";
     543           0 :             ss << vSubArguments[j]->GenSlidingWindowDeclRef();
     544           0 :             ss << ";\n";
     545             :             }
     546             :         }
     547           0 :     ss << "    double pmt ;\n";
     548           0 :     ss << "    if(arg0 == 0.0)\n";
     549           0 :     ss << "        return 0;\n";
     550           0 :     ss << "    double temp1 = 0;\n";
     551           0 :     ss << "    double abl = pow(1.0 + arg0, arg2);\n";
     552           0 :     ss << "    temp1 -= arg4;\n";
     553           0 :     ss << "    temp1 -= arg3 * abl;\n";
     554           0 :     ss << "    pmt = temp1 / (1.0 + arg0 * arg5) /";
     555           0 :     ss << " ( (abl - 1.0) / arg0);\n";
     556           0 :     ss << "    double temp = pow( 1 + arg0, arg1 - 2);\n";
     557           0 :     ss << "    if(arg1 == 1.0)\n";
     558           0 :     ss << "    {\n";
     559           0 :     ss << "        if(arg5 > 0.0)\n";
     560           0 :     ss << "            tmp = 0.0;\n";
     561           0 :     ss << "        else\n";
     562           0 :     ss << "            tmp = -arg3;\n";
     563           0 :     ss << "    }\n";
     564           0 :     ss << "    else\n";
     565           0 :     ss << "    {\n";
     566           0 :     ss << "        if(arg5 > 0.0)\n";
     567           0 :     ss << "            tmp = GetZw(arg0, arg1 - 2.0, pmt, arg3, 1.0)";
     568           0 :     ss << " - pmt;\n";
     569           0 :     ss << "        else\n";
     570           0 :     ss << "            tmp = GetZw(arg0, arg1 - 1.0, pmt, arg3, 0.0);\n";
     571           0 :     ss << "    }\n";
     572           0 :     ss << "    tmp = tmp * arg0;\n";
     573           0 :     ss << "    return tmp;\n";
     574           0 :     ss << "}";
     575           0 : }
     576           0 : void OpISPMT::GenSlidingWindowFunction(std::stringstream& ss,
     577             :     const std::string &sSymName, SubArguments& vSubArguments)
     578             : {
     579           0 :     ss << "\ndouble " << sSymName;
     580           0 :     ss << "_" << BinFuncName() <<"(";
     581           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     582             :     {
     583           0 :         if (i)
     584           0 :             ss << ",";
     585           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     586             :     }
     587           0 :     ss << ") {\n";
     588           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
     589           0 :     ss << "    int gid0 = get_global_id(0);\n";
     590           0 :     ss << "    double arg0 = " << GetBottom() << ";\n";
     591           0 :     ss << "    double arg1 = " << GetBottom() << ";\n";
     592           0 :     ss << "    double arg2 = " << GetBottom() << ";\n";
     593           0 :     ss << "    double arg3 = " << GetBottom() << ";\n";
     594           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     595             :     {
     596           0 :         FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
     597             :         assert(pCur);
     598           0 :         if (pCur->GetType() == formula::svSingleVectorRef)
     599             :         {
     600             : #ifdef  ISNAN
     601             :             const formula::SingleVectorRefToken* pSVR =
     602           0 :                 static_cast< const formula::SingleVectorRefToken* >(pCur);
     603           0 :             ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
     604             : #endif
     605             :         }
     606           0 :         else if (pCur->GetType() == formula::svDouble)
     607             :         {
     608             : #ifdef  ISNAN
     609           0 :             ss << "    {\n";
     610             : #endif
     611             :         }
     612             : #ifdef  ISNAN
     613           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
     614             :         {
     615           0 :             ss << "        if (isNan(";
     616           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
     617           0 :             ss << "))\n";
     618           0 :             ss << "            arg" << i << " = 0;\n";
     619           0 :             ss << "        else\n";
     620           0 :             ss << "            arg" << i << " = ";
     621           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
     622           0 :             ss << "    }\n";
     623             :         }
     624             :         else
     625             :         {
     626           0 :             ss << "    arg" << i << " = ";
     627           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
     628             :         }
     629             : #else
     630             :         ss << "    arg" << i;
     631             :         ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
     632             : #endif
     633             :     }
     634           0 :     ss << "    tmp = arg3 * arg0 * ( arg1 - arg2) * pow(arg2, -1);\n";
     635           0 :     ss << "    return tmp;\n";
     636           0 :     ss << "}";
     637           0 : }
     638             : 
     639           0 : void OpDuration::GenSlidingWindowFunction(std::stringstream& ss,
     640             :     const std::string &sSymName, SubArguments& vSubArguments)
     641             : {
     642           0 :     ss << "\ndouble " << sSymName;
     643           0 :     ss << "_" << BinFuncName() <<"(";
     644           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     645             :     {
     646           0 :         if (i)
     647           0 :             ss << ",";
     648           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     649             :     }
     650           0 :     ss << ") {\n";
     651           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
     652           0 :     ss << "    int gid0 = get_global_id(0);\n";
     653           0 :     ss << "    double arg0 = " << GetBottom() << ";\n";
     654           0 :     ss << "    double arg1 = " << GetBottom() << ";\n";
     655           0 :     ss << "    double arg2 = " << GetBottom() << ";\n";
     656           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     657             :     {
     658           0 :         FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
     659             :         assert(pCur);
     660           0 :         if (pCur->GetType() == formula::svSingleVectorRef)
     661             :         {
     662             : #ifdef  ISNAN
     663             :             const formula::SingleVectorRefToken* pSVR =
     664           0 :                 static_cast< const formula::SingleVectorRefToken* >(pCur);
     665           0 :             ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
     666             : #endif
     667             :         }
     668           0 :         else if (pCur->GetType() == formula::svDouble)
     669             :         {
     670             : #ifdef  ISNAN
     671           0 :             ss << "    {\n";
     672             : #endif
     673             :         }
     674             : #ifdef  ISNAN
     675           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
     676             :         {
     677           0 :             ss << "        if (isNan(";
     678           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
     679           0 :             ss << "))\n";
     680           0 :             ss << "            arg" << i << " = 0;\n";
     681           0 :             ss << "        else\n";
     682           0 :             ss << "            arg" << i << " = ";
     683           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
     684           0 :             ss << "    }\n";
     685             :         }
     686             :         else
     687             :         {
     688           0 :             ss << "    arg" << i << " = ";
     689           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
     690             :         }
     691             : #else
     692             :         ss << "    arg" << i;
     693             :         ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
     694             : #endif
     695             :     }
     696           0 :     ss << "    tmp = log(arg2 * pow( arg1,-1)) / log(arg0 + 1.0);\n";
     697           0 :     ss << "    return tmp;\n";
     698           0 :     ss << "}";
     699           0 : }
     700             : 
     701           0 : void OpDuration_ADD::BinInlineFun(std::set<std::string>& decls,
     702             :     std::set<std::string>& funs)
     703             : {
     704           0 :     decls.insert(GetDurationDecl);decls.insert(lcl_GetcoupnumDecl);
     705           0 :     decls.insert(GetYearFracDecl);decls.insert(DaysToDateDecl);
     706           0 :     decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
     707           0 :     decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
     708           0 :     funs.insert(GetDuration);funs.insert(lcl_Getcoupnum);
     709           0 :     funs.insert(GetYearFrac);funs.insert(DaysToDate);
     710           0 :     funs.insert(GetNullDate);funs.insert(DateToDays);
     711           0 :     funs.insert(DaysInMonth);funs.insert(IsLeapYear);
     712           0 : }
     713             : 
     714           0 : void OpDuration_ADD::GenSlidingWindowFunction(std::stringstream& ss,
     715             :     const std::string &sSymName, SubArguments& vSubArguments)
     716             : {
     717           0 :     ss << "\ndouble " << sSymName;
     718           0 :     ss << "_"<< BinFuncName() <<"(";
     719           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     720             :     {
     721           0 :         if (i)
     722           0 :             ss << ",";
     723           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     724             :     }
     725           0 :     ss << ") {\n";
     726           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
     727           0 :     ss << "    int gid0 = get_global_id(0);\n";
     728           0 :     ss << "    double arg0 = " << GetBottom() << ";\n";
     729           0 :     ss << "    double arg1 = " << GetBottom() << ";\n";
     730           0 :     ss << "    double arg2 = " << GetBottom() << ";\n";
     731           0 :     ss << "    double arg3 = " << GetBottom() << ";\n";
     732           0 :     ss << "    double arg4 = " << GetBottom() << ";\n";
     733           0 :     ss << "    double arg5 = " << GetBottom() << ";\n";
     734           0 :     unsigned j = vSubArguments.size();
     735           0 :     while (j--)
     736             :     {
     737           0 :         FormulaToken* pCur = vSubArguments[j]->GetFormulaToken();
     738             :         assert(pCur);
     739           0 :         if(pCur->GetType() == formula::svSingleVectorRef)
     740             :         {
     741             : #ifdef ISNAN
     742             :             const formula::SingleVectorRefToken* pSVR =
     743           0 :                 static_cast< const formula::SingleVectorRefToken* >(pCur);
     744           0 :             ss << "    if(gid0 >= " << pSVR->GetArrayLength() << " || isNan(";
     745           0 :             ss << vSubArguments[j]->GenSlidingWindowDeclRef();
     746           0 :             ss << "))\n";
     747           0 :             ss << "        arg" << j << " = " <<GetBottom() << ";\n";
     748           0 :             ss << "    else\n";
     749             : #endif
     750           0 :             ss << "        arg" << j << " = ";
     751           0 :             ss << vSubArguments[j]->GenSlidingWindowDeclRef();
     752           0 :             ss << ";\n";
     753             :             }
     754             :         }
     755           0 :     ss << "    int nNullDate = GetNullDate();\n";
     756           0 :     ss << "    tmp = GetDuration( nNullDate, (int)arg0, (int)arg1, arg2,";
     757           0 :     ss << " arg3, (int)arg4, (int)arg5);\n";
     758           0 :     ss << "    return tmp;\n";
     759           0 :     ss << "}";
     760           0 : }
     761           0 : void OpMDuration::BinInlineFun(std::set<std::string>& decls,
     762             :     std::set<std::string>& funs)
     763             : {
     764           0 :     decls.insert(GetDuration_newDecl);decls.insert(lcl_Getcoupnum_newDecl);
     765           0 :     decls.insert(addMonthsDecl);decls.insert(checklessthanDecl);
     766           0 :     decls.insert(setDayDecl);decls.insert(ScaDateDecl);
     767           0 :     decls.insert(GetYearFracDecl);decls.insert(DaysToDateDecl);
     768           0 :     decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
     769           0 :     funs.insert(GetDuration_new);funs.insert(lcl_Getcoupnum_new);
     770           0 :     funs.insert(addMonths);funs.insert(checklessthan);
     771           0 :     funs.insert(setDay);funs.insert(ScaDate);
     772           0 :     funs.insert(GetYearFrac);funs.insert(DaysToDate);
     773           0 :     funs.insert(DaysInMonth);funs.insert(IsLeapYear);
     774           0 : }
     775             : 
     776           0 : void OpMDuration::GenSlidingWindowFunction(std::stringstream& ss,
     777             :     const std::string &sSymName, SubArguments& vSubArguments)
     778             : {
     779           0 :     ss << "\ndouble " << sSymName;
     780           0 :     ss << "_"<< BinFuncName() <<"(";
     781           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     782             :     {
     783           0 :         if (i)
     784           0 :             ss << ",";
     785           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     786             :     }
     787           0 :     ss << ") {\n";
     788           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
     789           0 :     ss << "    int gid0 = get_global_id(0);\n";
     790           0 :     ss << "    double arg0 = " << GetBottom() << ";\n";
     791           0 :     ss << "    double arg1 = " << GetBottom() << ";\n";
     792           0 :     ss << "    double arg2 = " << GetBottom() << ";\n";
     793           0 :     ss << "    double arg3 = " << GetBottom() << ";\n";
     794           0 :     ss << "    double arg4 = " << GetBottom() << ";\n";
     795           0 :     ss << "    double arg5 = " << GetBottom() << ";\n";
     796           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     797             :     {
     798           0 :         FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
     799             :         assert(pCur);
     800           0 :         if (pCur->GetType() == formula::svSingleVectorRef)
     801             :         {
     802             : #ifdef  ISNAN
     803             :             const formula::SingleVectorRefToken* pSVR =
     804           0 :                 static_cast< const formula::SingleVectorRefToken* >(pCur);
     805           0 :             ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
     806             : #endif
     807             :         }
     808           0 :         else if (pCur->GetType() == formula::svDouble)
     809             :         {
     810             : #ifdef  ISNAN
     811           0 :             ss << "    {\n";
     812             : #endif
     813             :         }
     814             : #ifdef  ISNAN
     815           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
     816             :         {
     817           0 :             ss << "        if (isNan(";
     818           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
     819           0 :             ss << "))\n";
     820           0 :             ss << "            arg" << i << " = 0;\n";
     821           0 :             ss << "        else\n";
     822           0 :             ss << "            arg" << i << " = ";
     823           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
     824           0 :             ss << "    }\n";
     825             :         }
     826             :         else
     827             :         {
     828           0 :             ss << "    arg" << i << " = ";
     829           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
     830             :         }
     831             : #else
     832             :         ss << "    arg" << i;
     833             :         ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
     834             : #endif
     835             :     }
     836           0 :     ss << "    int nNullDate = 693594;\n";
     837           0 :     ss << "    tmp = GetDuration_new( nNullDate, (int)arg0, (int)arg1, arg2,";
     838           0 :     ss << " arg3, (int)arg4, (int)arg5);\n";
     839           0 :     ss << "    tmp = tmp * pow(1.0 + arg3 * pow((int)arg4, -1.0), -1);\n";
     840           0 :     ss << "    return tmp;\n";
     841           0 :     ss << "}";
     842           0 : }
     843           0 : void Fvschedule::GenSlidingWindowFunction(
     844             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
     845             : {
     846           0 :     FormulaToken* pCur = vSubArguments[1]->GetFormulaToken();
     847             :     assert(pCur);
     848             :     const formula::DoubleVectorRefToken* pCurDVR =
     849           0 :         static_cast<const formula::DoubleVectorRefToken *>(pCur);
     850           0 :     size_t nCurWindowSize = pCurDVR->GetRefRowSize();
     851           0 :     ss << "\ndouble " << sSymName;
     852           0 :     ss << "_"<< BinFuncName() <<"(";
     853           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     854             :     {
     855           0 :         if (i)
     856           0 :             ss << ",";
     857           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     858             :     }
     859           0 :     ss << ") {\n\t";
     860           0 :     ss << "double tmp = 1.0;\n\t";
     861           0 :     ss << "int gid0 = get_global_id(0);\n\t";
     862           0 :     ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
     863           0 :     ss << ";\n\t";
     864             : #ifdef ISNAN
     865           0 :     ss << "if (isNan(arg0))\n\t\t";
     866           0 :     ss << "arg0 = 0;\n\t";
     867             : #endif
     868           0 :     ss << "double arg1;\n\t";
     869           0 :     ss << "int arrayLength = " << pCurDVR->GetArrayLength() << ";\n\t";
     870             : #ifdef ISNAN
     871           0 :     ss << "for (int i = 0; i + gid0 < arrayLength &&";
     872           0 :     ss << " i < " << nCurWindowSize << "; i++){\n\t\t";
     873             : #else
     874             :     ss << "for (int i = 0; i < " << nCurWindowSize << "; i++){\n\t\t";
     875             : #endif
     876           0 :     ss << "arg1 = ";
     877           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n\t\t\t";
     878             : #ifdef ISNAN
     879           0 :     ss << "if (isNan(arg1))\n\t\t\t\t";
     880           0 :     ss << "arg1 = 0;\n\t\t\t";
     881             : #endif
     882           0 :     ss << "tmp *= arg1 + 1.0;\n\t\t";
     883           0 :     ss << "}\n\t";
     884           0 :     ss << "return (double)tmp * arg0";
     885           0 :     ss << ";\n}";
     886           0 : }
     887           0 : void Cumipmt::BinInlineFun(std::set<std::string>& decls,
     888             :     std::set<std::string>& funs)
     889             : {
     890           0 :     decls.insert(GetRmz_newDecl); decls.insert(GetZw_newDecl);
     891           0 :     funs.insert(GetRmz_new);funs.insert(GetZw_new);
     892           0 : }
     893           0 : void Cumipmt::GenSlidingWindowFunction(
     894             :     std::stringstream &ss, const std::string &sSymName, SubArguments &
     895             : vSubArguments)
     896             : {
     897           0 :     ss << "\ndouble " << sSymName;
     898           0 :     ss << "_"<< BinFuncName() <<"(";
     899           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     900             :     {
     901           0 :         if (i)
     902           0 :             ss << ",";
     903           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     904             :     }
     905           0 :     ss << ") {\n";
     906           0 :     ss << "    int gid0 = get_global_id(0);\n";
     907           0 :     ss << "    double fRate,fVal;\n";
     908           0 :     ss << "    int nStartPer,nEndPer,nNumPeriods,nPayType;\n";
     909             : #ifdef ISNAN
     910           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
     911           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
     912           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
     913           0 :     FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
     914           0 :     FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
     915           0 :     FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
     916             : #endif
     917             : #ifdef ISNAN
     918           0 :     if(tmpCur0->GetType() == formula::svSingleVectorRef)
     919             :     {
     920             :         const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
     921           0 :         formula::SingleVectorRefToken *>(tmpCur0);
     922           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR0->GetArrayLength()<<" || isNan(";
     923           0 :         ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
     924           0 :         ss <<"))\n";
     925           0 :         ss <<"        fRate = 0;\n    else\n";
     926             :     }
     927             : #endif
     928           0 :     ss <<"        fRate = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
     929           0 :     ss <<";\n";
     930             : #ifdef ISNAN
     931           0 :     if(tmpCur1->GetType() == formula::svSingleVectorRef)
     932             :     {
     933             :         const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
     934           0 :         formula::SingleVectorRefToken *>(tmpCur1);
     935           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR1->GetArrayLength()<<" || isNan(";
     936           0 :         ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
     937           0 :         ss <<"))\n";
     938           0 :         ss <<"        nNumPeriods = 0;\n    else\n";
     939             :     }
     940             : #endif
     941           0 :     ss <<"        nNumPeriods = (int)";
     942           0 :     ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
     943           0 :     ss <<";\n";
     944             : #ifdef ISNAN
     945           0 :     if(tmpCur2->GetType() == formula::svSingleVectorRef)
     946             :     {
     947             :         const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
     948           0 :         formula::SingleVectorRefToken *>(tmpCur2);
     949           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR2->GetArrayLength()<<" || isNan(";
     950           0 :         ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
     951           0 :         ss <<"))\n";
     952           0 :         ss <<"        fVal  = 0;\n    else\n";
     953             :     }
     954             : #endif
     955           0 :     ss <<"        fVal = "<<vSubArguments[2]->GenSlidingWindowDeclRef();
     956           0 :     ss <<";\n";
     957             : #ifdef ISNAN
     958           0 :     if(tmpCur3->GetType() == formula::svSingleVectorRef)
     959             :     {
     960             :         const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
     961           0 :         formula::SingleVectorRefToken *>(tmpCur3);
     962           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR3->GetArrayLength()<<" || isNan(";
     963           0 :         ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
     964           0 :         ss <<"))\n";
     965           0 :         ss <<"        nStartPer = 0;\n    else\n";
     966             :     }
     967             : #endif
     968           0 :     ss <<"        nStartPer = (int)";
     969           0 :     ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
     970           0 :     ss <<";\n";
     971             : #ifdef ISNAN
     972           0 :     if(tmpCur4->GetType() == formula::svSingleVectorRef)
     973             :     {
     974             :         const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
     975           0 :         formula::SingleVectorRefToken *>(tmpCur4);
     976           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR4->GetArrayLength()<<" || isNan(";
     977           0 :         ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
     978           0 :         ss <<"))\n";
     979           0 :         ss <<"        nEndPer = 0;\n    else\n";
     980             :     }
     981             : #endif
     982           0 :     ss <<"        nEndPer = (int)";
     983           0 :     ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
     984           0 :     ss <<";\n";
     985             : 
     986             : #ifdef ISNAN
     987           0 :     if(tmpCur5->GetType() == formula::svSingleVectorRef)
     988             :     {
     989             :         const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
     990           0 :         formula::SingleVectorRefToken *>(tmpCur5);
     991           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR5->GetArrayLength()<<" || isNan(";
     992           0 :         ss <<vSubArguments[5]->GenSlidingWindowDeclRef();
     993           0 :         ss <<"))\n";
     994           0 :         ss <<"        nPayType = 0;\n    else\n";
     995             :     }
     996             : #endif
     997           0 :     ss <<"    nPayType = (int)"<<vSubArguments[5]->GenSlidingWindowDeclRef();
     998           0 :     ss <<";\n";
     999           0 :     ss <<"    double fRmz;\n";
    1000           0 :     ss <<"    fRmz = GetRmz_new( fRate, nNumPeriods, fVal, 0.0, nPayType );\n";
    1001           0 :     ss <<"    double tmp = 0.0;\n";
    1002           0 :     ss <<"    if( nStartPer == 1 )\n";
    1003           0 :     ss <<"    {\n";
    1004           0 :     ss <<"        if( nPayType <= 0 )\n";
    1005           0 :     ss <<"            tmp = -fVal;\n";
    1006           0 :     ss <<"        nStartPer++;\n";
    1007           0 :     ss <<"    }\n";
    1008           0 :     ss <<"    for( ; nStartPer<= nEndPer ; nStartPer++ )\n";
    1009           0 :     ss <<"    {\n";
    1010           0 :     ss <<"        if( nPayType > 0 )\n";
    1011           0 :     ss <<"            tmp += GetZw_new( fRate,  nStartPer - 2 , ";
    1012           0 :     ss <<"fRmz, fVal, 1 ) - fRmz;\n";
    1013           0 :     ss <<"        else\n";
    1014           0 :     ss <<"            tmp += GetZw_new( fRate,  nStartPer - 1 , ";
    1015           0 :     ss <<"fRmz, fVal, 0 );\n";
    1016           0 :     ss <<"    }\n";
    1017           0 :     ss <<"    tmp *= fRate;\n";
    1018           0 :     ss <<"    return tmp;\n";
    1019           0 :     ss <<"}";
    1020           0 : }
    1021             : 
    1022           0 : void IRR::GenSlidingWindowFunction(std::stringstream &ss,
    1023             :             const std::string &sSymName, SubArguments &vSubArguments)
    1024             : {
    1025           0 :     ss << "\ndouble " << sSymName;
    1026           0 :     ss << "_" << BinFuncName() << "(";
    1027           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1028             :     {
    1029           0 :         if (i)
    1030           0 :             ss << ",";
    1031           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1032             :     }
    1033           0 :     ss << ") {\n";
    1034           0 :     ss << "    #define  Epsilon   1.0E-7\n";
    1035           0 :     ss << "    int gid0 = get_global_id(0);\n";
    1036           0 :     FormulaToken* pSur = vSubArguments[1]->GetFormulaToken();
    1037             :     assert(pSur);
    1038           0 :     ss << "    double fSchaetzwert = ";
    1039           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
    1040           0 :     ss << "    double fEps = 1.0;\n";
    1041           0 :     ss << "    double x = 0.0, xNeu = 0.0, fZaehler = 0.0, fNenner = 0.0;\n";
    1042           0 :     ss << "    double nCount = 0.0;\n";
    1043           0 :     if (pSur->GetType() == formula::svSingleVectorRef)
    1044             :     {
    1045             : #ifdef  ISNAN
    1046             :         const formula::SingleVectorRefToken* pSVR =
    1047           0 :             static_cast< const formula::SingleVectorRefToken* >(pSur);
    1048           0 :         ss << "    if (gid0 >= " << pSVR->GetArrayLength() << ")\n";
    1049           0 :         ss << "        fSchaetzwert = 0.1;\n";
    1050           0 :         ss << "    if (isNan(fSchaetzwert))\n";
    1051           0 :         ss << "        x = 0.1;\n";
    1052           0 :         ss << "    else\n";
    1053             : #endif
    1054             :     }
    1055           0 :     else if (pSur->GetType() == formula::svDouble)
    1056             :     {
    1057             : #ifdef  ISNAN
    1058           0 :         ss << "    if (isNan(fSchaetzwert))\n";
    1059           0 :         ss << "        x = 0.1;\n";
    1060           0 :         ss << "    else\n";
    1061             : #endif
    1062             :     }
    1063           0 :     ss << "        x = fSchaetzwert;\n";
    1064           0 :     ss << "    unsigned short nItCount = 0;\n";
    1065           0 :     ss << "    while (fEps > Epsilon && nItCount < 20){\n";
    1066           0 :     ss << "        nCount = 0.0; fZaehler = 0.0;  fNenner = 0.0;\n";
    1067           0 :     ss << "        double arg0, arg1;\n";
    1068           0 :     ss << "        int i = 0;\n";
    1069           0 :     FormulaToken* pCur = vSubArguments[0]->GetFormulaToken();
    1070             :     assert(pCur);
    1071             :     const formula::DoubleVectorRefToken* pDVR =
    1072           0 :         static_cast<const formula::DoubleVectorRefToken* >(pCur);
    1073           0 :     size_t nCurWindowSize = pDVR->GetRefRowSize();
    1074           0 :     ss << "        for ( ";
    1075           0 :     if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
    1076             : #ifdef  ISNAN
    1077           0 :         ss << "i = gid0; i < " << pDVR->GetArrayLength();
    1078           0 :         ss << " && i < " << nCurWindowSize << " /2*2; i++){\n";
    1079             : #else
    1080             :         ss << "i = gid0; i < " << nCurWindowSize << " /2*2; i++)\n";
    1081             : #endif
    1082           0 :         ss << "            arg0 = ";
    1083           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    1084           0 :         ss << "            i++;" << ";\n";
    1085           0 :         ss << "            arg1 = ";
    1086           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    1087             : #ifdef  ISNAN
    1088           0 :         ss << "            if (!isNan(arg0)){\n";
    1089             : #endif
    1090           0 :         ss << "            fZaehler += arg0 / pow(1.0 + x, nCount);\n";
    1091           0 :         ss << "            fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
    1092           0 :         ss << "            nCount += 1;\n";
    1093           0 :         ss << "            }\n";
    1094             : #ifdef  ISNAN
    1095           0 :         ss << "            if (!isNan(arg1)){\n";
    1096             : #endif
    1097           0 :         ss << "                fZaehler += arg1 / pow(1.0 + x, nCount);\n";
    1098           0 :         ss << "            fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
    1099           0 :         ss << "                nCount += 1;\n";
    1100           0 :         ss << "            }\n";
    1101             : #ifdef ISNAN
    1102           0 :         ss << "        }\n";
    1103           0 :         ss << "if(i < " << pDVR->GetArrayLength();
    1104           0 :         ss << " && i < " << nCurWindowSize << ") ;{\n";
    1105             : #else
    1106             :         ss << " i < " << nCurWindowSize << "){\n";
    1107             : #endif
    1108             :     }
    1109           0 :     else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
    1110             : #ifdef  ISNAN
    1111           0 :         ss << "; i < " << pDVR->GetArrayLength();
    1112           0 :         ss << " && i < (gid0+" << nCurWindowSize << " )/2*2; i++){\n";
    1113             : #else
    1114             :         ss << "; i < gid0+" << nCurWindowSize << " /2*2; i++)\n";
    1115             : #endif
    1116           0 :         ss << "            arg0 = ";
    1117           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    1118             : #ifdef  ISNAN
    1119           0 :         ss << "            if (!isNan(arg0)){\n";
    1120             : #endif
    1121           0 :         ss << "            fZaehler += arg0 / pow(1.0 + x, nCount);\n";
    1122           0 :         ss << "            fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
    1123           0 :         ss << "            nCount += 1;\n";
    1124             : #ifdef  ISNAN
    1125           0 :         ss << "            }\n";
    1126             : #endif
    1127           0 :         ss << "            i++;\n";
    1128           0 :         ss << "            arg1 = ";
    1129           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    1130             : #ifdef  ISNAN
    1131           0 :         ss << "            if (!isNan(arg1)){\n";
    1132             : #endif
    1133           0 :         ss << "                fZaehler += arg1 / pow(1.0 + x, nCount);\n";
    1134           0 :         ss << "            fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
    1135           0 :         ss << "                nCount+=1;\n";
    1136           0 :         ss << "            }\n";
    1137             : #ifdef ISNAN
    1138           0 :         ss << "        }\n";
    1139           0 :         ss << "        if(i < " << pDVR->GetArrayLength();
    1140           0 :         ss << " && i < gid0+" << nCurWindowSize << "){\n";
    1141             : #else
    1142             :         ss << " i < " << nCurWindowSize << "){\n";
    1143             : #endif
    1144             :     }
    1145           0 :     else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
    1146             : #ifdef  ISNAN
    1147           0 :         ss << " ; i + gid0 < " << pDVR->GetArrayLength();
    1148           0 :         ss << " &&  i < " << nCurWindowSize << " /2*2; i++){\n";
    1149             : #else
    1150             :         ss << "; i < " << nCurWindowSize << " /2*2; i++)\n";
    1151             : #endif
    1152           0 :         ss << "            arg0 = ";
    1153           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    1154           0 :         ss << "            i++;" << ";\n";
    1155           0 :         ss << "            arg1 = ";
    1156           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    1157             : #ifdef  ISNAN
    1158           0 :         ss << "            if (!isNan(arg0)){\n";
    1159             : #endif
    1160           0 :         ss << "            fZaehler += arg0 / pow(1.0 + x, nCount);\n";
    1161           0 :         ss << "            fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
    1162           0 :         ss << "            nCount += 1;\n";
    1163           0 :         ss << "            }\n";
    1164             : #ifdef  ISNAN
    1165           0 :         ss << "            if (!isNan(arg1)){\n";
    1166             : #endif
    1167           0 :         ss << "                fZaehler += arg1 / pow(1.0 + x, nCount);\n";
    1168           0 :         ss << "            fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
    1169           0 :         ss << "                nCount+=1;\n";
    1170           0 :         ss << "            }\n";
    1171             : #ifdef ISNAN
    1172           0 :         ss << "        }\n";
    1173           0 :         ss << "        if(i + gid0 < " << pDVR->GetArrayLength() << " &&";
    1174           0 :         ss << " i < " << nCurWindowSize << "){\n";
    1175             : #else
    1176             :         ss << " i < " << nCurWindowSize << "){\n";
    1177             : #endif
    1178             : 
    1179             :     } else {
    1180             : #ifdef  ISNAN
    1181           0 :         ss << "; i < " << nCurWindowSize << " /2*2; i++){\n";
    1182             : #else
    1183             :         ss << "; i < " << nCurWindowSize << " /2*2; i++)\n";
    1184             : #endif
    1185           0 :         ss << "            arg0 = ";
    1186           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    1187           0 :         ss << "            i++;" << ";\n";
    1188           0 :         ss << "            arg1 = ";
    1189           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    1190             : #ifdef  ISNAN
    1191           0 :         ss << "            if (!isNan(arg0)){\n";
    1192             : #endif
    1193           0 :         ss << "            fZaehler += arg0 / pow(1.0 + x, nCount);\n";
    1194           0 :         ss << "            fNenner+=-1*nCount*arg0/pow(1.0+x,nCount+1.0);\n";
    1195           0 :         ss << "            nCount += 1;\n";
    1196           0 :         ss << "            }\n";
    1197             : #ifdef  ISNAN
    1198           0 :         ss << "            if (!isNan(arg1)){\n";
    1199             : #endif
    1200           0 :         ss << "                fZaehler += arg1 / pow(1.0 + x, nCount);\n";
    1201           0 :         ss << "            fNenner+=-1*nCount*arg1/pow(1.0+x,nCount+1.0);\n";
    1202           0 :         ss << "                nCount+=1;\n";
    1203           0 :         ss << "            }\n";
    1204             : #ifdef ISNAN
    1205           0 :         ss << "        }\n";
    1206           0 :         ss << "if(i<" << nCurWindowSize << "){\n";
    1207             : #else
    1208             :         ss << " i < " << nCurWindowSize << "){\n";
    1209             : #endif
    1210             : 
    1211             :     }
    1212           0 :     ss << "            arg0 = ";
    1213           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    1214             : #ifdef  ISNAN
    1215           0 :     ss << "        if (isNan(arg0))\n";
    1216           0 :     ss << "            continue;\n";
    1217             : #endif
    1218           0 :     ss << "        fZaehler += arg0 / pow(1.0+x, nCount);\n";
    1219           0 :     ss << "        fNenner  += -nCount * arg0 / pow(1.0+x,nCount+1.0);\n";
    1220           0 :     ss << "        nCount+=1;\n";
    1221           0 :     ss << "        }\n";
    1222           0 :     ss << "        xNeu = x - fZaehler / fNenner;\n";
    1223           0 :     ss << "        fEps = fabs(xNeu - x);\n";
    1224           0 :     ss << "        x = xNeu;\n";
    1225           0 :     ss << "        nItCount++;\n    }\n";
    1226           0 :     ss << "        if (fSchaetzwert == 0.0 && fabs(x) < Epsilon)\n";
    1227           0 :     ss << "            x = 0.0;\n";
    1228           0 :     ss << "        if (fEps < Epsilon)\n";
    1229           0 :     ss << "            return x;\n";
    1230           0 :     ss << "        else\n";
    1231           0 :     ss << "            return (double)523;\n";
    1232           0 :     ss << "}";
    1233           0 : }
    1234             : 
    1235           0 : void XNPV::GenSlidingWindowFunction(
    1236             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
    1237             : {
    1238           0 :     FormulaToken *pCur = vSubArguments[1]->GetFormulaToken();
    1239             :     assert(pCur);
    1240             :     const formula::DoubleVectorRefToken* pCurDVR =
    1241           0 :         static_cast<const formula::DoubleVectorRefToken *>(pCur);
    1242           0 :     size_t nCurWindowSize = pCurDVR->GetRefRowSize();
    1243           0 :     ss << "\ndouble " << sSymName;
    1244           0 :     ss << "_"<< BinFuncName() <<"( ";
    1245           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1246             :     {
    1247           0 :         if (i)
    1248           0 :             ss << ",";
    1249           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1250             :     }
    1251             : 
    1252           0 :     ss << ") {\n\t";
    1253           0 :     ss << "double result = 0.0;\n\t";
    1254           0 :     ss << "int gid0 = get_global_id(0);\n\t";
    1255           0 :     ss << "int i=0;\n\t";
    1256           0 :     if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
    1257           0 :         ss<< "i=gid0;\n\t";
    1258             :     }
    1259           0 :     ss << "double date;\n\t";
    1260           0 :     ss << "double value;\n\t";
    1261           0 :     ss << "double rate;\n\t";
    1262           0 :     ss << "double dateNull;\n\t";
    1263             : #ifdef ISNAN
    1264           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    1265             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    1266           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    1267             : 
    1268           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    1269             :     const formula::DoubleVectorRefToken*tmpCurDVR1= static_cast<const
    1270           0 :     formula::DoubleVectorRefToken *>(tmpCur1);
    1271             : 
    1272           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
    1273             :     const formula::DoubleVectorRefToken*tmpCurDVR2= static_cast<const
    1274           0 :     formula::DoubleVectorRefToken *>(tmpCur2);
    1275           0 :     ss<< "int buffer_rate_len = ";
    1276           0 :     ss<< tmpCurDVR0->GetArrayLength();
    1277           0 :     ss << ";\n\t";
    1278           0 :     ss<< "int buffer_value_len = ";
    1279           0 :     ss<< tmpCurDVR1->GetArrayLength();
    1280           0 :     ss << ";\n\t";
    1281           0 :     ss<< "int buffer_date_len = ";
    1282           0 :     ss<< tmpCurDVR2->GetArrayLength();
    1283           0 :     ss << ";\n\t";
    1284             : #endif
    1285             : #ifdef ISNAN
    1286           0 :     ss<<"if((i+gid0)>=buffer_date_len || isNan(";
    1287           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    1288           0 :     ss<<"))\n\t\t";
    1289           0 :     ss<<"dateNull = 0;\n\telse \n\t\t";
    1290             : #endif
    1291           0 :     ss<<"dateNull = ";
    1292           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    1293           0 :     ss<<";\n\t";
    1294             : #ifdef ISNAN
    1295           0 :     ss<<"if((i+gid0)>=buffer_rate_len || isNan(";
    1296           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1297           0 :     ss<<"))\n\t\t";
    1298           0 :     ss<<"rate = 0;\n\telse \n\t\t";
    1299             : #endif
    1300           0 :     ss<<"rate = ";
    1301           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1302           0 :     ss<<";\n\t";
    1303           0 :     ss << "for (int i = ";
    1304           0 :     if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed())
    1305             :     {
    1306           0 :         ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n\t\t";
    1307             :     }
    1308           0 :     else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
    1309             :     {
    1310           0 :         ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n\t\t";
    1311             :     }
    1312             :     else
    1313             :     {
    1314           0 :         ss << "0; i < "<< nCurWindowSize <<"; i++)\n\t\t";
    1315             :     }
    1316           0 :     ss << "{\n\t";
    1317           0 :     ss << "result += ";
    1318           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    1319           0 :     ss << "/(pow((";
    1320           0 :     ss<<vSubArguments[0]->GenSlidingWindowDeclRef();
    1321           0 :     ss <<"+1),(";
    1322           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    1323           0 :     ss << "-dateNull)/365));\n\t";
    1324           0 :     ss <<"}\n\t";
    1325             : 
    1326           0 :     ss << "return result;\n";
    1327           0 :     ss << "}";
    1328           0 : }
    1329             : 
    1330           0 :  void PriceMat::BinInlineFun(std::set<std::string>& decls,
    1331             :     std::set<std::string>& funs)
    1332             : {
    1333           0 :     decls.insert(GetYearFracDecl);decls.insert(GetNullDateDecl);
    1334           0 :     decls.insert(DateToDaysDecl);decls.insert(DaysToDateDecl);
    1335           0 :     decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
    1336             : 
    1337           0 :     funs.insert(GetYearFrac);funs.insert(GetNullDate);
    1338           0 :     funs.insert(DateToDays);funs.insert(DaysToDate);
    1339           0 :     funs.insert(DaysInMonth);funs.insert(IsLeapYear);
    1340           0 : }
    1341           0 : void PriceMat::GenSlidingWindowFunction(
    1342             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
    1343             : {
    1344           0 :     ss << "\ndouble " << sSymName;
    1345           0 :     ss << "_"<< BinFuncName() <<"(";
    1346           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1347             :     {
    1348           0 :         if (i)
    1349           0 :             ss << ",";
    1350           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1351             :     }
    1352           0 :     ss << ") {\n\t";
    1353           0 :     ss << "int gid0 = get_global_id(0);\n\t";
    1354           0 :     ss << "double result=0;\n\t";
    1355           0 :     ss<< "int nNullDate = GetNullDate( );\n\t";
    1356           0 :     ss <<"int settle;\n\t";
    1357           0 :     ss <<"int mat;\n\t";
    1358           0 :     ss <<"int issue;\n\t";
    1359           0 :     ss <<"double rate;\n\t";
    1360           0 :     ss <<"double yield;\n\t";
    1361           0 :     ss <<"int  nBase;\n\t";
    1362             : #ifdef ISNAN
    1363           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    1364             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    1365           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    1366           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    1367             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    1368           0 :     formula::SingleVectorRefToken *>(tmpCur1);
    1369           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
    1370             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    1371           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    1372           0 :     FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
    1373             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    1374           0 :     formula::SingleVectorRefToken *>(tmpCur3);
    1375           0 :     FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
    1376             :     const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
    1377           0 :     formula::SingleVectorRefToken *>(tmpCur4);
    1378           0 :     FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
    1379             :     const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
    1380           0 :     formula::SingleVectorRefToken *>(tmpCur5);
    1381             : 
    1382           0 :     ss<< "int buffer_settle_len = ";
    1383           0 :     ss<< tmpCurDVR0->GetArrayLength();
    1384           0 :     ss << ";\n\t";
    1385           0 :      ss<< "int buffer_mat_len = ";
    1386           0 :     ss<< tmpCurDVR1->GetArrayLength();
    1387           0 :     ss << ";\n\t";
    1388           0 :     ss<< "int buffer_issue_len = ";
    1389           0 :     ss<< tmpCurDVR2->GetArrayLength();
    1390           0 :     ss << ";\n\t";
    1391           0 :     ss<< "int buffer_rate_len = ";
    1392           0 :     ss<< tmpCurDVR3->GetArrayLength();
    1393           0 :     ss << ";\n\t";
    1394           0 :     ss<< "int buffer_yield_len = ";
    1395           0 :     ss<< tmpCurDVR4->GetArrayLength();
    1396           0 :     ss << ";\n\t";
    1397           0 :     ss<< "int buffer_base_len = ";
    1398           0 :     ss<< tmpCurDVR5->GetArrayLength();
    1399           0 :     ss << ";\n\t";
    1400             : #endif
    1401             : #ifdef ISNAN
    1402           0 :     ss<<"if(gid0>=buffer_settle_len || isNan(";
    1403           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1404           0 :     ss<<"))\n\t\t";
    1405           0 :     ss<<"settle = 0;\n\telse \n\t\t";
    1406             : #endif
    1407           0 :     ss<<"settle = ";
    1408           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1409           0 :     ss<<";\n\t";
    1410             : #ifdef ISNAN
    1411           0 :     ss<<"if(gid0>=buffer_mat_len || isNan(";
    1412           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    1413           0 :     ss<<"))\n\t\t";
    1414           0 :     ss<<"mat = 0;\n\telse \n\t\t";
    1415             : #endif
    1416           0 :     ss<<"mat = ";
    1417           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    1418           0 :     ss<<";\n\t";
    1419             : #ifdef ISNAN
    1420           0 :     ss<<"if(gid0>=buffer_issue_len || isNan(";
    1421           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    1422           0 :     ss<<"))\n\t\t";
    1423           0 :     ss<<"issue = 0;\n\telse \n\t\t";
    1424             : #endif
    1425           0 :     ss<<"issue = ";
    1426           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    1427           0 :     ss<<";\n\t";
    1428             : #ifdef ISNAN
    1429           0 :     ss<<"if(gid0>=buffer_rate_len || isNan(";
    1430           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    1431           0 :     ss<<"))\n\t\t";
    1432           0 :     ss<<"rate = 0;\n\telse \n\t\t";
    1433             : #endif
    1434           0 :     ss<<"rate = ";
    1435           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    1436           0 :     ss<<";\n\t";
    1437             : #ifdef ISNAN
    1438           0 :     ss<<"if(gid0>=buffer_yield_len || isNan(";
    1439           0 :     ss << vSubArguments[4]->GenSlidingWindowDeclRef();
    1440           0 :     ss<<"))\n\t\t";
    1441           0 :     ss<<"yield = 0;\n\telse \n\t\t";
    1442             : #endif
    1443           0 :     ss<<"yield = ";
    1444           0 :     ss << vSubArguments[4]->GenSlidingWindowDeclRef();
    1445           0 :     ss<<";\n\t";
    1446             : #ifdef ISNAN
    1447           0 :     ss<<"if(gid0>=buffer_base_len || isNan(";
    1448           0 :     ss << vSubArguments[5]->GenSlidingWindowDeclRef();
    1449           0 :     ss<<"))\n\t\t";
    1450           0 :     ss<<"nBase = 0;\n\telse \n\t\t";
    1451             : #endif
    1452           0 :     ss<<"nBase = ";
    1453           0 :     ss << vSubArguments[5]->GenSlidingWindowDeclRef();
    1454           0 :     ss<<";\n\t";
    1455           0 :     ss<< "double fIssMat = GetYearFrac( nNullDate, issue, mat, nBase);\n";
    1456           0 :     ss<<"double fIssSet = GetYearFrac( nNullDate, issue, settle,nBase);\n";
    1457           0 :     ss<<"double fSetMat = GetYearFrac( nNullDate, settle, mat, nBase);\n";
    1458           0 :     ss<<"result = 1.0 + fIssMat * rate;\n\t";
    1459           0 :     ss<<"result /= 1.0 + fSetMat * yield;\n\t";
    1460           0 :     ss<<"result -= fIssSet * rate;\n\t";
    1461           0 :     ss<<"result*= 100.0;\n\t";
    1462           0 :     ss<<"return result;\n\t";
    1463           0 :     ss<<"}\n";
    1464           0 : }
    1465             : 
    1466           0 : void OpSYD::GenSlidingWindowFunction(std::stringstream &ss,
    1467             :             const std::string &sSymName, SubArguments &vSubArguments)
    1468             : {
    1469           0 :     ss << "\ndouble " << sSymName;
    1470           0 :     ss << "_"<< BinFuncName() <<"(";
    1471           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1472             :     {
    1473           0 :         if (i)
    1474           0 :             ss << ",";
    1475           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1476             :     }
    1477           0 :     ss << ") {\n";
    1478           0 :     ss << "    int gid0 = get_global_id(0);\n";
    1479           0 :     ss << "    double result=0;\n";
    1480           0 :     ss << "    double cost;\n";
    1481           0 :     ss << "    double salvage;\n";
    1482           0 :     ss << "    double life;\n";
    1483           0 :     ss << "    double period;\n";
    1484             : #ifdef ISNAN
    1485           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    1486             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    1487           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    1488             : 
    1489           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    1490             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    1491           0 :     formula::SingleVectorRefToken *>(tmpCur1);
    1492             : 
    1493           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
    1494             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    1495           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    1496             : 
    1497           0 :     FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
    1498             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    1499           0 :         formula::SingleVectorRefToken *>(tmpCur3);
    1500             : 
    1501           0 :     ss << "    int buffer_cost_len = ";
    1502           0 :     ss << tmpCurDVR0->GetArrayLength();
    1503           0 :     ss << ";\n";
    1504             : 
    1505           0 :     ss << "    int buffer_salvage_len = ";
    1506           0 :     ss << tmpCurDVR1->GetArrayLength();
    1507           0 :     ss << ";\n";
    1508             : 
    1509           0 :     ss << "    int buffer_life_len = ";
    1510           0 :     ss << tmpCurDVR2->GetArrayLength();
    1511           0 :     ss << ";\n";
    1512           0 :     ss << "    int buffer_period_len = ";
    1513           0 :     ss << tmpCurDVR3->GetArrayLength();
    1514           0 :     ss << ";\n";
    1515             : #endif
    1516             : 
    1517             : #ifdef ISNAN
    1518           0 :     ss <<"    if(gid0>=buffer_cost_len || isNan(";
    1519           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1520           0 :     ss <<"))\n";
    1521           0 :     ss <<"        cost = 0;\n\telse \n";
    1522             : #endif
    1523           0 :     ss <<"        cost = ";
    1524           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1525           0 :     ss <<";\n";
    1526             : #ifdef ISNAN
    1527           0 :     ss <<"    if(gid0>=buffer_salvage_len || isNan(";
    1528           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    1529           0 :     ss <<"))\n";
    1530           0 :     ss <<"        salvage = 0;\n\telse \n";
    1531             : #endif
    1532           0 :     ss <<"        salvage = ";
    1533           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    1534           0 :     ss <<";\n";
    1535             : #ifdef ISNAN
    1536           0 :     ss <<"    if(gid0>=buffer_life_len || isNan(";
    1537           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    1538           0 :     ss <<"))\n";
    1539           0 :     ss <<"        life = 0;\n\telse \n";
    1540             : #endif
    1541           0 :     ss <<"        life = ";
    1542           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    1543           0 :     ss <<";\n";
    1544             : #ifdef ISNAN
    1545           0 :     ss <<"    if(gid0>=buffer_period_len || isNan(";
    1546           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    1547           0 :     ss <<"))\n";
    1548           0 :     ss <<"        period = 0;\n\telse \n";
    1549             : #endif
    1550           0 :     ss <<"        period = ";
    1551           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    1552           0 :     ss <<";\n";
    1553           0 :     ss <<"    double tmpvalue = ((life*(life+1))*pow(2.0,-1));\n";
    1554           0 :     ss <<"    result = ((cost-salvage)*(life-period+1)";
    1555           0 :     ss << "*pow(tmpvalue,-1));\n";
    1556           0 :     ss <<"    return result;\n";
    1557           0 :     ss <<"}\n";
    1558           0 : }
    1559             : 
    1560           0 : void MIRR::GenSlidingWindowFunction(
    1561             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
    1562             : {
    1563           0 :     FormulaToken* pCur = vSubArguments[0]->GetFormulaToken();
    1564             :     assert(pCur);
    1565             :     const formula::DoubleVectorRefToken* pCurDVR =
    1566           0 :     static_cast<const formula::DoubleVectorRefToken *>(pCur);
    1567           0 :     size_t nCurWindowSize = pCurDVR->GetRefRowSize();
    1568           0 :     FormulaToken* pCur1 = vSubArguments[1]->GetFormulaToken();
    1569             :     assert(pCur1);
    1570             :     const formula::SingleVectorRefToken* pSVR1 =
    1571           0 :         static_cast< const formula::SingleVectorRefToken* >(pCur1);
    1572             :     assert(pSVR1);
    1573           0 :     FormulaToken* pCur2 = vSubArguments[2]->GetFormulaToken();
    1574             :     assert(pCur2);
    1575             :     const formula::SingleVectorRefToken* pSVR2 =
    1576           0 :         static_cast< const formula::SingleVectorRefToken* >(pCur2);
    1577             :     assert(pSVR2);
    1578             : 
    1579           0 :     ss << "\ndouble " << sSymName;
    1580           0 :     ss << "_"<< BinFuncName() <<"(";
    1581           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1582             :     {
    1583           0 :         if (i)
    1584           0 :             ss << ",";
    1585           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1586             :     }
    1587           0 :     ss << ") {\n\t";
    1588           0 :     ss << "double tmp = " << GetBottom() <<";\n\t";
    1589           0 :     ss << "int gid0 = get_global_id(0);\n\t";
    1590           0 :     ss << "double arg0, arg1, arg2;\n\t";
    1591           0 :     ss << "arg1 = " << vSubArguments[1]->GenSlidingWindowDeclRef();
    1592           0 :     ss << ";\n\t";
    1593           0 :     ss << "arg2 = " << vSubArguments[2]->GenSlidingWindowDeclRef();
    1594           0 :     ss << ";\n\t";
    1595           0 :     ss << "int argLen1 = " << pSVR1->GetArrayLength() << ";\n\t";
    1596           0 :     ss << "int argLen2 = " << pSVR2->GetArrayLength() << ";\n\t";
    1597             : #ifdef  ISNAN
    1598           0 :     ss << "if (gid0 >= argLen1)\n\t\t";
    1599           0 :     ss << "arg1 = 0.0;\n\t";
    1600           0 :     ss << "if (gid0 >= argLen2)\n\t\t";
    1601           0 :     ss << "arg2 = 0.0;\n\t";
    1602           0 :     ss << "if (isNan(arg1))\n\t\t";
    1603           0 :     ss << "arg1 = 0.0;\n\t";
    1604           0 :     ss << "if (isNan(arg2))\n\t\t";
    1605           0 :     ss << "arg2 = 0.0;\n\t";
    1606             : #endif
    1607           0 :     ss << "double invest = arg1 + 1.0;\n\t";
    1608           0 :     ss << "double reinvest = arg2 + 1.0;\n\t";
    1609           0 :     ss << "double NPV_invest = 0.0;\n\t";
    1610           0 :     ss << "double Pow_invest = 1.0;\n\t";
    1611           0 :     ss << "double NPV_reinvest = 0.0;\n\t";
    1612           0 :     ss << "double Pow_reinvest = 1.0;\n\t";
    1613           0 :     ss << "int nCount = 0;\n\t";
    1614           0 :     ss << "int arrayLength = " << pCurDVR->GetArrayLength() << ";\n\t";
    1615             : #ifdef  ISNAN
    1616           0 :     ss << "for (int i = 0; i + gid0 < arrayLength &&";
    1617           0 :     ss << " i < " << nCurWindowSize << "; i++){\n\t\t";
    1618             : #else
    1619             :     ss << "for (int i = 0; i < " << nCurWindowSize << "; i++){\n\t\t";
    1620             : #endif
    1621           0 :     ss << "arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
    1622           0 :     ss << ";\n\t\t";
    1623             : #ifdef ISNAN
    1624           0 :     ss << "if (isNan(arg0))\n\t\t\t";
    1625           0 :     ss << "continue;\n\t\t";
    1626             : #endif
    1627           0 :     ss << "if (arg0 > 0.0)\n\t\t\t";
    1628           0 :     ss << "NPV_reinvest += arg0 * Pow_reinvest;\n\t\t";
    1629           0 :     ss << "else if (arg0 < 0.0)\n\t\t\t";
    1630           0 :     ss << "NPV_invest += arg0 * Pow_invest;\n\t\t";
    1631           0 :     ss << "Pow_reinvest /= reinvest;\n\t\t";
    1632           0 :     ss << "Pow_invest /= invest;\n\t\t";
    1633           0 :     ss << "nCount++;\n\t";
    1634           0 :     ss << "}\n\t";
    1635           0 :     ss << "tmp = ";
    1636           0 :     ss << "-NPV_reinvest /NPV_invest * pow(reinvest,(double)nCount-1);\n\t";
    1637           0 :     ss << "tmp =  pow(tmp, 1.0 / (nCount - 1)) - 1.0;\n\t";
    1638           0 :     ss << "return (double)tmp;\n";
    1639           0 :     ss << "}";
    1640           0 : }
    1641             : 
    1642           0 : void OpEffective::GenSlidingWindowFunction(std::stringstream& ss,
    1643             :     const std::string &sSymName, SubArguments& vSubArguments)
    1644             : {
    1645           0 :     ss << "\ndouble " << sSymName;
    1646           0 :     ss << "_" << BinFuncName() << "(";
    1647           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1648             :     {
    1649           0 :         if (i)
    1650           0 :             ss << ",";
    1651           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1652             :     }
    1653           0 :     ss << ") {\n";
    1654           0 :     ss << "    double tmp = " << GetBottom() <<";\n";
    1655           0 :     ss << "    int gid0 = get_global_id(0);\n\t";
    1656           0 :     ss << "    double arg0 = " << GetBottom() << ";\n";
    1657           0 :     ss << "    double arg1 = " << GetBottom() << ";\n";
    1658           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1659             :     {
    1660           0 :         FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
    1661             :         assert(pCur);
    1662           0 :         if (pCur->GetType() == formula::svSingleVectorRef)
    1663             :         {
    1664             : #ifdef  ISNAN
    1665             :             const formula::SingleVectorRefToken* pSVR =
    1666           0 :                 static_cast< const formula::SingleVectorRefToken* >(pCur);
    1667           0 :             ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
    1668             : #endif
    1669             :         }
    1670           0 :         else if (pCur->GetType() == formula::svDouble)
    1671             :         {
    1672             : #ifdef  ISNAN
    1673           0 :             ss << "    {\n";
    1674             : #endif
    1675             :         }
    1676             : #ifdef  ISNAN
    1677           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
    1678             :         {
    1679           0 :             ss << "        if (isNan(";
    1680           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    1681           0 :             ss << "))\n";
    1682           0 :             ss << "            arg" << i << " = 0;\n";
    1683           0 :             ss << "        else\n";
    1684           0 :             ss << "            arg" << i << " = ";
    1685           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
    1686           0 :             ss << "    }\n";
    1687             :         }
    1688             :         else
    1689             :         {
    1690           0 :             ss << "    arg" << i << " = ";
    1691           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
    1692             :         }
    1693             : #else
    1694             :         ss << "    arg" << i;
    1695             :         ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
    1696             : #endif
    1697             :     }
    1698           0 :     ss << "    tmp = pow(1.0 + arg0 * pow(arg1, -1), arg1)-1.0;\n";
    1699           0 :     ss << "    return tmp;\n";
    1700           0 :     ss << "}";
    1701           0 : }
    1702             : 
    1703           0 :  void OpTbilleq::BinInlineFun(std::set<std::string>& decls,
    1704             :     std::set<std::string>& funs)
    1705             : {
    1706           0 :     decls.insert(GetDiffDate360_Decl);decls.insert(GetDiffDate360Decl);
    1707           0 :     decls.insert(DateToDaysDecl);decls.insert(DaysToDate_LocalBarrierDecl);
    1708           0 :     decls.insert(DaysInMonthDecl);decls.insert(GetNullDateDecl);
    1709           0 :     decls.insert(IsLeapYearDecl);
    1710           0 :     funs.insert(GetDiffDate360_);funs.insert(GetDiffDate360);
    1711           0 :     funs.insert(DateToDays);funs.insert(DaysToDate_LocalBarrier);
    1712           0 :     funs.insert(DaysInMonth);funs.insert(GetNullDate);
    1713           0 :     funs.insert(IsLeapYear);
    1714           0 : }
    1715           0 : void OpTbilleq::GenSlidingWindowFunction(
    1716             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
    1717             : {
    1718           0 :     ss << "\ndouble " << sSymName;
    1719           0 :     ss << "_"<< BinFuncName() <<"(";
    1720           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1721             :     {
    1722           0 :         if (i)
    1723           0 :             ss << ",";
    1724           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1725             :     }
    1726           0 :     ss << ") {\n\t";
    1727           0 :     ss << "   int gid0 = get_global_id(0);\n";
    1728           0 :     ss << "double tmp = 0;\n\t";
    1729           0 :     ss << "double tmp000;\n\t";
    1730           0 :     ss << "double tmp001;\n\t";
    1731           0 :     ss << "double tmp002;\n\t";
    1732             : 
    1733             : #ifdef ISNAN
    1734           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    1735             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    1736           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    1737             : 
    1738           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    1739             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    1740           0 :     formula::SingleVectorRefToken *>(tmpCur1);
    1741             : 
    1742           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
    1743             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    1744           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    1745             : 
    1746           0 :     ss<< "int buffer_tmp000_len = ";
    1747           0 :     ss<< tmpCurDVR0->GetArrayLength();
    1748           0 :     ss << ";\n\t";
    1749             : 
    1750           0 :     ss<< "int buffer_tmp001_len = ";
    1751           0 :     ss<< tmpCurDVR1->GetArrayLength();
    1752           0 :     ss << ";\n\t";
    1753             : 
    1754           0 :     ss<< "int buffer_tmp002_len = ";
    1755           0 :     ss<< tmpCurDVR2->GetArrayLength();
    1756           0 :     ss << ";\n\t";
    1757             : #endif
    1758             : 
    1759             : #ifdef ISNAN
    1760           0 :     ss<<"if(gid0>=buffer_tmp000_len || isNan(";
    1761           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1762           0 :     ss<<"))\n\t\t";
    1763           0 :     ss<<"tmp000 = 0;\n\telse \n\t\t";
    1764             : #endif
    1765           0 :     ss<<"tmp000 = ";
    1766           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1767           0 :     ss<<";\n\t";
    1768             : 
    1769             : #ifdef ISNAN
    1770           0 :     ss<<"if(gid0>=buffer_tmp001_len || isNan(";
    1771           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    1772           0 :     ss<<"))\n\t\t";
    1773           0 :     ss<<"tmp001 = 0;\n\telse \n\t\t";
    1774             : #endif
    1775           0 :     ss<<"tmp001 = ";
    1776           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    1777           0 :     ss<<";\n\t";
    1778             : 
    1779             : #ifdef ISNAN
    1780           0 :     ss<<"if(gid0>=buffer_tmp002_len || isNan(";
    1781           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    1782           0 :     ss<<"))\n\t\t";
    1783           0 :     ss<<"tmp002 = 0;\n\telse \n\t\t";
    1784             : #endif
    1785           0 :     ss<<"tmp002 = ";
    1786           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    1787           0 :     ss<<";\n\t";
    1788             : 
    1789           0 :     ss<<"tmp001+=1.0;\n";
    1790           0 :     ss<<"int   nDiff =GetDiffDate360(GetNullDate(),tmp000,tmp001,true);\n";
    1791           0 :     ss<<"tmp =( 365 * tmp002 ) / ( 360 - ( tmp002 * ( nDiff ) ) );\n";
    1792           0 :     ss << "return tmp;\n";
    1793           0 :     ss << "}";
    1794           0 : }
    1795           0 : void OpCumprinc::BinInlineFun(std::set<std::string>& decls,
    1796             :     std::set<std::string>& funs)
    1797             : {
    1798           0 :     decls.insert(GetRmz_newDecl); decls.insert(GetZw_newDecl);
    1799           0 :     funs.insert(GetRmz_new);funs.insert(GetZw_new);
    1800           0 : }
    1801           0 : void OpCumprinc::GenSlidingWindowFunction(std::stringstream &ss,
    1802             :             const std::string &sSymName, SubArguments &vSubArguments)
    1803             : {
    1804           0 :     ss << "\ndouble " << sSymName;
    1805           0 :     ss << "_"<< BinFuncName() <<"(";
    1806           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1807             :     {
    1808           0 :         if (i)
    1809           0 :             ss << ",";
    1810           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1811             :     }
    1812           0 :     ss << ") {\n";
    1813           0 :     ss << "    double tmp = " << GetBottom() <<";\n";
    1814           0 :     ss << "    int gid0 = get_global_id(0);\n";
    1815           0 :     ss << "    double fRate,fVal;\n";
    1816           0 :     ss << "    int nStartPer,nEndPer,nNumPeriods,nPayType;\n";
    1817             : #ifdef ISNAN
    1818           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    1819           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    1820           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
    1821           0 :     FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
    1822           0 :     FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
    1823           0 :     FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
    1824             : #endif
    1825             : #ifdef ISNAN
    1826           0 :     if(tmpCur0->GetType() == formula::svSingleVectorRef)
    1827             :     {
    1828             :         const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    1829           0 :         formula::SingleVectorRefToken *>(tmpCur0);
    1830           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR0->GetArrayLength()<<" || isNan(";
    1831           0 :         ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
    1832           0 :         ss <<"))\n";
    1833           0 :         ss <<"        fRate = 0;\n    else\n";
    1834             :     }
    1835             : #endif
    1836           0 :     ss <<"        fRate = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
    1837           0 :     ss <<";\n";
    1838             : #ifdef ISNAN
    1839           0 :     if(tmpCur1->GetType() == formula::svSingleVectorRef)
    1840             :     {
    1841             :         const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    1842           0 :         formula::SingleVectorRefToken *>(tmpCur1);
    1843           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR1->GetArrayLength()<<" || isNan(";
    1844           0 :         ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
    1845           0 :         ss <<"))\n";
    1846           0 :         ss <<"        nNumPeriods = 0;\n    else\n";
    1847             :     }
    1848             : #endif
    1849           0 :     ss <<"        nNumPeriods = (int)";
    1850           0 :     ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
    1851           0 :     ss <<";\n";
    1852             : #ifdef ISNAN
    1853           0 :     if(tmpCur2->GetType() == formula::svSingleVectorRef)
    1854             :     {
    1855             :         const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    1856           0 :         formula::SingleVectorRefToken *>(tmpCur2);
    1857           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR2->GetArrayLength()<<" || isNan(";
    1858           0 :         ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
    1859           0 :         ss <<"))\n";
    1860           0 :         ss <<"        fVal  = 0;\n    else\n";
    1861             :     }
    1862             : #endif
    1863           0 :     ss <<"        fVal = "<<vSubArguments[2]->GenSlidingWindowDeclRef();
    1864           0 :     ss <<";\n";
    1865             : #ifdef ISNAN
    1866           0 :     if(tmpCur3->GetType() == formula::svSingleVectorRef)
    1867             :     {
    1868             :         const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    1869           0 :         formula::SingleVectorRefToken *>(tmpCur3);
    1870           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR3->GetArrayLength()<<" || isNan(";
    1871           0 :         ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
    1872           0 :         ss <<"))\n";
    1873           0 :         ss <<"        nStartPer = 0;\n    else\n";
    1874             :     }
    1875             : #endif
    1876           0 :     ss <<"        nStartPer = (int)";
    1877           0 :     ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
    1878           0 :     ss <<";\n";
    1879             : #ifdef ISNAN
    1880           0 :     if(tmpCur4->GetType() == formula::svSingleVectorRef)
    1881             :     {
    1882             :         const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
    1883           0 :         formula::SingleVectorRefToken *>(tmpCur4);
    1884           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR4->GetArrayLength()<<" || isNan(";
    1885           0 :         ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
    1886           0 :         ss <<"))\n";
    1887           0 :         ss <<"        nEndPer = 0;\n    else\n";
    1888             :     }
    1889             : #endif
    1890           0 :     ss <<"        nEndPer = (int)";
    1891           0 :     ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
    1892           0 :     ss <<";\n";
    1893             : 
    1894             : #ifdef ISNAN
    1895           0 :     if(tmpCur5->GetType() == formula::svSingleVectorRef)
    1896             :     {
    1897             :         const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
    1898           0 :         formula::SingleVectorRefToken *>(tmpCur5);
    1899           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR5->GetArrayLength()<<" || isNan(";
    1900           0 :         ss <<vSubArguments[5]->GenSlidingWindowDeclRef();
    1901           0 :         ss <<"))\n";
    1902           0 :         ss <<"        nPayType = 0;\n    else\n";
    1903             :     }
    1904             : #endif
    1905           0 :     ss <<"        nPayType = (int)";
    1906           0 :     ss <<vSubArguments[5]->GenSlidingWindowDeclRef();
    1907           0 :     ss <<";\n";
    1908           0 :     ss <<"    double fRmz;\n";
    1909           0 :     ss <<"    fRmz = GetRmz_new( fRate, nNumPeriods,fVal,0.0,nPayType );\n";
    1910           0 :     ss <<"    if(nStartPer == 1)\n";
    1911           0 :     ss <<"    {\n";
    1912           0 :     ss <<"        if( nPayType <= 0 )\n";
    1913           0 :     ss <<"            tmp = fRmz + fVal * fRate;\n";
    1914           0 :     ss <<"        else\n";
    1915           0 :     ss <<"            tmp = fRmz;\n";
    1916           0 :     ss <<"        nStartPer=nStartPer+1;\n";
    1917           0 :     ss <<"    }\n";
    1918           0 :     ss <<"    for( int i = nStartPer ; i <= nEndPer ; i++ )\n";
    1919           0 :     ss <<"    {\n";
    1920           0 :     ss <<"        if( nPayType > 0 )\n";
    1921           0 :     ss <<"            tmp += fRmz - ( GetZw_new( fRate,i - 2,";
    1922           0 :     ss <<"fRmz,fVal,1)- fRmz ) * fRate;\n";
    1923           0 :     ss <<"        else\n";
    1924           0 :     ss <<"            tmp += fRmz - GetZw_new( fRate, i - 1,";
    1925           0 :     ss <<"fRmz,fVal,0 ) * fRate;\n";
    1926           0 :     ss <<"    }\n";
    1927           0 :     ss <<"    return tmp;\n";
    1928           0 :     ss <<"}";
    1929           0 : }
    1930           0 : void OpAccrint::BinInlineFun(std::set<std::string>& decls,
    1931             :     std::set<std::string>& funs)
    1932             : {
    1933           0 :     decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
    1934           0 :     decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
    1935           0 :     decls.insert(GetNullDateDecl); decls.insert(GetDiffDateDecl);
    1936           0 :     funs.insert(IsLeapYear);funs.insert(DaysInMonth);
    1937           0 :     funs.insert(DaysToDate);funs.insert(DateToDays);
    1938           0 :     funs.insert(GetNullDate);funs.insert(GetDiffDate);
    1939           0 : }
    1940           0 : void OpAccrint::GenSlidingWindowFunction(
    1941             :     std::stringstream &ss, const std::string &sSymName,
    1942             :     SubArguments &vSubArguments)
    1943             : {
    1944           0 :     ss << "\ndouble " << sSymName;
    1945           0 :     ss << "_"<< BinFuncName() <<"(";
    1946           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1947             :     {
    1948           0 :         if (i)
    1949           0 :             ss << ",";
    1950           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1951             :     }
    1952           0 :     ss << ") {\n";
    1953           0 :     ss << "    int gid0 = get_global_id(0);\n";
    1954           0 :     ss << "    double tmp = 0;\n";
    1955           0 :     ss << "    int nStartDate,nEndDate,mode,freq;\n";
    1956           0 :     ss << "    int nDays1stYear=0;\n";
    1957           0 :     ss << "    double fVal,fRate;\n";
    1958             : #ifdef ISNAN
    1959           0 :     FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
    1960             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    1961           0 :         formula::SingleVectorRefToken *>(tmpCur0);
    1962           0 :     FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
    1963             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    1964           0 :         formula::SingleVectorRefToken *>(tmpCur2);
    1965           0 :     FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
    1966             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    1967           0 :         formula::SingleVectorRefToken *>(tmpCur3);
    1968           0 :     FormulaToken* tmpCur4 = vSubArguments[4]->GetFormulaToken();
    1969             :     const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
    1970           0 :         formula::SingleVectorRefToken *>(tmpCur4);
    1971           0 :     FormulaToken* tmpCur5 = vSubArguments[5]->GetFormulaToken();
    1972             :     const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
    1973           0 :         formula::SingleVectorRefToken *>(tmpCur5);
    1974           0 :     FormulaToken* tmpCur6 = vSubArguments[6]->GetFormulaToken();
    1975             :     const formula::SingleVectorRefToken*tmpCurDVR6= static_cast<const
    1976           0 :         formula::SingleVectorRefToken *>(tmpCur6);
    1977           0 :     ss<< "    int buffer_nIssue_len = ";
    1978           0 :     ss<< tmpCurDVR0->GetArrayLength();
    1979           0 :     ss<< ";\n";
    1980           0 :     ss<< "    int buffer_nSettle_len = ";
    1981           0 :     ss<< tmpCurDVR2->GetArrayLength();
    1982           0 :     ss<< ";\n";
    1983           0 :     ss<< "    int buffer_fRate_len = ";
    1984           0 :     ss<< tmpCurDVR3->GetArrayLength();
    1985           0 :     ss<< ";\n";
    1986           0 :     ss<< "    int buffer_fVal_len = ";
    1987           0 :     ss<< tmpCurDVR4->GetArrayLength();
    1988           0 :     ss<< ";\n";
    1989           0 :     ss<< "    int buffer_nFreq_len = ";
    1990           0 :     ss<< tmpCurDVR5->GetArrayLength();
    1991           0 :     ss<< ";\n";
    1992           0 :     ss<< "    int buffer_nMode_len = ";
    1993           0 :     ss<< tmpCurDVR6->GetArrayLength();
    1994           0 :     ss << ";\n";
    1995             : #endif
    1996             : #ifdef ISNAN
    1997           0 :     ss<<"    if(gid0 >= buffer_nIssue_len || isNan(";
    1998           0 :     ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
    1999           0 :     ss <<"))\n";
    2000           0 :     ss <<"        nStartDate = 0;\n    else\n";
    2001             : #endif
    2002           0 :     ss <<"        nStartDate=(int)";
    2003           0 :     ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
    2004           0 :     ss <<";\n";
    2005             : #ifdef ISNAN
    2006           0 :     ss <<"    if(gid0 >= buffer_nSettle_len || isNan(";
    2007           0 :     ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
    2008           0 :     ss <<"))\n";
    2009           0 :     ss <<"        nEndDate = 0;\n    else\n";
    2010             : #endif
    2011           0 :     ss <<"        nEndDate=(int)";
    2012           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    2013           0 :     ss << ";\n";
    2014             : #ifdef ISNAN
    2015           0 :     ss <<"    if(gid0 >= buffer_fRate_len || isNan(";
    2016           0 :     ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
    2017           0 :     ss <<"))\n";
    2018           0 :     ss <<"        fRate = 0;\n    else\n";
    2019             : #endif
    2020           0 :     ss <<"        fRate=";
    2021           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    2022           0 :     ss <<";\n";
    2023             : #ifdef ISNAN
    2024           0 :     ss <<"    if(gid0 >= buffer_fVal_len || isNan(";
    2025           0 :     ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
    2026           0 :     ss <<"))\n";
    2027           0 :     ss <<"        fVal = 0;\n    else\n";
    2028             : #endif
    2029           0 :     ss <<"        fVal=";
    2030           0 :     ss << vSubArguments[4]->GenSlidingWindowDeclRef();
    2031           0 :     ss <<";\n";
    2032             : #ifdef ISNAN
    2033           0 :     ss <<"    if(gid0 >= buffer_nFreq_len || isNan(";
    2034           0 :     ss <<vSubArguments[5]->GenSlidingWindowDeclRef();
    2035           0 :     ss <<"))\n";
    2036           0 :     ss <<"        freq = 0;\n    else\n";
    2037             : #endif
    2038           0 :     ss <<"        freq= (int)";
    2039           0 :     ss << vSubArguments[5]->GenSlidingWindowDeclRef();
    2040           0 :     ss <<";\n";
    2041             : #ifdef ISNAN
    2042           0 :     ss <<"    if(gid0 >= buffer_nMode_len || isNan(";
    2043           0 :     ss <<vSubArguments[6]->GenSlidingWindowDeclRef();
    2044           0 :     ss <<"))\n";
    2045           0 :     ss <<"        mode = 0;\n    else\n";
    2046             : #endif
    2047           0 :     ss <<"        mode = (int)";
    2048           0 :     ss << vSubArguments[6]->GenSlidingWindowDeclRef();
    2049           0 :     ss <<";\n";
    2050           0 :     ss <<"    int nNullDate=GetNullDate();\n";
    2051           0 :     ss <<"    int nTotalDays = GetDiffDate(nNullDate,nStartDate,";
    2052           0 :     ss <<"nEndDate, mode,&nDays1stYear);\n";
    2053           0 :     ss <<"    tmp = fVal*fRate*convert_double(nTotalDays)";
    2054           0 :     ss <<"/convert_double(nDays1stYear);\n";
    2055           0 :     ss <<"    return tmp;\n";
    2056           0 :     ss <<"}";
    2057           0 : }
    2058             : 
    2059           0 : void OpAccrintm::BinInlineFun(std::set<std::string>& decls,
    2060             :     std::set<std::string>& funs)
    2061             : {
    2062           0 :     decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
    2063           0 :     decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
    2064           0 :     decls.insert(GetNullDateDecl); decls.insert(GetDiffDateDecl);
    2065           0 :     funs.insert(IsLeapYear);funs.insert(DaysInMonth);
    2066           0 :     funs.insert(DaysToDate);funs.insert(DateToDays);
    2067           0 :     funs.insert(GetNullDate);funs.insert(GetDiffDate);
    2068           0 : }
    2069           0 : void OpAccrintm::GenSlidingWindowFunction(
    2070             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
    2071             : {
    2072           0 :     ss << "\ndouble " << sSymName;
    2073           0 :     ss << "_"<< BinFuncName() <<"(";
    2074           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2075             :     {
    2076           0 :         if (i)
    2077           0 :             ss << ",";
    2078           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2079             :     }
    2080           0 :     ss << ") {\n\t";
    2081           0 :     ss << "int gid0 = get_global_id(0);\n\t";
    2082           0 :     ss << "double tmp = " << GetBottom() <<";\n\t";
    2083           0 :     ss << "int nStartDate,nEndDate,mode;\n\t";
    2084           0 :     ss << "double fRate,fVal;\n\t";
    2085             : #ifdef ISNAN
    2086           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    2087             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    2088           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    2089           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    2090             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    2091           0 :     formula::SingleVectorRefToken *>(tmpCur1);
    2092             : 
    2093           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
    2094             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    2095           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    2096             : 
    2097           0 :     FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
    2098             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    2099           0 :     formula::SingleVectorRefToken *>(tmpCur3);
    2100             : 
    2101           0 :     FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
    2102             :     const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
    2103           0 :     formula::SingleVectorRefToken *>(tmpCur4);
    2104           0 :     ss<< "int buffer_nIssue_len = ";
    2105           0 :     ss<< tmpCurDVR0->GetArrayLength();
    2106           0 :     ss << ";\n\t";
    2107             : 
    2108           0 :     ss<< "int buffer_nSettle_len = ";
    2109           0 :     ss<< tmpCurDVR1->GetArrayLength();
    2110           0 :     ss << ";\n\t";
    2111             : 
    2112           0 :     ss<< "int buffer_fRate_len = ";
    2113           0 :     ss<< tmpCurDVR2->GetArrayLength();
    2114           0 :     ss << ";\n\t";
    2115             : 
    2116           0 :     ss<< "int buffer_fVal_len = ";
    2117           0 :     ss<< tmpCurDVR3->GetArrayLength();
    2118           0 :     ss << ";\n\t";
    2119             : 
    2120           0 :     ss<< "int buffer_nMode_len = ";
    2121           0 :     ss<< tmpCurDVR4->GetArrayLength();
    2122           0 :     ss << ";\n\t";
    2123             : #endif
    2124             : #ifdef ISNAN
    2125           0 :      ss <<"if(gid0 >= buffer_nIssue_len || isNan(";
    2126           0 :      ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
    2127           0 :      ss <<"))\n\t\t";
    2128           0 :      ss <<"nStartDate = 0;\n\telse\n\t\t";
    2129             : #endif
    2130           0 :     ss << "nStartDate=(int)";
    2131           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    2132           0 :     ss <<";\n\t";
    2133             : #ifdef ISNAN
    2134           0 :     ss <<"if(gid0 >= buffer_nSettle_len || isNan(";
    2135           0 :     ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
    2136           0 :     ss <<"))\n\t\t";
    2137           0 :     ss <<"nEndDate = 0;\n\telse\n\t\t";
    2138             : #endif
    2139           0 :     ss << "nEndDate=(int)";
    2140           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    2141           0 :     ss << ";\n\t";
    2142             : 
    2143             : #ifdef ISNAN
    2144           0 :     ss <<"if(gid0 >= buffer_fRate_len || isNan(";
    2145           0 :     ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
    2146           0 :     ss <<"))\n\t\t";
    2147           0 :     ss <<"fRate = 0;\n\telse\n\t\t";
    2148             : #endif
    2149           0 :     ss << "fRate=";
    2150           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    2151           0 :     ss <<";\n\t";
    2152             : #ifdef ISNAN
    2153           0 :     ss <<"if(gid0 >= buffer_fVal_len || isNan(";
    2154           0 :     ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
    2155           0 :     ss <<"))\n\t\t";
    2156           0 :     ss <<"fVal = 0;\n\telse\n\t\t";
    2157             : #endif
    2158           0 :     ss << "fVal=";
    2159           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    2160           0 :     ss << ";\n\t";
    2161             : #ifdef ISNAN
    2162           0 :     ss <<"if(gid0 >= buffer_nMode_len || isNan(";
    2163           0 :     ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
    2164           0 :     ss <<"))\n\t\t";
    2165           0 :     ss <<"mode = 0;\n\telse\n\t\t";
    2166             : #endif
    2167           0 :     ss << "mode = (int)";
    2168           0 :     ss << vSubArguments[4]->GenSlidingWindowDeclRef();
    2169           0 :     ss << ";\n\t";
    2170           0 :     ss <<"int nDays1stYear=0;\n\t";
    2171           0 :     ss <<"int nNullDate=GetNullDate();\n\t";
    2172           0 :     ss <<"int nTotalDays = GetDiffDate(nNullDate,nStartDate,";
    2173           0 :     ss <<"nEndDate, mode,&nDays1stYear);\n\t";
    2174           0 :     ss <<"tmp = fVal*fRate*convert_double(nTotalDays)";
    2175           0 :     ss <<"/convert_double(nDays1stYear);\n\t";
    2176           0 :     ss << "return tmp;\n";
    2177           0 :     ss << "}";
    2178           0 : }
    2179             : 
    2180           0 :  void OpYield::BinInlineFun(std::set<std::string>& decls,
    2181             :     std::set<std::string>& funs)
    2182             : {
    2183           0 :     decls.insert(getYield_Decl);decls.insert(getPrice_Decl);
    2184           0 :     decls.insert(coupnumDecl);decls.insert(coupdaysncDecl);
    2185           0 :     decls.insert(coupdaybsDecl);decls.insert(coupdaysDecl);
    2186           0 :     decls.insert(lcl_GetcoupnumDecl);decls.insert(lcl_GetcoupdaysDecl);
    2187           0 :     decls.insert(lcl_GetcoupdaybsDecl);decls.insert(getDiffDecl);
    2188           0 :     decls.insert(getDaysInYearRangeDecl);decls.insert(GetDaysInYearDecl);
    2189           0 :     decls.insert(GetDaysInYearsDecl);decls.insert(getDaysInMonthRangeDecl);
    2190           0 :     decls.insert(addMonthsDecl);decls.insert(ScaDateDecl);
    2191           0 :     decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
    2192           0 :     decls.insert(DaysToDateDecl);decls.insert(DaysInMonthDecl);
    2193           0 :     decls.insert(IsLeapYearDecl);
    2194             : 
    2195           0 :     funs.insert(getYield_);funs.insert(getPrice_);
    2196           0 :     funs.insert(coupnum);funs.insert(coupdaysnc);
    2197           0 :     funs.insert(coupdaybs);funs.insert(coupdays);
    2198           0 :     funs.insert(lcl_Getcoupnum);funs.insert(lcl_Getcoupdays);
    2199           0 :     funs.insert(lcl_Getcoupdaybs);funs.insert(getDiff);
    2200           0 :     funs.insert(getDaysInYearRange);funs.insert(GetDaysInYear);
    2201           0 :     funs.insert(GetDaysInYears);funs.insert(getDaysInMonthRange);
    2202           0 :     funs.insert(addMonths);funs.insert(ScaDate);
    2203           0 :     funs.insert(GetNullDate);funs.insert(DateToDays);
    2204           0 :     funs.insert(DaysToDate);funs.insert(DaysInMonth);
    2205           0 :     funs.insert(IsLeapYear);
    2206           0 : }
    2207             : 
    2208             : 
    2209           0 : void OpYield::GenSlidingWindowFunction(
    2210             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
    2211             : {
    2212           0 :     ss << "\ndouble " << sSymName;
    2213           0 :     ss << "_"<< BinFuncName() <<"(";
    2214           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2215             :     {
    2216           0 :         if (i)
    2217           0 :             ss << ",";
    2218           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2219             :     }
    2220           0 :     ss << ") {\n\t";
    2221           0 :     ss << "double tmp = " <<"0"<<";\n\t";
    2222           0 :     ss << "int gid0 = get_global_id(0);\n\t";
    2223           0 :     ss << "double tmp000;\n\t";
    2224           0 :     ss << "double tmp001;\n\t";
    2225           0 :     ss << "double tmp002;\n\t";
    2226           0 :     ss << "double tmp003;\n\t";
    2227           0 :     ss << "double tmp004;\n\t";
    2228           0 :     ss << "double tmp005;\n\t";
    2229           0 :     ss << "double tmp006;\n\t";
    2230             : 
    2231             : 
    2232             : #ifdef ISNAN
    2233           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    2234             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    2235           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    2236             : 
    2237           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    2238             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    2239           0 :     formula::SingleVectorRefToken *>(tmpCur1);
    2240             : 
    2241           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
    2242             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    2243           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    2244             : 
    2245           0 :     FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
    2246             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    2247           0 :     formula::SingleVectorRefToken *>(tmpCur3);
    2248             : 
    2249           0 :     FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
    2250             :     const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
    2251           0 :     formula::SingleVectorRefToken *>(tmpCur4);
    2252             : 
    2253           0 :     FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
    2254             :     const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
    2255           0 :     formula::SingleVectorRefToken *>(tmpCur5);
    2256             : 
    2257           0 :     FormulaToken *tmpCur6 = vSubArguments[6]->GetFormulaToken();
    2258             :     const formula::SingleVectorRefToken*tmpCurDVR6= static_cast<const
    2259           0 :     formula::SingleVectorRefToken *>(tmpCur6);
    2260             : 
    2261           0 :     ss<< "int buffer_tmp000_len = ";
    2262           0 :     ss<< tmpCurDVR0->GetArrayLength();
    2263           0 :     ss << ";\n\t";
    2264             : 
    2265           0 :     ss<< "int buffer_tmp001_len = ";
    2266           0 :     ss<< tmpCurDVR1->GetArrayLength();
    2267           0 :     ss << ";\n\t";
    2268             : 
    2269           0 :     ss<< "int buffer_tmp002_len = ";
    2270           0 :     ss<< tmpCurDVR2->GetArrayLength();
    2271           0 :     ss << ";\n\t";
    2272             : 
    2273           0 :    ss<< "int buffer_tmp003_len = ";
    2274           0 :     ss<< tmpCurDVR3->GetArrayLength();
    2275           0 :     ss << ";\n\t";
    2276             : 
    2277           0 :     ss<< "int buffer_tmp004_len = ";
    2278           0 :     ss<< tmpCurDVR4->GetArrayLength();
    2279           0 :     ss << ";\n\t";
    2280             : 
    2281           0 :     ss<< "int buffer_tmp005_len = ";
    2282           0 :     ss<< tmpCurDVR5->GetArrayLength();
    2283           0 :     ss << ";\n\t";
    2284             : 
    2285           0 :     ss<< "int buffer_tmp006_len = ";
    2286           0 :     ss<< tmpCurDVR6->GetArrayLength();
    2287           0 :     ss << ";\n\t";
    2288             : #endif
    2289             : 
    2290             : #ifdef ISNAN
    2291           0 :     ss<<"if(gid0>=buffer_tmp000_len || isNan(";
    2292           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    2293           0 :     ss<<"))\n\t\t";
    2294           0 :     ss<<"tmp000 = 0;\n\telse \n\t\t";
    2295             : #endif
    2296           0 :     ss<<"tmp000 = ";
    2297           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    2298           0 :     ss<<";\n\t";
    2299             : 
    2300             : #ifdef ISNAN
    2301           0 :     ss<<"if(gid0>=buffer_tmp001_len || isNan(";
    2302           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    2303           0 :     ss<<"))\n\t\t";
    2304           0 :     ss<<"tmp001 = 0;\n\telse \n\t\t";
    2305             : #endif
    2306           0 :     ss<<"tmp001 = ";
    2307           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    2308           0 :     ss<<";\n\t";
    2309             : 
    2310             : #ifdef ISNAN
    2311           0 :     ss<<"if(gid0>=buffer_tmp002_len || isNan(";
    2312           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    2313           0 :     ss<<"))\n\t\t";
    2314           0 :     ss<<"tmp002 = 0;\n\telse \n\t\t";
    2315             : #endif
    2316           0 :     ss<<"tmp002 = ";
    2317           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    2318           0 :     ss<<";\n\t";
    2319             : 
    2320             : #ifdef ISNAN
    2321           0 :     ss<<"if(gid0>=buffer_tmp003_len || isNan(";
    2322           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    2323           0 :     ss<<"))\n\t\t";
    2324           0 :     ss<<"tmp003 = 0;\n\telse \n\t\t";
    2325             : #endif
    2326           0 :     ss<<"tmp003 = ";
    2327           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    2328           0 :     ss<<";\n\t";
    2329             : 
    2330             : #ifdef ISNAN
    2331           0 :     ss<<"if(gid0>=buffer_tmp004_len || isNan(";
    2332           0 :     ss << vSubArguments[4]->GenSlidingWindowDeclRef();
    2333           0 :     ss<<"))\n\t\t";
    2334           0 :     ss<<"tmp004 = 0;\n\telse \n\t\t";
    2335             : #endif
    2336           0 :     ss<<"tmp004 = ";
    2337           0 :     ss << vSubArguments[4]->GenSlidingWindowDeclRef();
    2338           0 :     ss<<";\n\t";
    2339             : 
    2340             : #ifdef ISNAN
    2341           0 :     ss<<"if(gid0>=buffer_tmp005_len || isNan(";
    2342           0 :     ss << vSubArguments[5]->GenSlidingWindowDeclRef();
    2343           0 :     ss<<"))\n\t\t";
    2344           0 :     ss<<"tmp005 = 0;\n\telse \n\t\t";
    2345             : #endif
    2346           0 :     ss<<"tmp005 = ";
    2347           0 :     ss << vSubArguments[5]->GenSlidingWindowDeclRef();
    2348           0 :     ss<<";\n\t";
    2349             : 
    2350             : #ifdef ISNAN
    2351           0 :     ss<<"if(gid0>=buffer_tmp006_len || isNan(";
    2352           0 :     ss << vSubArguments[6]->GenSlidingWindowDeclRef();
    2353           0 :     ss<<"))\n\t\t";
    2354           0 :     ss<<"tmp006 = 0;\n\telse \n\t\t";
    2355             : #endif
    2356           0 :     ss<<"tmp006 = ";
    2357           0 :     ss << vSubArguments[6]->GenSlidingWindowDeclRef();
    2358           0 :     ss<<";\n\t";
    2359             : 
    2360           0 :     ss << "tmp = getYield_(";
    2361           0 :     ss << "GetNullDate(),tmp000,tmp001,tmp002,tmp003,tmp004,tmp005,tmp006);\n\t ";
    2362           0 :     ss << "return tmp;\n";
    2363           0 :     ss << "}";
    2364           0 : }
    2365             : 
    2366           0 : void OpSLN::GenSlidingWindowFunction(std::stringstream &ss,
    2367             :             const std::string &sSymName, SubArguments &vSubArguments)
    2368             : {
    2369           0 :     ss << "\ndouble " << sSymName;
    2370           0 :     ss << "_"<< BinFuncName() <<"(";
    2371           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2372             :     {
    2373           0 :         if (i)
    2374           0 :             ss << ",";
    2375           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2376             :     }
    2377           0 :     ss << ") {\n";
    2378           0 :     ss << "    double tmp = " <<"0"<<";\n";
    2379           0 :     ss << "    int gid0 = get_global_id(0);\n";
    2380           0 :     ss << "    double wert;\n";
    2381           0 :     ss << "    double rest;\n";
    2382           0 :     ss << "    double dauer;\n";
    2383             : 
    2384             : #ifdef ISNAN
    2385           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    2386             :     const formula::SingleVectorRefToken*tmpCurDVR0=
    2387           0 :         static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
    2388           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    2389             :     const formula::SingleVectorRefToken*tmpCurDVR1=
    2390           0 :         static_cast<const formula::SingleVectorRefToken *>(tmpCur1);
    2391           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
    2392             :     const formula::SingleVectorRefToken*tmpCurDVR2=
    2393           0 :         static_cast<const formula::SingleVectorRefToken *>(tmpCur2);
    2394           0 :     ss<< "    int buffer_wert_len = ";
    2395           0 :     ss<< tmpCurDVR0->GetArrayLength();
    2396           0 :     ss << ";\n";
    2397           0 :     ss<< "    int buffer_rest_len = ";
    2398           0 :     ss<< tmpCurDVR1->GetArrayLength();
    2399           0 :     ss << ";\n";
    2400           0 :     ss<< "    int buffer_dauer_len = ";
    2401           0 :     ss<< tmpCurDVR2->GetArrayLength();
    2402           0 :     ss << ";\n";
    2403             : #endif
    2404             : #ifdef ISNAN
    2405           0 :     ss<<"    if(gid0>=buffer_wert_len || isNan(";
    2406           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    2407           0 :     ss<<"))\n";
    2408           0 :     ss<<"        wert = 0;\n\telse \n";
    2409             : #endif
    2410           0 :     ss<<"        wert = ";
    2411           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    2412           0 :     ss<<";\n";
    2413             : #ifdef ISNAN
    2414           0 :     ss<<"    if(gid0>=buffer_rest_len || isNan(";
    2415           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    2416           0 :     ss<<"))\n";
    2417           0 :     ss<<"        rest = 0;\n\telse \n";
    2418             : #endif
    2419           0 :     ss<<"        rest = ";
    2420           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    2421           0 :     ss<<";\n";
    2422             : #ifdef ISNAN
    2423           0 :     ss<<"    if(gid0>=buffer_dauer_len || isNan(";
    2424           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    2425           0 :     ss<<"))\n";
    2426           0 :     ss<<"        dauer = 0;\n\telse \n";
    2427             : #endif
    2428           0 :     ss<<"        dauer = ";
    2429           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    2430           0 :     ss<<";\n";
    2431           0 :     ss << "    tmp = (wert-rest)*pow(dauer,-1);\n";
    2432           0 :     ss << "    return tmp;\n";
    2433           0 :     ss << "}";
    2434           0 : }
    2435             : 
    2436           0 :  void OpYieldmat::BinInlineFun(std::set<std::string>& decls,
    2437             :     std::set<std::string>& funs)
    2438             : {
    2439           0 :     decls.insert(GetYearFrac_newDecl);decls.insert(GetNullDateDecl);
    2440           0 :     decls.insert(DateToDaysDecl);decls.insert(DaysToDate_newDecl);
    2441           0 :     decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
    2442           0 :     decls.insert(GetYieldmatDecl);
    2443             : 
    2444           0 :     funs.insert(GetYearFrac_new);funs.insert(GetNullDate);
    2445           0 :     funs.insert(DateToDays);funs.insert(DaysToDate_new);
    2446           0 :     funs.insert(DaysInMonth);funs.insert(IsLeapYear);
    2447           0 :     funs.insert(GetYieldmat);
    2448           0 : }
    2449             : 
    2450           0 : void OpYieldmat::GenSlidingWindowFunction(
    2451             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
    2452             : {
    2453           0 :     ss << "\ndouble " << sSymName;
    2454           0 :     ss << "_"<< BinFuncName() <<"(";
    2455           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2456             :     {
    2457           0 :         if (i)
    2458           0 :             ss << ",";
    2459           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2460             :     }
    2461           0 :     ss << ") {\n\t";
    2462           0 :     ss << "double tmp = " <<"0"<<";\n\t";
    2463           0 :     ss << "int gid0 = get_global_id(0);\n\t";
    2464           0 :     ss << "double tmp000;\n\t";
    2465           0 :     ss << "double tmp001;\n\t";
    2466           0 :     ss << "double tmp002;\n\t";
    2467           0 :     ss << "double tmp003;\n\t";
    2468           0 :     ss << "double tmp004;\n\t";
    2469           0 :     ss << "double tmp005;\n\t";
    2470             : 
    2471             : #ifdef ISNAN
    2472           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    2473             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    2474           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    2475             : 
    2476           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    2477             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    2478           0 :     formula::SingleVectorRefToken *>(tmpCur1);
    2479             : 
    2480           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
    2481             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    2482           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    2483             : 
    2484           0 :     FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
    2485             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    2486           0 :     formula::SingleVectorRefToken *>(tmpCur3);
    2487             : 
    2488           0 :     FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
    2489             :     const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
    2490           0 :     formula::SingleVectorRefToken *>(tmpCur4);
    2491             : 
    2492           0 :     FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
    2493             :     const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
    2494           0 :     formula::SingleVectorRefToken *>(tmpCur5);
    2495             : 
    2496           0 :     ss<< "int buffer_tmp000_len = ";
    2497           0 :     ss<< tmpCurDVR0->GetArrayLength();
    2498           0 :     ss << ";\n\t";
    2499             : 
    2500           0 :     ss<< "int buffer_tmp001_len = ";
    2501           0 :     ss<< tmpCurDVR1->GetArrayLength();
    2502           0 :     ss << ";\n\t";
    2503             : 
    2504           0 :     ss<< "int buffer_tmp002_len = ";
    2505           0 :     ss<< tmpCurDVR2->GetArrayLength();
    2506           0 :     ss << ";\n\t";
    2507             : 
    2508           0 :     ss<< "int buffer_tmp003_len = ";
    2509           0 :     ss<< tmpCurDVR3->GetArrayLength();
    2510           0 :     ss << ";\n\t";
    2511             : 
    2512           0 :     ss<< "int buffer_tmp004_len = ";
    2513           0 :     ss<< tmpCurDVR4->GetArrayLength();
    2514           0 :     ss << ";\n\t";
    2515             : 
    2516           0 :     ss<< "int buffer_tmp005_len = ";
    2517           0 :     ss<< tmpCurDVR5->GetArrayLength();
    2518           0 :     ss << ";\n\t";
    2519             : 
    2520             : #endif
    2521             : 
    2522             : #ifdef ISNAN
    2523           0 :     ss<<"if(gid0>=buffer_tmp000_len || isNan(";
    2524           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    2525           0 :     ss<<"))\n\t\t";
    2526           0 :     ss<<"tmp000 = 0;\n\telse \n\t\t";
    2527             : #endif
    2528           0 :     ss<<"tmp000 = ";
    2529           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    2530           0 :     ss<<";\n\t";
    2531             : 
    2532             : #ifdef ISNAN
    2533           0 :     ss<<"if(gid0>=buffer_tmp001_len || isNan(";
    2534           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    2535           0 :     ss<<"))\n\t\t";
    2536           0 :     ss<<"tmp001 = 0;\n\telse \n\t\t";
    2537             : #endif
    2538           0 :     ss<<"tmp001 = ";
    2539           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    2540           0 :     ss<<";\n\t";
    2541             : 
    2542             : #ifdef ISNAN
    2543           0 :     ss<<"if(gid0>=buffer_tmp002_len || isNan(";
    2544           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    2545           0 :     ss<<"))\n\t\t";
    2546           0 :     ss<<"tmp002 = 0;\n\telse \n\t\t";
    2547             : #endif
    2548           0 :     ss<<"tmp002 = ";
    2549           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    2550           0 :     ss<<";\n\t";
    2551             : 
    2552             : #ifdef ISNAN
    2553           0 :     ss<<"if(gid0>=buffer_tmp003_len || isNan(";
    2554           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    2555           0 :     ss<<"))\n\t\t";
    2556           0 :     ss<<"tmp003 = 0;\n\telse \n\t\t";
    2557             : #endif
    2558           0 :     ss<<"tmp003 = ";
    2559           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    2560           0 :     ss<<";\n\t";
    2561             : 
    2562             : #ifdef ISNAN
    2563           0 :     ss<<"if(gid0>=buffer_tmp004_len || isNan(";
    2564           0 :     ss << vSubArguments[4]->GenSlidingWindowDeclRef();
    2565           0 :     ss<<"))\n\t\t";
    2566           0 :     ss<<"tmp004 = 0;\n\telse \n\t\t";
    2567             : #endif
    2568           0 :     ss<<"tmp004 = ";
    2569           0 :     ss << vSubArguments[4]->GenSlidingWindowDeclRef();
    2570           0 :     ss<<";\n\t";
    2571             : 
    2572             : #ifdef ISNAN
    2573           0 :     ss<<"if(gid0>=buffer_tmp005_len || isNan(";
    2574           0 :     ss << vSubArguments[5]->GenSlidingWindowDeclRef();
    2575           0 :     ss<<"))\n\t\t";
    2576           0 :     ss<<"tmp005 = 0;\n\telse \n\t\t";
    2577             : #endif
    2578           0 :     ss<<"tmp005 = ";
    2579           0 :     ss << vSubArguments[5]->GenSlidingWindowDeclRef();
    2580           0 :     ss<<";\n\t";
    2581             : 
    2582           0 :     ss << "tmp = GetYieldmat(";
    2583           0 :     ss<<"GetNullDate(),tmp000,tmp001,tmp002,tmp003,tmp004,tmp005);\n\t";
    2584           0 :     ss << "return tmp;\n";
    2585           0 :     ss << "}";
    2586           0 : }
    2587             : 
    2588           0 : void OpPMT::GenSlidingWindowFunction(std::stringstream &ss,
    2589             :         const std::string &sSymName, SubArguments &vSubArguments)
    2590             : {
    2591           0 :     ss << "\ndouble " << sSymName;
    2592           0 :     ss << "_"<< BinFuncName() <<"(";
    2593           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2594             :     {
    2595           0 :         if (i)
    2596           0 :             ss << ", ";
    2597           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2598             :     }
    2599           0 :     ss<<") {\n";
    2600           0 :     ss<<"    double tmp = 0;\n";
    2601           0 :     ss<<"    double temp=0.0;\n";
    2602           0 :     ss<<"    int gid0 = get_global_id(0);\n";
    2603           0 :     ss<<"    double tmp0=0,tmp1=0,tmp2=0;\n";
    2604           0 :     ss<<"    double tmp3=0,tmp4=0;\n";
    2605           0 :     size_t i = vSubArguments.size();
    2606           0 :     ss <<"\n    ";
    2607             :     //while (i-- > 1)
    2608           0 :     for (i = 0; i < vSubArguments.size(); i++)
    2609             :     {
    2610           0 :         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
    2611             :         assert(pCur);
    2612           0 :         if (pCur->GetType() == formula::svSingleVectorRef)
    2613             :         {
    2614             : #ifdef  ISNAN
    2615             :                 const formula::SingleVectorRefToken* pSVR =
    2616           0 :                 static_cast< const formula::SingleVectorRefToken* >(pCur);
    2617           0 :             ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
    2618             : #else
    2619             : #endif
    2620             :         }
    2621           0 :         else if (pCur->GetType() == formula::svDouble)
    2622             :         {
    2623             : #ifdef  ISNAN
    2624           0 :             ss << "{\n";
    2625             : #endif
    2626             :         }
    2627             :         else
    2628             :         {
    2629             : #ifdef  ISNAN
    2630             : #endif
    2631             :         }
    2632             : #ifdef  ISNAN
    2633           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
    2634             :         {
    2635           0 :             ss <<"    temp="<<vSubArguments[i]->GenSlidingWindowDeclRef();
    2636           0 :             ss <<";\n";
    2637           0 :             ss <<"    if (isNan(temp))\n";
    2638           0 :             ss <<"        tmp"<<i<<"= 0;\n";
    2639           0 :             ss <<"    else\n";
    2640           0 :             ss <<"        tmp"<<i<<"=temp;\n";
    2641           0 :             ss <<"    }\n";
    2642             :         }
    2643             :         else
    2644             :         {
    2645           0 :             ss <<"    tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(
    2646           0 : );
    2647           0 :             ss <<";\n";
    2648             :         }
    2649             : #else
    2650             :     ss <<"    tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
    2651             :     ss <<";\n";
    2652             : 
    2653             : #endif
    2654             :     }
    2655           0 :     ss<<"    if(tmp0==0.0)\n";
    2656           0 :     ss<<"        return -(tmp2+tmp3)/tmp1;\n";
    2657           0 :     ss<<"    tmp-=tmp3;\n";
    2658           0 :     ss<<"    tmp=tmp-tmp2*pow(1.0+tmp0,tmp1);\n";
    2659           0 :     ss<<"    tmp=tmp*pow(( (1.0+tmp0*tmp4)* ";
    2660           0 :     ss<<"( (pow(1.0+tmp0,tmp1)-1.0)/tmp0)),-1);\n";
    2661           0 :     ss<<"    return tmp;\n";
    2662           0 :     ss<<"}";
    2663           0 : }
    2664             : 
    2665           0 : void OpNPV::GenSlidingWindowFunction(std::stringstream &ss,
    2666             :     const std::string &sSymName, SubArguments &vSubArguments)
    2667             : {
    2668           0 :     ss << "\ndouble " << sSymName;
    2669           0 :     ss << "_"<< BinFuncName() <<"(";
    2670           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2671             :     {
    2672           0 :       if (i)
    2673           0 :           ss << ", ";
    2674           0 :       vSubArguments[i]->GenSlidingWindowDecl(ss);
    2675             :     }
    2676           0 :     ss << ") {\n";
    2677           0 :     ss << "    double tmp = 0.0;\n";
    2678           0 :     ss << "    int gid0 = get_global_id(0);\n";
    2679           0 :     ss << "    int nCount = 1;\n";
    2680           0 :     ss << "    double arg0=";
    2681           0 :     ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
    2682           0 :     ss <<";\n";
    2683             :     //while (i-- > 1)
    2684           0 :     for (size_t i = 1; i < vSubArguments.size(); i++)
    2685             :     {
    2686           0 :       FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
    2687             :       assert(pCur);
    2688           0 :       if (pCur->GetType() == formula::svDoubleVectorRef)
    2689             :       {
    2690             :             const formula::DoubleVectorRefToken* pDVR =
    2691           0 :             static_cast<const formula::DoubleVectorRefToken *>(pCur);
    2692           0 :             size_t nCurWindowSize = pDVR->GetRefRowSize();
    2693           0 :             ss << "    for (int i = ";
    2694           0 :             if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
    2695             : #ifdef  ISNAN
    2696           0 :                 ss << "gid0; i < " << pDVR->GetArrayLength();
    2697           0 :                 ss << " && i < " << nCurWindowSize  << "; i++){\n";
    2698             : #else
    2699             :                 ss << "gid0; i < "<< nCurWindowSize << "; i++)\n";
    2700             : #endif
    2701           0 :             } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
    2702             : #ifdef  ISNAN
    2703           0 :                 ss << "0; i < " << pDVR->GetArrayLength();
    2704           0 :                 ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
    2705             : #else
    2706             :                 ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n";
    2707             : #endif
    2708           0 :             } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
    2709             : #ifdef  ISNAN
    2710           0 :                 ss << "0; i + gid0 < " << pDVR->GetArrayLength();
    2711           0 :                 ss << " &&  i < "<< nCurWindowSize << "; i++){\n";
    2712             : #else
    2713             :                 ss << "0; i < "<< nCurWindowSize << "; i++)\n";
    2714             : #endif
    2715             :             }
    2716             :             else {
    2717             : #ifdef  ISNAN
    2718           0 :                 ss << "0; i < "<< nCurWindowSize << "; i++){\n";
    2719             : #else
    2720             :                 ss << "0; i < "<< nCurWindowSize << "; i++)\n";
    2721             : #endif
    2722             :             }
    2723             :         }
    2724           0 :         else if (pCur->GetType() == formula::svSingleVectorRef)
    2725             :         {
    2726             : #ifdef  ISNAN
    2727             :             const formula::SingleVectorRefToken* pSVR =
    2728           0 :             static_cast< const formula::SingleVectorRefToken* >(pCur);
    2729           0 :             ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
    2730             : #else
    2731             : #endif
    2732             :         }
    2733           0 :         else if (pCur->GetType() == formula::svDouble)
    2734             :         {
    2735             : #ifdef  ISNAN
    2736           0 :             ss << "{\n";
    2737             : #endif
    2738             :         }
    2739             :         else
    2740             :         {
    2741             : #ifdef  ISNAN
    2742           0 :             ss << "nCount += 1;\n";
    2743             : #endif
    2744             :         }
    2745             : #ifdef  ISNAN
    2746           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
    2747             :         {
    2748           0 :             ss << "        double temp=";
    2749           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    2750           0 :             ss << ";\n";
    2751           0 :             ss << "        double temp1=1.0;";
    2752           0 :             ss << "        if (isNan(temp)){\n";
    2753           0 :             ss << "            tmp += 0;}\n";
    2754           0 :             ss << "        else{\n";
    2755           0 :             ss << "            for(int i=1;i<nCount;i+=2)\n";
    2756           0 :             ss << "                temp1*=pow(1.0f+ arg0 ,2);\n";
    2757           0 :             ss << "            if(nCount%2)\n";
    2758           0 :             ss << "                temp1*=1.0f+ arg0;\n";
    2759           0 :             ss << "            tmp +=temp/ temp1;\n";
    2760           0 :             ss << "        nCount += 1;\n";
    2761           0 :             ss << "        }\n";
    2762           0 :             ss << "    }\n";
    2763             :         }
    2764             :         else
    2765             :         {
    2766           0 :             ss << "        double temp=";
    2767           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    2768           0 :             ss << ";\n";
    2769           0 :             ss << "    double temp1=1.0;";
    2770           0 :             ss << "            for(int i=1;i<nCount;i+=2)";
    2771           0 :             ss << "                temp1*=pow(1.0f+ arg0 ,2);\n";
    2772           0 :             ss << "            if(nCount%2)";
    2773           0 :             ss << "                temp1*=1.0f+ arg0;\n";
    2774           0 :             ss << "            tmp +=temp/ temp1;\n";
    2775           0 :             ss << "        nCount += 1;\n";
    2776             :         }
    2777             : #else
    2778             :             ss << "tmp +="<<vSubArguments[i]->GenSlidingWindowDeclRef();
    2779             :             ss <<" / pow(1.0f+ arg0 ,";
    2780             :             ss <<" (double)nCount );\n";
    2781             :             ss << "        nCount += 1;\n";
    2782             : #endif
    2783             :     }
    2784           0 :         ss << "    return tmp;\n";
    2785           0 :         ss << "}";
    2786           0 : }
    2787             : 
    2788           0 :  void OpPrice::BinInlineFun(std::set<std::string>& decls,
    2789             :      std::set<std::string>& funs)
    2790             :  {
    2791           0 :     decls.insert(getPrice_new_Decl);
    2792           0 :     decls.insert(IsLeapYearDecl);decls.insert(DaysInMonthDecl);
    2793           0 :     decls.insert(DaysToDateDecl);
    2794           0 :     decls.insert(DateToDaysDecl);
    2795           0 :     decls.insert(ScaDateDecl);
    2796           0 :     decls.insert(setDayDecl);decls.insert(checklessthanDecl);
    2797           0 :     decls.insert(addMonthsDecl);decls.insert(lcl_Getcoupnum_newDecl);
    2798           0 :     decls.insert(coupnum_newDecl);
    2799           0 :     decls.insert(DateToDays_newDecl);
    2800           0 :     decls.insert(getDaysInMonthRangeDecl);
    2801           0 :     decls.insert(GetDaysInYearsDecl); decls.insert(GetDaysInYearDecl);
    2802           0 :     decls.insert(getDaysInYearRangeDecl); decls.insert(getDiffDecl);
    2803           0 :     decls.insert(coupdaybs_newDecl);
    2804           0 :     decls.insert(lcl_Getcoupdays_newDecl);
    2805           0 :     decls.insert(lcl_Getcoupdaybs_newDecl);
    2806           0 :     decls.insert(coupdays_newDecl);
    2807           0 :     decls.insert(coupdaysnc_newDecl);
    2808           0 :     funs.insert(IsLeapYear);funs.insert(DaysInMonth_new);
    2809           0 :     funs.insert(DaysToDate);funs.insert(DateToDays_new);
    2810           0 :     funs.insert(DateToDays);
    2811           0 :     funs.insert(ScaDate);
    2812           0 :     funs.insert(addMonths);funs.insert(getDaysInMonthRange);
    2813           0 :     funs.insert(GetDaysInYears);funs.insert(GetDaysInYear);
    2814           0 :     funs.insert(getDaysInYearRange);funs.insert(getDiff);
    2815           0 :     funs.insert(setDay);funs.insert(checklessthan);
    2816           0 :     funs.insert(lcl_Getcoupdaybs_new);
    2817           0 :     funs.insert(coupdaybs_new);
    2818           0 :     funs.insert(lcl_Getcoupdays_new);
    2819           0 :     funs.insert(coupdaysnc_new);
    2820           0 :     funs.insert(coupdays_new);
    2821           0 :     funs.insert(setDay);funs.insert(checklessthan);
    2822           0 :     funs.insert(lcl_Getcoupnum_new);
    2823           0 :     funs.insert(coupnum_new);funs.insert(getPrice_new);
    2824           0 :  }
    2825           0 : void OpPrice::GenSlidingWindowFunction(std::stringstream &ss,
    2826             :           const std::string &sSymName, SubArguments &vSubArguments)
    2827             : {
    2828           0 :     ss << "\ndouble " << sSymName;
    2829           0 :     ss << "_"<< BinFuncName() <<"(";
    2830           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2831             :     {
    2832           0 :       if (i)
    2833           0 :           ss << ", ";
    2834           0 :       vSubArguments[i]->GenSlidingWindowDecl(ss);
    2835             :     }
    2836           0 :     ss<<") {\n";
    2837           0 :     ss<<"    double tmp = 0;\n";
    2838           0 :     ss<<"    int gid0 = get_global_id(0);\n";
    2839           0 :     ss<<"    double tmp0=0;\n";
    2840           0 :     ss<<"    double tmp1=0;\n";
    2841           0 :     ss<<"    double tmp2=0;\n";
    2842           0 :     ss<<"    double tmp3=0;\n";
    2843           0 :     ss<<"    double tmp4=0,tmp5=0;\n";
    2844           0 :     ss<<"    double tmp6=0;\n";
    2845           0 :     ss<<"\n";
    2846           0 :     for (size_t i = 0; i < vSubArguments.size(); i++)
    2847             :     {
    2848           0 :         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
    2849             :         assert(pCur);
    2850           0 :         if (pCur->GetType() == formula::svSingleVectorRef)
    2851             :         {
    2852             : #ifdef  ISNAN
    2853             :             const formula::SingleVectorRefToken* pSVR =
    2854           0 :                 static_cast< const formula::SingleVectorRefToken* >(pCur);
    2855           0 :             ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
    2856             : #else
    2857             : #endif
    2858             :         }
    2859           0 :         else if (pCur->GetType() == formula::svDouble)
    2860             :         {
    2861             : #ifdef  ISNAN
    2862           0 :             ss << "{\n";
    2863             : #endif
    2864             :         }
    2865             :         else
    2866             :         {
    2867             : #ifdef  ISNAN
    2868             : #endif
    2869             :         }
    2870             : #ifdef  ISNAN
    2871           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
    2872             :         {
    2873           0 :             ss << "        if (isNan(";
    2874           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    2875           0 :             ss << "))\n";
    2876           0 :             ss << "            tmp"<<i<<"= 0;\n";
    2877           0 :             ss << "        else\n";
    2878           0 :             ss << "            tmp"<<i<<"=";
    2879           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    2880           0 :             ss << ";\n    }\n";
    2881             :         }
    2882             :         else
    2883             :         {
    2884           0 :             ss << "        tmp"<<i<<"=";
    2885           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    2886           0 :             ss <<";\n";
    2887             :         }
    2888             : #else
    2889             :         ss << "        tmp"<<i<<"=";
    2890             :         ss<<vSubArguments[i]->GenSlidingWindowDeclRef();
    2891             :         ss <<";\n";
    2892             : #endif
    2893             :     }
    2894           0 :     ss << "    tmp = getPrice_(tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);\n";
    2895           0 :     ss << "    return tmp;\n";
    2896           0 :     ss << "}";
    2897           0 : }
    2898             : 
    2899           0 : void OpOddlprice::BinInlineFun(std::set<std::string>& decls,
    2900             :      std::set<std::string>& funs)
    2901             : {
    2902           0 :     decls.insert(GetOddlpriceDecl);decls.insert(GetDiffDateDecl);
    2903           0 :     decls.insert(GetYearDiffDecl);decls.insert(IsLeapYearDecl);
    2904           0 :     decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
    2905           0 :     decls.insert(DaysToDateDecl);decls.insert(DaysInMonthDecl);
    2906           0 :     decls.insert(GetYearFracDecl);
    2907           0 :     funs.insert(GetOddlprice);funs.insert(GetDiffDate);
    2908           0 :     funs.insert(GetYearDiff);funs.insert(IsLeapYear);
    2909           0 :     funs.insert(GetNullDate);funs.insert(DaysInMonth);
    2910           0 :     funs.insert(DaysToDate);funs.insert(DateToDays);
    2911           0 :     funs.insert(GetYearFrac);
    2912           0 : }
    2913           0 : void OpOddlprice::GenSlidingWindowFunction(std::stringstream &ss,
    2914             :           const std::string &sSymName, SubArguments &vSubArguments)
    2915             : {
    2916           0 :     ss << "\ndouble " << sSymName;
    2917           0 :     ss << "_"<< BinFuncName() <<"(";
    2918           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2919             :     {
    2920           0 :         if (i)
    2921           0 :             ss << ", ";
    2922           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2923             :     }
    2924           0 :     ss <<") {\n";
    2925           0 :     ss <<"    double tmp = 0;\n";
    2926           0 :     ss <<"    int gid0 = get_global_id(0);\n";
    2927           0 :     ss <<"    double tmp0=0;\n";
    2928           0 :     ss <<"    double tmp1=0;\n";
    2929           0 :     ss <<"    double tmp2=0;\n";
    2930           0 :     ss <<"    double tmp3=0;\n";
    2931           0 :     ss <<"    double tmp4=0;\n";
    2932           0 :     ss <<"    double tmp5=0;\n";
    2933           0 :     ss <<"    double tmp6=0;\n";
    2934           0 :     ss <<"    double tmp7=0;\n";
    2935           0 :     size_t nItems = 0;
    2936           0 :     ss <<"    \n";
    2937           0 :     for (size_t i = 0; i < vSubArguments.size(); i++)
    2938             :     {
    2939           0 :         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
    2940             :         assert(pCur);
    2941           0 :         if (pCur->GetType() == formula::svDoubleVectorRef)
    2942             :         {
    2943             :             const formula::DoubleVectorRefToken* pDVR =
    2944           0 :             static_cast<const formula::DoubleVectorRefToken *>(pCur);
    2945           0 :             size_t nCurWindowSize = pDVR->GetRefRowSize();
    2946           0 :             ss << "    for (int i = ";
    2947           0 :             if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
    2948             : #ifdef  ISNAN
    2949           0 :                 ss << "gid0; i < " << pDVR->GetArrayLength();
    2950           0 :                 ss << " && i < " << nCurWindowSize  << "; i++){\n";
    2951             : #else
    2952             :                 ss << "gid0; i < "<< nCurWindowSize << "; i++)\n";
    2953             : #endif
    2954           0 :             } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
    2955             : #ifdef  ISNAN
    2956           0 :                 ss << "0; i < " << pDVR->GetArrayLength();
    2957           0 :                 ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
    2958             : #else
    2959             :                 ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n";
    2960             : #endif
    2961           0 :             } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
    2962             : #ifdef  ISNAN
    2963           0 :                 ss << "0; i + gid0 < " << pDVR->GetArrayLength();
    2964           0 :                 ss << " &&  i < "<< nCurWindowSize << "; i++){\n";
    2965             : #else
    2966             :                 ss << "0; i < "<< nCurWindowSize << "; i++)\n";
    2967             : #endif
    2968             :             }
    2969             :             else {
    2970             : #ifdef  ISNAN
    2971           0 :                 ss << "0; i < "<< nCurWindowSize << "; i++){\n";
    2972             : #else
    2973             :                 ss << "0; i < "<< nCurWindowSize << "; i++)\n";
    2974             : #endif
    2975             :             }
    2976           0 :             nItems += nCurWindowSize;
    2977             :         }
    2978           0 :         else if (pCur->GetType() == formula::svSingleVectorRef)
    2979             :         {
    2980             : #ifdef  ISNAN
    2981             :             const formula::SingleVectorRefToken* pSVR =
    2982           0 :             static_cast< const formula::SingleVectorRefToken* >(pCur);
    2983           0 :             ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
    2984             : #else
    2985             :             nItems += 1;
    2986             : #endif
    2987             :         }
    2988           0 :         else if (pCur->GetType() == formula::svDouble)
    2989             :         {
    2990             : #ifdef  ISNAN
    2991           0 :             ss << "{\n";
    2992             : #endif
    2993           0 :             nItems += 1;
    2994             :         }
    2995             :         else
    2996             :         {
    2997             : #ifdef  ISNAN
    2998             : #endif
    2999           0 :             nItems += 1;
    3000             :         }
    3001             : #ifdef  ISNAN
    3002           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
    3003             :         {
    3004           0 :             ss << "        if (isNan(";
    3005           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    3006           0 :             ss << "))\n";
    3007           0 :             ss << "            tmp"<<i<<"= 0;\n";
    3008           0 :             ss << "        else\n";
    3009           0 :             ss << "            tmp"<<i<<"=";
    3010           0 :             ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
    3011           0 :             ss << ";\n";
    3012           0 :             ss <<"    }\n";
    3013             :         }
    3014             :         else
    3015             :         {
    3016           0 :             ss << "        tmp"<<i<<"=";
    3017           0 :             ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
    3018           0 :             ss <<";\n";
    3019             :         }
    3020             : #else
    3021             :     ss << "        tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
    3022             :     ss <<";\n";
    3023             : #endif
    3024             :     }
    3025           0 :     ss <<"    int nNullDate = GetNullDate();\n";
    3026           0 :     ss <<"    tmp = GetOddlprice(nNullDate,tmp0,tmp1,";
    3027           0 :     ss <<"tmp2,tmp3,tmp4,tmp5,tmp6,tmp7);\n";
    3028           0 :     ss <<"    return tmp;\n";
    3029           0 :     ss <<"}";
    3030           0 : }
    3031           0 : void OpOddlyield::BinInlineFun(std::set<std::string>& decls,
    3032             :      std::set<std::string>& funs)
    3033             : {
    3034           0 :     decls.insert(GetDiffDateDecl);decls.insert(DaysToDateDecl);
    3035           0 :     decls.insert(GetYearDiffDecl);decls.insert(IsLeapYearDecl);
    3036           0 :     decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
    3037           0 :     decls.insert(DaysInMonthDecl);
    3038           0 :     decls.insert(GetYearFracDecl);decls.insert(GetOddlyieldDecl);
    3039           0 :     funs.insert(GetDiffDate);funs.insert(DaysToDate);
    3040           0 :     funs.insert(GetYearDiff);funs.insert(IsLeapYear);
    3041           0 :     funs.insert(GetNullDate);funs.insert(DaysInMonth);
    3042           0 :     funs.insert(DateToDays);
    3043           0 :     funs.insert(GetYearFrac);funs.insert(GetOddlyield);
    3044           0 : }
    3045           0 : void OpOddlyield::GenSlidingWindowFunction(std::stringstream &ss,
    3046             :           const std::string &sSymName, SubArguments &vSubArguments)
    3047             : {
    3048           0 :     ss << "\ndouble " << sSymName;
    3049           0 :     ss << "_"<< BinFuncName() <<"(";
    3050           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    3051             :     {
    3052           0 :         if (i)
    3053           0 :             ss << ", ";
    3054           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    3055             :     }
    3056           0 :     ss <<") {\n";
    3057           0 :     ss <<"    double tmp = 0;\n";
    3058           0 :     ss <<"    int gid0 = get_global_id(0);\n";
    3059           0 :     ss <<"    double tmp0=0;\n";
    3060           0 :     ss <<"    double tmp1=0;\n";
    3061           0 :     ss <<"    double tmp2=0;\n";
    3062           0 :     ss <<"    double tmp3=0;\n";
    3063           0 :     ss <<"    double tmp4=0;\n";
    3064           0 :     ss <<"    double tmp5=0;\n";
    3065           0 :     ss <<"    double tmp6=0;\n";
    3066           0 :     ss <<"    double tmp7=0;\n";
    3067           0 :     size_t nItems = 0;
    3068           0 :     ss <<"    \n";
    3069           0 :     for (size_t i = 0; i < vSubArguments.size(); i++)
    3070             :     {
    3071           0 :         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
    3072             :         assert(pCur);
    3073           0 :         if (pCur->GetType() == formula::svDoubleVectorRef)
    3074             :         {
    3075             :             const formula::DoubleVectorRefToken* pDVR =
    3076           0 :             static_cast<const formula::DoubleVectorRefToken *>(pCur);
    3077           0 :             size_t nCurWindowSize = pDVR->GetRefRowSize();
    3078           0 :             ss << "    for (int i = ";
    3079           0 :             if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
    3080             : #ifdef  ISNAN
    3081           0 :                 ss << "gid0; i < " << pDVR->GetArrayLength();
    3082           0 :                 ss << " && i < " << nCurWindowSize  << "; i++){\n";
    3083             : #else
    3084             :                 ss << "gid0; i < "<< nCurWindowSize << "; i++)\n";
    3085             : #endif
    3086           0 :             } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
    3087             : #ifdef  ISNAN
    3088           0 :                 ss << "0; i < " << pDVR->GetArrayLength();
    3089           0 :                 ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
    3090             : #else
    3091             :                 ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n";
    3092             : #endif
    3093           0 :             } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
    3094             : #ifdef  ISNAN
    3095           0 :                 ss << "0; i + gid0 < " << pDVR->GetArrayLength();
    3096           0 :                 ss << " &&  i < "<< nCurWindowSize << "; i++){\n";
    3097             : #else
    3098             :                 ss << "0; i < "<< nCurWindowSize << "; i++)\n";
    3099             : #endif
    3100             :             }
    3101             :             else {
    3102             : #ifdef  ISNAN
    3103           0 :                 ss << "0; i < "<< nCurWindowSize << "; i++){\n";
    3104             : #else
    3105             :                 ss << "0; i < "<< nCurWindowSize << "; i++)\n";
    3106             : #endif
    3107             :             }
    3108           0 :             nItems += nCurWindowSize;
    3109             :         }
    3110           0 :         else if (pCur->GetType() == formula::svSingleVectorRef)
    3111             :         {
    3112             : #ifdef  ISNAN
    3113             :             const formula::SingleVectorRefToken* pSVR =
    3114           0 :             static_cast< const formula::SingleVectorRefToken* >(pCur);
    3115           0 :             ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
    3116             : #else
    3117             :             nItems += 1;
    3118             : #endif
    3119             :         }
    3120           0 :         else if (pCur->GetType() == formula::svDouble)
    3121             :         {
    3122             : #ifdef  ISNAN
    3123           0 :             ss << "{\n";
    3124             : #endif
    3125           0 :             nItems += 1;
    3126             :         }
    3127             :         else
    3128             :         {
    3129             : #ifdef  ISNAN
    3130             : #endif
    3131           0 :             nItems += 1;
    3132             :         }
    3133             : #ifdef  ISNAN
    3134           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
    3135             :         {
    3136           0 :             ss << "        if (isNan(";
    3137           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    3138           0 :             ss << "))\n";
    3139           0 :             ss << "            tmp"<<i<<"= 0;\n";
    3140           0 :             ss << "        else\n";
    3141           0 :             ss << "            tmp"<<i<<"=";
    3142           0 :             ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
    3143           0 :             ss << ";\n";
    3144           0 :             ss <<"    }\n";
    3145             :         }
    3146             :         else
    3147             :         {
    3148           0 :             ss << "        tmp"<<i<<"=";
    3149           0 :             ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
    3150           0 :             ss <<";\n";
    3151             :         }
    3152             : #else
    3153             :     ss << "        tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
    3154             :     ss <<";\n";
    3155             : #endif
    3156             :     }
    3157           0 :     ss <<"    int nNullDate = GetNullDate();\n";
    3158           0 :     ss <<"    tmp = GetOddlyield(nNullDate,tmp0,tmp1";
    3159           0 :     ss <<",tmp2,tmp3,tmp4,tmp5,tmp6,tmp7);\n";
    3160           0 :     ss <<"    return tmp;\n";
    3161           0 :     ss <<"}";
    3162           0 : }
    3163           0 : void OpPriceDisc::BinInlineFun(std::set<std::string>& decls,
    3164             :      std::set<std::string>& funs)
    3165             : {
    3166           0 :     decls.insert(GetYearDiffDecl);decls.insert(getDiffDecl);
    3167           0 :     decls.insert(getDaysInYearRangeDecl);decls.insert(GetDaysInYearDecl);
    3168           0 :     decls.insert(GetDaysInYearsDecl);decls.insert(getDaysInMonthRangeDecl);
    3169           0 :     decls.insert(addMonthsDecl);decls.insert(ScaDateDecl);
    3170           0 :     decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
    3171           0 :     decls.insert(DaysToDateDecl);decls.insert(DaysInMonthDecl);
    3172           0 :     decls.insert(IsLeapYearDecl);decls.insert(GetDiffDateDecl);
    3173           0 :     funs.insert(GetYearDiff);funs.insert(getDiff);
    3174           0 :     funs.insert(getDaysInYearRange);funs.insert(GetDaysInYear);
    3175           0 :     funs.insert(GetDaysInYears);funs.insert(getDaysInMonthRange);
    3176           0 :     funs.insert(addMonths);funs.insert(ScaDate);
    3177           0 :     funs.insert(GetNullDate);funs.insert(DateToDays);
    3178           0 :     funs.insert(DaysToDate);funs.insert(DaysInMonth);
    3179           0 :     funs.insert(IsLeapYear);funs.insert(GetDiffDate);
    3180           0 : }
    3181           0 : void OpPriceDisc::GenSlidingWindowFunction(std::stringstream &ss,
    3182             :           const std::string &sSymName, SubArguments &vSubArguments)
    3183             : {
    3184           0 :     ss << "\ndouble " << sSymName;
    3185           0 :     ss << "_"<< BinFuncName() <<"(";
    3186           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    3187             :     {
    3188           0 :         if (i)
    3189           0 :             ss << ", ";
    3190           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    3191             :     }
    3192           0 :     ss << ") {\n";
    3193           0 :     ss << "    double tmp = 0;\n";
    3194           0 :     ss << "    int gid0 = get_global_id(0);\n";
    3195           0 :     ss<<"    double tmp0=0;\n";
    3196           0 :     ss<<"    double tmp1=0;\n";
    3197           0 :     ss<<"    double tmp2=0;\n";
    3198           0 :     ss<<"    double tmp3=0;\n";
    3199           0 :     ss<<"    double tmp4=0;\n";
    3200           0 :     ss <<"    \n";
    3201           0 :     for (size_t i = 0; i < vSubArguments.size(); i++)
    3202             :     {
    3203           0 :         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
    3204             :         assert(pCur);
    3205           0 :         if (pCur->GetType() == formula::svSingleVectorRef)
    3206             :         {
    3207             : #ifdef  ISNAN
    3208             :             const formula::SingleVectorRefToken* pSVR =
    3209           0 :             static_cast< const formula::SingleVectorRefToken* >(pCur);
    3210           0 :             ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
    3211             : #else
    3212             : #endif
    3213             :         }
    3214           0 :         else if (pCur->GetType() == formula::svDouble)
    3215             :         {
    3216             : #ifdef  ISNAN
    3217           0 :             ss << "{\n";
    3218             : #endif
    3219             :         }
    3220             :         else
    3221             :         {
    3222             : #ifdef  ISNAN
    3223             : #endif
    3224             :         }
    3225             : #ifdef  ISNAN
    3226           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
    3227             :         {
    3228           0 :             ss << "        if (isNan(";
    3229           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    3230           0 :             ss << "))\n";
    3231           0 :             ss << "            tmp"<<i<<"= 0;\n";
    3232           0 :             ss << "        else\n";
    3233           0 :             ss << "            tmp"<<i<<"=";
    3234           0 :             ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
    3235           0 :             ss << ";\n";
    3236           0 :             ss <<"    }\n";
    3237             :         }
    3238             :         else
    3239             :         {
    3240           0 :             ss << "        tmp"<<i<<"=";
    3241           0 :             ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
    3242           0 :             ss <<";\n";
    3243             :         }
    3244             : #else
    3245             :     ss << "        tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
    3246             :     ss <<";\n";
    3247             : #endif
    3248             :     }
    3249           0 :     ss <<"    int nNullDate = GetNullDate();\n";
    3250           0 :     ss <<"    tmp=tmp3* ( 1.0 -tmp2*GetYearDiff( nNullDate, ";
    3251           0 :     ss <<"tmp0,tmp1,tmp4));\n";
    3252           0 :     ss <<"    return tmp;\n";
    3253           0 :     ss <<"}";
    3254           0 : }
    3255           0 : void OpNper::GenSlidingWindowFunction(std::stringstream &ss,
    3256             :          const std::string &sSymName, SubArguments &vSubArguments)
    3257             :  {
    3258           0 :     ss << "\ndouble " << sSymName;
    3259           0 :     ss << "_"<< BinFuncName() <<"(";
    3260           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    3261             :     {
    3262           0 :      if (i)
    3263           0 :          ss << ", ";
    3264           0 :      vSubArguments[i]->GenSlidingWindowDecl(ss);
    3265             :     }
    3266           0 :     ss << ") {\n";
    3267           0 :     ss << "    double tmp = 0;\n";
    3268           0 :     ss << "    int gid0 = get_global_id(0);\n";
    3269           0 :     ss <<"    double tmp0=0;\n";
    3270           0 :     ss <<"    double tmp1=0;\n";
    3271           0 :     ss <<"    double tmp2=0;\n";
    3272           0 :     ss <<"    double tmp3=0;\n";
    3273           0 :     ss <<"    double tmp4=0;\n";
    3274           0 :     size_t nItems = 0;
    3275           0 :     for (size_t i = 0; i < vSubArguments.size(); i++)
    3276             :     {
    3277           0 :         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
    3278             :         assert(pCur);
    3279           0 :         if (pCur->GetType() == formula::svSingleVectorRef)
    3280             :         {
    3281             : #ifdef  ISNAN
    3282             :             const formula::SingleVectorRefToken* pSVR =
    3283           0 :             static_cast< const formula::SingleVectorRefToken* >(pCur);
    3284           0 :             ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
    3285             : #else
    3286             :             nItems += 1;
    3287             : #endif
    3288             :         }
    3289           0 :         else if (pCur->GetType() == formula::svDouble)
    3290             :         {
    3291             : #ifdef  ISNAN
    3292           0 :             ss << "{\n";
    3293             : #endif
    3294           0 :             nItems += 1;
    3295             :         }
    3296             :         else
    3297             :         {
    3298             : #ifdef  ISNAN
    3299             : #endif
    3300           0 :             nItems += 1;
    3301             :         }
    3302             : #ifdef  ISNAN
    3303           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
    3304             :         {
    3305           0 :             ss << "        if (isNan(";
    3306           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    3307           0 :             ss << "))\n";
    3308           0 :             ss << "            tmp"<<i<<"= 0;\n";
    3309           0 :             ss << "        else\n";
    3310           0 :             ss << "            tmp"<<i<<"=";
    3311           0 :             ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
    3312           0 :             ss << ";\n";
    3313           0 :             ss <<"    }\n";
    3314             :         }
    3315             :         else
    3316             :         {
    3317           0 :             ss << "        tmp"<<i<<"=";
    3318           0 :             ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
    3319           0 :             ss <<";\n";
    3320             :         }
    3321             : #else
    3322             :     ss << "        tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
    3323             :     ss <<";\n";
    3324             : #endif
    3325             :     }
    3326           0 :     ss <<"    if (tmp0 == 0.0)\n";
    3327           0 :     ss <<"        tmp=(-1*(tmp2 + tmp3)/tmp1);\n";
    3328           0 :     ss <<"    else if (tmp4 > 0.0)\n";
    3329           0 :     ss <<"        tmp=log(-1*(tmp0*tmp3-tmp1*(1.0+tmp0))*";
    3330           0 :     ss <<"pow((tmp0*tmp2+tmp1*(1.0+tmp0)),-1))/log(1.0+tmp0);\n";
    3331           0 :     ss <<"    else\n";
    3332           0 :     ss <<"        tmp=log(-1*(tmp0*tmp3-tmp1)*pow(tmp0*tmp2+tmp1,-1))";
    3333           0 :     ss <<"/log(1.0+tmp0);\n";
    3334           0 :     ss <<"    return tmp;\n";
    3335           0 :     ss <<"}";
    3336           0 :  }
    3337             : 
    3338           0 : void OpPPMT::BinInlineFun(std::set<std::string>& decls,
    3339             :         std::set<std::string>& funs)
    3340             : {
    3341           0 :     decls.insert(GetZwDecl);
    3342           0 :     funs.insert(GetZw);
    3343           0 : }
    3344             : 
    3345           0 : void OpPPMT::GenSlidingWindowFunction(std::stringstream &ss,
    3346             :         const std::string &sSymName, SubArguments &vSubArguments)
    3347             : {
    3348           0 :     ss << "\ndouble " << sSymName;
    3349           0 :     ss << "_"<< BinFuncName() <<"(";
    3350           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    3351             :     {
    3352           0 :         if (i)
    3353           0 :             ss << ", ";
    3354           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    3355             :     }
    3356           0 :     ss<<") {\n";
    3357           0 :     ss<<"    double tmp = 0;\n";
    3358           0 :     ss<<"    int gid0 = get_global_id(0);\n";
    3359           0 :     ss<<"    double arg=0;\n";
    3360           0 :     ss<<"    double tmp0=0;\n";
    3361           0 :     ss<<"    double tmp1=0;\n";
    3362           0 :     ss<<"    double tmp2=0;\n";
    3363           0 :     ss<<"    double tmp3=0;\n";
    3364           0 :     ss<<"    double tmp4=0,tmp5=0;\n";
    3365           0 :     ss <<"\n    ";
    3366             :     //while (i-- > 1)
    3367           0 :     for (size_t i = 0; i < vSubArguments.size(); i++)
    3368             :     {
    3369           0 :         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
    3370             :         assert(pCur);
    3371           0 :         if (pCur->GetType() == formula::svSingleVectorRef)
    3372             :         {
    3373             : #ifdef  ISNAN
    3374             :             const formula::SingleVectorRefToken* pSVR =
    3375           0 :                 static_cast< const formula::SingleVectorRefToken* >(pCur);
    3376           0 :             ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
    3377             : #else
    3378             : #endif
    3379             :         }
    3380           0 :         else if (pCur->GetType() == formula::svDouble)
    3381             :         {
    3382             : #ifdef  ISNAN
    3383           0 :             ss << "{\n";
    3384             : #endif
    3385             :         }
    3386             :         else
    3387             :         {
    3388             : #ifdef  ISNAN
    3389             : #endif
    3390             :         }
    3391             : #ifdef  ISNAN
    3392           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
    3393             :         {
    3394           0 :             ss << "        arg=";
    3395           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    3396           0 :             ss << ";\n";
    3397           0 :             ss << "        if (isNan(arg))\n";
    3398           0 :             ss << "            tmp"<<i<<"= 0;\n";
    3399           0 :             ss << "        else\n";
    3400           0 :             ss << "            tmp"<<i<<"=arg;\n";
    3401           0 :             ss << "    }\n";
    3402             :         }
    3403             :         else
    3404             :         {
    3405           0 :             ss<<"    tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
    3406           0 :             ss<<";\n";
    3407             :         }
    3408             : #else
    3409             :         ss<<"tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
    3410             :         ss<<";\n";
    3411             : #endif
    3412             :     }
    3413           0 :     ss<<"    double pmt=0 ;\n";
    3414           0 :     ss<<"    if(tmp0==0.0)\n";
    3415           0 :     ss<<"        return -(tmp3+tmp4)/tmp2;\n";
    3416           0 :     ss<<"    pmt=pmt-tmp4-tmp3*pow(1.0+tmp0,tmp2);\n";
    3417           0 :     ss<<"    pmt=pmt*pow(( (1.0+tmp0*tmp5)* ";
    3418           0 :     ss<<"( (pow(1.0+tmp0,tmp2)-1.0)/tmp0)),-1);\n";
    3419           0 :     ss<<"    double temp = pow( 1+tmp0,tmp1-2);\n";
    3420           0 :     ss<<"    double re;\n";
    3421           0 :     ss<<"    if(tmp1==1.0){\n";
    3422           0 :     ss<<"        if(tmp5>0.0)\n";
    3423           0 :     ss<<"            re=0.0;\n";
    3424           0 :     ss<<"        else\n";
    3425           0 :     ss<<"            re=-tmp3;\n";
    3426           0 :     ss<<"    }\n";
    3427           0 :     ss<<"    else\n";
    3428           0 :     ss<<"    {\n";
    3429           0 :     ss<<"        if(tmp5>0.0)\n    ";
    3430           0 :     ss<<"            re=GetZw(tmp0, tmp1-2.0, pmt, tmp3, 1.0) - pmt;\n";
    3431           0 :     ss<<"        else\n";
    3432           0 :     ss<<"            re=GetZw(tmp0, tmp1-1.0, pmt, tmp3, 0.0);\n";
    3433           0 :     ss<<"    }\n    ";
    3434           0 :     ss<<"    re = re * tmp0;\n";
    3435           0 :     ss<<"    tmp = pmt - re;\n";
    3436           0 :     ss<<"    return tmp;\n";
    3437           0 :     ss<<"}";
    3438           0 : }
    3439             : 
    3440           0 : void OpCoupdaybs::BinInlineFun(std::set<std::string>& decls,
    3441             :     std::set<std::string>& funs)
    3442             : {
    3443           0 :     decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
    3444           0 :     decls.insert(DaysToDateDecl); decls.insert(DateToDays_newDecl);
    3445           0 :     decls.insert(GetNullDate_newDecl); decls.insert(ScaDateDecl);
    3446           0 :     decls.insert(addMonthsDecl); decls.insert(getDaysInMonthRangeDecl);
    3447           0 :     decls.insert(GetDaysInYearsDecl);
    3448           0 :     decls.insert(getDaysInYearRangeDecl); decls.insert(getDiffDecl);
    3449           0 :     decls.insert(setDayDecl);decls.insert(checklessthanDecl);
    3450           0 :     decls.insert(lcl_Getcoupdaybs_newDecl);
    3451           0 :     decls.insert(coupdaybs_newDecl);
    3452           0 :     funs.insert(IsLeapYear);funs.insert(DaysInMonth);
    3453           0 :     funs.insert(DaysToDate);funs.insert(DateToDays_new);
    3454           0 :     funs.insert(GetNullDate_new);funs.insert(ScaDate);
    3455           0 :     funs.insert(addMonths);funs.insert(getDaysInMonthRange);
    3456           0 :     funs.insert(GetDaysInYears);
    3457           0 :     funs.insert(getDaysInYearRange);funs.insert(getDiff);
    3458           0 :     funs.insert(setDay);funs.insert(checklessthan);
    3459           0 :     funs.insert(lcl_Getcoupdaybs_new);
    3460           0 :     funs.insert(coupdaybs_new);
    3461           0 : }
    3462           0 : void OpCoupdaybs::GenSlidingWindowFunction(
    3463             :     std::stringstream &ss, const std::string &sSymName, SubArguments &
    3464             : vSubArguments)
    3465             : {
    3466           0 :     ss << "\ndouble " << sSymName;
    3467           0 :     ss << "_"<< BinFuncName() <<"(";
    3468           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    3469             :     {
    3470           0 :         if (i)
    3471           0 :             ss << ",";
    3472           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    3473             :     }
    3474           0 :     ss << ") {\n";
    3475           0 :     ss << "    double tmp = 0;\n";
    3476           0 :     ss << "    int gid0 = get_global_id(0);\n";
    3477           0 :     ss << "    int nSettle,nMat,nFreq,nBase;\n";
    3478             : #ifdef ISNAN
    3479           0 :     FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
    3480           0 :     FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
    3481           0 :     FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
    3482           0 :     FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
    3483             : #endif
    3484             : #ifdef ISNAN
    3485           0 :     if(tmpCur0->GetType() == formula::svSingleVectorRef)
    3486             :     {
    3487             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    3488           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    3489           0 :     ss <<"    if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
    3490           0 :     ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
    3491           0 :     ss <<"        nSettle = 0;\n    else\n";
    3492             :     }
    3493             : #endif
    3494           0 :     ss <<"        nSettle=(int)";
    3495           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    3496           0 :     ss <<";\n";
    3497             : #ifdef ISNAN
    3498           0 :     if(tmpCur1->GetType() == formula::svSingleVectorRef)
    3499             :     {
    3500             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    3501           0 :         formula::SingleVectorRefToken *>(tmpCur1);
    3502           0 :     ss <<"    if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
    3503           0 :     ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
    3504           0 :     ss <<"        nMat = 0;\n    else\n";
    3505             :     }
    3506             : #endif
    3507           0 :     ss <<"        nMat=(int)";
    3508           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    3509           0 :     ss <<";\n";
    3510             : #ifdef ISNAN
    3511           0 :     if(tmpCur2->GetType() == formula::svSingleVectorRef)
    3512             :     {
    3513             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    3514           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    3515           0 :     ss <<"    if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
    3516           0 :     ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
    3517           0 :     ss <<"        nFreq = 0;\n    else\n";
    3518             :     }
    3519             : #endif
    3520           0 :     ss << "        nFreq=(int)";
    3521           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    3522           0 :     ss <<";\n";
    3523             : #ifdef ISNAN
    3524           0 :     if(tmpCur3->GetType() == formula::svSingleVectorRef)
    3525             :     {
    3526             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    3527           0 :         formula::SingleVectorRefToken *>(tmpCur3);
    3528           0 :     ss <<"    if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
    3529           0 :     ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
    3530           0 :     ss <<"        nBase = 0;\n    else\n";
    3531             :     }
    3532             : #endif
    3533           0 :     ss << "        nBase=(int)";
    3534           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    3535           0 :     ss << ";\n";
    3536           0 :     ss <<"    tmp = coupdaybs_new(nSettle,nMat,nFreq,nBase);\n";
    3537           0 :     ss <<"    return tmp;\n";
    3538           0 :     ss <<"}";
    3539           0 : }
    3540             : 
    3541           0 : void OpCoupdays::BinInlineFun(std::set<std::string>& decls,
    3542             :     std::set<std::string>& funs)
    3543             : {
    3544           0 :     decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
    3545           0 :     decls.insert(DaysToDateDecl); decls.insert(DateToDays_newDecl);
    3546           0 :     decls.insert(GetNullDate_newDecl); decls.insert(ScaDateDecl);
    3547           0 :     decls.insert(addMonthsDecl); decls.insert(getDaysInMonthRangeDecl);
    3548           0 :     decls.insert(GetDaysInYearsDecl); decls.insert(GetDaysInYearDecl);
    3549           0 :     decls.insert(getDaysInYearRangeDecl); decls.insert(getDiffDecl);
    3550           0 :     decls.insert(setDayDecl);decls.insert(checklessthanDecl);
    3551           0 :     decls.insert(lcl_Getcoupdays_newDecl);
    3552           0 :     decls.insert(coupdays_newDecl);
    3553           0 :     funs.insert(IsLeapYear);funs.insert(DaysInMonth);
    3554           0 :     funs.insert(DaysToDate);funs.insert(DateToDays_new);
    3555           0 :     funs.insert(GetNullDate_new);funs.insert(ScaDate);
    3556           0 :     funs.insert(addMonths);funs.insert(getDaysInMonthRange);
    3557           0 :     funs.insert(GetDaysInYears);funs.insert(GetDaysInYear);
    3558           0 :     funs.insert(getDaysInYearRange);funs.insert(getDiff);
    3559           0 :     funs.insert(lcl_Getcoupdays_new);
    3560           0 :     funs.insert(setDay);funs.insert(checklessthan);
    3561           0 :     funs.insert(coupdays_new);
    3562           0 : }
    3563           0 : void OpCoupdays::GenSlidingWindowFunction(
    3564             :     std::stringstream &ss, const std::string &sSymName, SubArguments &
    3565             : vSubArguments)
    3566             : {
    3567           0 :     ss << "\ndouble " << sSymName;
    3568           0 :     ss << "_"<< BinFuncName() <<"(";
    3569           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    3570             :     {
    3571           0 :       if (i)
    3572           0 :           ss << ",";
    3573           0 :       vSubArguments[i]->GenSlidingWindowDecl(ss);
    3574             :     }
    3575           0 :     ss << ") {\n";
    3576           0 :     ss << "    double tmp = 0;\n";
    3577           0 :     ss << "    int gid0 = get_global_id(0);\n";
    3578           0 :     ss << "    int nSettle,nMat,nFreq,nBase;\n";
    3579             : #ifdef ISNAN
    3580           0 :     FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
    3581           0 :     FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
    3582           0 :     FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
    3583           0 :     FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
    3584             : #endif
    3585             : #ifdef ISNAN
    3586           0 :     if(tmpCur0->GetType() == formula::svSingleVectorRef)
    3587             :     {
    3588             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    3589           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    3590           0 :     ss <<"    if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
    3591           0 :     ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
    3592           0 :     ss <<"        nSettle = 0;\n    else\n";
    3593             :     }
    3594             : #endif
    3595           0 :     ss <<"        nSettle=(int)";
    3596           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    3597           0 :     ss <<";\n";
    3598             : #ifdef ISNAN
    3599           0 :     if(tmpCur1->GetType() == formula::svSingleVectorRef)
    3600             :     {
    3601             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    3602           0 :         formula::SingleVectorRefToken *>(tmpCur1);
    3603           0 :     ss <<"    if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
    3604           0 :     ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
    3605           0 :     ss <<"        nMat = 0;\n    else\n";
    3606             :     }
    3607             : #endif
    3608           0 :     ss <<"        nMat=(int)";
    3609           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    3610           0 :     ss <<";\n";
    3611             : #ifdef ISNAN
    3612           0 :     if(tmpCur2->GetType() == formula::svSingleVectorRef)
    3613             :     {
    3614             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    3615           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    3616           0 :     ss <<"    if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
    3617           0 :     ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
    3618           0 :     ss <<"        nFreq = 0;\n    else\n";
    3619             :     }
    3620             : #endif
    3621           0 :     ss << "        nFreq=(int)";
    3622           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    3623           0 :     ss <<";\n";
    3624             : #ifdef ISNAN
    3625           0 :     if(tmpCur3->GetType() == formula::svSingleVectorRef)
    3626             :     {
    3627             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    3628           0 :         formula::SingleVectorRefToken *>(tmpCur3);
    3629           0 :     ss <<"    if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
    3630           0 :     ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
    3631           0 :     ss <<"        nBase = 0;\n    else\n";
    3632             :     }
    3633             : #endif
    3634           0 :     ss << "        nBase=(int)";
    3635           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    3636           0 :     ss << ";\n";
    3637           0 :     ss <<"    tmp = coupdays_new(nSettle,nMat,nFreq,nBase);\n";
    3638           0 :     ss <<"    return tmp;\n";
    3639           0 :     ss << "}";
    3640           0 : }
    3641           0 : void OpCouppcd::BinInlineFun(std::set<std::string>& decls,
    3642             :     std::set<std::string>& funs)
    3643             : {
    3644           0 :     decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
    3645           0 :     decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
    3646           0 :     decls.insert(GetNullDateDecl);
    3647           0 :     decls.insert(ScaDateDecl);
    3648           0 :     decls.insert(addMonthsDecl);
    3649           0 :     decls.insert(setDayDecl);decls.insert(checklessthanDecl);
    3650           0 :     decls.insert(lcl_GetCouppcdDecl);
    3651           0 :     funs.insert(IsLeapYear);funs.insert(DaysInMonth);
    3652           0 :     funs.insert(DaysToDate);funs.insert(DateToDays);
    3653           0 :     funs.insert(GetNullDate);
    3654           0 :     funs.insert(ScaDate);
    3655           0 :     funs.insert(addMonths);
    3656           0 :     funs.insert(setDay);funs.insert(checklessthan);
    3657           0 :     funs.insert(lcl_GetCouppcd);
    3658           0 : }
    3659           0 : void OpCouppcd::GenSlidingWindowFunction(
    3660             :     std::stringstream &ss, const std::string &sSymName,
    3661             :     SubArguments &vSubArguments)
    3662             : {
    3663           0 :     ss << "\ndouble " << sSymName;
    3664           0 :     ss << "_"<< BinFuncName() <<"(";
    3665           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    3666             :     {
    3667           0 :       if (i)
    3668           0 :           ss << ",";
    3669           0 :       vSubArguments[i]->GenSlidingWindowDecl(ss);
    3670             :     }
    3671           0 :     ss << ") {\n";
    3672           0 :     ss << "    double tmp = 0;\n";
    3673           0 :     ss << "    int gid0 = get_global_id(0);\n";
    3674           0 :     ss << "    int nSettle,nMat,nFreq,nBase;\n";
    3675             : #ifdef ISNAN
    3676           0 :     FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
    3677           0 :     FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
    3678           0 :     FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
    3679           0 :     FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
    3680             : #endif
    3681             : #ifdef ISNAN
    3682           0 :     if(tmpCur0->GetType() == formula::svSingleVectorRef)
    3683             :     {
    3684             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    3685           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    3686           0 :     ss <<"    if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
    3687           0 :     ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
    3688           0 :     ss <<"        nSettle = 0;\n    else\n";
    3689             :     }
    3690             : #endif
    3691           0 :     ss <<"        nSettle=(int)";
    3692           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    3693           0 :     ss <<";\n";
    3694             : #ifdef ISNAN
    3695           0 :     if(tmpCur1->GetType() == formula::svSingleVectorRef)
    3696             :     {
    3697             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    3698           0 :         formula::SingleVectorRefToken *>(tmpCur1);
    3699           0 :     ss <<"    if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
    3700           0 :     ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
    3701           0 :     ss <<"        nMat = 0;\n    else\n";
    3702             :     }
    3703             : #endif
    3704           0 :     ss <<"        nMat=(int)";
    3705           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    3706           0 :     ss <<";\n";
    3707             : #ifdef ISNAN
    3708           0 :     if(tmpCur2->GetType() == formula::svSingleVectorRef)
    3709             :     {
    3710             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    3711           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    3712           0 :     ss <<"    if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
    3713           0 :     ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
    3714           0 :     ss <<"        nFreq = 0;\n    else\n";
    3715             :     }
    3716             : #endif
    3717           0 :     ss << "        nFreq=(int)";
    3718           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    3719           0 :     ss <<";\n";
    3720             : #ifdef ISNAN
    3721           0 :     if(tmpCur3->GetType() == formula::svSingleVectorRef)
    3722             :     {
    3723             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    3724           0 :         formula::SingleVectorRefToken *>(tmpCur3);
    3725           0 :     ss <<"    if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
    3726           0 :     ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
    3727           0 :     ss <<"        nBase = 0;\n    else\n";
    3728             :     }
    3729             : #endif
    3730           0 :     ss << "        nBase=(int)";
    3731           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    3732           0 :     ss << ";\n";
    3733           0 :     ss <<"    int nNullDate=693594;\n";
    3734           0 :     ss <<"    tmp = lcl_GetCouppcd(nNullDate,nSettle,nMat,nFreq,nBase);\n";
    3735           0 :     ss <<"    return tmp;\n";
    3736           0 :     ss <<"}";
    3737           0 : }
    3738           0 : void OpCoupncd::BinInlineFun(std::set<std::string>& decls,
    3739             :     std::set<std::string>& funs)
    3740             : {
    3741           0 :     decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
    3742           0 :     decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
    3743           0 :     decls.insert(GetNullDateDecl);
    3744           0 :     decls.insert(ScaDateDecl);
    3745           0 :     decls.insert(addMonthsDecl);
    3746           0 :     decls.insert(setDayDecl);decls.insert(checklessthanDecl);
    3747           0 :     decls.insert(lcl_GetCoupncdDecl);
    3748           0 :     funs.insert(IsLeapYear);funs.insert(DaysInMonth);
    3749           0 :     funs.insert(DaysToDate);funs.insert(DateToDays);
    3750           0 :     funs.insert(GetNullDate);
    3751           0 :     funs.insert(ScaDate);
    3752           0 :     funs.insert(addMonths);
    3753           0 :     funs.insert(setDay);funs.insert(checklessthan);
    3754           0 :     funs.insert(lcl_GetCoupncd);
    3755           0 : }
    3756           0 : void OpCoupncd::GenSlidingWindowFunction(
    3757             :     std::stringstream &ss, const std::string &sSymName, SubArguments &
    3758             : vSubArguments)
    3759             : {
    3760           0 :     ss << "\ndouble " << sSymName;
    3761           0 :     ss << "_"<< BinFuncName() <<"(";
    3762           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    3763             :     {
    3764           0 :       if (i)
    3765           0 :           ss << ",";
    3766           0 :       vSubArguments[i]->GenSlidingWindowDecl(ss);
    3767             :     }
    3768           0 :     ss << ") {\n";
    3769           0 :     ss << "    double tmp = 0;\n";
    3770           0 :     ss << "    int gid0 = get_global_id(0);\n";
    3771           0 :     ss << "    int nSettle,nMat,nFreq,nBase;\n";
    3772             : #ifdef ISNAN
    3773           0 :     FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
    3774           0 :     FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
    3775           0 :     FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
    3776           0 :     FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
    3777             : #endif
    3778             : #ifdef ISNAN
    3779           0 :     if(tmpCur0->GetType() == formula::svSingleVectorRef)
    3780             :     {
    3781             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    3782           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    3783           0 :     ss <<"    if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
    3784           0 :     ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
    3785           0 :     ss <<"        nSettle = 0;\n    else\n";
    3786             :     }
    3787             : #endif
    3788           0 :     ss <<"        nSettle=(int)";
    3789           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    3790           0 :     ss <<";\n";
    3791             : #ifdef ISNAN
    3792           0 :     if(tmpCur1->GetType() == formula::svSingleVectorRef)
    3793             :     {
    3794             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    3795           0 :         formula::SingleVectorRefToken *>(tmpCur1);
    3796           0 :     ss <<"    if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
    3797           0 :     ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
    3798           0 :     ss <<"        nMat = 0;\n    else\n";
    3799             :     }
    3800             : #endif
    3801           0 :     ss <<"        nMat=(int)";
    3802           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    3803           0 :     ss <<";\n";
    3804             : #ifdef ISNAN
    3805           0 :     if(tmpCur2->GetType() == formula::svSingleVectorRef)
    3806             :     {
    3807             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    3808           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    3809           0 :     ss <<"    if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
    3810           0 :     ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
    3811           0 :     ss <<"        nFreq = 0;\n    else\n";
    3812             :     }
    3813             : #endif
    3814           0 :     ss << "        nFreq=(int)";
    3815           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    3816           0 :     ss <<";\n";
    3817             : #ifdef ISNAN
    3818           0 :     if(tmpCur3->GetType() == formula::svSingleVectorRef)
    3819             :     {
    3820             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    3821           0 :         formula::SingleVectorRefToken *>(tmpCur3);
    3822           0 :     ss <<"    if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
    3823           0 :     ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
    3824           0 :     ss <<"        nBase = 0;\n    else\n";
    3825             :     }
    3826             : #endif
    3827           0 :     ss << "        nBase=(int)";
    3828           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    3829           0 :     ss << ";\n";
    3830           0 :     ss <<"    int nNullDate=693594;\n";
    3831           0 :     ss <<"    tmp = lcl_GetCoupncd(nNullDate,nSettle,nMat,nFreq,nBase);\n";
    3832           0 :     ss <<"    return tmp;\n";
    3833           0 :     ss <<"}";
    3834           0 : }
    3835             : 
    3836           0 : void OpCoupdaysnc::BinInlineFun(std::set<std::string>& decls,
    3837             :     std::set<std::string>& funs)
    3838             : {
    3839           0 :     decls.insert(IsLeapYearDecl); decls.insert(DaysInMonth_newDecl);
    3840           0 :     decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
    3841           0 :     decls.insert(DateToDays_newDecl);
    3842           0 :     decls.insert(ScaDateDecl);
    3843           0 :     decls.insert(addMonthsDecl); decls.insert(getDaysInMonthRangeDecl);
    3844           0 :     decls.insert(GetDaysInYearsDecl); decls.insert(GetDaysInYearDecl);
    3845           0 :     decls.insert(getDaysInYearRangeDecl); decls.insert(getDiffDecl);
    3846           0 :     decls.insert(setDayDecl);decls.insert(checklessthanDecl);
    3847           0 :     decls.insert(coupdaybs_newDecl);
    3848           0 :     decls.insert(lcl_Getcoupdays_newDecl);
    3849           0 :     decls.insert(lcl_Getcoupdaybs_newDecl);
    3850           0 :     decls.insert(coupdays_newDecl);
    3851           0 :     decls.insert(coupdaysnc_newDecl);
    3852           0 :     funs.insert(IsLeapYear);funs.insert(DaysInMonth_new);
    3853           0 :     funs.insert(DaysToDate);funs.insert(DateToDays_new);
    3854           0 :     funs.insert(DateToDays);
    3855           0 :     funs.insert(ScaDate);
    3856           0 :     funs.insert(addMonths);funs.insert(getDaysInMonthRange);
    3857           0 :     funs.insert(GetDaysInYears);funs.insert(GetDaysInYear);
    3858           0 :     funs.insert(getDaysInYearRange);funs.insert(getDiff);
    3859           0 :     funs.insert(setDay);funs.insert(checklessthan);
    3860           0 :     funs.insert(lcl_Getcoupdaybs_new);
    3861           0 :     funs.insert(coupdaybs_new);
    3862           0 :     funs.insert(lcl_Getcoupdays_new);
    3863           0 :     funs.insert(coupdaysnc_new);
    3864           0 :     funs.insert(coupdays_new);
    3865           0 : }
    3866           0 : void OpCoupdaysnc::GenSlidingWindowFunction(
    3867             :     std::stringstream &ss, const std::string &sSymName,
    3868             :     SubArguments &vSubArguments)
    3869             : {
    3870           0 :     ss << "\ndouble " << sSymName;
    3871           0 :     ss << "_"<< BinFuncName() <<"(";
    3872           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    3873             :     {
    3874           0 :       if (i)
    3875           0 :           ss << ",";
    3876           0 :       vSubArguments[i]->GenSlidingWindowDecl(ss);
    3877             :     }
    3878           0 :     ss << ") {\n";
    3879           0 :     ss << "    double tmp = 0;\n";
    3880           0 :     ss << "    int gid0 = get_global_id(0);\n";
    3881           0 :     ss << "    int nSettle,nMat,nFreq,nBase;\n";
    3882             : #ifdef ISNAN
    3883           0 :     FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
    3884           0 :     FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
    3885           0 :     FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
    3886           0 :     FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
    3887             : #endif
    3888             : #ifdef ISNAN
    3889           0 :     if(tmpCur0->GetType() == formula::svSingleVectorRef)
    3890             :     {
    3891             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    3892           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    3893           0 :     ss <<"    if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
    3894           0 :     ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
    3895           0 :     ss <<"        nSettle = 0;\n    else\n";
    3896             :     }
    3897             : #endif
    3898           0 :     ss <<"        nSettle=(int)";
    3899           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    3900           0 :     ss <<";\n";
    3901             : #ifdef ISNAN
    3902           0 :     if(tmpCur1->GetType() == formula::svSingleVectorRef)
    3903             :     {
    3904             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    3905           0 :         formula::SingleVectorRefToken *>(tmpCur1);
    3906           0 :     ss <<"    if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
    3907           0 :     ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
    3908           0 :     ss <<"        nMat = 0;\n    else\n";
    3909             :     }
    3910             : #endif
    3911           0 :     ss <<"        nMat=(int)";
    3912           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    3913           0 :     ss <<";\n";
    3914             : #ifdef ISNAN
    3915           0 :     if(tmpCur2->GetType() == formula::svSingleVectorRef)
    3916             :     {
    3917             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    3918           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    3919           0 :     ss <<"    if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
    3920           0 :     ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
    3921           0 :     ss <<"        nFreq = 0;\n    else\n";
    3922             :     }
    3923             : #endif
    3924           0 :     ss << "        nFreq=(int)";
    3925           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    3926           0 :     ss <<";\n";
    3927             : #ifdef ISNAN
    3928           0 :     if(tmpCur3->GetType() == formula::svSingleVectorRef)
    3929             :     {
    3930             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    3931           0 :         formula::SingleVectorRefToken *>(tmpCur3);
    3932           0 :     ss <<"    if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
    3933           0 :     ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
    3934           0 :     ss <<"        nBase = 0;\n    else\n";
    3935             :     }
    3936             : #endif
    3937           0 :     ss << "        nBase=(int)";
    3938           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    3939           0 :     ss << ";\n";
    3940           0 :     ss <<"    tmp = coupdaysnc_new(nSettle,nMat,nFreq,nBase);\n";
    3941           0 :     ss <<"    return tmp;\n";
    3942           0 :     ss << "}";
    3943           0 : }
    3944             : 
    3945           0 : void OpCoupnum::BinInlineFun(std::set<std::string>& decls,
    3946             :     std::set<std::string>& funs)
    3947             : {
    3948           0 :     decls.insert(IsLeapYearDecl);decls.insert(DaysInMonthDecl);
    3949           0 :     decls.insert(DaysToDateDecl);
    3950           0 :     decls.insert(DateToDaysDecl);
    3951           0 :     decls.insert(ScaDateDecl);
    3952           0 :     decls.insert(setDayDecl);decls.insert(checklessthanDecl);
    3953           0 :     decls.insert(addMonthsDecl);decls.insert(lcl_Getcoupnum_newDecl);
    3954           0 :     decls.insert(coupnum_newDecl);
    3955           0 :     funs.insert(IsLeapYear);funs.insert(DaysInMonth_new);
    3956           0 :     funs.insert(DaysToDate);
    3957           0 :     funs.insert(DateToDays);
    3958           0 :     funs.insert(ScaDate);
    3959           0 :     funs.insert(setDay);funs.insert(checklessthan);
    3960           0 :     funs.insert(addMonths);funs.insert(lcl_Getcoupnum_new);
    3961           0 :     funs.insert(coupnum_new);
    3962           0 : }
    3963           0 : void OpCoupnum::GenSlidingWindowFunction(std::stringstream &ss,
    3964             :         const std::string &sSymName, SubArguments &vSubArguments)
    3965             : {
    3966           0 :     ss << "\ndouble " << sSymName;
    3967           0 :     ss << "_"<< BinFuncName() <<"(";
    3968           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    3969             :     {
    3970           0 :       if (i)
    3971           0 :           ss << ",";
    3972           0 :       vSubArguments[i]->GenSlidingWindowDecl(ss);
    3973             :     }
    3974           0 :     ss << ") {\n";
    3975           0 :     ss << "    double tmp = 0;\n";
    3976           0 :     ss << "    int gid0 = get_global_id(0);\n";
    3977           0 :     ss << "    int nSettle,nMat,nFreq,nBase;\n";
    3978             : #ifdef ISNAN
    3979           0 :     FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
    3980           0 :     FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
    3981           0 :     FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
    3982           0 :     FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
    3983             : #endif
    3984             : #ifdef ISNAN
    3985           0 :     if(tmpCur0->GetType() == formula::svSingleVectorRef)
    3986             :     {
    3987             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    3988           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    3989           0 :     ss <<"    if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
    3990           0 :     ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
    3991           0 :     ss <<"        nSettle = 0;\n    else\n";
    3992             :     }
    3993             : #endif
    3994           0 :     ss <<"        nSettle=(int)";
    3995           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    3996           0 :     ss <<";\n";
    3997             : #ifdef ISNAN
    3998           0 :     if(tmpCur1->GetType() == formula::svSingleVectorRef)
    3999             :     {
    4000             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    4001           0 :         formula::SingleVectorRefToken *>(tmpCur1);
    4002           0 :     ss <<"    if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
    4003           0 :     ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
    4004           0 :     ss <<"        nMat = 0;\n    else\n";
    4005             :     }
    4006             : #endif
    4007           0 :     ss <<"        nMat=(int)";
    4008           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    4009           0 :     ss <<";\n";
    4010             : #ifdef ISNAN
    4011           0 :     if(tmpCur2->GetType() == formula::svSingleVectorRef)
    4012             :     {
    4013             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    4014           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    4015           0 :     ss <<"    if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
    4016           0 :     ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
    4017           0 :     ss <<"        nFreq = 0;\n    else\n";
    4018             :     }
    4019             : #endif
    4020           0 :     ss << "        nFreq=(int)";
    4021           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    4022           0 :     ss <<";\n";
    4023             : #ifdef ISNAN
    4024           0 :     if(tmpCur3->GetType() == formula::svSingleVectorRef)
    4025             :     {
    4026             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    4027           0 :         formula::SingleVectorRefToken *>(tmpCur3);
    4028           0 :     ss <<"    if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
    4029           0 :     ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
    4030           0 :     ss <<"        nBase = 0;\n    else\n";
    4031             :     }
    4032             : #endif
    4033           0 :     ss << "        nBase=(int)";
    4034           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    4035           0 :     ss << ";\n";
    4036           0 :     ss <<"    tmp = coupnum_new(nSettle,nMat,nFreq,nBase);\n";
    4037           0 :     ss <<"    return tmp;\n";
    4038           0 :     ss << "}";
    4039           0 : }
    4040           0 : void OpAmordegrc::BinInlineFun(std::set<std::string>& decls,
    4041             :     std::set<std::string>& funs)
    4042             : {
    4043           0 :     decls.insert(nKorrValDecl); decls.insert(RoundDecl);
    4044           0 :     decls.insert(IsLeapYearDecl);decls.insert(DaysInMonthDecl);
    4045           0 :     decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
    4046           0 :     decls.insert(GetNullDateDecl); decls.insert(GetYearFracDecl);
    4047           0 :     funs.insert(Round);
    4048           0 :     funs.insert(IsLeapYear);funs.insert(DaysInMonth);
    4049           0 :     funs.insert(DaysToDate);funs.insert(DateToDays);
    4050           0 :     funs.insert(GetNullDate);funs.insert(GetYearFrac);
    4051           0 : }
    4052           0 : void OpAmordegrc::GenSlidingWindowFunction(std::stringstream &ss,
    4053             :             const std::string &sSymName, SubArguments &vSubArguments)
    4054             : {
    4055           0 :     ss << "\ndouble " << sSymName;
    4056           0 :     ss << "_"<< BinFuncName() <<"(";
    4057           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    4058             :     {
    4059           0 :       if (i)
    4060           0 :         ss << ",";
    4061           0 :       vSubArguments[i]->GenSlidingWindowDecl(ss);
    4062             :     }
    4063           0 :     ss << ") {\n    ";
    4064           0 :     ss << "int gid0 = get_global_id(0);\n";
    4065           0 :     ss << "    double tmp = " << GetBottom() <<";\n";
    4066           0 :     ss << "    double fCost,fRestVal,fPer,fRate;\n";
    4067           0 :     ss << "    int nDate,nFirstPer,nBase;\n";
    4068             : #ifdef ISNAN
    4069           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    4070           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    4071           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
    4072           0 :     FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
    4073           0 :     FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
    4074           0 :     FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
    4075           0 :     FormulaToken *tmpCur6 = vSubArguments[6]->GetFormulaToken();
    4076             : #endif
    4077             : #ifdef ISNAN
    4078           0 :     if(tmpCur0->GetType() == formula::svSingleVectorRef)
    4079             :     {
    4080             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    4081           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    4082           0 :     ss <<"    if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
    4083           0 :     ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
    4084           0 :     ss <<"        fCost = 0;\n    else\n";
    4085             :     }
    4086             : #endif
    4087           0 :     ss << "        fCost=";
    4088           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    4089           0 :     ss <<";\n";
    4090             : #ifdef ISNAN
    4091           0 :     if(tmpCur1->GetType() == formula::svSingleVectorRef)
    4092             :     {
    4093             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    4094           0 :     formula::SingleVectorRefToken *>(tmpCur1);
    4095           0 :     ss <<"    if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
    4096           0 :     ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
    4097           0 :     ss <<"        nDate = 0;\n    else\n";
    4098             :     }
    4099             : #endif
    4100           0 :     ss << "        nDate=(int)";
    4101           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    4102           0 :     ss << ";\n";
    4103             : #ifdef ISNAN
    4104           0 :     if(tmpCur2->GetType() == formula::svSingleVectorRef)
    4105             :     {
    4106             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    4107           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    4108           0 :     ss <<"    if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
    4109           0 :     ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
    4110           0 :     ss <<"        nFirstPer = 0;\n    else\n";
    4111             :     }
    4112             : #endif
    4113           0 :     ss << "        nFirstPer=(int)";
    4114           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    4115           0 :     ss <<";\n";
    4116             : #ifdef ISNAN
    4117           0 :     if(tmpCur3->GetType() == formula::svSingleVectorRef)
    4118             :     {
    4119             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    4120           0 :     formula::SingleVectorRefToken *>(tmpCur3);
    4121           0 :     ss <<"    if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
    4122           0 :     ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
    4123           0 :     ss <<"        fRestVal = 0;\n    else\n";
    4124             :     }
    4125             : #endif
    4126           0 :     ss << "        fRestVal=";
    4127           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    4128           0 :     ss << ";\n";
    4129             : #ifdef ISNAN
    4130           0 :     if(tmpCur4->GetType() == formula::svSingleVectorRef)
    4131             :     {
    4132             :     const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
    4133           0 :     formula::SingleVectorRefToken *>(tmpCur4);
    4134           0 :     ss <<"    if(isNan(" <<vSubArguments[4]->GenSlidingWindowDeclRef();
    4135           0 :     ss <<")||(gid0 >="<<tmpCurDVR4->GetArrayLength()<<"))\n";
    4136           0 :     ss <<"        fPer = 0;\n    else\n";
    4137             :     }
    4138             : #endif
    4139           0 :     ss << "        fPer = ";
    4140           0 :     ss << vSubArguments[4]->GenSlidingWindowDeclRef();
    4141           0 :     ss <<";\n";
    4142             : #ifdef ISNAN
    4143           0 :     if(tmpCur5->GetType() == formula::svSingleVectorRef)
    4144             :     {
    4145             :     const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
    4146           0 :     formula::SingleVectorRefToken *>(tmpCur5);
    4147           0 :     ss <<"    if(isNan(" <<vSubArguments[5]->GenSlidingWindowDeclRef();
    4148           0 :     ss <<")||(gid0 >="<<tmpCurDVR5->GetArrayLength()<<"))\n";
    4149           0 :     ss <<"        fRate = 0;\n    else\n";
    4150             :     }
    4151             : #endif
    4152           0 :     ss << "        fRate=";
    4153           0 :     ss << vSubArguments[5]->GenSlidingWindowDeclRef();
    4154           0 :     ss << ";\n";
    4155             : #ifdef ISNAN
    4156           0 :     if(tmpCur6->GetType() == formula::svSingleVectorRef)
    4157             :     {
    4158             :     const formula::SingleVectorRefToken*tmpCurDVR6= static_cast<const
    4159           0 :     formula::SingleVectorRefToken *>(tmpCur6);
    4160           0 :     ss <<"    if(isNan(" <<vSubArguments[6]->GenSlidingWindowDeclRef();
    4161           0 :     ss <<")||(gid0 >="<<tmpCurDVR6->GetArrayLength()<<"))\n";
    4162           0 :     ss <<"        nBase = 0;\n    else\n";
    4163             :     }
    4164             : #endif
    4165           0 :     ss << "        nBase = (int)";
    4166           0 :     ss << vSubArguments[6]->GenSlidingWindowDeclRef();
    4167           0 :     ss << ";\n";
    4168           0 :     ss <<"    uint nPer = convert_int( fPer );\n";
    4169           0 :     ss <<"    double fUsePer = 1.0 *pow( fRate,-1);\n";
    4170           0 :     ss <<"    double fAmorCoeff;\n";
    4171           0 :     ss <<"    if( fUsePer < 3.0 )\n";
    4172           0 :     ss <<"        fAmorCoeff = 1.0;\n";
    4173           0 :     ss <<"    else if( fUsePer < 5.0 )\n";
    4174           0 :     ss <<"        fAmorCoeff = 1.5;\n";
    4175           0 :     ss <<"    else if( fUsePer <= 6.0 )\n";
    4176           0 :     ss <<"        fAmorCoeff = 2.0;\n";
    4177           0 :     ss <<"    else\n";
    4178           0 :     ss <<"        fAmorCoeff = 2.5;\n";
    4179           0 :     ss <<"    fRate *= fAmorCoeff;\n";
    4180           0 :     ss <<"    tmp = Round( GetYearFrac( 693594,";
    4181           0 :     ss <<"nDate, nFirstPer, nBase ) * fRate * fCost);\n";
    4182           0 :     ss <<"    fCost = fCost-tmp;\n";
    4183           0 :     ss <<"    double fRest = fCost - fRestVal;\n";
    4184           0 :     ss <<"    for( uint n = 0 ; n < nPer ; n++ )\n";
    4185           0 :     ss <<"    {\n";
    4186           0 :     ss <<"        tmp = Round( fRate * fCost);\n";
    4187           0 :     ss <<"        fRest -= tmp;\n";
    4188           0 :     ss <<"        if( fRest < 0.0 )\n";
    4189           0 :     ss <<"        {\n";
    4190           0 :     ss <<"            switch( nPer - n )\n";
    4191           0 :     ss <<"            {\n";
    4192           0 :     ss <<"                case 0:\n";
    4193           0 :     ss <<"                case 1:\n";
    4194           0 :     ss <<"                    tmp = Round( fCost * 0.5);\n";
    4195           0 :     ss <<"                default:\n";
    4196           0 :     ss <<"                    tmp = 0.0;\n";
    4197           0 :     ss <<"            }\n";
    4198           0 :     ss <<"        }\n";
    4199           0 :     ss <<"        fCost -= tmp;\n";
    4200           0 :     ss <<"    }\n";
    4201           0 :     ss <<"    return tmp;\n";
    4202           0 :     ss <<"}";
    4203           0 : }
    4204           0 : void OpAmorlinc::BinInlineFun(std::set<std::string>& decls,
    4205             :     std::set<std::string>& funs)
    4206             : {
    4207           0 :     decls.insert(nKorrValDecl); decls.insert(RoundDecl);
    4208           0 :     decls.insert(IsLeapYearDecl);decls.insert(DaysInMonthDecl);
    4209           0 :     decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
    4210           0 :     decls.insert(GetYearFracDecl);
    4211           0 :     funs.insert(Round);
    4212           0 :     funs.insert(IsLeapYear);funs.insert(DaysInMonth);
    4213           0 :     funs.insert(DaysToDate);funs.insert(DateToDays);
    4214           0 :     funs.insert(GetYearFrac);
    4215           0 : }
    4216           0 : void OpAmorlinc::GenSlidingWindowFunction(std::stringstream &ss,
    4217             :              const std::string &sSymName, SubArguments &vSubArguments)
    4218             : {
    4219           0 :     ss << "\ndouble " << sSymName;
    4220           0 :     ss << "_"<< BinFuncName() <<"(";
    4221           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    4222             :     {
    4223           0 :         if (i)
    4224           0 :             ss << ",";
    4225           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    4226             :     }
    4227           0 :     ss << ") {\n";
    4228           0 :     ss << "    int gid0 = get_global_id(0);\n";
    4229           0 :     ss << "    double tmp = 0;\n";
    4230           0 :     ss << "    double fCost,fRestVal,fPer,fRate;\n";
    4231           0 :     ss << "    int nDate,nFirstPer,nBase;\n";
    4232             : #ifdef ISNAN
    4233           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    4234           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    4235           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
    4236           0 :     FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
    4237           0 :     FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
    4238           0 :     FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
    4239           0 :     FormulaToken *tmpCur6 = vSubArguments[6]->GetFormulaToken();
    4240             : #endif
    4241             : #ifdef ISNAN
    4242           0 :     if(tmpCur0->GetType() == formula::svSingleVectorRef)
    4243             :     {
    4244             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    4245           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    4246           0 :     ss <<"    if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
    4247           0 :     ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
    4248           0 :     ss <<"        fCost = 0;\n    else\n";
    4249             :     }
    4250             : #endif
    4251           0 :     ss << "        fCost=";
    4252           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    4253           0 :     ss <<";\n";
    4254             : #ifdef ISNAN
    4255           0 :     if(tmpCur1->GetType() == formula::svSingleVectorRef)
    4256             :     {
    4257             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    4258           0 :     formula::SingleVectorRefToken *>(tmpCur1);
    4259           0 :     ss <<"    if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
    4260           0 :     ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
    4261           0 :     ss <<"        nDate = 0;\n    else\n";
    4262             :     }
    4263             : #endif
    4264           0 :     ss << "        nDate=(int)";
    4265           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    4266           0 :     ss << ";\n";
    4267             : #ifdef ISNAN
    4268           0 :     if(tmpCur2->GetType() == formula::svSingleVectorRef)
    4269             :     {
    4270             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    4271           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    4272           0 :     ss <<"    if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
    4273           0 :     ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
    4274           0 :     ss <<"        nFirstPer = 0;\n    else\n";
    4275             :     }
    4276             : #endif
    4277           0 :     ss << "        nFirstPer=(int)";
    4278           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    4279           0 :     ss <<";\n";
    4280             : #ifdef ISNAN
    4281           0 :     if(tmpCur3->GetType() == formula::svSingleVectorRef)
    4282             :     {
    4283             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    4284           0 :     formula::SingleVectorRefToken *>(tmpCur3);
    4285           0 :     ss <<"    if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
    4286           0 :     ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
    4287           0 :     ss <<"        fRestVal = 0;\n    else\n";
    4288             :     }
    4289             : #endif
    4290           0 :     ss << "        fRestVal=";
    4291           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    4292           0 :     ss << ";\n";
    4293             : #ifdef ISNAN
    4294           0 :     if(tmpCur4->GetType() == formula::svSingleVectorRef)
    4295             :     {
    4296             :     const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
    4297           0 :     formula::SingleVectorRefToken *>(tmpCur4);
    4298           0 :     ss <<"    if(isNan(" <<vSubArguments[4]->GenSlidingWindowDeclRef();
    4299           0 :     ss <<")||(gid0 >="<<tmpCurDVR4->GetArrayLength()<<"))\n";
    4300           0 :     ss <<"        fPer = 0;\n    else\n";
    4301             :     }
    4302             : #endif
    4303           0 :     ss << "        fPer = ";
    4304           0 :     ss << vSubArguments[4]->GenSlidingWindowDeclRef();
    4305           0 :     ss <<";\n";
    4306             : #ifdef ISNAN
    4307           0 :     if(tmpCur5->GetType() == formula::svSingleVectorRef)
    4308             :     {
    4309             :     const formula::SingleVectorRefToken*tmpCurDVR5= static_cast<const
    4310           0 :     formula::SingleVectorRefToken *>(tmpCur5);
    4311           0 :     ss <<"    if(isNan(" <<vSubArguments[5]->GenSlidingWindowDeclRef();
    4312           0 :     ss <<")||(gid0 >="<<tmpCurDVR5->GetArrayLength()<<"))\n";
    4313           0 :     ss <<"        fRate = 0;\n    else\n";
    4314             :     }
    4315             : #endif
    4316           0 :     ss << "        fRate=";
    4317           0 :     ss << vSubArguments[5]->GenSlidingWindowDeclRef();
    4318           0 :     ss << ";\n";
    4319             : #ifdef ISNAN
    4320           0 :     if(tmpCur6->GetType() == formula::svSingleVectorRef)
    4321             :     {
    4322             :     const formula::SingleVectorRefToken*tmpCurDVR6= static_cast<const
    4323           0 :     formula::SingleVectorRefToken *>(tmpCur6);
    4324           0 :     ss <<"    if(isNan(" <<vSubArguments[6]->GenSlidingWindowDeclRef();
    4325           0 :     ss <<")||(gid0 >="<<tmpCurDVR6->GetArrayLength()<<"))\n";
    4326           0 :     ss <<"        nBase = 0;\n    else\n";
    4327             :     }
    4328             : #endif
    4329           0 :     ss << "        nBase = (int)";
    4330           0 :     ss << vSubArguments[6]->GenSlidingWindowDeclRef();
    4331           0 :     ss << ";\n";
    4332           0 :     ss <<"    int  nPer = convert_int( fPer );\n";
    4333           0 :     ss <<"    double fOneRate = fCost * fRate;\n";
    4334           0 :     ss <<"    double fCostDelta = fCost - fRestVal;\n";
    4335           0 :     ss <<"    double f0Rate = GetYearFrac( 693594,";
    4336           0 :     ss <<"nDate, nFirstPer, nBase )* fRate * fCost;\n";
    4337           0 :     ss <<"    int nNumOfFullPeriods = (int)";
    4338           0 :     ss <<"( ( fCost - fRestVal - f0Rate) *pow(fOneRate,-1) );\n";
    4339           0 :     ss <<"    if( nPer == 0 )\n";
    4340           0 :     ss <<"        tmp = f0Rate;\n";
    4341           0 :     ss <<"    else if( nPer <= nNumOfFullPeriods )\n";
    4342           0 :     ss <<"        tmp = fOneRate;\n";
    4343           0 :     ss <<"    else if( nPer == nNumOfFullPeriods + 1 )\n";
    4344           0 :     ss <<"        tmp = fCostDelta - fOneRate * nNumOfFullPeriods - f0Rate;\n";
    4345           0 :     ss <<"    else\n";
    4346           0 :     ss <<"        tmp = 0.0;\n";
    4347           0 :     ss <<"    return tmp;\n";
    4348           0 :     ss <<"}";
    4349           0 : }
    4350           0 : void OpReceived::BinInlineFun(std::set<std::string>& decls,
    4351             :     std::set<std::string>& funs)
    4352             : {
    4353           0 :     decls.insert(GetYearDiffDecl);decls.insert(GetDiffDateDecl);
    4354           0 :     decls.insert(DaysToDateDecl);decls.insert(DaysInMonthDecl);
    4355           0 :     decls.insert(GetNullDateDecl);decls.insert(IsLeapYearDecl);
    4356           0 :     decls.insert(DateToDaysDecl);
    4357           0 :     funs.insert(GetDiffDate);funs.insert(DaysToDate);
    4358           0 :     funs.insert(DaysInMonth);funs.insert(GetNullDate);
    4359           0 :     funs.insert(DateToDays);funs.insert(IsLeapYear);
    4360           0 :     funs.insert(GetYearDiff);
    4361           0 : }
    4362             : 
    4363           0 : void OpReceived::GenSlidingWindowFunction(std::stringstream &ss,
    4364             :         const std::string &sSymName, SubArguments &vSubArguments)
    4365             : {
    4366           0 :     ss << "\ndouble " << sSymName;
    4367           0 :     ss << "_"<< BinFuncName() <<"(";
    4368           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    4369             :     {
    4370           0 :         if (i)
    4371           0 :             ss << ",";
    4372           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    4373             :     }
    4374           0 :     ss << ") {\n";
    4375           0 :     ss << "    double tmp = " << GetBottom() <<";\n";
    4376           0 :     ss << "    int gid0 = get_global_id(0);\n";
    4377           0 :     ss << "    int nSettle, nMat;\n";
    4378           0 :     ss << "    double fInvest,fDisc;\n";
    4379           0 :     ss << "    int rOB;\n";
    4380             : #ifdef ISNAN
    4381           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    4382             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    4383           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    4384           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    4385             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    4386           0 :     formula::SingleVectorRefToken *>(tmpCur1);
    4387           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
    4388             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    4389           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    4390           0 :     FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
    4391             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    4392           0 :     formula::SingleVectorRefToken *>(tmpCur3);
    4393           0 :     FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
    4394             :     const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
    4395           0 :     formula::SingleVectorRefToken *>(tmpCur4);
    4396           0 :     ss<< "    int buffer_settle_len = ";
    4397           0 :     ss<< tmpCurDVR0->GetArrayLength();
    4398           0 :     ss << ";\n";
    4399           0 :     ss<< "    int buffer_mat_len = ";
    4400           0 :     ss<< tmpCurDVR1->GetArrayLength();
    4401           0 :     ss << ";\n";
    4402           0 :     ss<< "    int buffer_invest_len = ";
    4403           0 :     ss<< tmpCurDVR2->GetArrayLength();
    4404           0 :     ss << ";\n";
    4405           0 :     ss<< "    int buffer_disc_len = ";
    4406           0 :     ss<< tmpCurDVR3->GetArrayLength();
    4407           0 :     ss << ";\n";
    4408           0 :     ss<< "    int buffer_rob_len = ";
    4409           0 :     ss<< tmpCurDVR4->GetArrayLength();
    4410           0 :     ss << ";\n";
    4411             : #endif
    4412             : #ifdef ISNAN
    4413           0 :     ss <<"    if(gid0 >= buffer_settle_len || isNan(";
    4414           0 :     ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
    4415           0 :     ss <<"))\n";
    4416           0 :     ss <<"        nSettle = 0;\n\telse\n";
    4417             : #endif
    4418           0 :     ss <<"        nSettle = (int)"<<vSubArguments[0]->GenSlidingWindowDeclRef();
    4419           0 :     ss <<";\n";
    4420             : #ifdef ISNAN
    4421           0 :     ss <<"    if(gid0 >= buffer_mat_len || isNan(";
    4422           0 :     ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
    4423           0 :     ss <<"))\n";
    4424           0 :     ss <<"        nMat = 0;\n\telse\n";
    4425             : #endif
    4426           0 :     ss <<"        nMat = (int)";
    4427           0 :     ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
    4428           0 :     ss <<";\n";
    4429             : #ifdef ISNAN
    4430           0 :     ss <<"    if(gid0 >= buffer_invest_len || isNan(";
    4431           0 :     ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
    4432           0 :     ss <<"))\n";
    4433           0 :     ss <<"        fInvest = 0;\n\telse\n";
    4434             : #endif
    4435           0 :     ss <<"        fInvest = "<<vSubArguments[2]->GenSlidingWindowDeclRef();
    4436           0 :     ss <<";\n";
    4437             : #ifdef ISNAN
    4438           0 :     ss <<"    if(gid0 >= buffer_disc_len || isNan(";
    4439           0 :     ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
    4440           0 :     ss <<"))\n";
    4441           0 :     ss <<"        fDisc = 0;\n\telse\n";
    4442             : #endif
    4443           0 :     ss <<"        fDisc = "<<vSubArguments[3]->GenSlidingWindowDeclRef();
    4444           0 :     ss <<";\n";
    4445             : #ifdef ISNAN
    4446           0 :     ss <<"    if(gid0 >= buffer_rob_len || isNan(";
    4447           0 :     ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
    4448           0 :     ss <<"))\n";
    4449           0 :     ss <<"        rOB = 0;\n\telse\n";
    4450             : #endif
    4451           0 :     ss <<"        rOB = (int)"<<vSubArguments[4]->GenSlidingWindowDeclRef();
    4452           0 :     ss <<";\n";
    4453           0 :     ss << "    double tmpvalue = (1.0-(fDisc";
    4454           0 :     ss <<" * GetYearDiff( GetNullDate()";
    4455           0 :     ss <<",nSettle,nMat,rOB)));\n";
    4456           0 :     ss << "    tmp = fInvest*pow(tmpvalue,-1);\n";
    4457           0 :     ss << "    return tmp;\n";
    4458           0 :     ss << "}";
    4459           0 : }
    4460             : 
    4461           0 :  void OpYielddisc::BinInlineFun(std::set<std::string>& decls,
    4462             :     std::set<std::string>& funs)
    4463             : {
    4464           0 :     decls.insert(GetYearFracDecl);decls.insert(GetNullDateDecl);
    4465           0 :     decls.insert(DateToDaysDecl);decls.insert(DaysToDateDecl);
    4466           0 :     decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
    4467             : 
    4468           0 :     funs.insert(GetYearFrac);funs.insert(GetNullDate);
    4469           0 :     funs.insert(DateToDays);funs.insert(DaysToDate);
    4470           0 :     funs.insert(DaysInMonth);funs.insert(IsLeapYear);
    4471           0 : }
    4472           0 : void OpYielddisc::GenSlidingWindowFunction(
    4473             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
    4474             : {
    4475           0 :     ss << "\ndouble " << sSymName;
    4476           0 :     ss << "_"<< BinFuncName() <<"(";
    4477           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    4478             :     {
    4479           0 :         if (i)
    4480           0 :             ss << ",";
    4481           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    4482             :     }
    4483           0 :     ss << ") {\n\t";
    4484           0 :     ss << "double tmp = " <<"0"<<";\n\t";
    4485           0 :     ss << "int gid0 = get_global_id(0);\n\t";
    4486           0 :     ss << "double tmp000;\n\t";
    4487           0 :     ss << "double tmp001;\n\t";
    4488           0 :     ss << "double tmp002;\n\t";
    4489           0 :     ss << "double tmp003;\n\t";
    4490           0 :     ss << "double tmp004;\n\t";
    4491             : 
    4492             : 
    4493             : #ifdef ISNAN
    4494           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    4495             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    4496           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    4497             : 
    4498           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    4499             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    4500           0 :     formula::SingleVectorRefToken *>(tmpCur1);
    4501             : 
    4502           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
    4503             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    4504           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    4505             : 
    4506           0 :     FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
    4507             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    4508           0 :     formula::SingleVectorRefToken *>(tmpCur3);
    4509             : 
    4510           0 :     FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
    4511             :     const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
    4512           0 :     formula::SingleVectorRefToken *>(tmpCur4);
    4513             : 
    4514           0 :     ss<< "int buffer_tmp000_len = ";
    4515           0 :     ss<< tmpCurDVR0->GetArrayLength();
    4516           0 :     ss << ";\n\t";
    4517             : 
    4518           0 :     ss<< "int buffer_tmp001_len = ";
    4519           0 :     ss<< tmpCurDVR1->GetArrayLength();
    4520           0 :     ss << ";\n\t";
    4521             : 
    4522           0 :     ss<< "int buffer_tmp002_len = ";
    4523           0 :     ss<< tmpCurDVR2->GetArrayLength();
    4524           0 :     ss << ";\n\t";
    4525             : 
    4526           0 :    ss<< "int buffer_tmp003_len = ";
    4527           0 :     ss<< tmpCurDVR3->GetArrayLength();
    4528           0 :     ss << ";\n\t";
    4529             : 
    4530           0 :     ss<< "int buffer_tmp004_len = ";
    4531           0 :     ss<< tmpCurDVR4->GetArrayLength();
    4532           0 :     ss << ";\n\t";
    4533             : 
    4534             : #endif
    4535             : 
    4536             : #ifdef ISNAN
    4537           0 :     ss<<"if(gid0>=buffer_tmp000_len || isNan(";
    4538           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    4539           0 :     ss<<"))\n\t\t";
    4540           0 :     ss<<"tmp000 = 0;\n\telse \n\t\t";
    4541             : #endif
    4542           0 :     ss<<"tmp000 = ";
    4543           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    4544           0 :     ss<<";\n\t";
    4545             : 
    4546             : #ifdef ISNAN
    4547           0 :     ss<<"if(gid0>=buffer_tmp001_len || isNan(";
    4548           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    4549           0 :     ss<<"))\n\t\t";
    4550           0 :     ss<<"tmp001 = 0;\n\telse \n\t\t";
    4551             : #endif
    4552           0 :     ss<<"tmp001 = ";
    4553           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    4554           0 :     ss<<";\n\t";
    4555             : 
    4556             : #ifdef ISNAN
    4557           0 :     ss<<"if(gid0>=buffer_tmp002_len || isNan(";
    4558           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    4559           0 :     ss<<"))\n\t\t";
    4560           0 :     ss<<"tmp002 = 0;\n\telse \n\t\t";
    4561             : #endif
    4562           0 :     ss<<"tmp002 = ";
    4563           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    4564           0 :     ss<<";\n\t";
    4565             : 
    4566             : #ifdef ISNAN
    4567           0 :     ss<<"if(gid0>=buffer_tmp003_len || isNan(";
    4568           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    4569           0 :     ss<<"))\n\t\t";
    4570           0 :     ss<<"tmp003 = 0;\n\telse \n\t\t";
    4571             : #endif
    4572           0 :     ss<<"tmp003 = ";
    4573           0 :     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    4574           0 :     ss<<";\n\t";
    4575             : 
    4576             : #ifdef ISNAN
    4577           0 :     ss<<"if(gid0>=buffer_tmp004_len || isNan(";
    4578           0 :     ss << vSubArguments[4]->GenSlidingWindowDeclRef();
    4579           0 :     ss<<"))\n\t\t";
    4580           0 :     ss<<"tmp004 = 0;\n\telse \n\t\t";
    4581             : #endif
    4582           0 :     ss<<"tmp004 = ";
    4583           0 :     ss << vSubArguments[4]->GenSlidingWindowDeclRef();
    4584           0 :     ss<<";\n\t";
    4585             : 
    4586           0 :     ss<< "tmp = (tmp003/tmp002)-1;\n\t";
    4587           0 :     ss << "tmp /= GetYearFrac( GetNullDate(),tmp000,tmp001,tmp004);\n\t";
    4588           0 :     ss << "return tmp;\n";
    4589           0 :     ss << "}";
    4590           0 : }
    4591             : 
    4592           0 :  void OpTbillprice::BinInlineFun(std::set<std::string>& decls,
    4593             :     std::set<std::string>& funs)
    4594             : {
    4595           0 :     decls.insert(GetYearFracDecl);
    4596           0 :     decls.insert(DateToDaysDecl);decls.insert(DaysToDateDecl);
    4597           0 :     decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
    4598             : 
    4599           0 :     funs.insert(GetYearFrac);
    4600           0 :     funs.insert(DateToDays);funs.insert(DaysToDate);
    4601           0 :     funs.insert(DaysInMonth);funs.insert(IsLeapYear);
    4602           0 : }
    4603             : 
    4604           0 : void OpTbillprice::GenSlidingWindowFunction(
    4605             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
    4606             : {
    4607           0 :     ss << "\ndouble " << sSymName;
    4608           0 :     ss << "_"<< BinFuncName() <<"(";
    4609           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    4610             :     {
    4611           0 :         if (i)
    4612           0 :             ss << ",";
    4613           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    4614             :     }
    4615           0 :     ss << ") {\n";
    4616           0 :     ss << "    int gid0 = get_global_id(0);\n";
    4617           0 :     ss << "    double tmp = 0;\n";
    4618             : 
    4619           0 :     ss << "    int singleIndex = gid0;\n";
    4620           0 :     ss << "    int doubleIndex = gid0;\n";
    4621           0 :     ss << "    int i = gid0;\n";
    4622           0 :     GenTmpVariables(ss,vSubArguments);
    4623           0 :     CheckAllSubArgumentIsNan(ss,vSubArguments);
    4624             : 
    4625           0 :     ss << "    tmp1+=1.0;\n";
    4626           0 :     ss << "    double  fFraction =GetYearFrac(693594,tmp0,tmp1,0);\n";
    4627           0 :     ss << "    tmp = 100.0 * ( 1.0 - tmp2 * fFraction );\n";
    4628           0 :     ss << "    return tmp;\n";
    4629           0 :     ss << "}\n";
    4630           0 : }
    4631           0 :  void RATE::BinInlineFun(std::set<std::string>& decls,
    4632             :     std::set<std::string>& funs)
    4633             : {
    4634           0 :     decls.insert(approxEqualDecl);decls.insert(nKorrValDecl);
    4635           0 :     decls.insert(SCdEpsilonDecl);decls.insert(RoundDecl);
    4636           0 :     funs.insert(approxEqual);funs.insert(Round);
    4637           0 : }
    4638             : 
    4639           0 : void RATE::GenSlidingWindowFunction(
    4640             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
    4641             : {
    4642           0 :     ss << "\ndouble " << sSymName;
    4643           0 :     ss << "_"<< BinFuncName() <<"(";
    4644           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    4645             :     {
    4646           0 :         if (i)
    4647           0 :             ss << ",";
    4648           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    4649             :     }
    4650             : 
    4651           0 :     FormulaToken* pCur = vSubArguments[5]->GetFormulaToken();
    4652             :     assert(pCur);
    4653             :     const formula::SingleVectorRefToken* pSVR =
    4654           0 :         static_cast< const formula::SingleVectorRefToken* >(pCur);
    4655             :     assert(pSVR);
    4656           0 :     ss << ") {\n";
    4657           0 :     ss << "    double result;\n";
    4658           0 :     ss << "    int gid0 = get_global_id(0);\n";
    4659           0 :     ss << "    bool bValid = true, bFound = false;\n";
    4660           0 :     ss << "    double fX, fXnew, fTerm, fTermDerivation;\n";
    4661           0 :     ss << "    double fGeoSeries, fGeoSeriesDerivation;\n";
    4662           0 :     ss << "    int nIterationsMax = 150;\n";
    4663           0 :     ss << "    int nCount = 0;\n";
    4664           0 :     ss << "    double fEpsilonSmall = 1.0E-14;\n";
    4665           0 :     ss << "    double arg0, arg1, arg2, arg3, arg4, arg5;\n";
    4666           0 :     ss << "    arg0=" << vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n";
    4667           0 :     ss << "    arg1=" << vSubArguments[1]->GenSlidingWindowDeclRef()<<";\n";
    4668           0 :     ss << "    arg2=" << vSubArguments[2]->GenSlidingWindowDeclRef()<<";\n";
    4669           0 :     ss << "    arg3=" << vSubArguments[3]->GenSlidingWindowDeclRef()<<";\n";
    4670           0 :     ss << "    arg4=" << vSubArguments[4]->GenSlidingWindowDeclRef()<<";\n";
    4671           0 :     ss << "    arg5=" << vSubArguments[5]->GenSlidingWindowDeclRef()<<";\n";
    4672           0 :     ss << "    int guessLen = " << pSVR->GetArrayLength() << ";\n";
    4673             :     #ifdef  ISNAN
    4674           0 :     ss << "    if (isNan(arg0) || isNan(arg1) || isNan(arg2)){\n";
    4675           0 :     ss << "        result = 523;\n";
    4676           0 :     ss << "        return result;\n";
    4677           0 :     ss << "    }\n";
    4678           0 :     ss << "    if (isNan(arg3))\n";
    4679           0 :     ss << "        arg3 = 0.0;\n";
    4680           0 :     ss << "    if (isNan(arg4))\n";
    4681           0 :     ss << "        arg4 = 0.0;\n";
    4682           0 :     ss << "    if (isNan(arg5))\n";
    4683           0 :     ss << "        arg5 = 0.1;\n";
    4684           0 :     ss << "    if (gid0 >= guessLen)\n";
    4685           0 :     ss << "        arg5 = 0.1;\n";
    4686             :     #endif
    4687           0 :     ss << "    arg3 = arg3 - arg1 * arg4;\n";
    4688           0 :     ss << "    arg2 = arg2 + arg1 * arg4;\n";
    4689           0 :     ss << "    if (arg0 == Round(arg0)){\n";
    4690           0 :     ss << "        fX = arg5;\n";
    4691           0 :     ss << "        double fPowN, fPowNminus1;\n";
    4692           0 :     ss << "        while (!bFound && nCount < nIterationsMax)\n";
    4693           0 :     ss << "        {\n";
    4694           0 :     ss << "            fPowNminus1 = pow( 1.0+fX, arg0-1.0);\n";
    4695           0 :     ss << "            fPowN = fPowNminus1 * (1.0+fX);\n";
    4696           0 :     ss << "            if (approxEqual( fabs(fX), 0.0))\n";
    4697           0 :     ss << "            {\n";
    4698           0 :     ss << "                fGeoSeries = arg0;\n";
    4699           0 :     ss << "                fGeoSeriesDerivation = arg0 * (arg0-1.0)";
    4700           0 :     ss << "*pow(2.0,-1);\n";
    4701           0 :     ss << "            }\n";
    4702           0 :     ss << "            else\n";
    4703           0 :     ss << "            {";
    4704           0 :     ss << "                fGeoSeries = (fPowN-1.0)*pow(fX,-1);\n";
    4705           0 :     ss << "                fGeoSeriesDerivation =";
    4706           0 :     ss << " arg0 * fPowNminus1 * pow( fX , -1) - fGeoSeries * pow(fX, -1);\n";
    4707           0 :     ss << "            }\n";
    4708           0 :     ss << "            fTerm = arg3 + arg2 *fPowN+ arg1 * fGeoSeries;\n";
    4709           0 :     ss << "            fTermDerivation = arg2 * arg0 * fPowNminus1 +";
    4710           0 :     ss << "arg1 * fGeoSeriesDerivation;\n";
    4711           0 :     ss << "            if (fabs(fTerm) < fEpsilonSmall)\n";
    4712           0 :     ss << "                bFound = true;\n";
    4713           0 :     ss << "            else\n";
    4714           0 :     ss << "            {\n";
    4715           0 :     ss << "                if (approxEqual(fabs(fTermDerivation), 0.0))\n";
    4716           0 :     ss << "                    fXnew = fX + 1.1 * SCdEpsilon;\n";
    4717           0 :     ss << "                else\n";
    4718           0 :     ss << "                    fXnew = fX - fTerm ";
    4719           0 :     ss << "*pow( fTermDerivation,-1);\n";
    4720           0 :     ss << "                nCount++;\n";
    4721           0 :     ss << "                bFound = (fabs(fXnew - fX) < SCdEpsilon);\n";
    4722           0 :     ss << "                fX = fXnew;\n";
    4723           0 :     ss << "            }\n";
    4724           0 :     ss << "        }\n";
    4725           0 :     ss << "    }\n";
    4726           0 :     ss << "    else\n";
    4727           0 :     ss << "    {";
    4728           0 :     ss << "        fX = (arg5 < -1.0) ? -1.0 : arg5;\n";
    4729           0 :     ss << "        while (bValid && !bFound && nCount < nIterationsMax)\n";
    4730           0 :     ss << "        {\n";
    4731           0 :     ss << "            if (approxEqual(fabs(fX), 0.0)){\n";
    4732           0 :     ss << "                fGeoSeries = arg0;\n";
    4733           0 :     ss << "                fGeoSeriesDerivation = arg0 * ";
    4734           0 :     ss << "(arg0-1.0)* pow(2.0,-1);\n";
    4735           0 :     ss << "            }else{\n";
    4736           0 :     ss << "                fGeoSeries = (pow( 1.0+fX, arg0) - 1.0)";
    4737           0 :     ss << " *pow( fX,-1);\n";
    4738           0 :     ss << "                fGeoSeriesDerivation =";
    4739           0 :     ss << " arg0 * pow(1.0+fX,arg0-1.0) *pow(fX,-1)";
    4740           0 :     ss << " - fGeoSeries *pow( fX,-1);\n";
    4741           0 :     ss << "            }\n";
    4742           0 :     ss << "            fTerm = arg3 + arg2 *pow(1.0+fX, arg0)";
    4743           0 :     ss << "+ arg1 * fGeoSeries;\n";
    4744           0 :     ss << "            fTermDerivation =";
    4745           0 :     ss << "arg2*arg0*pow(1.0+fX,arg0-1.0)";
    4746           0 :     ss << "+arg1*fGeoSeriesDerivation;\n";
    4747           0 :     ss << "            if (fabs(fTerm) < fEpsilonSmall)\n";
    4748           0 :     ss << "                bFound = true;\n";
    4749           0 :     ss << "            else{\n";
    4750           0 :     ss << "                if (approxEqual(fabs(fTermDerivation), 0.0))\n";
    4751           0 :     ss << "                    fXnew = fX + 1.1 * SCdEpsilon;\n";
    4752           0 :     ss << "                else\n";
    4753           0 :     ss << "                    fXnew = fX - fTerm ";
    4754           0 :     ss << "*pow( fTermDerivation,-1);\n";
    4755           0 :     ss << "                nCount++;\n";
    4756           0 :     ss << "                bFound = (fabs(fXnew - fX) < SCdEpsilon);\n";
    4757           0 :     ss << "                fX = fXnew;\n";
    4758           0 :     ss << "                bValid = (fX >= -1.0);\n";
    4759           0 :     ss << "            }\n";
    4760           0 :     ss << "        }\n";
    4761           0 :     ss << "    }\n";
    4762           0 :     ss << "    if (bValid && bFound)\n";
    4763           0 :     ss << "        result = fX;\n";
    4764           0 :     ss << "    else\n";
    4765           0 :     ss << "        result = 523;\n";
    4766           0 :     ss << "    return result;\n";
    4767           0 :     ss << "}";
    4768           0 : }
    4769             : 
    4770           0 :  void OpTbillyield::BinInlineFun(std::set<std::string>& decls,
    4771             :     std::set<std::string>& funs)
    4772             : {
    4773           0 :     decls.insert(GetDiffDate360Decl);decls.insert(IsLeapYearDecl);
    4774           0 :     decls.insert(DateToDaysDecl);decls.insert(DaysToDate_LocalBarrierDecl);
    4775           0 :     decls.insert(DaysInMonthDecl);decls.insert(GetNullDateDecl);
    4776           0 :     decls.insert(GetDiffDate360_Decl);
    4777           0 :     funs.insert(GetDiffDate360);funs.insert(DateToDays);
    4778           0 :     funs.insert(DaysToDate_LocalBarrier);funs.insert(IsLeapYear);
    4779           0 :     funs.insert(DaysInMonth);funs.insert(GetNullDate);
    4780           0 :     funs.insert(GetDiffDate360_);
    4781             : 
    4782           0 : }
    4783             : 
    4784           0 : void OpTbillyield::GenSlidingWindowFunction(
    4785             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
    4786             : {
    4787           0 :     ss << "\ndouble " << sSymName;
    4788           0 :     ss << "_"<< BinFuncName() <<"(";
    4789           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    4790             :     {
    4791           0 :         if (i)
    4792           0 :             ss << ",";
    4793           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    4794             :     }
    4795           0 :     ss << ") {\n\t";
    4796           0 :     ss << "int gid0 = get_global_id(0);\n\t";
    4797           0 :     ss << "double tmp = 0;\n\t";
    4798           0 :     ss << "double tmp000;\n\t";
    4799           0 :     ss << "double tmp001;\n\t";
    4800           0 :     ss << "double tmp002;\n\t";
    4801             : 
    4802             : #ifdef ISNAN
    4803           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    4804             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    4805           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    4806             : 
    4807           0 :     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    4808             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    4809           0 :     formula::SingleVectorRefToken *>(tmpCur1);
    4810             : 
    4811           0 :     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
    4812             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    4813           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    4814             : 
    4815           0 :     ss<< "int buffer_tmp000_len = ";
    4816           0 :     ss<< tmpCurDVR0->GetArrayLength();
    4817           0 :     ss << ";\n\t";
    4818             : 
    4819           0 :     ss<< "int buffer_tmp001_len = ";
    4820           0 :     ss<< tmpCurDVR1->GetArrayLength();
    4821           0 :     ss << ";\n\t";
    4822             : 
    4823           0 :     ss<< "int buffer_tmp002_len = ";
    4824           0 :     ss<< tmpCurDVR2->GetArrayLength();
    4825           0 :     ss << ";\n\t";
    4826             : #endif
    4827             : 
    4828             : #ifdef ISNAN
    4829           0 :     ss<<"if(gid0>=buffer_tmp000_len || isNan(";
    4830           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    4831           0 :     ss<<"))\n\t\t";
    4832           0 :     ss<<"tmp000 = 0;\n\telse \n\t\t";
    4833             : #endif
    4834           0 :     ss<<"tmp000 = ";
    4835           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    4836           0 :     ss<<";\n\t";
    4837             : 
    4838             : #ifdef ISNAN
    4839           0 :     ss<<"if(gid0>=buffer_tmp001_len || isNan(";
    4840           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    4841           0 :     ss<<"))\n\t\t";
    4842           0 :     ss<<"tmp001 = 0;\n\telse \n\t\t";
    4843             : #endif
    4844           0 :     ss<<"tmp001 = ";
    4845           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    4846           0 :     ss<<";\n\t";
    4847             : 
    4848             : #ifdef ISNAN
    4849           0 :     ss<<"if(gid0>=buffer_tmp002_len || isNan(";
    4850           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    4851           0 :     ss<<"))\n\t\t";
    4852           0 :     ss<<"tmp002 = 0;\n\telse \n\t\t";
    4853             : #endif
    4854           0 :     ss<<"tmp002 = ";
    4855           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    4856           0 :     ss<<";\n\t";
    4857           0 :     ss <<"    int nDiff=GetDiffDate360(GetNullDate(),tmp000,tmp001,true);\n";
    4858           0 :     ss <<"    nDiff++;\n";
    4859           0 :     ss <<"    tmp=100.0;\n";
    4860           0 :     ss <<"    tmp = tmp *pow( tmp002,-1);\n";
    4861           0 :     ss <<"    tmp = tmp - 1.0;\n";
    4862           0 :     ss <<"    tmp = tmp * pow( nDiff,-1.0 );\n";
    4863           0 :     ss <<"    tmp = tmp * 360.0;\n";
    4864           0 :     ss <<"    return tmp;\n";
    4865           0 :     ss << "}\n";
    4866           0 : }
    4867           0 : void OpDDB::GenSlidingWindowFunction(std::stringstream& ss,
    4868             :             const std::string &sSymName, SubArguments& vSubArguments)
    4869             : {
    4870           0 :     ss << "\ndouble " << sSymName;
    4871           0 :     ss << "_"<< BinFuncName() <<"(";
    4872           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    4873             :     {
    4874           0 :         if (i)
    4875           0 :             ss << ",";
    4876           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    4877             :     }
    4878           0 :     ss << ") {\n";
    4879           0 :     ss << "    int gid0 = get_global_id(0);\n";
    4880           0 :     ss << "    double tmp = 0;\n";
    4881           0 :     ss << "    double fWert,fRest,fDauer,fPeriode,fFaktor;\n";
    4882           0 :     ss << "    double fZins, fAlterWert, fNeuerWert;\n";
    4883             : 
    4884             : #ifdef ISNAN
    4885           0 :     FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
    4886           0 :     FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
    4887           0 :     FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
    4888           0 :     FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
    4889           0 :     FormulaToken* tmpCur4 = vSubArguments[4]->GetFormulaToken();
    4890             : #endif
    4891             : #ifdef ISNAN
    4892           0 :     if(tmpCur0->GetType() == formula::svSingleVectorRef)
    4893             :     {
    4894             :         const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    4895           0 :         formula::SingleVectorRefToken *>(tmpCur0);
    4896           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR0->GetArrayLength()<<" || isNan(";
    4897           0 :         ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
    4898           0 :         ss <<"))\n";
    4899           0 :         ss <<"        fWert = 0;\n    else\n";
    4900             :     }
    4901             : #endif
    4902           0 :     ss <<"        fWert = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
    4903           0 :     ss <<";\n";
    4904             : #ifdef ISNAN
    4905           0 :     if(tmpCur1->GetType() == formula::svSingleVectorRef)
    4906             :     {
    4907             :         const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    4908           0 :         formula::SingleVectorRefToken *>(tmpCur1);
    4909           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR1->GetArrayLength()<<" || isNan(";
    4910           0 :         ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
    4911           0 :         ss <<"))\n";
    4912           0 :         ss <<"        fRest = 0;\n    else\n";
    4913             :     }
    4914             : #endif
    4915           0 :     ss <<"        fRest = ";
    4916           0 :     ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
    4917           0 :     ss <<";\n";
    4918             : #ifdef ISNAN
    4919           0 :     if(tmpCur2->GetType() == formula::svSingleVectorRef)
    4920             :     {
    4921             :         const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    4922           0 :         formula::SingleVectorRefToken *>(tmpCur2);
    4923           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR2->GetArrayLength()<<" || isNan(";
    4924           0 :         ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
    4925           0 :         ss <<"))\n";
    4926           0 :         ss <<"        fDauer = 0;\n    else\n";
    4927             :     }
    4928             : #endif
    4929           0 :     ss <<"        fDauer = ";
    4930           0 :     ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
    4931           0 :     ss <<";\n";
    4932             : #ifdef ISNAN
    4933           0 :     if(tmpCur3->GetType() == formula::svSingleVectorRef)
    4934             :     {
    4935             :         const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    4936           0 :         formula::SingleVectorRefToken *>(tmpCur3);
    4937           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR3->GetArrayLength()<<" || isNan(";
    4938           0 :         ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
    4939           0 :         ss <<"))\n";
    4940           0 :         ss <<"        fPeriode = 0;\n    else\n";
    4941             :     }
    4942             : #endif
    4943           0 :     ss <<"        fPeriode = "<<vSubArguments[3]->GenSlidingWindowDeclRef();
    4944           0 :     ss <<";\n";
    4945             : #ifdef ISNAN
    4946           0 :     if(tmpCur4->GetType() == formula::svSingleVectorRef)
    4947             :     {
    4948             :         const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
    4949           0 :         formula::SingleVectorRefToken *>(tmpCur4);
    4950           0 :         ss <<"    if(gid0 >= "<<tmpCurDVR4->GetArrayLength()<<" || isNan(";
    4951           0 :         ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
    4952           0 :         ss <<"))\n";
    4953           0 :         ss <<"        fFaktor = 0;\n    else\n";
    4954             :     }
    4955             : #endif
    4956           0 :     ss <<"        fFaktor = "<<vSubArguments[4]->GenSlidingWindowDeclRef();
    4957           0 :     ss <<";\n";
    4958           0 :     ss <<"    fZins = fFaktor * pow(fDauer,-1);\n";
    4959           0 :     ss <<"    if (fZins >= 1.0)\n";
    4960           0 :     ss <<"    {\n";
    4961           0 :     ss <<"        fZins = 1.0;\n";
    4962           0 :     ss <<"        if (fPeriode == 1.0)\n";
    4963           0 :     ss <<"            fAlterWert = fWert;\n";
    4964           0 :     ss <<"        else\n";
    4965           0 :     ss <<"            fAlterWert = 0.0;\n";
    4966           0 :     ss <<"    }\n";
    4967           0 :     ss <<"    else\n";
    4968           0 :     ss <<"        fAlterWert = fWert * pow(1.0 - fZins, fPeriode - 1);\n";
    4969           0 :     ss <<"    fNeuerWert = fWert * pow(1.0 - fZins, fPeriode);\n";
    4970           0 :     ss <<"    if (fNeuerWert < fRest)\n";
    4971           0 :     ss <<"        tmp = fAlterWert - fRest;\n";
    4972           0 :     ss <<"    else\n";
    4973           0 :     ss <<"        tmp = fAlterWert - fNeuerWert;\n";
    4974           0 :     ss <<"    if (tmp < 0.0)\n";
    4975           0 :     ss <<"        tmp = 0.0;\n";
    4976           0 :     ss <<"    return tmp;\n";
    4977           0 :     ss <<"}";
    4978           0 : }
    4979           0 : void OpPV::GenSlidingWindowFunction(
    4980             :     std::stringstream &ss, const std::string &sSymName, SubArguments &
    4981             : vSubArguments)
    4982             : {
    4983           0 :     ss << "\ndouble " << sSymName;
    4984           0 :     ss << "_"<< BinFuncName() <<"(";
    4985           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    4986             :     {
    4987           0 :         if (i)
    4988           0 :             ss << ",";
    4989           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    4990             :     }
    4991           0 :     ss << ") {\n";
    4992           0 :     ss << "    double result = " <<"0"<<";\n";
    4993           0 :     ss << "    int gid0 = get_global_id(0);\n";
    4994           0 :     ss << "    double zins;\n";
    4995           0 :     ss << "    double zzr;\n";
    4996           0 :     ss << "    double rmz;\n";
    4997           0 :     ss << "    double zw;\n";
    4998           0 :     ss << "    double flag;\n";
    4999             : 
    5000             : #ifdef ISNAN
    5001           0 :      FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    5002             :      const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    5003           0 :      formula::SingleVectorRefToken *>(tmpCur0);
    5004             : 
    5005           0 :      FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    5006             :      const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    5007           0 :      formula::SingleVectorRefToken *>(tmpCur1);
    5008             : 
    5009           0 :      FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
    5010             :      const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    5011           0 :      formula::SingleVectorRefToken *>(tmpCur2);
    5012             : 
    5013             :      const formula::SingleVectorRefToken*tmpCurDVR3;
    5014             :      const formula::SingleVectorRefToken*tmpCurDVR4;
    5015             : 
    5016           0 :     if(vSubArguments.size()>3)
    5017             :     {
    5018           0 :         FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
    5019             :         tmpCurDVR3= static_cast<const formula::SingleVectorRefToken *>(
    5020           0 : tmpCur3);
    5021           0 :         ss<< "    int buffer_zw_len = ";
    5022           0 :         ss<< tmpCurDVR3->GetArrayLength();
    5023           0 :         ss << ";\n";
    5024             :         }
    5025             : 
    5026           0 :     if(vSubArguments.size()>4)
    5027             :     {
    5028           0 :         FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
    5029             :         tmpCurDVR4= static_cast<const formula::SingleVectorRefToken *>(
    5030           0 : tmpCur4);
    5031           0 :         ss<< "    int buffer_flag_len = ";
    5032           0 :         ss<< tmpCurDVR4->GetArrayLength();
    5033           0 :         ss << ";\n";
    5034             :     }
    5035             : 
    5036           0 :     ss<< "    int buffer_zins_len = ";
    5037           0 :     ss<< tmpCurDVR0->GetArrayLength();
    5038           0 :     ss << ";\n";
    5039             : 
    5040           0 :     ss<< "    int buffer_zzr_len = ";
    5041           0 :     ss<< tmpCurDVR1->GetArrayLength();
    5042           0 :     ss << ";\n";
    5043             : 
    5044           0 :     ss<< "    int buffer_rmz_len = ";
    5045           0 :     ss<< tmpCurDVR2->GetArrayLength();
    5046           0 :     ss << ";\n";
    5047             : 
    5048             : #endif
    5049             : 
    5050             : #ifdef ISNAN
    5051           0 :     ss<<"    if(gid0>=buffer_zins_len || isNan(";
    5052           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    5053           0 :     ss<<"))\n";
    5054           0 :     ss<<"        zins = 0;\n    else \n";
    5055             : #endif
    5056           0 :     ss<<"        zins = ";
    5057           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    5058           0 :     ss<<";\n";
    5059             : 
    5060             : #ifdef ISNAN
    5061           0 :     ss<<"    if(gid0>=buffer_zzr_len || isNan(";
    5062           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    5063           0 :     ss<<"))\n";
    5064           0 :     ss<<"        zzr = 0;\n    else \n";
    5065             : #endif
    5066           0 :     ss<<"        zzr = ";
    5067           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    5068           0 :     ss<<";\n";
    5069             : 
    5070             : #ifdef ISNAN
    5071           0 :     ss<<"    if(gid0>=buffer_rmz_len || isNan(";
    5072           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    5073           0 :     ss<<"))\n";
    5074           0 :     ss<<"        rmz = 0;\n    else \n";
    5075             : #endif
    5076           0 :     ss<<"        rmz = ";
    5077           0 :     ss << vSubArguments[2]->GenSlidingWindowDeclRef();
    5078           0 :     ss<<";\n";
    5079             : 
    5080           0 :     if(vSubArguments.size()>3)
    5081             :     {
    5082             : #ifdef ISNAN
    5083           0 :         ss<<"    if(gid0>=buffer_zw_len || isNan(";
    5084           0 :         ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    5085           0 :         ss<<"))\n";
    5086           0 :         ss<<"        zw = 0;\n    else \n";
    5087             : #endif
    5088           0 :         ss<<"        zw = ";
    5089           0 :         ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    5090           0 :         ss<<";\n";
    5091             :     }else
    5092             :     {
    5093           0 :         ss<<"    zw = 0;\n";
    5094             :     }
    5095             : 
    5096           0 :     if(vSubArguments.size()>4)
    5097             :     {
    5098             : #ifdef ISNAN
    5099           0 :         ss<<"    if(gid0>=buffer_flag_len || isNan(";
    5100           0 :         ss << vSubArguments[4]->GenSlidingWindowDeclRef();
    5101           0 :         ss<<"))\n";
    5102           0 :         ss<<"        flag = 0;\n    else \n";
    5103             : #endif
    5104           0 :         ss<<"        flag = ";
    5105           0 :         ss << vSubArguments[4]->GenSlidingWindowDeclRef();
    5106           0 :         ss<<";\n";
    5107             :     }else
    5108             :     {
    5109           0 :         ss<<"        flag = 0;\n";
    5110             :     }
    5111           0 :     ss << "    if(zins == 0)\n";
    5112           0 :     ss << "        result=zw+rmz*zzr;\n";
    5113           0 :     ss << "    else if(flag > 0)\n";
    5114           0 :     ss << "        result=(zw*pow(1+zins,-zzr))+";
    5115           0 :     ss << "(rmz*(1-pow(1+zins,-zzr+1))*pow(zins,-1))+rmz;\n";
    5116           0 :     ss << "    else\n";
    5117           0 :     ss << "        result=(zw*pow(1+zins,-zzr))+";
    5118           0 :     ss << "(rmz*(1-pow(1+zins,-zzr))*pow(zins,-1));\n";
    5119           0 :     ss << "    return -result;\n";
    5120           0 :     ss << "}";
    5121           0 : }
    5122           0 :  void OpVDB::BinInlineFun(std::set<std::string>& decls,
    5123             :     std::set<std::string>& funs)
    5124             : {
    5125           0 :     decls.insert(ScGetGDADecl);decls.insert(DblMinDecl);
    5126           0 :     decls.insert(ScInterVDBDecl);decls.insert(VDBImplementDecl);
    5127           0 :     funs.insert(ScGetGDA);funs.insert(DblMin);
    5128           0 :     funs.insert(ScInterVDB);funs.insert(VDBImplement);
    5129           0 : }
    5130             : 
    5131           0 : void OpVDB::GenSlidingWindowFunction(
    5132             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
    5133             : {
    5134           0 :     ss << "\ndouble " << sSymName;
    5135           0 :     ss << "_"<< BinFuncName() <<"(";
    5136           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    5137             :     {
    5138           0 :         if (i)
    5139           0 :             ss << ",";
    5140           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    5141             :     }
    5142           0 :     ss << ") {\n";
    5143           0 :     ss << "    int gid0 = get_global_id(0);\n";
    5144           0 :     ss << "    int singleIndex = gid0;\n";
    5145           0 :     ss << "    double result = 0;\n";
    5146           0 :     if(vSubArguments.size()<5)
    5147             :     {
    5148           0 :         ss << "    result = -DBL_MAX;\n";
    5149           0 :         ss << "    return result;\n";
    5150             :     }else
    5151             :     {
    5152           0 :         GenTmpVariables(ss,vSubArguments);
    5153           0 :         CheckAllSubArgumentIsNan(ss,vSubArguments);
    5154           0 :         if(vSubArguments.size() <= 6)
    5155             :         {
    5156           0 :             ss << "    int tmp6  = 0;\n";
    5157             :         }
    5158           0 :         if(vSubArguments.size() == 5)
    5159             :         {
    5160           0 :             ss << "    double tmp5= 2.0;\n";
    5161             :         }
    5162           0 :         ss << "    if(tmp3 < 0 || tmp4<tmp3 || tmp4>tmp2 || tmp0<0 ||tmp1>tmp0";
    5163           0 :         ss << "|| tmp5 <=0)\n";
    5164           0 :         ss << "        result = -DBL_MAX;\n";
    5165           0 :         ss << "    else\n";
    5166           0 :         ss << "        result =";
    5167           0 :         ss << "VDBImplement(tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);\n";
    5168           0 :         ss << "    return result;\n";
    5169           0 :         ss << "}";
    5170             :     }
    5171             : 
    5172           0 : }
    5173             : 
    5174           0 : void OpXirr::GenSlidingWindowFunction(std::stringstream &ss,
    5175             :              const std::string &sSymName, SubArguments &vSubArguments)
    5176             : {
    5177           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
    5178             :     const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
    5179           0 :          formula::DoubleVectorRefToken *>(tmpCur);
    5180           0 :     size_t nCurWindowSize = pCurDVR->GetArrayLength() <
    5181           0 :     pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
    5182           0 :     pCurDVR->GetRefRowSize() ;
    5183           0 :     ss << "\ndouble " << sSymName;
    5184           0 :     ss << "_"<< BinFuncName() <<"(";
    5185           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    5186             :     {
    5187           0 :         if (i)
    5188           0 :             ss << ",";
    5189           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    5190             :     }
    5191           0 :     ss << ") {\n";
    5192           0 :     ss << "    int gid0 = get_global_id(0);\n";
    5193           0 :     ss << "    int doubleIndex = gid0;\n";
    5194           0 :     ss << "    int singleIndex = gid0;\n";
    5195           0 :     ss << "    double result = 0;\n";
    5196           0 :     ss << "    int i=0;\n";
    5197           0 :     if(vSubArguments.size()<2)
    5198             :     {
    5199           0 :         ss << "    result = -DBL_MAX;\n";
    5200           0 :         ss << "    return result;\n";
    5201             :     }else
    5202             :     {
    5203           0 :         GenTmpVariables(ss,vSubArguments);
    5204           0 :         if(vSubArguments.size() == 2)
    5205             :         {
    5206           0 :             ss << "    double tmp2  = 0.1;\n";
    5207             :         }else
    5208             :         {
    5209           0 :             CheckSubArgumentIsNan(ss,vSubArguments,2);
    5210             :         }
    5211           0 :         ss << "    if(tmp2<=-1)\n";
    5212           0 :         ss << "        result = -DBL_MAX;\n";
    5213           0 :         ss << "    else\n";
    5214           0 :         ss << "    {\n";
    5215           0 :         ss << "        double fMaxEps = 1e-10;\n";
    5216           0 :         ss << "        int nMaxIter = 50;\n";
    5217           0 :         ss << "        double fNewRate, fRateEps, fResultValue, fResultValue2;\n";
    5218           0 :         ss << "        int nIter = 0;\n";
    5219           0 :         ss << "        int bContLoop;\n";
    5220           0 :         ss << "        int windowsSize = ";
    5221           0 :         ss << nCurWindowSize;
    5222           0 :         ss << ";\n";
    5223           0 :         CheckSubArgumentIsNan(ss,vSubArguments,0);
    5224           0 :         CheckSubArgumentIsNan(ss,vSubArguments,1);
    5225           0 :         ss << "        double D_0 = tmp1;\n";
    5226           0 :         ss << "        double V_0 = tmp0;\n";
    5227           0 :         ss << "        double fResultRate = tmp2;\n";
    5228           0 :         ss << "        double r;\n";
    5229           0 :         ss << "        double fResult;\n";
    5230           0 :         ss << "        do\n";
    5231           0 :         ss << "        {\n";
    5232           0 :         ss << "            fResultValue = V_0;\n";
    5233           0 :         ss << "            r = fResultRate + 1;\n";
    5234           0 :         ss << "            for (i = ";
    5235           0 :         if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
    5236           0 :            ss << "gid0+1; i < "<< nCurWindowSize <<"; i++)\n";
    5237           0 :         } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
    5238           0 :            ss << "1; i < gid0+"<< nCurWindowSize <<"; i++)\n";
    5239             :         } else {
    5240           0 :            ss << "1; i < "<< nCurWindowSize <<"; i++)\n";
    5241             :         }
    5242           0 :         ss << "            {\n";
    5243           0 :         if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
    5244             :         {
    5245           0 :            ss<< "                doubleIndex =i+gid0;\n";
    5246             :         }else
    5247             :         {
    5248           0 :            ss<< "                doubleIndex =i;\n";
    5249             :         }
    5250           0 :         CheckSubArgumentIsNan(ss,vSubArguments,0);
    5251           0 :         CheckSubArgumentIsNan(ss,vSubArguments,1);
    5252           0 :         ss << "                fResultValue += tmp0/pow(r,(tmp1 - D_0)/365.0);\n";
    5253           0 :         ss << "            }\n";
    5254           0 :         ss << "            fResultValue2 = 0;\n";
    5255             : 
    5256           0 :         ss << "            for (i = ";
    5257           0 :         if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
    5258           0 :            ss << "gid0+1; i < "<< nCurWindowSize <<"; i++)\n";
    5259           0 :         } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
    5260           0 :            ss << "1; i < gid0+"<< nCurWindowSize <<"; i++)\n";
    5261             :         } else {
    5262           0 :            ss << "1; i < "<< nCurWindowSize <<"; i++)\n";
    5263             :         }
    5264           0 :         ss << "            {\n";
    5265           0 :         if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
    5266             :         {
    5267           0 :            ss<< "                doubleIndex =i+gid0;\n";
    5268             :         }else
    5269             :         {
    5270           0 :            ss<< "                doubleIndex =i;\n";
    5271             :         }
    5272           0 :         CheckSubArgumentIsNan(ss,vSubArguments,0);
    5273           0 :         CheckSubArgumentIsNan(ss,vSubArguments,1);
    5274           0 :         ss << "                double E_i = (tmp1 - D_0)/365.0;\n";
    5275           0 :         ss << "                fResultValue2 -= E_i * tmp0 / pow(r,E_i + 1.0);\n";
    5276           0 :         ss << "            }\n";
    5277           0 :         ss << "            fNewRate = fResultRate - fResultValue / fResultValue2;\n";
    5278           0 :         ss << "            fRateEps = fabs( fNewRate - fResultRate );\n";
    5279           0 :         ss << "            fResultRate = fNewRate;\n";
    5280           0 :         ss << "            bContLoop = (fRateEps > fMaxEps) && (fabs( fResultValue ) > fMaxEps);\n";
    5281           0 :         ss << "        }\n";
    5282           0 :         ss << "        while( bContLoop && (++nIter < nMaxIter) );\n";
    5283           0 :         ss << "        if( bContLoop )\n";
    5284           0 :         ss << "            result = -DBL_MAX;\n";
    5285           0 :         ss << "        result = fResultRate;\n";
    5286           0 :         ss << "    }\n";
    5287           0 :         ss << "    return result;\n";
    5288           0 :         ss << "}";
    5289             :     }
    5290             : 
    5291           0 : }
    5292           0 : void OpDB::GenSlidingWindowFunction(std::stringstream& ss,
    5293             :             const std::string &sSymName, SubArguments& vSubArguments)
    5294             : {
    5295           0 :     ss << "\ndouble " << sSymName;
    5296           0 :     ss << "_"<< BinFuncName() <<"(";
    5297           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    5298             :     {
    5299           0 :         if (i)
    5300           0 :             ss << ",";
    5301           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    5302             :     }
    5303           0 :     ss << ") {\n";
    5304           0 :     ss << "    int gid0 = get_global_id(0);\n";
    5305           0 :     ss << "    double nWert,nRest,nDauer,nPeriode;\n";
    5306           0 :     ss << "    int nMonate;\n";
    5307           0 :     ss << "    double tmp = 0;\n";
    5308             : #ifdef ISNAN
    5309           0 :     FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
    5310             :     const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
    5311           0 :     formula::SingleVectorRefToken *>(tmpCur0);
    5312           0 :     FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
    5313             :     const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
    5314           0 :     formula::SingleVectorRefToken *>(tmpCur1);
    5315           0 :     FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
    5316             :     const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
    5317           0 :     formula::SingleVectorRefToken *>(tmpCur2);
    5318           0 :     FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
    5319             :     const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
    5320           0 :     formula::SingleVectorRefToken *>(tmpCur3);
    5321           0 :     FormulaToken* tmpCur4 = vSubArguments[4]->GetFormulaToken();
    5322             :     const formula::SingleVectorRefToken*tmpCurDVR4= static_cast<const
    5323           0 :     formula::SingleVectorRefToken *>(tmpCur4);
    5324           0 :     ss<< "    int buffer_wert_len = ";
    5325           0 :     ss<< tmpCurDVR0->GetArrayLength();
    5326           0 :     ss << ";\n";
    5327           0 :     ss<< "    int buffer_rest_len = ";
    5328           0 :     ss<< tmpCurDVR1->GetArrayLength();
    5329           0 :     ss << ";\n";
    5330           0 :     ss<< "    int buffer_dauer_len = ";
    5331           0 :     ss<< tmpCurDVR2->GetArrayLength();
    5332           0 :     ss << ";\n";
    5333           0 :     ss<< "    int buffer_periode_len = ";
    5334           0 :     ss<< tmpCurDVR3->GetArrayLength();
    5335           0 :     ss << ";\n";
    5336           0 :     ss<< "    int buffer_nMonate_len = ";
    5337           0 :     ss<< tmpCurDVR4->GetArrayLength();
    5338           0 :     ss << ";\n";
    5339             : #endif
    5340             : #ifdef ISNAN
    5341           0 :     ss <<"    if(gid0 >= buffer_wert_len || isNan(";
    5342           0 :     ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
    5343           0 :     ss <<"))\n";
    5344           0 :     ss <<"        nWert = 0;\n    else\n";
    5345             : #endif
    5346           0 :     ss <<"        nWert = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
    5347           0 :     ss <<";\n";
    5348             : #ifdef ISNAN
    5349           0 :     ss <<"    if(gid0 >= buffer_rest_len || isNan(";
    5350           0 :     ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
    5351           0 :     ss <<"))\n";
    5352           0 :     ss <<"        nRest = 0;\n    else\n";
    5353             : #endif
    5354           0 :     ss <<"        nRest = ";
    5355           0 :     ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
    5356           0 :     ss <<";\n";
    5357             : #ifdef ISNAN
    5358           0 :     ss <<"    if(gid0 >= buffer_dauer_len || isNan(";
    5359           0 :     ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
    5360           0 :     ss <<"))\n";
    5361           0 :     ss <<"        nDauer = 0;\n    else\n";
    5362             : #endif
    5363           0 :     ss <<"        nDauer = "<<vSubArguments[2]->GenSlidingWindowDeclRef();
    5364           0 :     ss <<";\n";
    5365             : #ifdef ISNAN
    5366           0 :     ss <<"    if(gid0 >= buffer_periode_len || isNan(";
    5367           0 :     ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
    5368           0 :     ss <<"))\n";
    5369           0 :     ss <<"        nPeriode = 0;\n    else\n";
    5370             : #endif
    5371           0 :     ss <<"        nPeriode = "<<vSubArguments[3]->GenSlidingWindowDeclRef();
    5372           0 :     ss <<";\n";
    5373             : #ifdef ISNAN
    5374           0 :     ss <<"    if(gid0 >= buffer_nMonate_len || isNan(";
    5375           0 :     ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
    5376           0 :     ss <<"))\n";
    5377           0 :     ss <<"        nMonate = 0;\n    else\n";
    5378             : #endif
    5379           0 :     ss <<"        nMonate = (int)"<<vSubArguments[4]->GenSlidingWindowDeclRef();
    5380           0 :     ss <<";\n";
    5381           0 :     ss <<"    double nAbRate = 1.0 - pow(nRest / nWert, 1.0 / nDauer);\n";
    5382           0 :     ss <<"    nAbRate = ((int)(nAbRate * 1000.0 + 0.5)) / 1000.0;\n";
    5383           0 :     ss <<"    double nErsteAbRate = nWert * nAbRate * nMonate / 12.0;\n";
    5384           0 :     ss <<"    double nGda2 = 0.0;\n";
    5385           0 :     ss <<"    if ((int)(nPeriode) == 1)\n";
    5386           0 :     ss <<"        nGda2 = nErsteAbRate;\n";
    5387           0 :     ss <<"    else\n";
    5388           0 :     ss <<"    {\n";
    5389           0 :     ss <<"        double nSummAbRate = nErsteAbRate;\n";
    5390           0 :     ss <<"        double nMin = nDauer;\n";
    5391           0 :     ss <<"        if (nMin > nPeriode) nMin = nPeriode;\n";
    5392           0 :     ss <<"        int iMax = (int)nMin;\n";
    5393           0 :     ss <<"        for (int i = 2; i <= iMax; i++)\n";
    5394           0 :     ss <<"        {\n";
    5395           0 :     ss <<"            nGda2 = (nWert - nSummAbRate) * nAbRate;\n";
    5396           0 :     ss <<"            nSummAbRate += nGda2;\n";
    5397           0 :     ss <<"        }\n";
    5398           0 :     ss <<"        if (nPeriode > nDauer)\n";
    5399           0 :     ss <<"            nGda2 = ((nWert - nSummAbRate)";
    5400           0 :     ss <<"* nAbRate * (12.0 - nMonate)) / 12.0;\n";
    5401           0 :     ss <<"    }\n";
    5402           0 :     ss <<"    tmp = nGda2;\n";
    5403           0 :     ss <<"    return tmp;\n";
    5404           0 :     ss <<"}";
    5405           0 : }
    5406           0 : }}
    5407             : 
    5408             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10