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

Generated by: LCOV version 1.11