American-transaction costs 1.0.0.0
American option pricer under proportional transaction costs
flexibletree.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 FLEXIBLETREE_H
00021 #define FLEXIBLETREE_H
00022 
00023 #include "../parameter/bridge.h"
00024 #include "../parameter/integrablebridge.h"
00025 #include "../statisticsgatherer/some.h"
00026 #include "../treeproduct/americanbuyer.h"
00027 #include "../treeproduct/americanseller.h"
00028 
00029 typedef std::vector<size_t> path_type;
00030 
00039 class FlexibleTree
00040 {
00041 
00042 public:
00054         FlexibleTree (const coefficient& S, const ParameterIntegrableBridge& sigma, const ParameterIntegrableBridge& kappa_sigma_square, const ShortRate& r, const ParameterBridge& mu, const ParameterBridge& lambda, const size_t N, const coefficient& T);
00055 
00057         coefficient price (const TreeProduct& product, const Portfolio& wealth = Portfolio (0,0)) const
00058         {
00059                 StatisticsGatherer<PiecewiseLinear> dummyhedge;
00060                 StatisticsGatherer<Spot> dummyspot;
00061                 StatisticsGathererInitial<PiecewiseLinear> initial;
00062 
00063                 pricing_function (product, dummyspot, initial, dummyhedge);
00064 
00065                 return product.current_price (initial, wealth);
00066         }
00067 
00071         void pricing_function (const TreeProduct& product, StatisticsGatherer<Spot>& gather_spot, StatisticsGatherer<PiecewiseLinear>& gather_current_hedge, StatisticsGatherer<PiecewiseLinear>& gather_future_hedge) const;
00072 
00080         inline StatisticsGathererPath<Portfolio> hedge (const size_t scenario, const TreeProduct& product, const coefficient shares = 0.0) const
00081         {
00082                 return hedge (path (scenario), product, shares);
00083         }
00084 
00092         StatisticsGathererPath<Portfolio> hedge (const path_type& path, const TreeProduct& product, const coefficient shares = 0.0) const;
00093 
00097         void hedging_function (const TreeProduct& product, const StatisticsGathererPath<Spot>& gather_spot, const PiecewiseLinear& current_hedge,  const StatisticsGathererPath<PiecewiseLinear>& gather_future_hedge, StatisticsGathererPath<Portfolio>& strategy, const coefficient shares = 0.0) const;
00098 
00099 //      ///Conditional transition probabilities associated with optimal equivalent martingale measure
00100 //      inline coefficient EMM (const size_t scenario, const TreeProductSeller& product, const coefficient shares = 0.0) const
00101 //      {
00102 //              return EMM (path(scenario), product, shares);
00103 //      }
00104 
00105 //      ///Conditional transition probabilities associated with optimal equivalent martingale measure
00106 //      coefficient EMM (const path_type& course, const TreeProductSeller& product, const coefficient shares = 0.0) const;
00107 
00112         void EMM_exercise_function (const TreeProductAmericanSeller& product, const StatisticsGathererPath<Spot>& gather_spot, const StatisticsGathererSome<PiecewiseLinear>& gather_current_hedge, const StatisticsGathererPath<PiecewiseLinear>& gather_future_hedge, StatisticsGathererSome<coefficient>& value, StatisticsGathererPath<coefficient>& chi, StatisticsGathererSome<coefficient>& x, StatisticsGathererPath<coefficient>& y, StatisticsGathererPath<coefficient>& S, StatisticsGathererSome<coefficient>& p, StatisticsGatherer<Portfolio>& strategy, const coefficient shares = 0.0) const;
00113 
00114 //      /*
00115 //       * Stopping time for the buyer of an option.
00116 //       * @param scenario Scenario in which to superreplicate
00117 //       * @param product Objective to superreplicate
00118 //       * @param shares Initial share holding. The cash holding is adjusted to reflect the cost of superreplication
00119 //       * @return Time at which to stop. Either in interval [0,T()] or INFINITY.
00120 //       */
00121 //      inline coefficient stopping_time (const size_t scenario, const TreeProductBuyer& product, const coefficient shares = 0.0) const
00122 //      {
00123 //              return stopping_time (path(scenario),product,shares);
00124 //      }
00125 
00126 //      /*
00127 //       * Stopping time for the buyer of an option.
00128 //       * @param path Scenario in which to superreplicate
00129 //       * @param product Objective to superreplicate
00130 //       * @param shares Initial share holding. The cash holding is adjusted to reflect the cost of superreplication
00131 //       * @return Time at which to stop. Either in interval [0,T()] or INFINITY.
00132 //       */
00133 //      coefficient stopping_time (const path_type course, const TreeProductBuyer& product, const coefficient shares = 0.0) const
00134 //      {
00135 //              StatisticsGathererPath<int> decision = exercise (course, product, shares);
00136 
00137 //              for (size_t n = 0; n <= N(); n++)
00138 //                      if (decision[n])
00139 //                              return n*dt();
00140 
00141 //              return INFINITY;
00142 //      }
00143 
00144 //      /*
00145 //       * Stopping time for the buyer of an option as sequence of binary exercise decisions
00146 //       * @param scenario Scenario in which to superreplicate
00147 //       * @param product Objective to superreplicate
00148 //       * @param shares Initial share holding. The cash holding is adjusted to reflect the cost of superreplication
00149 //       * @return Sequence of N()+1 numbers in set \f$ \{0,1\} \f$ where the \f$ k \f$-th number is 1 if exercise should take place at time \f$ k \f$ and 0 otherwise. If the option is not to be exercised at all in this scenario, then all numbers are 0.
00150 //       */
00151 //      inline StatisticsGathererPath<int> exercise (const size_t scenario, const TreeProductBuyer& product, const coefficient shares = 0.0) const
00152 //      {
00153 //              return exercise (path(scenario), product, shares);
00154 //      }
00155 
00156 //      /*
00157 //       * Stopping time for the buyer of an option as sequence of binary exercise decisions
00158 //       * @param course Scenario in which to superreplicate
00159 //       * @param product Objective to superreplicate
00160 //       * @param shares Initial share holding. The cash holding is adjusted to reflect the cost of superreplication
00161 //       * @return Sequence of N()+1 numbers in set \f$ \{0,1\} \f$ where the \f$ k \f$-th number is 1 if exercise should take place at time \f$ k \f$ and 0 otherwise. If the option is not to be exercised at all in this scenario, then all numbers are 0.
00162 //       */
00163 //      StatisticsGathererPath<int> exercise (const path_type& course, const TreeProductExercisable& product, const coefficient shares = 0.0) const;
00164 
00165 //      /*
00166 //       * Stopping time for the seller of an option as sequence of randomised exercise decisions
00167 //       * @param scenario Scenario in which to superreplicate
00168 //       * @param product Objective to superreplicate
00169 //       * @param shares Initial share holding. The cash holding is adjusted to reflect the cost of superreplication
00170 //       * @return Sequence of N()+1 numbers in set \f$ [0,1] \f$ where the \f$ k \f$-th number is the probability that the option is exercised at time \f$ k \f$. If there is a possibility that the option may not to be exercised at all in this scenario, then the numbers will not add up to 1.
00171 //       */
00172 //      inline StatisticsGathererPath<coefficient> exercise (const size_t scenario, const TreeProductSeller& product, const coefficient shares = 0.0) const
00173 //      {
00174 //              return exercise (path(scenario), product, shares);
00175 //      }
00176 
00177 //      /*
00178 //       * Stopping time for the seller of an option as sequence of randomised exercise decisions
00179 //       * @param course Scenario in which to superreplicate
00180 //       * @param product Objective to superreplicate
00181 //       * @param shares Initial share holding. The cash holding is adjusted to reflect the cost of superreplication
00182 //       * @return Sequence of N()+1 numbers in set \f$ [0,1] \f$ where the \f$ k \f$-th number is the probability that the option is exercised at time \f$ k \f$. If there is a possibility that the option may not to be exercised at all in this scenario, then the numbers will not add up to 1.
00183 //       */
00184 //      StatisticsGathererPath<coefficient> exercise (const path_type& course, const TreeProductSeller& product, const coefficient shares = 0.0) const;
00185 
00189         void exercise_function (const TreeProductAmericanBuyer& product, const StatisticsGathererPath< Spot >& gather_spot, const StatisticsGathererPath< Portfolio >& strategy, StatisticsGathererPath< int >& decision) const;
00190 
00194         virtual size_t scenarios () const = 0;
00195 
00199         virtual size_t nodes (const size_t n) const = 0;
00200 
00202         path_type successors (const size_t n, const size_t k) const
00203         {
00204                 path_type successors;
00205                 successors_function (n, k, successors);
00206                 return successors;
00207         }
00208 
00212         virtual void successors_function (const size_t n, const size_t k, path_type& successors) const = 0;
00213 
00219         virtual path_type path (const size_t scenario) const = 0;
00220 
00226         virtual size_t scenario (const path_type& path) const = 0;
00227 
00233         std::vector<path_type > with_siblings (const path_type& path) const
00234         {
00235                 std::vector<path_type > siblings;
00236 
00237                 siblings.push_back (path_type (1,path[0]));
00238 
00239                 for (size_t t = 1; t < path.size(); t++)
00240                         siblings.push_back (successors (t-1,path[t-1]));
00241 
00242                 return siblings;
00243         }
00244 
00246         std::vector<Spot> spot (const size_t n) const
00247         {
00248                 std::vector<Spot> spot;
00249                 spot_function (n, spot);
00250                 return spot;
00251         }
00252 
00254         virtual void spot_function (const size_t n, std::vector<Spot>& spot) const = 0;
00255 
00257         inline StatisticsGathererPath<Spot> spot_path (const size_t scenario) const     {       return spot_path (path(scenario));      }
00258 
00260         StatisticsGathererPath<Spot> spot_path (const path_type& course) const
00261         {
00262                 StatisticsGathererPath<Spot> gather_spot (course);
00263                 spot_path_function (gather_spot);
00264                 return gather_spot;
00265         }
00266 
00270         virtual void spot_path_function (StatisticsGathererPath<Spot>& gather_spot) const = 0;
00271 
00273         coefficient logS () const       {       return _logS;   }
00274 
00276         coefficient T () const
00277         {
00278                 return _T;
00279         }
00280 
00282         size_t N () const       {       return _N;      }
00283 
00285         coefficient dt () const {       return _dt;     }
00286 
00290         coefficient jump (const size_t n) const {       return _jump[n];        }
00291 
00295         coefficient drift (const size_t n) const        {       return _drift[n];       }
00296 
00298         coefficient discount (const size_t n) const     {       return _discount[n];    }
00299 
00301         coefficient accumulate (const size_t n) const   {       return _accumulate[n];  }
00302 
00304         coefficient mu (const size_t n) const   {       return _mu[n];  }
00305 
00307         coefficient lambda (const size_t n) const       {       return _lambda[n];      }
00308 
00309 private:
00310         size_t _N;
00311 
00312         coefficient _T, _dt, _logS;
00313 
00314         std::vector<coefficient> _jump, _drift, _discount, _accumulate, _mu, _lambda;
00315 
00316 };
00317 
00318 #endif // FLEXIBLETREE_H
 All Classes Namespaces Files Functions Variables Typedefs Defines