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 #ifndef TRADING_H 00020 #define TRADING_H 00021 00027 #include "config.h" 00028 #include "piecewiselinear/piecewiselinear.h" 00029 #include "spot.h" 00030 #include "portfolio.h" 00031 00033 inline PiecewiseLinear solvency_cone (const Spot& spot) 00034 { 00035 line_array newfunction; 00036 newfunction.push_back (Line (-spot.ask(),0)); 00037 if (spot.ask() > spot.bid()) 00038 newfunction.push_back (Line (-spot.bid(), 0)); 00039 return PiecewiseLinear (newfunction); 00040 } 00041 00043 inline PiecewiseLinear portfolios_that_can_afford (const Portfolio& portfolio, const Spot& spot) 00044 { 00045 PiecewiseLinear current = solvency_cone ( spot ); 00046 current.shift ( portfolio.shares(), portfolio.cash() ); 00047 return current; 00048 } 00049 00055 inline void ensure_solvent (PiecewiseLinear& portfolios, const Spot& spot) 00056 { 00057 PiecewiseLinear reference = solvency_cone (spot); 00058 portfolios = maximum (portfolios, reference); 00059 } 00060 00066 inline void include_solvent_portfolios (PiecewiseLinear& portfolios, const Spot& spot) 00067 { 00068 PiecewiseLinear reference = solvency_cone (spot); 00069 portfolios = minimum (portfolios, reference); 00070 } 00071 00073 inline int soluble (const Portfolio& portfolio, const Spot& spot) 00074 { 00075 return greaterequal (portfolio.cash()- (portfolio.shares() >0.0) ? portfolio.shares() *spot.bid() : portfolio.shares() *spot.ask() ,0.0); 00076 } 00077 00079 inline void untangle_restriction (Portfolio& portfolio, const PiecewiseLinear& portfolios, const Spot& spot) 00080 { 00081 #ifdef VERBOSE_UNTANGLE_RESTRICTION 00082 std::cout << "Unrestricted portfolios: " << portfolios << "." << std::endl; 00083 std::cout << "Spot: " << spot << std::endl; 00084 #endif 00085 //This portfolio fell out of the epigraph in the process of slope restriction 00086 if (lessthan (portfolio.cash(), portfolios (portfolio.shares()))) 00087 { 00088 size_t k = portfolios.piece (portfolio.shares()); 00089 coefficient new_shares; 00090 00091 //Slope too steep, move to the right. 00092 if ( (k == 0) || lessthan (portfolios.slope (k),-spot.ask())) 00093 { 00094 new_shares = crossing (Line (-spot.ask(),portfolio.cash() +spot.ask() *portfolio.shares()),portfolios,portfolio.shares(),PIECEWISELINEAR_CROSSING_RIGHT); 00095 } 00096 else 00097 { 00098 new_shares = crossing (Line (-spot.bid(),portfolio.cash() +spot.bid() *portfolio.shares()),portfolios,portfolio.shares(),PIECEWISELINEAR_CROSSING_LEFT); 00099 } 00100 portfolio.buy (new_shares - portfolio.shares(), spot); 00101 #ifdef VERBOSE_UNTANGLE_RESTRICTION 00102 std::cout << "Portfolio becomes " << portfolio << "." << std::endl; 00103 #endif 00104 } 00105 //portfolio hedges fine 00106 else 00107 { 00108 #ifdef VERBOSE_UNTANGLE_RESTRICTION 00109 std::cout << "Portfolio remains unchanged." << std::endl; 00110 #endif 00111 } 00112 } 00113 00114 #endif