American-transaction costs 1.0.0.0
American option pricer under proportional transaction costs
|
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_ALL_H 00021 #define STATISTICSGATHERER_ALL_H 00022 00023 //#include <vector> 00024 //#include <ostream> 00025 00027 template<class T> 00028 class StatisticsGathererAll : public StatisticsGatherer<T> 00029 { 00030 public: 00034 StatisticsGathererAll () 00035 {} 00036 00037 operator StatisticsGathererInitial<T>() const 00038 { 00039 StatisticsGathererInitial<T> gatherer; 00040 gatherer.dump_result (0, 0, _object[0][0]); 00041 00042 return gatherer; 00043 } 00044 00045 StatisticsGathererPath<T> operator() (const std::vector<size_t>& path) const 00046 { 00047 StatisticsGathererPath<T> gatherer (path); 00048 for (size_t t = 0; t < _object.size(); t++) 00049 for (size_t k = 0; k < _object[t].size(); k++) 00050 gatherer.dump_result (t,k,_object[t][k]); 00051 return gatherer; 00052 }; 00053 00054 StatisticsGathererSome<T> operator() (const std::vector< std::vector<size_t> >& path) const 00055 { 00056 StatisticsGathererSome<T> gatherer (path); 00057 for (size_t t = 0; t < _object.size(); t++) 00058 for (size_t k = 0; k < _object[t].size(); k++) 00059 gatherer.dump_result (t,k,_object[t][k]); 00060 return gatherer; 00061 }; 00062 00063 virtual void dump_result (const size_t t, const size_t k, const T& object) 00064 { 00065 if (t >= _object.size()) 00066 _object.resize(t+1); 00067 if (k >= _object[t].size()) 00068 _object[t].resize(k+1); 00069 00070 _object[t][k] = object; 00071 } 00072 00073 std::vector<T> operator[] (const size_t t) const 00074 { 00075 return _object[t]; 00076 }; 00077 00078 std::vector<T>& operator[] (const size_t t) 00079 { 00080 return _object[t]; 00081 }; 00082 00083 T operator() (const size_t t, const size_t k) const 00084 { 00085 return _object[t][k]; 00086 }; 00087 00088 T& operator() (const size_t t, const size_t k) 00089 { 00090 return _object[t][k]; 00091 }; 00092 00094 size_t size() const 00095 { 00096 return _object.size(); 00097 } 00098 00100 size_t size (const size_t t) const 00101 { 00102 return _object[t].size(); 00103 } 00104 00105 private: 00106 std::vector< std::vector<T> > _object; 00107 }; 00108 00109 template<class T> 00110 inline std::ostream& operator<< (std::ostream& output, const StatisticsGathererAll<T>& function) 00111 { 00112 for (size_t t = 0; t < function.size(); t++) 00113 for (size_t k = 0; k < function.size (t); k++) 00114 output << "(" << t << "," << k << "): " << function (t,k) << std::endl; 00115 return output; 00116 } 00117 00118 00119 #endif // STATISTICSGATHERER_ALL_H