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

- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

line.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
    00025 #ifndef LINE_H
    00026 #define LINE_H
    00027
    00028 #include <ostream>
    00029
    00030 #include "../numbers.h"
    00031
    00033
    00037 class Line
    00038 {
    00039 public:
    00041         Line (const coefficient slope, const coefficient intercept)
    00042                         : _slope (slope), _intercept (intercept)
    00043         {
    00044                 check();
    00045         }
    00046
    00048         inline coefficient slope() const;
    00049
    00051         inline coefficient intercept() const;
    00052
    00057         inline void shift (const coefficient x, const coefficient y);
    00058
    00060         inline void negate();
    00061
    00066         inline void swivel (const coefficient slope, const coefficient x);
    00067
    00069         inline coefficient operator() (const coefficient x) const;
    00070
    00072         inline Line& operator*= (const coefficient value);
    00073
    00075         inline void check ();
    00076
    00077 private:
    00078         coefficient _slope, _intercept;
    00079 };
    00080
    00081 coefficient Line::slope() const
    00082 {
    00083         return _slope;
    00084 }
    00085
    00086 coefficient Line::intercept() const
    00087 {
    00088         return _intercept;
    00089 }
    00090
    00091 void Line::negate()
    00092 {
    00093         _slope = -_slope;
    00094         _intercept = -_intercept;
    00095 }
    00096
    00097 void Line::shift (const coefficient x, const coefficient y)
    00098 {
    00099         _intercept += y - slope() *x;
    00100         check();
    00101 }
    00102
    00103 void Line::swivel (const coefficient slope, const coefficient x)
    00104 {
    00105         _intercept += x* (_slope-slope);
    00106         _slope = slope;
    00107         check();
    00108 }
    00109
    00110 coefficient Line::operator() (const coefficient x) const
    00111 {
    00112         return intercept() + x*slope();
    00113 }
    00114
    00115 Line& Line::operator*= (const coefficient value)
    00116 {
    00117         _intercept *= value;
    00118         _slope *= value;
    00119         check();
    00120         return *this;
    00121 }
    00122
    00123 void Line::check()
    00124 {
    00125         fixzero (_slope);
    00126         fixzero (_intercept);
    00127 }
    00128
    00130 inline std::ostream& operator<< (std::ostream& output, const Line& line)
    00131 {
    00132         output << line.slope() << "*x";
    00133         if (isnan (line.intercept()) || (line.intercept() > 0))
    00134                 output << "+" << line.intercept();
    00135         else if (line.intercept() < 0)
    00136                 output << line.intercept();
    00137         return output;
    00138 }
    00139
    00141 inline int parallel (const Line &line1, const Line &line2)
    00142 {
    00143         return equal (line1.slope(),line2.slope());
    00144 };
    00145
    00147 inline coefficient crossing (const Line &line1, const Line &line2)
    00148 {
    00149         if (parallel (line1, line2))
    00150                 return NAN;
    00151
    00152         if (equal (line1.intercept(),line2.intercept()))
    00153                 return 0.0;
    00154
    00155         return (line2.intercept()-line1.intercept()) / (line1.slope()-line2.slope());
    00156 };
    00157
    00158 #endif // LINE_H

All Classes Namespaces Files Functions Variables Typedefs Defines