Update of /cvsroot/quantlibaddin/QuantLibAddin/Addins/Calc
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv9830/Addins/Calc
Modified Files:
AddinCalc.vcproj AddinCalc_vc8.vcproj Makefile.am Makefile.vc
calcutils.hpp conversions.cpp conversions.hpp
Added Files:
loop.hpp
Log Message:
support loop functions on Calc
--- NEW FILE: loop.hpp ---
/*
Copyright (C) 2006 Eric Ehlers
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it under the
terms of the QuantLib license. You should have received a copy of the
license along with this program; if not, please email qua...@li...
The license is also available online at http://quantlib.org/html/license.html
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
#ifndef qla_calc_loop_hpp
#define qla_calc_loop_hpp
namespace QuantLibAddin {
template<class LoopFunction, class InputType, class OutputType>
void loopIteration(LoopFunction &loopFunction, const ANY &anyIn, ANY &anyOut) {
InputType inputItem;
calcToScalar(inputItem, anyIn);
OutputType returnItem = loopFunction(inputItem);
scalarToCalc(anyOut, returnItem);
}
template<class LoopFunction, class InputType, class OutputType>
void loop(LoopFunction &loopFunction, const SEQSEQ(ANY) &anyIn, SEQSEQ(ANY) &anyOut) {
// if the input is a scalar then call the function once & return
if (anyIn.getLength() == 1 && anyIn[0].getLength() == 1) {
anyOut.realloc(1);
anyOut[0].realloc(1);
loopIteration<LoopFunction, InputType, OutputType>(
loopFunction, anyIn[0][0], anyOut[0][0]);
return;
}
anyOut.realloc(anyIn.getLength());
for (int i=0; i<anyIn.getLength(); i++) {
anyOut[i].realloc(anyIn[i].getLength());
for (int j=0; j<anyIn[i].getLength(); j++) {
loopIteration<LoopFunction, InputType, OutputType>(
loopFunction, anyIn[i][j], anyOut[i][j]);
}
}
}
}
#endif
Index: conversions.hpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/Addins/Calc/conversions.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** conversions.hpp 28 Aug 2006 10:05:22 -0000 1.2
--- conversions.hpp 9 Oct 2006 15:30:58 -0000 1.3
***************
*** 26,45 ****
#include <vector>
! void calcToLib(QuantLib::Date &, const sal_Int32&);
! void calcToLib(QuantLib::Calendar &, const STRING &id);
! void calcToLib(QuantLib::Period &, const STRING &id);
! void calcToVectorLib(std::vector<QuantLib::Date> &, const SEQSEQ(sal_Int32) &);
! void calcToVectorLib(QuantLib::Array &, const SEQSEQ(double) &);
! void calcToVectorLib(std::vector<std::string> &, const SEQSEQ(ANY) &);
! void calcToVectorLib(std::vector<long> &, const SEQSEQ(sal_Int32) &);
! void calcToVectorLib(std::vector<bool> &, const SEQSEQ(sal_Int32) &);
! void calcToVectorLib(std::vector<QuantLib::Period> &, const SEQSEQ(ANY) &);
QuantLib::Matrix calcToQlMatrix(const SEQSEQ(double) &);
! void scalarToCalcLib(sal_Int32 &, const QuantLib::Date &);
! void scalarToCalcLib(double &, const QuantLib::Real &);
! void vectorToCalcLib(SEQSEQ(sal_Int32) &, const std::vector<QuantLib::Date> &);
! void vectorToCalcLib(SEQSEQ(double) &, const QuantLib::Array &);
! void matrixToCalcLib(SEQSEQ(double) &, const QuantLib::Matrix &);
#endif
--- 26,46 ----
#include <vector>
! void calcToScalar(QuantLib::Date &, const sal_Int32&);
! void calcToScalar(QuantLib::Date &, const ANY&);
! void calcToScalar(QuantLib::Calendar &, const STRING &id);
! void calcToScalar(QuantLib::Period &, const STRING &id);
! void calcToVector(std::vector<QuantLib::Date> &, const SEQSEQ(sal_Int32) &);
! void calcToVector(QuantLib::Array &, const SEQSEQ(double) &);
! void calcToVector(std::vector<std::string> &, const SEQSEQ(ANY) &);
! void calcToVector(std::vector<long> &, const SEQSEQ(sal_Int32) &);
! void calcToVector(std::vector<bool> &, const SEQSEQ(sal_Int32) &);
! void calcToVector(std::vector<QuantLib::Period> &, const SEQSEQ(ANY) &);
QuantLib::Matrix calcToQlMatrix(const SEQSEQ(double) &);
! void scalarToCalc(sal_Int32 &, const QuantLib::Date &);
! void scalarToCalc(double &, const QuantLib::Real &);
! void vectorToCalc(SEQSEQ(sal_Int32) &, const std::vector<QuantLib::Date> &);
! void vectorToCalc(SEQSEQ(double) &, const QuantLib::Array &);
! void matrixToCalc(SEQSEQ(double) &, const QuantLib::Matrix &);
#endif
Index: AddinCalc.vcproj
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/Addins/Calc/AddinCalc.vcproj,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** AddinCalc.vcproj 6 Oct 2006 16:40:44 -0000 1.5
--- AddinCalc.vcproj 9 Oct 2006 15:30:58 -0000 1.6
***************
*** 72,75 ****
--- 72,78 ----
</File>
<File
+ RelativePath=".\ratehelpers.cpp">
+ </File>
+ <File
RelativePath=".\session.cpp">
</File>
***************
*** 78,81 ****
--- 81,87 ----
</File>
<File
+ RelativePath=".\termstructures.cpp">
+ </File>
+ <File
RelativePath=".\utilities.cpp">
</File>
***************
*** 100,103 ****
--- 106,112 ----
</File>
<File
+ RelativePath=".\loop.hpp">
+ </File>
+ <File
RelativePath=".\mathf.hpp">
</File>
***************
*** 127,133 ****
--- 136,148 ----
</File>
<File
+ RelativePath=".\ratehelpers.hpp">
+ </File>
+ <File
RelativePath=".\settings.hpp">
</File>
<File
+ RelativePath=".\termstructures.hpp">
+ </File>
+ <File
RelativePath=".\utilities.hpp">
</File>
Index: calcutils.hpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/Addins/Calc/calcutils.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** calcutils.hpp 28 Aug 2006 10:05:22 -0000 1.2
--- calcutils.hpp 9 Oct 2006 15:30:58 -0000 1.3
***************
*** 64,68 ****
}
! void calcToScalar(bool &ret, const sal_Int32&value);
void calcToScalar(boost::any &ret, const ANY &value);
void calcToScalar(long &ret, const ANY &value, const long &defaultValue = 0);
--- 64,68 ----
}
! void calcToScalar(bool &ret, const sal_Int32 &value);
void calcToScalar(boost::any &ret, const ANY &value);
void calcToScalar(long &ret, const ANY &value, const long &defaultValue = 0);
Index: conversions.cpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/Addins/Calc/conversions.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** conversions.cpp 6 Oct 2006 16:40:44 -0000 1.3
--- conversions.cpp 9 Oct 2006 15:30:58 -0000 1.4
***************
*** 16,19 ****
--- 16,20 ----
*/
+ #include <ql/Utilities/dataparsers.hpp>
#include <Addins/Calc/conversions.hpp>
#include <Addins/Calc/calcutils.hpp>
***************
*** 22,30 ****
#include <oh/objecthandler.hpp>
! void calcToLib(QuantLib::Date &ret, const sal_Int32 &date) {
ret = QuantLib::Date(date);
}
! //void calcToLib(QuantLib::Calendar &ret, const STRING &id2) {
// std::string id = ouStringToStlString(id2);
// if (QuantLibAddin::Create<QuantLib::Calendar>().checkType(id)) {
--- 23,37 ----
#include <oh/objecthandler.hpp>
! void calcToScalar(QuantLib::Date &ret, const sal_Int32 &date) {
ret = QuantLib::Date(date);
}
! void calcToScalar(QuantLib::Date &ret, const ANY &date) {
! long dateLong;
! calcToScalar(dateLong, date);
! ret = QuantLib::Date(dateLong);
! }
!
! //void calcToScalar(QuantLib::Calendar &ret, const STRING &id2) {
// std::string id = ouStringToStlString(id2);
// if (QuantLibAddin::Create<QuantLib::Calendar>().checkType(id)) {
***************
*** 37,44 ****
//}
! void calcToLib(QuantLib::Period &ret, const STRING &id) {
}
! void calcToVectorLib(std::vector<QuantLib::Date> &ret,
const SEQSEQ(sal_Int32) &in) {
for (int i=0; i<in.getLength(); i++)
--- 44,53 ----
//}
! void calcToScalar(QuantLib::Period &ret, const STRING &id) {
! std::string idCpp = ouStringToStlString(id);
! ret = QuantLib::PeriodParser::parse(idCpp);
}
! void calcToVector(std::vector<QuantLib::Date> &ret,
const SEQSEQ(sal_Int32) &in) {
for (int i=0; i<in.getLength(); i++)
***************
*** 48,64 ****
}
! void calcToVectorLib(QuantLib::Array &ret, const SEQSEQ(double) &in) {
}
! void calcToVectorLib(std::vector<std::string> &ret, const SEQSEQ(ANY) &in) {
}
! void calcToVectorLib(std::vector<long> &ret, const SEQSEQ(sal_Int32) &in) {
}
! void calcToVectorLib(std::vector<bool> &ret, const SEQSEQ(sal_Int32) &in) {
}
! void calcToVectorLib(std::vector<QuantLib::Period> &ret, const SEQSEQ(ANY) &in) {
}
--- 57,80 ----
}
! void calcToVector(QuantLib::Array &ret, const SEQSEQ(double) &in) {
}
! void calcToVector(std::vector<std::string> &ret, const SEQSEQ(ANY) &in) {
! for (int i=0; i<in.getLength(); i++) {
! for (int j=0; j<in[i].getLength(); j++) {
! std::string s;
! calcToScalar(s, in[i][j]);
! ret.push_back(s);
! }
! }
}
! void calcToVector(std::vector<long> &ret, const SEQSEQ(sal_Int32) &in) {
}
! void calcToVector(std::vector<bool> &ret, const SEQSEQ(sal_Int32) &in) {
}
! void calcToVector(std::vector<QuantLib::Period> &ret, const SEQSEQ(ANY) &in) {
}
***************
*** 81,93 ****
! void scalarToCalcLib(sal_Int32 &ret, const QuantLib::Date &in) {
ret = in.serialNumber();
}
! void scalarToCalcLib(double &ret, const QuantLib::Real &in) {
ret = in;
}
! void vectorToCalcLib(SEQSEQ(sal_Int32) &ret, const std::vector<QuantLib::Date> &v) {
ret.realloc(v.size());
for (unsigned int i=0; i<v.size(); i++) {
--- 97,109 ----
! void scalarToCalc(sal_Int32 &ret, const QuantLib::Date &in) {
ret = in.serialNumber();
}
! void scalarToCalc(double &ret, const QuantLib::Real &in) {
ret = in;
}
! void vectorToCalc(SEQSEQ(sal_Int32) &ret, const std::vector<QuantLib::Date> &v) {
ret.realloc(v.size());
for (unsigned int i=0; i<v.size(); i++) {
***************
*** 98,102 ****
}
! void vectorToCalcLib(SEQSEQ(double) &ret, const QuantLib::Array &in) {
ret.realloc(in.size());
for (unsigned int i=0; i<in.size(); i++) {
--- 114,118 ----
}
! void vectorToCalc(SEQSEQ(double) &ret, const QuantLib::Array &in) {
ret.realloc(in.size());
for (unsigned int i=0; i<in.size(); i++) {
***************
*** 107,111 ****
}
! void matrixToCalcLib(SEQSEQ(double) &ret, const QuantLib::Matrix &in) {
ret.realloc(in.rows());
for (unsigned int i=0; i<in.rows(); i++) {
--- 123,127 ----
}
! void matrixToCalc(SEQSEQ(double) &ret, const QuantLib::Matrix &in) {
ret.realloc(in.rows());
for (unsigned int i=0; i<in.rows(); i++) {
Index: Makefile.am
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/Addins/Calc/Makefile.am,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Makefile.am 7 Oct 2006 14:30:16 -0000 1.5
--- Makefile.am 9 Oct 2006 15:30:58 -0000 1.6
***************
*** 65,68 ****
--- 65,69 ----
exercise.hpp \
instruments.hpp \
+ loop.hpp \
mathf.hpp \
ohfunctions.hpp \
Index: AddinCalc_vc8.vcproj
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/Addins/Calc/AddinCalc_vc8.vcproj,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** AddinCalc_vc8.vcproj 7 Oct 2006 14:30:16 -0000 1.5
--- AddinCalc_vc8.vcproj 9 Oct 2006 15:30:58 -0000 1.6
***************
*** 99,102 ****
--- 99,106 ----
</File>
<File
+ RelativePath=".\ratehelpers.cpp"
+ >
+ </File>
+ <File
RelativePath=".\session.cpp"
>
***************
*** 107,110 ****
--- 111,118 ----
</File>
<File
+ RelativePath=".\termstructures.cpp"
+ >
+ </File>
+ <File
RelativePath=".\utilities.cpp"
>
***************
*** 136,139 ****
--- 144,151 ----
</File>
<File
+ RelativePath=".\loop.hpp"
+ >
+ </File>
+ <File
RelativePath=".\mathf.hpp"
>
***************
*** 172,179 ****
--- 184,199 ----
</File>
<File
+ RelativePath=".\ratehelpers.hpp"
+ >
+ </File>
+ <File
RelativePath=".\settings.hpp"
>
</File>
<File
+ RelativePath=".\termstructures.hpp"
+ >
+ </File>
+ <File
RelativePath=".\utilities.hpp"
>
Index: Makefile.vc
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/Addins/Calc/Makefile.vc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Makefile.vc 6 Oct 2006 16:40:44 -0000 1.3
--- Makefile.vc 9 Oct 2006 15:30:58 -0000 1.4
***************
*** 47,52 ****
--- 47,54 ----
"$(INT_DIR)\processes.obj" \
"$(INT_DIR)\qladdin.obj" \
+ "$(INT_DIR)\ratehelpers.obj" \
"$(INT_DIR)\session.obj" \
"$(INT_DIR)\settings.obj" \
+ "$(INT_DIR)\termstructures.obj" \
"$(INT_DIR)\utilities.obj" \
"$(INT_DIR)\volatilities.obj"
|