American-transaction costs 1.0.0.0
American option pricer under proportional transaction costs
portfolio.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 #ifndef PORTFOLIO_H
00020 #define PORTFOLIO_H
00021 
00022 #include "spot.h"
00023 #include "shortrate.h"
00024 
00031 
00032 class Portfolio
00033 {
00034 public:
00035         Portfolio (const coefficient shares = NAN, const coefficient cash = NAN)
00036                         : _cash (cash),_shares (shares)
00037         {
00038                 check();
00039         }
00040 
00042         coefficient cash() const
00043         {
00044                 return _cash;
00045         }
00046 
00048         coefficient shares() const
00049         {
00050                 return _shares;
00051         }
00052 
00054         Portfolio& operator= (const Portfolio& portfolio)
00055         {
00056                 _cash = portfolio.cash();
00057                 _shares = portfolio.shares();
00058                 check();
00059                 return *this;
00060         }
00061 
00063         Portfolio operator- () const
00064         {
00065                 return Portfolio (-_shares, -_cash);
00066         }
00067 
00069         Portfolio& operator+= (const Portfolio& portfolio)
00070         {
00071                 _cash += portfolio.cash();
00072                 _shares += portfolio.shares();
00073                 check();
00074                 return *this;
00075         }
00076 
00078         Portfolio& operator*= (const coefficient scale)
00079         {
00080                 _cash *= scale;
00081                 _shares *= scale;
00082                 check();
00083                 return *this;
00084         }
00085 
00087         void buy (const coefficient s, const Spot& spot)
00088         {
00089                 _shares += s;
00090                 _cash -= (s > 0) ? s*spot.ask() : s*spot.bid();
00091                 check();
00092         }
00093 
00095         void accumulate (const coefficient R)
00096         {
00097                 _cash *= R;
00098                 fixzero (_cash);
00099         }
00100 
00102         void accumulate (const ShortRate& r, const coefficient t1, const coefficient t2)
00103         {
00104                 accumulate (r.accumulate (t1,t2));
00105         }
00106 
00108         coefficient value (const coefficient spot) const
00109         {
00110           return cash() + spot*shares();
00111         }
00112 
00113 private:
00115         void check()
00116         {
00117                 fixzero (_cash);
00118                 fixzero (_shares);
00119         }
00120 
00121         coefficient _cash,_shares;
00122 };
00123 
00124 std::ostream& operator<< (std::ostream& output, const Portfolio& portfolio);
00125 
00126 #endif // PORTFOLIO_H
 All Classes Namespaces Files Functions Variables Typedefs Defines