American-transaction costs 1.0.0.0
American option pricer under proportional transaction costs
path.h
Go to the documentation of this file.
00001 /*
00002     American option pricer under proportional transaction costs
00003     Copyright (C) 2011 Alet Roux alet.roux@york.ac.uk
00004 
00005     This program is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 */
00019 
00020 #ifndef STATISTICSGATHERER_PATH_H
00021 #define STATISTICSGATHERER_PATH_H
00022 
00023 #include <vector>
00024 #include <ostream>
00025 #include "initial.h"
00026 
00028 template<class T>
00029 class StatisticsGathererPath : public StatisticsGatherer<T>
00030 {
00031 public:
00036         StatisticsGathererPath (const std::vector< size_t >& path)
00037                         : _path (path), _object (path.size())
00038         {}
00039 
00040         operator StatisticsGathererInitial<T>() const
00041         {
00042                 StatisticsGathererInitial<T> gatherer;
00043                 gatherer.dump_result (0, 0, _object[0]);
00044 
00045                 return gatherer;
00046         }
00047 
00048         operator T() const
00049         {
00050                 return _object[0];
00051         }
00052 
00053         virtual void dump_result (const size_t t, const size_t k, const T& object)
00054         {
00055                 if (_path[t] == k)
00056                         _object[t] = object;
00057         }
00058 
00060         size_t node (const size_t t) const
00061         {
00062                 return _path[t];
00063         };
00064 
00065         T operator[] (const size_t t) const
00066         {
00067                 return _object[t];
00068         };
00069 
00070         T& operator[] (const size_t t)
00071         {
00072                 return _object[t];
00073         };
00074 
00076         size_t size() const
00077         {
00078                 return _path.size();
00079         }
00080 
00081 private:
00082         std::vector<size_t> _path;
00083         std::vector<T> _object;
00084 };
00085 
00086 template<class T>
00087 inline std::ostream& operator<< (std::ostream& output, const StatisticsGathererPath<T>& function)
00088 {
00089         for (size_t k = 0; k < function.size(); k++)
00090                 output << "(" << k << "," << function.node (k) << "): " << function[k] << std::endl;
00091         return output;
00092 }
00093 
00094 
00095 #endif // STATISTICSGATHERER_PATH_H
 All Classes Namespaces Files Functions Variables Typedefs Defines