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

Generated by: LCOV version 1.10