American-transaction costs 1.0.0.0 American option pricer under proportional transaction costs

- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

some.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_SOME_H
    00021 #define STATISTICSGATHERER_SOME_H
    00022
    00025
    00026 //#include "initial.h"
    00027 #include "path.h"
    00028
    00030 template<class T>
    00031 class StatisticsGathererSome : public StatisticsGatherer<T>
    00032 {
    00033 public:
    00038         StatisticsGathererSome (const std::vector< std::vector<size_t> >& path)
    00039                         : _path (path)
    00040         {
    00041                 for (size_t t = 0; t < _path.size(); t++)
    00042                         _object.push_back (std::vector<T> (_path[t].size()));
    00043         }
    00044
    00045         operator StatisticsGathererInitial<T>() const
    00046         {
    00047                 StatisticsGathererInitial<T> gatherer;
    00048                 gatherer.dump_result (0, 0, _object[0][0]);
    00049
    00050                 return gatherer;
    00051         }
    00052
    00053         operator T() const
    00054         {
    00055                 return _object[0][0];
    00056         }
    00057
    00058         virtual void dump_result (const size_t t, const size_t k, const T& object)
    00059         {
    00060                 for (size_t l = 0; l < _path[t].size(); l++)
    00061                         if (_path[t][l] == k)
    00062                                 _object[t][l] = object;
    00063         }
    00064
    00065         std::vector<T> operator[] (const size_t t) const
    00066         {
    00067                 return _object[t];
    00068         };
    00069
    00070         std::vector<T>& operator[] (const size_t t)
    00071         {
    00072                 return _object[t];
    00073         };
    00074
    00075         T operator() (const size_t t, const size_t k) const
    00076         {
    00077                 return _object[t][k];
    00078         };
    00079
    00080         T& operator() (const size_t t, const size_t k)
    00081         {
    00082                 return _object[t][k];
    00083         };
    00084
    00085         StatisticsGathererPath<T> operator() (const std::vector<size_t>& path) const
    00086         {
    00087                 StatisticsGathererPath<T> gatherer (path);
    00088                 for (size_t t = 0; t < _path.size(); t++)
    00089                         for (size_t k = 0; k < _path[t].size(); k++)
    00090                                 gatherer.dump_result (t,_path[t][k],_object[t][k]);
    00091                 return gatherer;
    00092         };
    00093
    00095         size_t size() const
    00096         {
    00097                 return _object.size();
    00098         }
    00099
    00101         size_t size (const size_t t) const
    00102         {
    00103                 return _object[t].size();
    00104         }
    00105
    00107         size_t node (const size_t t, const size_t k) const
    00108         {
    00109                 return _path[t][k];
    00110         };
    00111
    00112
    00113 private:
    00114         std::vector< std::vector<size_t> > _path;
    00115         std::vector< std::vector<T> > _object;
    00116 };
    00117
    00118 template<class T>
    00119 inline std::ostream& operator<< (std::ostream& output, const StatisticsGathererSome<T>& function)
    00120 {
    00121         for (size_t t = 0; t < function.size(); t++)
    00122                 for (size_t k = 0; k < function.size (t); k++)
    00123                         output << "(" << t << "," << function.node (t,k) << "): " << function (t,k) << std::endl;
    00124         return output;
    00125 }
    00126
    00127 #endif // STATISTICSGATHERER_SOME_H

All Classes Namespaces Files Functions Variables Typedefs Defines