[Libreoffice-commits] core.git: Branch 'private/kohei/calc-group-interpreter-4-dynamic-kernels-reviewed' - 2 commits - sc/Library_scopencl.mk sc/source
Kohei Yoshida
kohei.yoshida at collabora.com
Tue Oct 29 21:19:13 CET 2013
sc/Library_scopencl.mk | 4
sc/source/core/opencl/OPBase.hxx | 197 --
sc/source/core/opencl/OP_Statistical.cxx | 738 -------
sc/source/core/opencl/OP_database.cxx | 32
sc/source/core/opencl/OP_finacial.cxx | 2916 -------------------------------
sc/source/core/opencl/OP_math.cxx | 98 -
sc/source/core/opencl/formulagroupcl.cxx | 8
sc/source/core/opencl/op_database.cxx | 18
sc/source/core/opencl/op_database.hxx | 21
sc/source/core/opencl/op_financial.cxx | 2720 ++++++++++++++++++++++++++++
sc/source/core/opencl/op_financial.hxx | 337 +++
sc/source/core/opencl/op_math.cxx | 88
sc/source/core/opencl/op_math.hxx | 38
sc/source/core/opencl/op_statistical.cxx | 700 +++++++
sc/source/core/opencl/op_statistical.hxx | 109 +
sc/source/core/opencl/opbase.hxx | 201 ++
16 files changed, 4240 insertions(+), 3985 deletions(-)
New commits:
commit 05cde23cb837083ff175dc68708943cf8592390b
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Tue Oct 29 15:44:27 2013 -0400
Properly split header and source files.
Without this, formulagroupcl.cxx alone would take minutes to compile.
Change-Id: I7d55ed22fbd7f5c0859d5f1bf2a4e4eafd47ac3b
diff --git a/sc/Library_scopencl.mk b/sc/Library_scopencl.mk
index b7e4b05..0efe3cf 100644
--- a/sc/Library_scopencl.mk
+++ b/sc/Library_scopencl.mk
@@ -38,6 +38,10 @@ $(eval $(call gb_Library_use_libraries,scopencl,\
$(eval $(call gb_Library_add_exception_objects,scopencl,\
sc/source/core/opencl/formulagroupcl \
sc/source/core/opencl/openclwrapper \
+ sc/source/core/opencl/op_financial \
+ sc/source/core/opencl/op_database \
+ sc/source/core/opencl/op_math \
+ sc/source/core/opencl/op_statistical \
sc/source/core/opencl/clcc/clew \
))
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index aca185a..665f822 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -18,10 +18,10 @@
#include "openclwrapper.hxx"
-#include "op_financial.cxx"
-#include "op_database.cxx"
-#include "op_math.cxx"
-#include "op_statistical.cxx"
+#include "op_financial.hxx"
+#include "op_database.hxx"
+#include "op_math.hxx"
+#include "op_statistical.hxx"
#include "formulagroupcl_public.hxx"
#include "formulagroupcl_finacial.hxx"
diff --git a/sc/source/core/opencl/op_database.cxx b/sc/source/core/opencl/op_database.cxx
index 147a862..471ad7c 100644
--- a/sc/source/core/opencl/op_database.cxx
+++ b/sc/source/core/opencl/op_database.cxx
@@ -7,26 +7,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#ifndef OP_DATABASE
-#define OP_DATABASE
-#include "formulagroup.hxx"
-#include "document.hxx"
-#include "formulacell.hxx"
-#include "tokenarray.hxx"
-#include "compiler.hxx"
-#include "interpre.hxx"
-#include "opbase.hxx"
-#include<list>
-#include <iostream>
-#include <sstream>
-#include <algorithm>
-
-#include <memory>
-using namespace formula;
+#include "op_database.hxx"
namespace sc { namespace opencl {
+
+
}}
-#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/op_database.hxx b/sc/source/core/opencl/op_database.hxx
new file mode 100644
index 0000000..e29cc3f
--- /dev/null
+++ b/sc/source/core/opencl/op_database.hxx
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef SC_OPENCL_OP_DATABASE_HXX
+#define SC_OPENCL_OP_DATABASE_HXX
+
+namespace sc { namespace opencl {
+
+
+
+}}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index da48e44..a638530 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -7,16 +7,15 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#ifndef OP_FINACIAL
-#define OP_FINACIAL
+#include "op_financial.hxx"
+
#include "formulagroup.hxx"
#include "document.hxx"
#include "formulacell.hxx"
#include "tokenarray.hxx"
#include "compiler.hxx"
#include "interpre.hxx"
-#include "opbase.hxx"
-#include<list>
+#include <list>
#include <iostream>
#include <sstream>
#include <algorithm>
@@ -25,1411 +24,1316 @@
using namespace formula;
namespace sc { namespace opencl {
-class RRI: public SlidingFunctionBase, public OpBase
+
+void RRI::GenSlidingWindowFunction(
+ std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
{
-public:
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
- const std::string sSymName, SubArguments &vSubArguments)
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
{
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"(";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
- ss << ") {\n\t";
- ss << "double tmp = " << GetBottom() <<";\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss << "double fv;\n\t";
- ss << "double pv;\n\t";
- ss << "double nper;\n\t";
-#ifdef ISNAN
- FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
-
- FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur1);
-
- FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur2);
-
- ss<< "int buffer_nper_len = ";
- ss<< tmpCurDVR0->GetArrayLength();
- ss << ";\n\t";
-
- ss<< "int buffer_pv_len = ";
- ss<< tmpCurDVR1->GetArrayLength();
- ss << ";\n\t";
-
- ss<< "int buffer_fv_len = ";
- ss<< tmpCurDVR2->GetArrayLength();
- ss << ";\n\t";
-#endif
-
-#ifdef ISNAN
- ss<<"if(gid0>=buffer_nper_len || isNan(";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"nper = 0;\n\telse \n\t\t";
-#endif
- ss<<"nper = ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
+ }
+ ss << ") {\n\t";
+ ss << "double tmp = " << GetBottom() <<";\n\t";
+ ss << "int gid0 = get_global_id(0);\n\t";
+ ss << "double fv;\n\t";
+ ss << "double pv;\n\t";
+ ss << "double nper;\n\t";
+#ifdef ISNAN
+ FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
+
+ FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur1);
+
+ FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur2);
+
+ ss<< "int buffer_nper_len = ";
+ ss<< tmpCurDVR0->GetArrayLength();
+ ss << ";\n\t";
+
+ ss<< "int buffer_pv_len = ";
+ ss<< tmpCurDVR1->GetArrayLength();
+ ss << ";\n\t";
+
+ ss<< "int buffer_fv_len = ";
+ ss<< tmpCurDVR2->GetArrayLength();
+ ss << ";\n\t";
+#endif
#ifdef ISNAN
- ss<<"if(gid0>=buffer_pv_len || isNan(";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"pv = 0;\n\telse \n\t\t";
+ ss<<"if(gid0>=buffer_nper_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"nper = 0;\n\telse \n\t\t";
#endif
- ss<<"pv = ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
+ ss<<"nper = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
#ifdef ISNAN
- ss<<"if(gid0>=buffer_pv_len || isNan(";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"fv = 0;\n\telse \n\t\t";
+ ss<<"if(gid0>=buffer_pv_len || isNan(";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"pv = 0;\n\telse \n\t\t";
#endif
- ss<<"fv = ";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
- ss << "tmp = pow(fv/pv,1.0/nper)-1;\n\t;";
- ss << "return tmp;\n";
- ss << "}";
- }
-};
+ ss<<"pv = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
-class OpRRI:public RRI
-{
-public:
- virtual std::string GetBottom(void) { return "0"; }
- virtual std::string BinFuncName(void) const { return "RRI"; }
-};
+#ifdef ISNAN
+ ss<<"if(gid0>=buffer_pv_len || isNan(";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"fv = 0;\n\telse \n\t\t";
+#endif
+ ss<<"fv = ";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+ ss << "tmp = pow(fv/pv,1.0/nper)-1;\n\t;";
+ ss << "return tmp;\n";
+ ss << "}";
+}
-class OpNominal: public Normal
+void OpNominal::GenSlidingWindowFunction(
+ std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
{
-public:
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
- const std::string sSymName, SubArguments &vSubArguments)
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
{
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"(";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
- ss << ") {\n\t";
- ss << "double tmp = 0;\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss <<"double tmp0 = ";
- ss <<vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n\t";
- ss <<"double tmp1 = ";
- ss <<vSubArguments[1]->GenSlidingWindowDeclRef()<<";\n\t";
-#ifdef ISNAN
-
- FormulaToken *tmpCur0 = vSubArguments[0]
- ->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
- ss<<"if("<<tmpCurDVR0->GetArrayLength()<<"<=gid0||";
- ss <<"isNan(tmp0))\n\t\t";
- ss<<" tmp0= 0;\n\t";
- FormulaToken *tmpCur1 = vSubArguments[1]
- ->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur1);
- ss<<"if("<<tmpCurDVR1->GetArrayLength()<<"<=gid0||";
- ss <<"isNan(tmp1))\n\t\t";
- ss<<" tmp1= 0;\n\t";
-#endif
- ss<<"if(tmp1==0)\n\t";
- ss<<"\treturn 0;\n\t";
- ss<<"tmp=( pow( tmp0+ 1.0, 1.0 / tmp1 ) - 1.0 ) *";
- ss<<"tmp1;\n\t";
- ss << "return tmp;\n";
- ss << "}";
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
}
- virtual std::string BinFuncName(void) const { return "NOMINAL_ADD"; }
-};
+ ss << ") {\n\t";
+ ss << "double tmp = 0;\n\t";
+ ss << "int gid0 = get_global_id(0);\n\t";
+ ss <<"double tmp0 = ";
+ ss <<vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n\t";
+ ss <<"double tmp1 = ";
+ ss <<vSubArguments[1]->GenSlidingWindowDeclRef()<<";\n\t";
+#ifdef ISNAN
+
+ FormulaToken *tmpCur0 = vSubArguments[0]
+ ->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
+ ss<<"if("<<tmpCurDVR0->GetArrayLength()<<"<=gid0||";
+ ss <<"isNan(tmp0))\n\t\t";
+ ss<<" tmp0= 0;\n\t";
+ FormulaToken *tmpCur1 = vSubArguments[1]
+ ->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur1);
+ ss<<"if("<<tmpCurDVR1->GetArrayLength()<<"<=gid0||";
+ ss <<"isNan(tmp1))\n\t\t";
+ ss<<" tmp1= 0;\n\t";
+#endif
+ ss<<"if(tmp1==0)\n\t";
+ ss<<"\treturn 0;\n\t";
+ ss<<"tmp=( pow( tmp0+ 1.0, 1.0 / tmp1 ) - 1.0 ) *";
+ ss<<"tmp1;\n\t";
+ ss << "return tmp;\n";
+ ss << "}";
+}
-class OpDollarde:public Normal
+void OpDollarde::GenSlidingWindowFunction(
+ std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
{
-public:
- virtual std::string GetBottom(void) { return "0"; }
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
- const std::string sSymName, SubArguments &vSubArguments)
- {
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"(";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
- ss << ") {\n\t";
- ss << "double tmp = " << GetBottom() <<";\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss << "double fInt = " << GetBottom() <<";\n\t";
- ss << "double dollar;\n\t";
- ss << "double fFrac;\n\t";
- #ifdef ISNAN
- FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
- FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur1);
- ss<< "int buffer_dollar_len = ";
- ss<< tmpCurDVR0->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_frac_len = ";
- ss<< tmpCurDVR1->GetArrayLength();
- ss << ";\n\t";
- #endif
- #ifdef ISNAN
- ss<<"if((gid0)>=buffer_dollar_len || isNan(";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"dollar = 0;\n\telse \n\t\t";
- #endif
- ss<<"dollar = ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
- #ifdef ISNAN
- ss<<"if((gid0)>=buffer_frac_len || isNan(";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"fFrac = 0;\n\telse \n\t\t";
- #endif
- ss<<"fFrac = ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
- ss << "tmp = modf( dollar , &fInt );\n\t";
- ss << "tmp /= fFrac;\n\t";
- ss << "tmp *= pow( 10.0 , ceil( log10(fFrac ) ) );\n\t";
- ss << "tmp += fInt;\t";
- ss << "\n\treturn tmp;\n";
- ss << "}";
- }
-virtual std::string BinFuncName(void) const { return "Dollarde"; }
-
-};
-class OpDollarfr:public Normal
-{
-public:
- virtual std::string GetBottom(void) { return "0"; }
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
- const std::string sSymName, SubArguments &vSubArguments)
- {
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"(";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
- ss << ") {\n\t";
- ss << "double tmp = " << GetBottom() <<";\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss << "double fInt = " << GetBottom() <<";\n\t";
- ss << "double dollar;\n\t";
- ss << "double fFrac;\n\t";
- #ifdef ISNAN
- FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
- FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur1);
- ss<< "int buffer_dollar_len = ";
- ss<< tmpCurDVR0->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_frac_len = ";
- ss<< tmpCurDVR1->GetArrayLength();
- ss << ";\n\t";
- #endif
- #ifdef ISNAN
- ss<<"if((gid0)>=buffer_dollar_len || isNan(";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"dollar = 0;\n\telse \n\t\t";
- #endif
- ss<<"dollar = ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
- #ifdef ISNAN
- ss<<"if((gid0)>=buffer_frac_len || isNan(";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"fFrac = 0;\n\telse \n\t\t";
- #endif
- ss<<"fFrac = ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
- ss << "tmp = modf( dollar , &fInt );\n\t";
- ss << "tmp *= fFrac;\n\t";
- ss << "tmp *= pow( 10.0 , -ceil( log10(fFrac ) ) );\n\t";
- ss << "tmp += fInt;\t";
- ss << "\n\treturn tmp;\n";
- ss << "}";
- }
- virtual std::string BinFuncName(void) const { return "Dollarfr"; }
-
-};
-class OpDISC: public Normal {
-public:
- virtual std::string GetBottom(void) { return "0"; }
-
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
- const std::string sSymName, SubArguments &vSubArguments)
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
{
-
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"(";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
- ss << ") {\n\t";
- ss << "double tmp = " << GetBottom() <<";\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss << "double settle = " << GetBottom() <<";\n\t";
- ss << "double maturity = " << GetBottom() <<";\n\t";
- ss << "double price = " << GetBottom() <<";\n\t";
- ss << "double redemp = " << GetBottom() <<";\n\t";
- ss << "int mode = " << GetBottom() <<";\n\t";
- #ifdef ISNAN
- FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
- FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur1);
- FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur2);
- FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur3);
- FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur4);
- ss<< "int buffer_settle_len = ";
- ss<< tmpCurDVR0->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_maturity_len = ";
- ss<< tmpCurDVR1->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_price_len = ";
- ss<< tmpCurDVR2->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_redemp_len = ";
- ss<< tmpCurDVR3->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_mode_len = ";
- ss<< tmpCurDVR4->GetArrayLength();
- ss << ";\n\t";
- #endif
- #ifdef ISNAN
- ss<<"if((gid0)>=buffer_settle_len || isNan(";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"settle = 0;\n\telse \n\t\t";
- #endif
- ss<<"settle = ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
- #ifdef ISNAN
- ss<<"if((gid0)>=buffer_maturity_len || isNan(";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"maturity = 0;\n\telse \n\t\t";
- #endif
- ss<<"maturity = ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
- #ifdef ISNAN
- ss<<"if((gid0)>=buffer_price_len || isNan(";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"price = 0;\n\telse \n\t\t";
- #endif
- ss<<"price = ";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
- #ifdef ISNAN
- ss<<"if((gid0)>=buffer_redemp_len || isNan(";
- ss << vSubArguments[3]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"redemp = 0;\n\telse \n\t\t";
- #endif
- ss<<"redemp = ";
- ss << vSubArguments[3]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
- #ifdef ISNAN
- ss<<"if((gid0)>=buffer_mode_len || isNan(";
- ss << vSubArguments[4]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"mode = 0;\n\telse \n\t\t";
- #endif
- ss<<"mode = ";
- ss << vSubArguments[4]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
- ss << "int nNullDate = GetNullDate( 30 , 12 , 1899 );\n\t";
- ss << "tmp = 1.0 - price / redemp;\n\t";
- ss << "tmp /= GetYearFrac( nNullDate , settle , maturity , mode );\n\t";
- ss << "return tmp;\n";
- ss << "}";
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
}
- virtual std::string BinFuncName(void) const { return "DISC"; }
-};
-class OpINTRATE: public Normal {
-public:
- virtual std::string GetBottom(void) { return "0"; }
-
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
- const std::string sSymName, SubArguments &vSubArguments)
- {
+ ss << ") {\n\t";
+ ss << "double tmp = " << GetBottom() <<";\n\t";
+ ss << "int gid0 = get_global_id(0);\n\t";
+ ss << "double fInt = " << GetBottom() <<";\n\t";
+ ss << "double dollar;\n\t";
+ ss << "double fFrac;\n\t";
+#ifdef ISNAN
+ FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
+ FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur1);
+ ss<< "int buffer_dollar_len = ";
+ ss<< tmpCurDVR0->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_frac_len = ";
+ ss<< tmpCurDVR1->GetArrayLength();
+ ss << ";\n\t";
+#endif
+#ifdef ISNAN
+ ss<<"if((gid0)>=buffer_dollar_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"dollar = 0;\n\telse \n\t\t";
+#endif
+ ss<<"dollar = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+#ifdef ISNAN
+ ss<<"if((gid0)>=buffer_frac_len || isNan(";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"fFrac = 0;\n\telse \n\t\t";
+#endif
+ ss<<"fFrac = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+ ss << "tmp = modf( dollar , &fInt );\n\t";
+ ss << "tmp /= fFrac;\n\t";
+ ss << "tmp *= pow( 10.0 , ceil( log10(fFrac ) ) );\n\t";
+ ss << "tmp += fInt;\t";
+ ss << "\n\treturn tmp;\n";
+ ss << "}";
+}
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"(";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
- ss << ") {\n\t";
- ss << "double tmp = " << GetBottom() <<";\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss << "double settle = " << GetBottom() <<";\n\t";
- ss << "double maturity = " << GetBottom() <<";\n\t";
- ss << "double price = " << GetBottom() <<";\n\t";
- ss << "double redemp = " << GetBottom() <<";\n\t";
- ss << "int mode = " << GetBottom() <<";\n\t";
- #ifdef ISNAN
- FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
- FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur1);
- FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur2);
- FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur3);
- FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur4);
- ss << "int buffer_settle_len = ";
- ss << tmpCurDVR0->GetArrayLength();
- ss << ";\n\t";
- ss << "int buffer_maturity_len = ";
- ss << tmpCurDVR1->GetArrayLength();
- ss << ";\n\t";
- ss << "int buffer_price_len = ";
- ss << tmpCurDVR2->GetArrayLength();
- ss << ";\n\t";
- ss << "int buffer_redemp_len = ";
- ss << tmpCurDVR3->GetArrayLength();
- ss << ";\n\t";
- ss << "int buffer_mode_len = ";
- ss << tmpCurDVR4->GetArrayLength();
- ss << ";\n\t";
- #endif
- #ifdef ISNAN
- ss << "if((gid0)>=buffer_settle_len || isNan(";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss << "))\n\t\t";
- ss << "settle = 0;\n\telse \n\t\t";
- #endif
- ss << "settle = ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss << ";\n\t";
- #ifdef ISNAN
- ss << "if((gid0)>=buffer_maturity_len || isNan(";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss << "))\n\t\t";
- ss << "maturity = 0;\n\telse \n\t\t";
- #endif
- ss << "maturity = ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss << ";\n\t";
- #ifdef ISNAN
- ss << "if((gid0)>=buffer_price_len || isNan(";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss << "))\n\t\t";
- ss << "price = 0;\n\telse \n\t\t";
- #endif
- ss << "price = ";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss << ";\n\t";
- #ifdef ISNAN
- ss << "if((gid0)>=buffer_redemp_len || isNan(";
- ss << vSubArguments[3]->GenSlidingWindowDeclRef();
- ss << "))\n\t\t";
- ss << "redemp = 0;\n\telse \n\t\t";
- #endif
- ss << "redemp = ";
- ss << vSubArguments[3]->GenSlidingWindowDeclRef();
- ss << ";\n\t";
- #ifdef ISNAN
- ss << "if((gid0)>=buffer_mode_len || isNan(";
- ss << vSubArguments[4]->GenSlidingWindowDeclRef();
- ss << "))\n\t\t";
- ss << "mode = 0;\n\telse \n\t\t";
- #endif
- ss << "mode = ";
- ss << vSubArguments[4]->GenSlidingWindowDeclRef();
- ss << ";\n\t";
- ss << "int nNullDate = GetNullDate(30,12,1899);\n\t";
- ss << "tmp = (redemp / price - 1.0) / GetYearDiff(nNullDate, settle, maturity, mode);\n\t";
- ss << "return tmp;\n";
- ss << "}";
- }
- virtual std::string BinFuncName(void) const { return "INTRATE"; }
-};
-class Fvschedule: public Normal
+void OpDollarfr::GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments)
{
-public:
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
- const std::string sSymName, SubArguments &vSubArguments)
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
{
- FormulaToken* pCur = vSubArguments[1]->GetFormulaToken();
- assert(pCur);
- const formula::DoubleVectorRefToken* pCurDVR =
- dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
- size_t nCurWindowSize = pCurDVR->GetRefRowSize();
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"(";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
- ss << ") {\n\t";
- ss << "double tmp = 1.0;\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss << ";\n\t";
- #ifdef ISNAN
- ss << "if (isNan(arg0))\n\t\t";
- ss << "arg0 = 0;\n\t";
- #endif
- ss << "double arg1;\n\t";
- ss << "int arrayLength = " << pCurDVR->GetArrayLength() << ";\n\t";
- #ifdef ISNAN
- ss << "for (int i = 0; i + gid0 < arrayLength &&";
- ss << " i < " << nCurWindowSize << "; i++){\n\t\t";
- #else
- ss << "for (int i = 0; i < " << nCurWindowSize << "; i++){\n\t\t";
- #endif
- ss << "arg1 = ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n\t\t\t";
- #ifdef ISNAN
- ss << "if (isNan(arg1))\n\t\t\t\t";
- ss << "arg1 = 0;\n\t\t\t";
- #endif
- ss << "tmp *= arg1 + 1.0;\n\t\t";
- ss << "}\n\t";
- ss << "return (double)tmp * arg0";
- ss << ";\n}";
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
}
-};
+ ss << ") {\n\t";
+ ss << "double tmp = " << GetBottom() <<";\n\t";
+ ss << "int gid0 = get_global_id(0);\n\t";
+ ss << "double fInt = " << GetBottom() <<";\n\t";
+ ss << "double dollar;\n\t";
+ ss << "double fFrac;\n\t";
+#ifdef ISNAN
+ FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
+ FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur1);
+ ss<< "int buffer_dollar_len = ";
+ ss<< tmpCurDVR0->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_frac_len = ";
+ ss<< tmpCurDVR1->GetArrayLength();
+ ss << ";\n\t";
+#endif
+#ifdef ISNAN
+ ss<<"if((gid0)>=buffer_dollar_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"dollar = 0;\n\telse \n\t\t";
+#endif
+ ss<<"dollar = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+#ifdef ISNAN
+ ss<<"if((gid0)>=buffer_frac_len || isNan(";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"fFrac = 0;\n\telse \n\t\t";
+#endif
+ ss<<"fFrac = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+ ss << "tmp = modf( dollar , &fInt );\n\t";
+ ss << "tmp *= fFrac;\n\t";
+ ss << "tmp *= pow( 10.0 , -ceil( log10(fFrac ) ) );\n\t";
+ ss << "tmp += fInt;\t";
+ ss << "\n\treturn tmp;\n";
+ ss << "}";
+}
-class Cumipmt: public Normal
+void OpDISC::GenSlidingWindowFunction(
+ std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
{
-public:
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
- const std::string sSymName, SubArguments &vSubArguments)
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
{
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"(";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
- ss << ") {\n\t";
-
- ss << " int gid0 = get_global_id(0);\n";
- ss << "double fRate,fVal;\n\t";
- ss <<"int nStartPer,nEndPer,nNumPeriods,nPayType;\n\t";
-#ifdef ISNAN
- FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
- FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur1);
- FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur2);
- FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur3);
- FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur4);
- FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR5= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur5);
- ss<< "int buffer_rate_len = ";
- ss<< tmpCurDVR0->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_NumPeriods_len = ";
- ss<< tmpCurDVR1->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_Val_len = ";
- ss<< tmpCurDVR2->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_StartPer_len = ";
- ss<< tmpCurDVR3->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_EndPer_len = ";
- ss<< tmpCurDVR4->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_PayType_len = ";
- ss<< tmpCurDVR5->GetArrayLength();
- ss << ";\n\t";
-#endif
-#ifdef ISNAN
- ss <<"if(gid0 >= buffer_rate_len || isNan(";
- ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
- ss <<"))\n\t\t";
- ss <<"fRate = 0;\n\telse\n\t\t";
-#endif
- ss <<"fRate = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
- ss <<";\n\t";
-#ifdef ISNAN
- ss <<"if(gid0 >= buffer_NumPeriods_len || isNan(";
- ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
- ss <<"))\n\t\t";
- ss <<"nNumPeriods = 0;\n\telse\n\t\t";
-#endif
- ss <<"nNumPeriods = (int)";
- ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
- ss <<";\n\t";
-#ifdef ISNAN
- ss <<"if(gid0 >= buffer_Val_len || isNan(";
- ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
- ss <<"))\n\t\t";
- ss <<"fVal = 0;\n\telse\n\t\t";
-#endif
- ss <<"fVal = "<<vSubArguments[2]->GenSlidingWindowDeclRef();
- ss <<";\n\t";
-#ifdef ISNAN
- ss <<"if(gid0 >= buffer_StartPer_len || isNan(";
- ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
- ss <<"))\n\t\t";
- ss <<"nStartPer = 0;\n\telse\n\t\t";
-#endif
- ss <<"nStartPer = (int)"<<vSubArguments[3]->GenSlidingWindowDeclRef();
- ss <<";\n\t";
-#ifdef ISNAN
- ss <<"if(gid0 >= buffer_EndPer_len || isNan(";
- ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
- ss <<"))\n\t\t";
- ss <<"nEndPer = 0;\n\telse\n\t\t";
-#endif
- ss <<"nEndPer = (int)"<<vSubArguments[4]->GenSlidingWindowDeclRef();
- ss <<";\n\t";
-#ifdef ISNAN
- ss <<"if(gid0 >= buffer_PayType_len || isNan(";
- ss <<vSubArguments[5]->GenSlidingWindowDeclRef();
- ss <<"))\n\t\t";
- ss <<"nPayType = 0;\n\telse\n\t\t";
-#endif
- ss <<"nPayType = (int)"<<vSubArguments[5]->GenSlidingWindowDeclRef();
- ss <<";\n\t";
- ss << " double fRmz;\n";
- ss << "fRmz = GetRmz( fRate, nNumPeriods, fVal, 0.0, nPayType );\n";
- ss << "double tmp = 0.0;\n";
- ss << "uint nStart = nStartPer ;\n";
- ss << "uint nEnd = nEndPer ;\n";
- ss << " if( nStart == 1 )\n";
- ss << " {\n";
- ss << " if( nPayType <= 0 )\n";
- ss << " tmp = -fVal;\n";
- ss << " nStart++;\n";
- ss << " }\n";
- ss << " for( uint i = nStart ; i <= nEnd ; i++ )\n";
- ss << " {\n";
- ss << " if( nPayType > 0 )\n";
- ss << " tmp += GetZw( fRate, convert_double( i - 2 ), ";
- ss << "fRmz, fVal, 1 ) - fRmz;\n";
- ss << " else\n";
- ss << " tmp += GetZw( fRate, convert_double( i - 1 ), ";
- ss << "fRmz, fVal, 0 );\n";
- ss << " }\n";
- ss << "tmp *= fRate;\n";
- ss << "return tmp;\n";
- ss << "}";
-
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
}
-};
+ ss << ") {\n\t";
+ ss << "double tmp = " << GetBottom() <<";\n\t";
+ ss << "int gid0 = get_global_id(0);\n\t";
+ ss << "double settle = " << GetBottom() <<";\n\t";
+ ss << "double maturity = " << GetBottom() <<";\n\t";
+ ss << "double price = " << GetBottom() <<";\n\t";
+ ss << "double redemp = " << GetBottom() <<";\n\t";
+ ss << "int mode = " << GetBottom() <<";\n\t";
+#ifdef ISNAN
+ FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
+ FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur1);
+ FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur2);
+ FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur3);
+ FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur4);
+ ss<< "int buffer_settle_len = ";
+ ss<< tmpCurDVR0->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_maturity_len = ";
+ ss<< tmpCurDVR1->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_price_len = ";
+ ss<< tmpCurDVR2->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_redemp_len = ";
+ ss<< tmpCurDVR3->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_mode_len = ";
+ ss<< tmpCurDVR4->GetArrayLength();
+ ss << ";\n\t";
+#endif
+#ifdef ISNAN
+ ss<<"if((gid0)>=buffer_settle_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"settle = 0;\n\telse \n\t\t";
+#endif
+ ss<<"settle = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+#ifdef ISNAN
+ ss<<"if((gid0)>=buffer_maturity_len || isNan(";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"maturity = 0;\n\telse \n\t\t";
+#endif
+ ss<<"maturity = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+#ifdef ISNAN
+ ss<<"if((gid0)>=buffer_price_len || isNan(";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"price = 0;\n\telse \n\t\t";
+#endif
+ ss<<"price = ";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+#ifdef ISNAN
+ ss<<"if((gid0)>=buffer_redemp_len || isNan(";
+ ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"redemp = 0;\n\telse \n\t\t";
+#endif
+ ss<<"redemp = ";
+ ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+#ifdef ISNAN
+ ss<<"if((gid0)>=buffer_mode_len || isNan(";
+ ss << vSubArguments[4]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"mode = 0;\n\telse \n\t\t";
+#endif
+ ss<<"mode = ";
+ ss << vSubArguments[4]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+ ss << "int nNullDate = GetNullDate( 30 , 12 , 1899 );\n\t";
+ ss << "tmp = 1.0 - price / redemp;\n\t";
+ ss << "tmp /= GetYearFrac( nNullDate , settle , maturity , mode );\n\t";
+ ss << "return tmp;\n";
+ ss << "}";
+}
-class IRR: public Normal
+void OpINTRATE::GenSlidingWindowFunction(
+ std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
{
-public:
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
- const std::string sSymName, SubArguments &vSubArguments)
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
{
- FormulaToken* pCur = vSubArguments[0]->GetFormulaToken();
- assert(pCur);
- const formula::DoubleVectorRefToken* pCurDVR =
- dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
- size_t nCurWindowSize = pCurDVR->GetRefRowSize();
- FormulaToken* pCur1 = vSubArguments[1]->GetFormulaToken();
- assert(pCur1);
- const formula::SingleVectorRefToken* pSVR1 =
- dynamic_cast< const formula::SingleVectorRefToken* >(pCur1);
- assert(pSVR1);
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"(";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
- ss << ") {\n";
- ss << "#define Epsilon 1.0E-7\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss << "double fSchaetzwert = ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n\t";
- ss << "double fEps = 1.0;\n\t";
- ss << "double x = 0.0, xNeu = 0.0, fZaehler = 0.0, fNenner = 0.0;\n\t";
- ss << "double nCount = 0.0;\n\t";
- ss << "int argLen1 = " << pSVR1->GetArrayLength() << ";\n\t";
- #ifdef ISNAN
- ss << "if (gid0 >= argLen1)\n\t\t";
- ss << "fSchaetzwert = 0.1;\n\t";
- ss << "if (isNan(fSchaetzwert))\n\t\t";
- ss << "x = 0.1;\n\t";
- ss << "else\n\t\t";
- #endif
- ss << "x = fSchaetzwert;\n\t";
- ss << "unsigned short nItCount = 0;\n\t";
- ss << "while (fEps > Epsilon && nItCount < 20){\n\t\t";
- ss << "nCount = 0.0;\n\t\tfZaehler = 0.0;\n\t\tfNenner = 0.0;\n\t\t";
- ss << "double arg0;\n\t\t";
- ss << "int arrayLength = " << pCurDVR->GetArrayLength() << ";\n\t";
- #ifdef ISNAN
- ss << "for (int i = 0; i + gid0 < arrayLength &&";
- ss << " i < " << nCurWindowSize << "; i++){\n\t\t\t";
- #else
- ss << "for (int i = 0; i < " << nCurWindowSize << "; i++){\n\t\t\t";
- #endif
- ss << "arg0 = ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n\t\t\t";
- #ifdef ISNAN
- ss << "if (isNan(arg0))\n\t\t\t\t";
- ss << "continue;\n\t\t\t";
- #endif
- ss << "fZaehler += arg0 / pow(1.0+x, nCount);\n\t\t\t";
- ss << "fNenner += -nCount * arg0 / pow(1.0+x,nCount+1.0);\n\t\t\t";
- ss << "nCount+=1;\n";
- ss << "\n\t\t}\n\t\t";
- ss << "xNeu = x - fZaehler / fNenner;\n\t\t";
- ss << "fEps = fabs(xNeu - x);\n\t\t";
- ss << "x = xNeu;\n\t\t";
- ss << "nItCount++;\n\t}\n\t";
- ss << "if (fSchaetzwert == 0.0 && fabs(x) < Epsilon)\n\t\t";
- ss << "x = 0.0;\n\t";
- ss << "if (fEps < Epsilon)\n\t\t";
- ss << "return x;\n\t";
- ss << "else\n\t\t";
- ss << "return (double)523;\n";
- ss << "}";
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
}
-};
-class OpIRR: public IRR{
-public:
- virtual std::string GetBottom(void) { return "0"; }
- virtual std::string BinFuncName(void) const { return "IRR"; }
-};
-
-class XNPV: public Normal
+ ss << ") {\n\t";
+ ss << "double tmp = " << GetBottom() <<";\n\t";
+ ss << "int gid0 = get_global_id(0);\n\t";
+ ss << "double settle = " << GetBottom() <<";\n\t";
+ ss << "double maturity = " << GetBottom() <<";\n\t";
+ ss << "double price = " << GetBottom() <<";\n\t";
+ ss << "double redemp = " << GetBottom() <<";\n\t";
+ ss << "int mode = " << GetBottom() <<";\n\t";
+#ifdef ISNAN
+ FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
+ FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur1);
+ FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur2);
+ FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur3);
+ FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur4);
+ ss << "int buffer_settle_len = ";
+ ss << tmpCurDVR0->GetArrayLength();
+ ss << ";\n\t";
+ ss << "int buffer_maturity_len = ";
+ ss << tmpCurDVR1->GetArrayLength();
+ ss << ";\n\t";
+ ss << "int buffer_price_len = ";
+ ss << tmpCurDVR2->GetArrayLength();
+ ss << ";\n\t";
+ ss << "int buffer_redemp_len = ";
+ ss << tmpCurDVR3->GetArrayLength();
+ ss << ";\n\t";
+ ss << "int buffer_mode_len = ";
+ ss << tmpCurDVR4->GetArrayLength();
+ ss << ";\n\t";
+#endif
+#ifdef ISNAN
+ ss << "if((gid0)>=buffer_settle_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss << "))\n\t\t";
+ ss << "settle = 0;\n\telse \n\t\t";
+#endif
+ ss << "settle = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss << ";\n\t";
+#ifdef ISNAN
+ ss << "if((gid0)>=buffer_maturity_len || isNan(";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss << "))\n\t\t";
+ ss << "maturity = 0;\n\telse \n\t\t";
+#endif
+ ss << "maturity = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss << ";\n\t";
+#ifdef ISNAN
+ ss << "if((gid0)>=buffer_price_len || isNan(";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss << "))\n\t\t";
+ ss << "price = 0;\n\telse \n\t\t";
+#endif
+ ss << "price = ";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss << ";\n\t";
+#ifdef ISNAN
+ ss << "if((gid0)>=buffer_redemp_len || isNan(";
+ ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss << "))\n\t\t";
+ ss << "redemp = 0;\n\telse \n\t\t";
+#endif
+ ss << "redemp = ";
+ ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss << ";\n\t";
+#ifdef ISNAN
+ ss << "if((gid0)>=buffer_mode_len || isNan(";
+ ss << vSubArguments[4]->GenSlidingWindowDeclRef();
+ ss << "))\n\t\t";
+ ss << "mode = 0;\n\telse \n\t\t";
+#endif
+ ss << "mode = ";
+ ss << vSubArguments[4]->GenSlidingWindowDeclRef();
+ ss << ";\n\t";
+ ss << "int nNullDate = GetNullDate(30,12,1899);\n\t";
+ ss << "tmp = (redemp / price - 1.0) / GetYearDiff(nNullDate, settle, maturity, mode);\n\t";
+ ss << "return tmp;\n";
+ ss << "}";
+}
+
+void Fvschedule::GenSlidingWindowFunction(
+ std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
{
- public:
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
- const std::string sSymName, SubArguments &vSubArguments)
+ FormulaToken* pCur = vSubArguments[1]->GetFormulaToken();
+ assert(pCur);
+ const formula::DoubleVectorRefToken* pCurDVR =
+ dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+ size_t nCurWindowSize = pCurDVR->GetRefRowSize();
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
{
- FormulaToken *pCur = vSubArguments[1]->GetFormulaToken();
- assert(pCur);
- const formula::DoubleVectorRefToken* pCurDVR =
- dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
- size_t nCurWindowSize = pCurDVR->GetRefRowSize();
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"( ";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
-
- ss << ") {\n\t";
- ss << "double result = 0.0;\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss << "int i=0;\n\t";
- if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
- ss<< "i=gid0;\n\t";
- }
- ss << "double date;\n\t";
- ss << "double value;\n\t";
- ss << "double rate;\n\t";
- ss << "double dateNull;\n\t";
-#ifdef ISNAN
- FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
-
- FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
- const formula::DoubleVectorRefToken*tmpCurDVR1= dynamic_cast<const
- formula::DoubleVectorRefToken *>(tmpCur1);
-
- FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
- const formula::DoubleVectorRefToken*tmpCurDVR2= dynamic_cast<const
- formula::DoubleVectorRefToken *>(tmpCur2);
- ss<< "int buffer_rate_len = ";
- ss<< tmpCurDVR0->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_value_len = ";
- ss<< tmpCurDVR1->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_date_len = ";
- ss<< tmpCurDVR2->GetArrayLength();
- ss << ";\n\t";
-#endif
-#ifdef ISNAN
- ss<<"if((i+gid0)>=buffer_date_len || isNan(";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"dateNull = 0;\n\telse \n\t\t";
-#endif
- ss<<"dateNull = ";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
+ }
+ ss << ") {\n\t";
+ ss << "double tmp = 1.0;\n\t";
+ ss << "int gid0 = get_global_id(0);\n\t";
+ ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss << ";\n\t";
#ifdef ISNAN
- ss<<"if((i+gid0)>=buffer_rate_len || isNan(";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"rate = 0;\n\telse \n\t\t";
+ ss << "if (isNan(arg0))\n\t\t";
+ ss << "arg0 = 0;\n\t";
#endif
- ss<<"rate = ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
- ss << "for (int i = ";
- if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
- ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n\t\t";
- } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
- ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n\t\t";
- } else {
- ss << "0; i < "<< nCurWindowSize <<"; i++)\n\t\t";
- }
- ss << "{\n\t";
- ss << "result += ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss << "/(pow((";
- ss<<vSubArguments[0]->GenSlidingWindowDeclRef();
- ss <<"+1),(";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss << "-dateNull)/365));\n\t";
- ss <<"}\n\t";
-
- ss << "return result;\n";
- ss << "}";
- }
-};
-class PriceMat: public Normal
+ ss << "double arg1;\n\t";
+ ss << "int arrayLength = " << pCurDVR->GetArrayLength() << ";\n\t";
+#ifdef ISNAN
+ ss << "for (int i = 0; i + gid0 < arrayLength &&";
+ ss << " i < " << nCurWindowSize << "; i++){\n\t\t";
+#else
+ ss << "for (int i = 0; i < " << nCurWindowSize << "; i++){\n\t\t";
+#endif
+ ss << "arg1 = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n\t\t\t";
+#ifdef ISNAN
+ ss << "if (isNan(arg1))\n\t\t\t\t";
+ ss << "arg1 = 0;\n\t\t\t";
+#endif
+ ss << "tmp *= arg1 + 1.0;\n\t\t";
+ ss << "}\n\t";
+ ss << "return (double)tmp * arg0";
+ ss << ";\n}";
+}
+
+void Cumipmt::GenSlidingWindowFunction(
+ std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
{
- public:
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
- const std::string sSymName, SubArguments &vSubArguments)
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
{
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"(";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
- ss << ") {\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss << "double result=0;\n\t";
- ss<< "int nNullDate = GetNullDate( );\n\t";
- ss <<"int settle;\n\t";
- ss <<"int mat;\n\t";
- ss <<"int issue;\n\t";
- ss <<"double rate;\n\t";
- ss <<"double yield;\n\t";
- ss <<"int nBase;\n\t";
-#ifdef ISNAN
- FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
- FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur1);
- FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur2);
- FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur3);
- FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur4);
- FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR5= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur5);
-
- ss<< "int buffer_settle_len = ";
- ss<< tmpCurDVR0->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_mat_len = ";
- ss<< tmpCurDVR1->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_issue_len = ";
- ss<< tmpCurDVR2->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_rate_len = ";
- ss<< tmpCurDVR3->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_yield_len = ";
- ss<< tmpCurDVR4->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_base_len = ";
- ss<< tmpCurDVR5->GetArrayLength();
- ss << ";\n\t";
-#endif
-#ifdef ISNAN
- ss<<"if(gid0>=buffer_settle_len || isNan(";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"settle = 0;\n\telse \n\t\t";
-#endif
- ss<<"settle = ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
+ }
+ ss << ") {\n\t";
+
+ ss << " int gid0 = get_global_id(0);\n";
+ ss << "double fRate,fVal;\n\t";
+ ss <<"int nStartPer,nEndPer,nNumPeriods,nPayType;\n\t";
+#ifdef ISNAN
+ FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
+ FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur1);
+ FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur2);
+ FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur3);
+ FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur4);
+ FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR5= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur5);
+ ss<< "int buffer_rate_len = ";
+ ss<< tmpCurDVR0->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_NumPeriods_len = ";
+ ss<< tmpCurDVR1->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_Val_len = ";
+ ss<< tmpCurDVR2->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_StartPer_len = ";
+ ss<< tmpCurDVR3->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_EndPer_len = ";
+ ss<< tmpCurDVR4->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_PayType_len = ";
+ ss<< tmpCurDVR5->GetArrayLength();
+ ss << ";\n\t";
+#endif
+#ifdef ISNAN
+ ss <<"if(gid0 >= buffer_rate_len || isNan(";
+ ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss <<"))\n\t\t";
+ ss <<"fRate = 0;\n\telse\n\t\t";
+#endif
+ ss <<"fRate = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss <<";\n\t";
#ifdef ISNAN
- ss<<"if(gid0>=buffer_mat_len || isNan(";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"mat = 0;\n\telse \n\t\t";
+ ss <<"if(gid0 >= buffer_NumPeriods_len || isNan(";
+ ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss <<"))\n\t\t";
+ ss <<"nNumPeriods = 0;\n\telse\n\t\t";
#endif
- ss<<"mat = ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
+ ss <<"nNumPeriods = (int)";
+ ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss <<";\n\t";
#ifdef ISNAN
- ss<<"if(gid0>=buffer_issue_len || isNan(";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"issue = 0;\n\telse \n\t\t";
+ ss <<"if(gid0 >= buffer_Val_len || isNan(";
+ ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss <<"))\n\t\t";
+ ss <<"fVal = 0;\n\telse\n\t\t";
#endif
- ss<<"issue = ";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
+ ss <<"fVal = "<<vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss <<";\n\t";
#ifdef ISNAN
- ss<<"if(gid0>=buffer_rate_len || isNan(";
- ss << vSubArguments[3]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"rate = 0;\n\telse \n\t\t";
+ ss <<"if(gid0 >= buffer_StartPer_len || isNan(";
+ ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss <<"))\n\t\t";
+ ss <<"nStartPer = 0;\n\telse\n\t\t";
#endif
- ss<<"rate = ";
- ss << vSubArguments[3]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
+ ss <<"nStartPer = (int)"<<vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss <<";\n\t";
#ifdef ISNAN
- ss<<"if(gid0>=buffer_yield_len || isNan(";
- ss << vSubArguments[4]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"yield = 0;\n\telse \n\t\t";
+ ss <<"if(gid0 >= buffer_EndPer_len || isNan(";
+ ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
+ ss <<"))\n\t\t";
+ ss <<"nEndPer = 0;\n\telse\n\t\t";
#endif
- ss<<"yield = ";
- ss << vSubArguments[4]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
+ ss <<"nEndPer = (int)"<<vSubArguments[4]->GenSlidingWindowDeclRef();
+ ss <<";\n\t";
#ifdef ISNAN
- ss<<"if(gid0>=buffer_base_len || isNan(";
- ss << vSubArguments[5]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"nBase = 0;\n\telse \n\t\t";
+ ss <<"if(gid0 >= buffer_PayType_len || isNan(";
+ ss <<vSubArguments[5]->GenSlidingWindowDeclRef();
+ ss <<"))\n\t\t";
+ ss <<"nPayType = 0;\n\telse\n\t\t";
#endif
- ss<<"nBase = ";
- ss << vSubArguments[5]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
- ss<< "double fIssMat = GetYearFrac( nNullDate, issue, mat, nBase);\n";
- ss<<"double fIssSet = GetYearFrac( nNullDate, issue, settle,nBase);\n";
- ss<<"double fSetMat = GetYearFrac( nNullDate, settle, mat, nBase);\n";
- ss<<"result = 1.0 + fIssMat * rate;\n\t";
- ss<<"result /= 1.0 + fSetMat * yield;\n\t";
- ss<<"result -= fIssSet * rate;\n\t";
- ss<<"result*= 100.0;\n\t";
- ss<<"return result;\n\t";
- ss<<"}\n";
- }
-};
-class OpSYD: public Normal
+ ss <<"nPayType = (int)"<<vSubArguments[5]->GenSlidingWindowDeclRef();
+ ss <<";\n\t";
+ ss << " double fRmz;\n";
+ ss << "fRmz = GetRmz( fRate, nNumPeriods, fVal, 0.0, nPayType );\n";
+ ss << "double tmp = 0.0;\n";
+ ss << "uint nStart = nStartPer ;\n";
+ ss << "uint nEnd = nEndPer ;\n";
+ ss << " if( nStart == 1 )\n";
+ ss << " {\n";
+ ss << " if( nPayType <= 0 )\n";
+ ss << " tmp = -fVal;\n";
+ ss << " nStart++;\n";
+ ss << " }\n";
+ ss << " for( uint i = nStart ; i <= nEnd ; i++ )\n";
+ ss << " {\n";
+ ss << " if( nPayType > 0 )\n";
+ ss << " tmp += GetZw( fRate, convert_double( i - 2 ), ";
+ ss << "fRmz, fVal, 1 ) - fRmz;\n";
+ ss << " else\n";
+ ss << " tmp += GetZw( fRate, convert_double( i - 1 ), ";
+ ss << "fRmz, fVal, 0 );\n";
+ ss << " }\n";
+ ss << "tmp *= fRate;\n";
+ ss << "return tmp;\n";
+ ss << "}";
+}
+
+void IRR::GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments)
+{
+ FormulaToken* pCur = vSubArguments[0]->GetFormulaToken();
+ assert(pCur);
+ const formula::DoubleVectorRefToken* pCurDVR =
+ dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+ size_t nCurWindowSize = pCurDVR->GetRefRowSize();
+ FormulaToken* pCur1 = vSubArguments[1]->GetFormulaToken();
+ assert(pCur1);
+ const formula::SingleVectorRefToken* pSVR1 =
+ dynamic_cast< const formula::SingleVectorRefToken* >(pCur1);
+ assert(pSVR1);
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
+ {
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
+ }
+ ss << ") {\n";
+ ss << "#define Epsilon 1.0E-7\n\t";
+ ss << "int gid0 = get_global_id(0);\n\t";
+ ss << "double fSchaetzwert = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n\t";
+ ss << "double fEps = 1.0;\n\t";
+ ss << "double x = 0.0, xNeu = 0.0, fZaehler = 0.0, fNenner = 0.0;\n\t";
+ ss << "double nCount = 0.0;\n\t";
+ ss << "int argLen1 = " << pSVR1->GetArrayLength() << ";\n\t";
+#ifdef ISNAN
+ ss << "if (gid0 >= argLen1)\n\t\t";
+ ss << "fSchaetzwert = 0.1;\n\t";
+ ss << "if (isNan(fSchaetzwert))\n\t\t";
+ ss << "x = 0.1;\n\t";
+ ss << "else\n\t\t";
+#endif
+ ss << "x = fSchaetzwert;\n\t";
+ ss << "unsigned short nItCount = 0;\n\t";
+ ss << "while (fEps > Epsilon && nItCount < 20){\n\t\t";
+ ss << "nCount = 0.0;\n\t\tfZaehler = 0.0;\n\t\tfNenner = 0.0;\n\t\t";
+ ss << "double arg0;\n\t\t";
+ ss << "int arrayLength = " << pCurDVR->GetArrayLength() << ";\n\t";
+#ifdef ISNAN
+ ss << "for (int i = 0; i + gid0 < arrayLength &&";
+ ss << " i < " << nCurWindowSize << "; i++){\n\t\t\t";
+#else
+ ss << "for (int i = 0; i < " << nCurWindowSize << "; i++){\n\t\t\t";
+#endif
+ ss << "arg0 = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n\t\t\t";
+#ifdef ISNAN
+ ss << "if (isNan(arg0))\n\t\t\t\t";
+ ss << "continue;\n\t\t\t";
+#endif
+ ss << "fZaehler += arg0 / pow(1.0+x, nCount);\n\t\t\t";
+ ss << "fNenner += -nCount * arg0 / pow(1.0+x,nCount+1.0);\n\t\t\t";
+ ss << "nCount+=1;\n";
+ ss << "\n\t\t}\n\t\t";
+ ss << "xNeu = x - fZaehler / fNenner;\n\t\t";
+ ss << "fEps = fabs(xNeu - x);\n\t\t";
+ ss << "x = xNeu;\n\t\t";
+ ss << "nItCount++;\n\t}\n\t";
+ ss << "if (fSchaetzwert == 0.0 && fabs(x) < Epsilon)\n\t\t";
+ ss << "x = 0.0;\n\t";
+ ss << "if (fEps < Epsilon)\n\t\t";
+ ss << "return x;\n\t";
+ ss << "else\n\t\t";
+ ss << "return (double)523;\n";
+ ss << "}";
+}
+
+void XNPV::GenSlidingWindowFunction(
+ std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
+{
+ FormulaToken *pCur = vSubArguments[1]->GetFormulaToken();
+ assert(pCur);
+ const formula::DoubleVectorRefToken* pCurDVR =
+ dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+ size_t nCurWindowSize = pCurDVR->GetRefRowSize();
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"( ";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
+ {
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
+ }
+
+ ss << ") {\n\t";
+ ss << "double result = 0.0;\n\t";
+ ss << "int gid0 = get_global_id(0);\n\t";
+ ss << "int i=0;\n\t";
+ if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
+ ss<< "i=gid0;\n\t";
+ }
+ ss << "double date;\n\t";
+ ss << "double value;\n\t";
+ ss << "double rate;\n\t";
+ ss << "double dateNull;\n\t";
+#ifdef ISNAN
+ FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
+
+ FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+ const formula::DoubleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+ formula::DoubleVectorRefToken *>(tmpCur1);
+
+ FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
+ const formula::DoubleVectorRefToken*tmpCurDVR2= dynamic_cast<const
+ formula::DoubleVectorRefToken *>(tmpCur2);
+ ss<< "int buffer_rate_len = ";
+ ss<< tmpCurDVR0->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_value_len = ";
+ ss<< tmpCurDVR1->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_date_len = ";
+ ss<< tmpCurDVR2->GetArrayLength();
+ ss << ";\n\t";
+#endif
+#ifdef ISNAN
+ ss<<"if((i+gid0)>=buffer_date_len || isNan(";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"dateNull = 0;\n\telse \n\t\t";
+#endif
+ ss<<"dateNull = ";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+#ifdef ISNAN
+ ss<<"if((i+gid0)>=buffer_rate_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"rate = 0;\n\telse \n\t\t";
+#endif
+ ss<<"rate = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+ ss << "for (int i = ";
+ if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed())
+ {
+ ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n\t\t";
+ }
+ else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
+ {
+ ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n\t\t";
+ }
+ else
+ {
+ ss << "0; i < "<< nCurWindowSize <<"; i++)\n\t\t";
+ }
+ ss << "{\n\t";
+ ss << "result += ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss << "/(pow((";
+ ss<<vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss <<"+1),(";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss << "-dateNull)/365));\n\t";
+ ss <<"}\n\t";
+
+ ss << "return result;\n";
+ ss << "}";
+}
+
+void PriceMat::GenSlidingWindowFunction(
+ std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
{
- public:
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
+ {
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
+ }
+ ss << ") {\n\t";
+ ss << "int gid0 = get_global_id(0);\n\t";
+ ss << "double result=0;\n\t";
+ ss<< "int nNullDate = GetNullDate( );\n\t";
+ ss <<"int settle;\n\t";
+ ss <<"int mat;\n\t";
+ ss <<"int issue;\n\t";
+ ss <<"double rate;\n\t";
+ ss <<"double yield;\n\t";
+ ss <<"int nBase;\n\t";
+#ifdef ISNAN
+ FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
+ FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur1);
+ FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur2);
+ FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur3);
+ FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur4);
+ FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR5= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur5);
+
+ ss<< "int buffer_settle_len = ";
+ ss<< tmpCurDVR0->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_mat_len = ";
+ ss<< tmpCurDVR1->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_issue_len = ";
+ ss<< tmpCurDVR2->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_rate_len = ";
+ ss<< tmpCurDVR3->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_yield_len = ";
+ ss<< tmpCurDVR4->GetArrayLength();
+ ss << ";\n\t";
+ ss<< "int buffer_base_len = ";
+ ss<< tmpCurDVR5->GetArrayLength();
+ ss << ";\n\t";
+#endif
+#ifdef ISNAN
+ ss<<"if(gid0>=buffer_settle_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"settle = 0;\n\telse \n\t\t";
+#endif
+ ss<<"settle = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+#ifdef ISNAN
+ ss<<"if(gid0>=buffer_mat_len || isNan(";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"mat = 0;\n\telse \n\t\t";
+#endif
+ ss<<"mat = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+#ifdef ISNAN
+ ss<<"if(gid0>=buffer_issue_len || isNan(";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"issue = 0;\n\telse \n\t\t";
+#endif
+ ss<<"issue = ";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+#ifdef ISNAN
+ ss<<"if(gid0>=buffer_rate_len || isNan(";
+ ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"rate = 0;\n\telse \n\t\t";
+#endif
+ ss<<"rate = ";
+ ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+#ifdef ISNAN
+ ss<<"if(gid0>=buffer_yield_len || isNan(";
+ ss << vSubArguments[4]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"yield = 0;\n\telse \n\t\t";
+#endif
+ ss<<"yield = ";
+ ss << vSubArguments[4]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+#ifdef ISNAN
+ ss<<"if(gid0>=buffer_base_len || isNan(";
+ ss << vSubArguments[5]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"nBase = 0;\n\telse \n\t\t";
+#endif
+ ss<<"nBase = ";
+ ss << vSubArguments[5]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
+ ss<< "double fIssMat = GetYearFrac( nNullDate, issue, mat, nBase);\n";
+ ss<<"double fIssSet = GetYearFrac( nNullDate, issue, settle,nBase);\n";
+ ss<<"double fSetMat = GetYearFrac( nNullDate, settle, mat, nBase);\n";
+ ss<<"result = 1.0 + fIssMat * rate;\n\t";
+ ss<<"result /= 1.0 + fSetMat * yield;\n\t";
+ ss<<"result -= fIssSet * rate;\n\t";
+ ss<<"result*= 100.0;\n\t";
+ ss<<"return result;\n\t";
+ ss<<"}\n";
+}
+
+void OpSYD::GenSlidingWindowFunction(std::stringstream &ss,
const std::string sSymName, SubArguments &vSubArguments)
+{
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
{
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"(";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
- ss << ") {\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss << "double result=0;\n\t";
- ss << "double cost;\n\t";
- ss << "double salvage;\n\t";
- ss << "double life;\n\t";
- ss << "double period;\n\t";
-#ifdef ISNAN
- FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
-
- FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur1);
-
- FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur2);
-
- FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur3);
-
- ss<< "int buffer_cost_len = ";
- ss<< tmpCurDVR0->GetArrayLength();
- ss << ";\n\t";
-
- ss<< "int buffer_salvage_len = ";
- ss<< tmpCurDVR1->GetArrayLength();
- ss << ";\n\t";
-
- ss<< "int buffer_life_len = ";
- ss<< tmpCurDVR2->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_period_len = ";
- ss<< tmpCurDVR3->GetArrayLength();
- ss << ";\n\t";
-#endif
-
-#ifdef ISNAN
- ss<<"if(gid0>=buffer_cost_len || isNan(";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"cost = 0;\n\telse \n\t\t";
-#endif
- ss<<"cost = ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
+ }
+ ss << ") {\n\t";
+ ss << "int gid0 = get_global_id(0);\n\t";
+ ss << "double result=0;\n\t";
+ ss << "double cost;\n\t";
+ ss << "double salvage;\n\t";
+ ss << "double life;\n\t";
+ ss << "double period;\n\t";
+#ifdef ISNAN
+ FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
+
+ FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur1);
+
+ FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur2);
+
+ FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur3);
+
+ ss << "int buffer_cost_len = ";
+ ss << tmpCurDVR0->GetArrayLength();
+ ss << ";\n\t";
+
+ ss << "int buffer_salvage_len = ";
+ ss << tmpCurDVR1->GetArrayLength();
+ ss << ";\n\t";
+
+ ss << "int buffer_life_len = ";
+ ss << tmpCurDVR2->GetArrayLength();
+ ss << ";\n\t";
+ ss << "int buffer_period_len = ";
+ ss << tmpCurDVR3->GetArrayLength();
+ ss << ";\n\t";
+#endif
+
#ifdef ISNAN
- ss<<"if(gid0>=buffer_salvage_len || isNan(";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"salvage = 0;\n\telse \n\t\t";
+ ss <<"if(gid0>=buffer_cost_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss <<"))\n\t\t";
+ ss <<"cost = 0;\n\telse \n\t\t";
#endif
- ss<<"salvage = ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
+ ss <<"cost = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss <<";\n\t";
#ifdef ISNAN
- ss<<"if(gid0>=buffer_life_len || isNan(";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"life = 0;\n\telse \n\t\t";
+ ss <<"if(gid0>=buffer_salvage_len || isNan(";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss <<"))\n\t\t";
+ ss <<"salvage = 0;\n\telse \n\t\t";
#endif
- ss<<"life = ";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
+ ss <<"salvage = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss <<";\n\t";
#ifdef ISNAN
- ss<<"if(gid0>=buffer_period_len || isNan(";
- ss << vSubArguments[3]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"period = 0;\n\telse \n\t\t";
+ ss <<"if(gid0>=buffer_life_len || isNan(";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss <<"))\n\t\t";
+ ss <<"life = 0;\n\telse \n\t\t";
#endif
- ss<<"period = ";
- ss << vSubArguments[3]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
- ss<<"result = ((cost-salvage)*(life-period+1)/((life*(life+1))/2));\n\t";
- ss<<"return result;\n\t";
- ss<<"}\n";
- }
- virtual std::string BinFuncName(void) const { return "SYD"; }
-};
-class MIRR: public Normal
+ ss <<"life = ";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss <<";\n\t";
+#ifdef ISNAN
+ ss <<"if(gid0>=buffer_period_len || isNan(";
+ ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss <<"))\n\t\t";
+ ss <<"period = 0;\n\telse \n\t\t";
+#endif
+ ss <<"period = ";
+ ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss <<";\n\t";
+ ss <<"result = ((cost-salvage)*(life-period+1)/((life*(life+1))/2));\n\t";
+ ss <<"return result;\n\t";
+ ss <<"}\n";
+}
+
+void MIRR::GenSlidingWindowFunction(
+ std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
{
-public:
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
- const std::string sSymName, SubArguments &vSubArguments)
+ FormulaToken* pCur = vSubArguments[0]->GetFormulaToken();
+ assert(pCur);
+ const formula::DoubleVectorRefToken* pCurDVR =
+ dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+ size_t nCurWindowSize = pCurDVR->GetRefRowSize();
+ FormulaToken* pCur1 = vSubArguments[1]->GetFormulaToken();
+ assert(pCur1);
+ const formula::SingleVectorRefToken* pSVR1 =
+ dynamic_cast< const formula::SingleVectorRefToken* >(pCur1);
+ assert(pSVR1);
+ FormulaToken* pCur2 = vSubArguments[2]->GetFormulaToken();
+ assert(pCur2);
+ const formula::SingleVectorRefToken* pSVR2 =
+ dynamic_cast< const formula::SingleVectorRefToken* >(pCur2);
+ assert(pSVR2);
+
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
{
- FormulaToken* pCur = vSubArguments[0]->GetFormulaToken();
- assert(pCur);
- const formula::DoubleVectorRefToken* pCurDVR =
- dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
- size_t nCurWindowSize = pCurDVR->GetRefRowSize();
- FormulaToken* pCur1 = vSubArguments[1]->GetFormulaToken();
- assert(pCur1);
- const formula::SingleVectorRefToken* pSVR1 =
- dynamic_cast< const formula::SingleVectorRefToken* >(pCur1);
- assert(pSVR1);
- FormulaToken* pCur2 = vSubArguments[2]->GetFormulaToken();
- assert(pCur2);
- const formula::SingleVectorRefToken* pSVR2 =
- dynamic_cast< const formula::SingleVectorRefToken* >(pCur2);
- assert(pSVR2);
-
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"(";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
- ss << ") {\n\t";
- ss << "double tmp = " << GetBottom() <<";\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss << "double arg0, arg1, arg2;\n\t";
- ss << "arg1 = " << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss << ";\n\t";
- ss << "arg2 = " << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss << ";\n\t";
- ss << "int argLen1 = " << pSVR1->GetArrayLength() << ";\n\t";
- ss << "int argLen2 = " << pSVR2->GetArrayLength() << ";\n\t";
- #ifdef ISNAN
- ss << "if (gid0 >= argLen1)\n\t\t";
- ss << "arg1 = 0.0;\n\t";
- ss << "if (gid0 >= argLen2)\n\t\t";
- ss << "arg2 = 0.0;\n\t";
- ss << "if (isNan(arg1))\n\t\t";
- ss << "arg1 = 0.0;\n\t";
- ss << "if (isNan(arg2))\n\t\t";
- ss << "arg2 = 0.0;\n\t";
- #endif
- ss << "double invest = arg1 + 1.0;\n\t";
- ss << "double reinvest = arg2 + 1.0;\n\t";
- ss << "double NPV_invest = 0.0;\n\t";
- ss << "double Pow_invest = 1.0;\n\t";
- ss << "double NPV_reinvest = 0.0;\n\t";
- ss << "double Pow_reinvest = 1.0;\n\t";
- ss << "int nCount = 0;\n\t";
- ss << "int arrayLength = " << pCurDVR->GetArrayLength() << ";\n\t";
- #ifdef ISNAN
- ss << "for (int i = 0; i + gid0 < arrayLength &&";
- ss << " i < " << nCurWindowSize << "; i++){\n\t\t";
- #else
- ss << "for (int i = 0; i < " << nCurWindowSize << "; i++){\n\t\t";
- #endif
- ss << "arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss << ";\n\t\t";
- #ifdef ISNAN
- ss << "if (isNan(arg0))\n\t\t\t";
- ss << "continue;\n\t\t";
- #endif
- ss << "if (arg0 > 0.0)\n\t\t\t";
- ss << "NPV_reinvest += arg0 * Pow_reinvest;\n\t\t";
- ss << "else if (arg0 < 0.0)\n\t\t\t";
- ss << "NPV_invest += arg0 * Pow_invest;\n\t\t";
- ss << "Pow_reinvest /= reinvest;\n\t\t";
- ss << "Pow_invest /= invest;\n\t\t";
- ss << "nCount++;\n\t";
- ss << "}\n\t";
- ss << "tmp = ";
- ss << "-NPV_reinvest /NPV_invest * pow(reinvest,(double)nCount-1);\n\t";
- ss << "tmp = pow(tmp, 1.0 / (nCount - 1)) - 1.0;\n\t";
- ss << "return (double)tmp;\n";
- ss << "}";
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
}
-};
-
+ ss << ") {\n\t";
+ ss << "double tmp = " << GetBottom() <<";\n\t";
+ ss << "int gid0 = get_global_id(0);\n\t";
+ ss << "double arg0, arg1, arg2;\n\t";
+ ss << "arg1 = " << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss << ";\n\t";
+ ss << "arg2 = " << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss << ";\n\t";
+ ss << "int argLen1 = " << pSVR1->GetArrayLength() << ";\n\t";
+ ss << "int argLen2 = " << pSVR2->GetArrayLength() << ";\n\t";
+#ifdef ISNAN
+ ss << "if (gid0 >= argLen1)\n\t\t";
+ ss << "arg1 = 0.0;\n\t";
+ ss << "if (gid0 >= argLen2)\n\t\t";
+ ss << "arg2 = 0.0;\n\t";
+ ss << "if (isNan(arg1))\n\t\t";
+ ss << "arg1 = 0.0;\n\t";
+ ss << "if (isNan(arg2))\n\t\t";
+ ss << "arg2 = 0.0;\n\t";
+#endif
+ ss << "double invest = arg1 + 1.0;\n\t";
+ ss << "double reinvest = arg2 + 1.0;\n\t";
+ ss << "double NPV_invest = 0.0;\n\t";
+ ss << "double Pow_invest = 1.0;\n\t";
+ ss << "double NPV_reinvest = 0.0;\n\t";
+ ss << "double Pow_reinvest = 1.0;\n\t";
+ ss << "int nCount = 0;\n\t";
+ ss << "int arrayLength = " << pCurDVR->GetArrayLength() << ";\n\t";
+#ifdef ISNAN
+ ss << "for (int i = 0; i + gid0 < arrayLength &&";
+ ss << " i < " << nCurWindowSize << "; i++){\n\t\t";
+#else
+ ss << "for (int i = 0; i < " << nCurWindowSize << "; i++){\n\t\t";
+#endif
+ ss << "arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss << ";\n\t\t";
+#ifdef ISNAN
+ ss << "if (isNan(arg0))\n\t\t\t";
+ ss << "continue;\n\t\t";
+#endif
+ ss << "if (arg0 > 0.0)\n\t\t\t";
+ ss << "NPV_reinvest += arg0 * Pow_reinvest;\n\t\t";
+ ss << "else if (arg0 < 0.0)\n\t\t\t";
+ ss << "NPV_invest += arg0 * Pow_invest;\n\t\t";
+ ss << "Pow_reinvest /= reinvest;\n\t\t";
+ ss << "Pow_invest /= invest;\n\t\t";
+ ss << "nCount++;\n\t";
+ ss << "}\n\t";
+ ss << "tmp = ";
+ ss << "-NPV_reinvest /NPV_invest * pow(reinvest,(double)nCount-1);\n\t";
+ ss << "tmp = pow(tmp, 1.0 / (nCount - 1)) - 1.0;\n\t";
+ ss << "return (double)tmp;\n";
+ ss << "}";
+}
-class OpEffective:public Normal
+void OpEffective::GenSlidingWindowFunction(
+ std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
{
-public:
- virtual std::string GetBottom(void) { return "0"; }
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
- const std::string sSymName, SubArguments &vSubArguments)
- {
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"(";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
- ss << ") {\n\t";
- ss << "double tmp = " << GetBottom() <<";\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss << "double nominal = " << GetBottom() <<";\n\t";
- ss << "double period = "<< GetBottom() <<";\n\t";
-#ifdef ISNAN
- FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
- FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur1);
- ss << "int buffer_nominal_len = ";
- ss << tmpCurDVR0->GetArrayLength();
- ss << ";\n\t";
- ss << "int buffer_period_len = ";
- ss << tmpCurDVR1->GetArrayLength();
- ss << ";\n\t";
- ss << "if((gid0)>=buffer_nominal_len || isNan(";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss << "))\n\t\t";
- ss << "nominal = 0;\n\telse \n\t\t";
-#endif
- ss << "nominal = ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss << ";\n\t";
-#ifdef ISNAN
- ss << "if((gid0)>=buffer_period_len || isNan(";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss << "))\n\t\t";
- ss << "period = 0;\n\telse \n\t\t";
-#endif
- ss << "period = ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss << ";\n\t";
- ss << "tmp = pow(1.0 + nominal / period, period)-1.0;\t";
- ss << "\n\treturn tmp;\n";
- ss << "}";
- }
- virtual std::string BinFuncName(void) const { return "Effect_Add"; }
-};
-
-class OpCumipmt: public Cumipmt {
-public:
- virtual std::string GetBottom(void) { return "0"; }
- virtual std::string BinFuncName(void) const { return "Cumipmt"; }
-};
-class OpXNPV:public XNPV{
-
- public:
- virtual std::string GetBottom(void) { return "0"; }
- virtual std::string BinFuncName(void) const { return "XNPV"; }
-
-};
-class OpTbilleq:public Normal{
- public:
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
- const std::string sSymName, SubArguments &vSubArguments)
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
{
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"(";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
- ss << ") {\n\t";
- ss << " int gid0 = get_global_id(0);\n";
- ss << "double tmp = 0;\n\t";
- ss << "double tmp000;\n\t";
- ss << "double tmp001;\n\t";
- ss << "double tmp002;\n\t";
-
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
+ }
+ ss << ") {\n\t";
+ ss << "double tmp = " << GetBottom() <<";\n\t";
+ ss << "int gid0 = get_global_id(0);\n\t";
+ ss << "double nominal = " << GetBottom() <<";\n\t";
+ ss << "double period = "<< GetBottom() <<";\n\t";
+#ifdef ISNAN
+ FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
+ FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur1);
+ ss << "int buffer_nominal_len = ";
+ ss << tmpCurDVR0->GetArrayLength();
+ ss << ";\n\t";
+ ss << "int buffer_period_len = ";
+ ss << tmpCurDVR1->GetArrayLength();
+ ss << ";\n\t";
+ ss << "if((gid0)>=buffer_nominal_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss << "))\n\t\t";
+ ss << "nominal = 0;\n\telse \n\t\t";
+#endif
+ ss << "nominal = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss << ";\n\t";
+#ifdef ISNAN
+ ss << "if((gid0)>=buffer_period_len || isNan(";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss << "))\n\t\t";
+ ss << "period = 0;\n\telse \n\t\t";
+#endif
+ ss << "period = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss << ";\n\t";
+ ss << "tmp = pow(1.0 + nominal / period, period)-1.0;\t";
+ ss << "\n\treturn tmp;\n";
+ ss << "}";
+}
+void OpTbilleq::GenSlidingWindowFunction(
+ std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
+{
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
+ {
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
+ }
+ ss << ") {\n\t";
+ ss << " int gid0 = get_global_id(0);\n";
+ ss << "double tmp = 0;\n\t";
+ ss << "double tmp000;\n\t";
+ ss << "double tmp001;\n\t";
+ ss << "double tmp002;\n\t";
#ifdef ISNAN
- FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
+ FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
- FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur1);
+ FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur1);
- FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur2);
+ FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur2);
- ss<< "int buffer_tmp000_len = ";
- ss<< tmpCurDVR0->GetArrayLength();
- ss << ";\n\t";
+ ss<< "int buffer_tmp000_len = ";
+ ss<< tmpCurDVR0->GetArrayLength();
+ ss << ";\n\t";
- ss<< "int buffer_tmp001_len = ";
- ss<< tmpCurDVR1->GetArrayLength();
- ss << ";\n\t";
+ ss<< "int buffer_tmp001_len = ";
+ ss<< tmpCurDVR1->GetArrayLength();
+ ss << ";\n\t";
- ss<< "int buffer_tmp002_len = ";
- ss<< tmpCurDVR2->GetArrayLength();
- ss << ";\n\t";
+ ss<< "int buffer_tmp002_len = ";
+ ss<< tmpCurDVR2->GetArrayLength();
+ ss << ";\n\t";
#endif
#ifdef ISNAN
- ss<<"if(gid0>=buffer_tmp000_len || isNan(";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"tmp000 = 0;\n\telse \n\t\t";
+ ss<<"if(gid0>=buffer_tmp000_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"tmp000 = 0;\n\telse \n\t\t";
#endif
- ss<<"tmp000 = ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
+ ss<<"tmp000 = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
#ifdef ISNAN
- ss<<"if(gid0>=buffer_tmp001_len || isNan(";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"tmp001 = 0;\n\telse \n\t\t";
+ ss<<"if(gid0>=buffer_tmp001_len || isNan(";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"tmp001 = 0;\n\telse \n\t\t";
#endif
- ss<<"tmp001 = ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
+ ss<<"tmp001 = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
#ifdef ISNAN
- ss<<"if(gid0>=buffer_tmp002_len || isNan(";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"tmp002 = 0;\n\telse \n\t\t";
+ ss<<"if(gid0>=buffer_tmp002_len || isNan(";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss<<"))\n\t\t";
+ ss<<"tmp002 = 0;\n\telse \n\t\t";
#endif
- ss<<"tmp002 = ";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
+ ss<<"tmp002 = ";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss<<";\n\t";
- ss<<"tmp001+=1.0;\n";
- ss<<"int nDiff =GetDiffDate360(GetNullDate(),tmp000,tmp001,true);\n";
- ss<<"tmp =( 365 * tmp002 ) / ( 360 - ( tmp002 * ( nDiff ) ) );\n";
- ss << "return tmp;\n";
- ss << "}";
- }
- virtual std::string BinFuncName(void) const { return "fTbilleq"; }
-};
+ ss<<"tmp001+=1.0;\n";
+ ss<<"int nDiff =GetDiffDate360(GetNullDate(),tmp000,tmp001,true);\n";
+ ss<<"tmp =( 365 * tmp002 ) / ( 360 - ( tmp002 * ( nDiff ) ) );\n";
+ ss << "return tmp;\n";
+ ss << "}";
+}
-class OpCumprinc: public Normal
-{
-public:
- virtual std::string GetBottom(void) { return "0"; }
- virtual void GenSlidingWindowFunction(std::stringstream &ss,
+void OpCumprinc::GenSlidingWindowFunction(std::stringstream &ss,
const std::string sSymName, SubArguments &vSubArguments)
- {
- ss << "\ndouble " << sSymName;
- ss << "_"<< BinFuncName() <<"(";
- for (unsigned i = 0; i < vSubArguments.size(); i++)
- {
- if (i)
- ss << ",";
- vSubArguments[i]->GenSlidingWindowDecl(ss);
- }
- ss << ") {\n\t";
- ss << "double tmp = " << GetBottom() <<";\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss << "double fRate,fVal;\n\t";
- ss <<"int nStartPer,nEndPer,nNumPeriods,nPayType;\n\t";
-#ifdef ISNAN
- FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
- FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur1);
- FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur2);
- FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur3);
- FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur4);
- FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR5= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur5);
- ss<< "int buffer_rate_len = ";
- ss<< tmpCurDVR0->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_NumPeriods_len = ";
- ss<< tmpCurDVR1->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_Val_len = ";
- ss<< tmpCurDVR2->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_StartPer_len = ";
- ss<< tmpCurDVR3->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_EndPer_len = ";
- ss<< tmpCurDVR4->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_PayType_len = ";
- ss<< tmpCurDVR5->GetArrayLength();
- ss << ";\n\t";
-#endif
-#ifdef ISNAN
- ss <<"if(gid0 >= buffer_rate_len || isNan(";
- ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
- ss <<"))\n\t\t";
- ss <<"fRate = 0;\n\telse\n\t\t";
-#endif
- ss <<"fRate = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
- ss <<";\n\t";
-#ifdef ISNAN
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list