├── CppOptions ├── .gitignore ├── Makefile ├── .DS_Store ├── hist.hpp ├── GericDerivative.cpp ├── MonteCarlo.hpp ├── blas_samp.hpp ├── boosttest.hpp ├── c20test.hpp ├── stl_alg.hpp ├── LatticeModel.hpp ├── BlackScholesPricer.hpp ├── GericDerivative.h ├── qlibsample.hpp ├── hist.cpp ├── c20test.cpp ├── RungeKutta.hpp ├── Prototype.hpp ├── DataSource.hpp ├── Integration.hpp ├── BlackScholes.hpp ├── DesignPatterns.cpp ├── EulersMethod.hpp ├── RandomWalk.hpp ├── GenericOption.h ├── DesignPatterns.hpp ├── Functional.hpp ├── NewtonMethod.hpp ├── DateCompact.h ├── Dictionary.h ├── MathFunction.hpp ├── blas_samp.cpp ├── Matrix.h ├── DataSource.cpp ├── CDS.h ├── Prototype.cpp ├── RandomWalkGenerator.h ├── Observer.hpp ├── templates.hpp ├── LAVectors.hpp ├── EulersMethod.cpp ├── Date.h ├── OOExamples.cpp ├── RandomWalk.cpp ├── RungeKutta.cpp ├── templates.cpp ├── boosttest.cpp ├── Integration.cpp ├── OOExamples.h ├── MathFunction.cpp ├── RandomWalkGenerator.cpp ├── GenericOption.cpp ├── NewtonMethod.cpp ├── LAVectors.cpp ├── Dictionary.cpp ├── Observer.cpp ├── MonteCarlo.cpp ├── BlackScholesPricer.cpp ├── DateCompact.cpp ├── BlackScholes.cpp ├── mymod.py ├── Matrix.cpp ├── CDS.cpp ├── Functional.cpp ├── qlibsample.cpp ├── LatticeModel.cpp ├── Date.cpp └── stl_alg.cpp ├── .gitattributes ├── Appendix A.pdf ├── 9781484263143.jpg ├── CppOptions.xcodeproj ├── xcuserdata │ └── carlosoliveira.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── CppOptions.xcscheme ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcuserdata │ │ └── carlosoliveira.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── project.pbxproj ├── errata.md ├── README.md ├── Contributing.md └── LICENSE.txt /CppOptions/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Appendix A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/options-derivatives-programming-cpp20/HEAD/Appendix A.pdf -------------------------------------------------------------------------------- /CppOptions/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CPPFLAGS=-std=c++2a 3 | 4 | DateCompact: Date.o 5 | 6 | clean: ; rm -f *.o 7 | -------------------------------------------------------------------------------- /9781484263143.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/options-derivatives-programming-cpp20/HEAD/9781484263143.jpg -------------------------------------------------------------------------------- /CppOptions/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/options-derivatives-programming-cpp20/HEAD/CppOptions/.DS_Store -------------------------------------------------------------------------------- /CppOptions.xcodeproj/xcuserdata/carlosoliveira.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /CppOptions.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CppOptions.xcodeproj/project.xcworkspace/xcuserdata/carlosoliveira.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/options-derivatives-programming-cpp20/HEAD/CppOptions.xcodeproj/project.xcworkspace/xcuserdata/carlosoliveira.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /CppOptions/hist.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // hist.hpp 3 | // CppOptions 4 | // 5 | // Created by Carlos Oliveira on 8/8/20. 6 | // Copyright © 2020 Carlos Oliveira. All rights reserved. 7 | // 8 | 9 | #ifndef hist_hpp 10 | #define hist_hpp 11 | 12 | #include 13 | 14 | #endif /* hist_hpp */ 15 | -------------------------------------------------------------------------------- /errata.md: -------------------------------------------------------------------------------- 1 | # Errata for *Options and Derivatives Programming in C++20* 2 | 3 | On **page xx** [Summary of error]: 4 | 5 | Details of error here. Highlight key pieces in **bold**. 6 | 7 | *** 8 | 9 | On **page xx** [Summary of error]: 10 | 11 | Details of error here. Highlight key pieces in **bold**. 12 | 13 | *** -------------------------------------------------------------------------------- /CppOptions.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CppOptions/GericDerivative.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // GericDerivative.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #include "GericDerivative.h" 12 | -------------------------------------------------------------------------------- /CppOptions/MonteCarlo.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MonteCarlo.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef MonteCarlo_hpp 12 | #define MonteCarlo_hpp 13 | 14 | 15 | 16 | 17 | #endif /* MonteCarlo_hpp */ 18 | -------------------------------------------------------------------------------- /CppOptions/blas_samp.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // blas_samp.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef blas_samp_hpp 12 | #define blas_samp_hpp 13 | 14 | #include 15 | 16 | #endif /* blas_samp_hpp */ 17 | -------------------------------------------------------------------------------- /CppOptions/boosttest.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // boosttest.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef boosttest_hpp 12 | #define boosttest_hpp 13 | 14 | #include 15 | 16 | #endif /* boosttest_hpp */ 17 | -------------------------------------------------------------------------------- /CppOptions/c20test.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // c20test.hpp 3 | // CppOptions 4 | // 5 | // (c) 2020 Carlos Oliveira 6 | // This code is part of the book 7 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 8 | // by Carlos Oliveira, Apress, 2020. 9 | // For more information, visit http://coliveira.net 10 | 11 | 12 | #ifndef c20test_hpp 13 | #define c20test_hpp 14 | 15 | #include 16 | 17 | #endif /* c20test_hpp */ 18 | -------------------------------------------------------------------------------- /CppOptions/stl_alg.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // stl_alg.hpp 3 | // CppOptions 4 | // 5 | // 6 | // (c) 2020 Carlos Oliveira 7 | // This code is part of the book 8 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 9 | // by Carlos Oliveira, Apress, 2020. 10 | // For more information, visit http://coliveira.net 11 | 12 | #ifndef stl_alg_hpp 13 | #define stl_alg_hpp 14 | 15 | #include 16 | 17 | #endif /* stl_alg_hpp */ 18 | -------------------------------------------------------------------------------- /CppOptions/LatticeModel.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // LatticeModel.hpp 3 | // CppOptions 4 | // 5 | // (c) 2020 Carlos Oliveira 6 | // This code is part of the book 7 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 8 | // by Carlos Oliveira, Apress, 2020. 9 | // For more information, visit http://coliveira.net 10 | 11 | #ifndef LatticeModel_hpp 12 | #define LatticeModel_hpp 13 | 14 | #include 15 | 16 | #endif /* LatticeModel_hpp */ 17 | -------------------------------------------------------------------------------- /CppOptions/BlackScholesPricer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // BlackScholesPricer.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef BlackScholesPricer_hpp 12 | #define BlackScholesPricer_hpp 13 | 14 | 15 | 16 | 17 | 18 | #endif /* BlackScholesPricer_hpp */ 19 | -------------------------------------------------------------------------------- /CppOptions/GericDerivative.h: -------------------------------------------------------------------------------- 1 | // 2 | // GericDerivative.h 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef __CppOptions__GericDerivative__ 12 | #define __CppOptions__GericDerivative__ 13 | 14 | #include 15 | 16 | #endif /* defined(__CppOptions__GericDerivative__) */ 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apress Source Code 2 | 3 | This repository accompanies [*Options and Derivatives Programming in C++20*](https://www.apress.com/9781484263143) by Carlos Oliveira (Apress, 2020). 4 | 5 | [comment]: #cover 6 | ![Cover image](9781484263143.jpg) 7 | 8 | Download the files as a zip using the green button, or clone the repository to your machine using Git. 9 | 10 | ## Releases 11 | 12 | Release v1.0 corresponds to the code in the published book, without corrections or updates. 13 | 14 | ## Contributions 15 | 16 | See the file Contributing.md for more information on how you can contribute to this repository. -------------------------------------------------------------------------------- /CppOptions/qlibsample.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // qlibsample.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef qlibsample_hpp 12 | #define qlibsample_hpp 13 | 14 | #include 15 | 16 | 17 | #include 18 | 19 | 20 | #include 21 | 22 | 23 | 24 | 25 | 26 | #endif /* qlibsample_hpp */ 27 | -------------------------------------------------------------------------------- /CppOptions.xcodeproj/xcuserdata/carlosoliveira.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CppOptions.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 739F95401B50183A00966A6F 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to Apress Source Code 2 | 3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. 4 | 5 | ## How to Contribute 6 | 7 | 1. Make sure you have a GitHub account. 8 | 2. Fork the repository for the relevant book. 9 | 3. Create a new branch on which to make your change, e.g. 10 | `git checkout -b my_code_contribution` 11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. 12 | 5. Submit a pull request. 13 | 14 | Thank you for your contribution! -------------------------------------------------------------------------------- /CppOptions/hist.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // hist.cpp 3 | // CppOptions 4 | // 5 | // Created by Carlos Oliveira on 8/8/20. 6 | // Copyright © 2020 Carlos Oliveira. All rights reserved. 7 | // 8 | 9 | #include "hist.hpp" 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | int main() { 20 | using namespace boost::histogram; 21 | 22 | std::ostringstream os; 23 | 24 | auto h1 = make_histogram(axis::regular<>(5, -1.0, 1.0, "axis 1")); 25 | h1.at(0) = 2; 26 | h1.at(1) = 4; 27 | h1.at(2) = 3; 28 | h1.at(4) = 1; 29 | 30 | // 1D histograms are rendered as an ASCII drawing 31 | os << h1; 32 | std::cout << h1; 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /CppOptions/c20test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // c20test.cpp 3 | // CppOptions 4 | // 5 | // (c) 2020 Carlos Oliveira 6 | // This code is part of the book 7 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 8 | // by Carlos Oliveira, Apress, 2020. 9 | // For more information, visit http://coliveira.net 10 | 11 | #include "c20test.hpp" 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | std::pair myfun() { return std::pair(1,2); } 18 | 19 | void s() { 20 | std::map s; 21 | for (auto [aa,bb] : s) { 22 | std::cout<< aa << bb; 23 | } 24 | std::vector vec{1, 2, 3, 4, 5, 6}; 25 | auto [x,z] = myfun(); 26 | // std::cout << *v.begin() << '\n'; // prints 4 27 | } 28 | -------------------------------------------------------------------------------- /CppOptions/RungeKutta.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // RungeKutta.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef RungeKutta_hpp 12 | #define RungeKutta_hpp 13 | 14 | #include "EulersMethod.hpp" 15 | 16 | class RungeKuttaMethod { 17 | public: 18 | RungeKuttaMethod(DEMathFunction &f); 19 | RungeKuttaMethod(const RungeKuttaMethod &p); 20 | ~RungeKuttaMethod(); 21 | RungeKuttaMethod &operator=(const RungeKuttaMethod &p); 22 | double solve(int n, double x0, double y0, double c); 23 | private: 24 | DEMathFunction &m_func; 25 | }; 26 | 27 | #endif /* RungeKutta_hpp */ 28 | -------------------------------------------------------------------------------- /CppOptions/Prototype.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Prototype.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef Prototype_hpp 12 | #define Prototype_hpp 13 | 14 | class Prototype { 15 | private: 16 | Prototype(); 17 | Prototype(const Prototype &p); 18 | Prototype &operator=(const Prototype &p); 19 | 20 | public: 21 | ~Prototype(); 22 | Prototype *clone() const; 23 | void setVar1(int v); 24 | static const Prototype &getPrototype(); 25 | 26 | private: 27 | int m_var1; 28 | static Prototype *s_prototype; 29 | 30 | }; 31 | 32 | 33 | 34 | #endif /* Prototype_hpp */ 35 | -------------------------------------------------------------------------------- /CppOptions/DataSource.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // DataSource.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef DataSource_hpp 12 | #define DataSource_hpp 13 | 14 | #include 15 | 16 | class DataSource { 17 | private: 18 | DataSource(const std::string &name); 19 | DataSource(const DataSource &p); 20 | DataSource &operator=(const DataSource &p); 21 | public: 22 | ~DataSource(); // must be public so clients can use delete 23 | 24 | static DataSource *createInstance(); 25 | 26 | void readData(); 27 | 28 | private: 29 | std::string m_dataName; 30 | }; 31 | 32 | 33 | 34 | 35 | #endif /* DataSource_hpp */ 36 | -------------------------------------------------------------------------------- /CppOptions/Integration.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Integration.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef Integration_hpp 12 | #define Integration_hpp 13 | 14 | #include "MathFunction.hpp" 15 | 16 | class SimpsonsIntegration { 17 | public: 18 | SimpsonsIntegration(MathFunction &f); 19 | SimpsonsIntegration(const SimpsonsIntegration &p); 20 | ~SimpsonsIntegration(); 21 | SimpsonsIntegration &operator=(const SimpsonsIntegration &p); 22 | 23 | double getIntegral(double a, double b); 24 | void setNumIntervals(int n); 25 | private: 26 | MathFunction &m_f; 27 | int m_numIntervals; 28 | }; 29 | 30 | 31 | #endif /* Integration_hpp */ 32 | -------------------------------------------------------------------------------- /CppOptions/BlackScholes.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // BlackScholes.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef BlackScholes_hpp 12 | #define BlackScholes_hpp 13 | 14 | #include 15 | 16 | class BlackScholesMethod { 17 | public: 18 | BlackScholesMethod(double expiration, double maxPrice, double strike, double intRate); 19 | BlackScholesMethod(const BlackScholesMethod &p); 20 | ~BlackScholesMethod(); 21 | BlackScholesMethod &operator=(const BlackScholesMethod &p); 22 | 23 | std::vector solve(double volatility, int nx, int timeSteps); 24 | private: 25 | double m_expiration; 26 | double m_maxPrice; 27 | double m_strike; 28 | double m_intRate; 29 | }; 30 | #endif /* BlackScholes_hpp */ 31 | -------------------------------------------------------------------------------- /CppOptions/DesignPatterns.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // DesignPatterns.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #include "DesignPatterns.hpp" 12 | 13 | ClearingHouse *ClearingHouse::s_clearingHouse = nullptr; 14 | 15 | 16 | ClearingHouse::ClearingHouse() 17 | { 18 | } 19 | 20 | ClearingHouse::~ClearingHouse() 21 | { 22 | 23 | } 24 | 25 | ClearingHouse &ClearingHouse::getClearingHouse() 26 | { 27 | if (!s_clearingHouse) 28 | { 29 | s_clearingHouse = new ClearingHouse(); 30 | } 31 | return *s_clearingHouse; 32 | } 33 | 34 | void ClearingHouse::clearTrade(const Trade &t) 35 | { 36 | } 37 | 38 | void useClearingHouse() 39 | { 40 | Trade trade; 41 | ClearingHouse &ch = ClearingHouse::getClearingHouse(); 42 | ch.clearTrade(trade); 43 | } 44 | -------------------------------------------------------------------------------- /CppOptions/EulersMethod.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // EulersMethod.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef EulersMethod_hpp 12 | #define EulersMethod_hpp 13 | 14 | 15 | class DEMathFunction { 16 | public: 17 | 18 | virtual ~DEMathFunction() {} 19 | virtual double operator()(double x, double y) = 0; // version with two variables 20 | private: 21 | // this just an interface 22 | }; 23 | 24 | 25 | class EulersMethod { 26 | public: 27 | EulersMethod(DEMathFunction &f); 28 | EulersMethod(const EulersMethod &p); 29 | ~EulersMethod(); 30 | EulersMethod &operator=(const EulersMethod &p); 31 | 32 | double solve(int n, double x0, double y0, double c); 33 | private: 34 | DEMathFunction &m_f; 35 | }; 36 | 37 | 38 | #endif /* EulersMethod_hpp */ 39 | -------------------------------------------------------------------------------- /CppOptions/RandomWalk.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // RandomWalk.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef RandomWalk_hpp 12 | #define RandomWalk_hpp 13 | 14 | 15 | #include 16 | 17 | // Simple random walk for price simulation 18 | class RandomWalkModel { 19 | public: 20 | RandomWalkModel(int size, double start, double step); 21 | RandomWalkModel(const RandomWalkModel &p); 22 | ~RandomWalkModel(); 23 | RandomWalkModel &operator=(const RandomWalkModel &p); 24 | 25 | std::vector getWalk(); 26 | private: 27 | int random_integer(int max); 28 | 29 | int m_numSteps; // number of steps 30 | double m_stepSize; // size of each step (in percentage) 31 | double m_startPrice; // starting price 32 | }; 33 | 34 | 35 | #endif /* defined(__FinancialSamples__RandonWalk__) */ 36 | 37 | -------------------------------------------------------------------------------- /CppOptions/GenericOption.h: -------------------------------------------------------------------------------- 1 | // 2 | // GenericOption.h 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef __CppOptions__GenericOption__ 12 | #define __CppOptions__GenericOption__ 13 | 14 | #include 15 | 16 | enum OptionType { 17 | OptionType_Call, 18 | OptionType_Put 19 | }; 20 | 21 | 22 | class GenericOption { 23 | public: 24 | GenericOption(double strike, OptionType type, double cost); 25 | GenericOption(const GenericOption &p); 26 | ~GenericOption(); 27 | GenericOption &operator=(const GenericOption &p); 28 | 29 | double valueAtExpiration(double underlyingAtExpiration); 30 | double profitAtExpiration(double underlyingAtExpiration); 31 | private: 32 | double m_strike; 33 | OptionType m_type; 34 | double m_cost; 35 | }; 36 | 37 | #endif /* defined(__CppOptions__GenericOption__) */ 38 | -------------------------------------------------------------------------------- /CppOptions/DesignPatterns.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // DesignPatterns.hpp 3 | // CppOptions 4 | // 5 | // (c) 2020 Carlos Oliveira 6 | // This code is part of the book 7 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 8 | // by Carlos Oliveira, Apress, 2020. 9 | // For more information, visit http://coliveira.net 10 | 11 | 12 | #ifndef DesignPatterns_hpp 13 | #define DesignPatterns_hpp 14 | 15 | class Trade { 16 | // .... 17 | }; 18 | 19 | class ClearingHouse { 20 | private: // these are all private because this is a singleton 21 | ClearingHouse(); 22 | // the copy constructor is not implemented 23 | ClearingHouse(const ClearingHouse &p); 24 | ~ClearingHouse(); 25 | // assignment operator is not implemented 26 | ClearingHouse &operator=(const ClearingHouse &p); 27 | 28 | public: 29 | static ClearingHouse &getClearingHouse(); 30 | 31 | void clearTrade(const Trade &); 32 | 33 | private: 34 | static ClearingHouse *s_clearingHouse; 35 | }; 36 | 37 | 38 | 39 | #endif /* DesignPatterns_hpp */ 40 | -------------------------------------------------------------------------------- /CppOptions/Functional.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Functional.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef Functional_hpp 12 | #define Functional_hpp 13 | 14 | class SimpleOption { 15 | public: 16 | // other definitions here 17 | int daysToExpiration() const { return m_daysToExpiration; } 18 | 19 | double getInTheMoneyProbability(int numDays, double currentUnderlyingPrice) const ; 20 | private: 21 | int m_daysToExpiration; 22 | }; 23 | 24 | 25 | class OptionComparison { 26 | public: 27 | OptionComparison(bool directionLess); 28 | OptionComparison(const OptionComparison &p); 29 | ~OptionComparison(); 30 | OptionComparison &operator=(const OptionComparison &p); 31 | 32 | bool operator()(const SimpleOption &o1, const SimpleOption &o2); 33 | private: 34 | bool m_directionLess; 35 | }; 36 | 37 | 38 | #endif /* Functional_hpp */ 39 | -------------------------------------------------------------------------------- /CppOptions/NewtonMethod.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // NewtonMethod.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef NewtonMethod_hpp 12 | #define NewtonMethod_hpp 13 | 14 | #include "MathFunction.hpp" 15 | 16 | // 17 | // a Newton method implementation. 18 | // 19 | class NewtonMethod { 20 | public: 21 | // Takes as parameter the function and its derivatives 22 | // 23 | NewtonMethod(MathFunction &f, MathFunction &derivative); 24 | NewtonMethod(MathFunction &f, MathFunction &derivative, double error); 25 | NewtonMethod(const NewtonMethod &p); 26 | virtual ~NewtonMethod(); 27 | NewtonMethod &operator=(const NewtonMethod &p); 28 | 29 | double getFunctionRoot(double initialValue); 30 | private: 31 | MathFunction &m_f; 32 | MathFunction &m_derivative; 33 | double m_error; 34 | }; 35 | 36 | 37 | #endif /* NewtonMethod_hpp */ 38 | -------------------------------------------------------------------------------- /CppOptions/DateCompact.h: -------------------------------------------------------------------------------- 1 | // 2 | // DateCompact.h 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef __CppOptions__DateCompact__ 12 | #define __CppOptions__DateCompact__ 13 | 14 | // 15 | // a compact representation for dates, using a character string 16 | // 17 | class DateCompact { 18 | public: 19 | DateCompact(int year, int month, int day); 20 | DateCompact(const DateCompact &p); 21 | ~DateCompact(); 22 | DateCompact &operator=(const DateCompact &p); 23 | 24 | void setYear(int y); 25 | void setMonth(int m); 26 | void setDay(int d); 27 | 28 | int year(); 29 | int month(); 30 | int day(); 31 | 32 | void print(); 33 | 34 | bool operator==(const DateCompact &d) const; 35 | bool operator<(const DateCompact &d) const; 36 | 37 | private: 38 | char m_date[8]; 39 | }; 40 | 41 | 42 | #endif /* defined(__CppOptions__DateCompact__) */ 43 | -------------------------------------------------------------------------------- /CppOptions/Dictionary.h: -------------------------------------------------------------------------------- 1 | // 2 | // Dictionary.h 3 | 4 | #ifndef __StringProduction__Dictionary__ 5 | #define __StringProduction__Dictionary__ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | // 13 | // stores the words in the dictionary and provides an adjacency matrix for the words 14 | class Dictionary { 15 | public: 16 | Dictionary(int wordSize); 17 | ~Dictionary() {} 18 | Dictionary &operator=(const Dictionary &p); // not implemented 19 | private: 20 | Dictionary(const Dictionary &p); // not implemented 21 | public: 22 | void addElement(const std::string &s); 23 | void buildAdjancencyMatrix(); 24 | bool contains(const std::string &s); 25 | const std::vector > &adjList(); 26 | int elemPosition(const std::string &s); 27 | int size() { return (int)m_values.size(); } 28 | std::string elemAtPos(int i); 29 | private: 30 | std::vector m_values; 31 | std::map m_valuePositions; 32 | std::vector > m_adjacencyList; 33 | int m_wordSize; 34 | }; 35 | 36 | 37 | #endif /* defined(__StringProduction__Dictionary__) */ 38 | -------------------------------------------------------------------------------- /CppOptions/MathFunction.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MathFunction.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef MathFunction_hpp 12 | #define MathFunction_hpp 13 | 14 | #include 15 | #include 16 | 17 | 18 | class MathFunction { 19 | public: 20 | 21 | virtual ~MathFunction() {} 22 | virtual double operator()(double x) = 0; 23 | private: 24 | // this just an interface 25 | }; 26 | 27 | 28 | // 29 | // Polynomial has the form c_1 x^n + c_2 x^n-1 + .... + c_n-1 x^1 + c_n 30 | class PolynomialFunction : public MathFunction { 31 | public: 32 | PolynomialFunction(const std::vector &coef); 33 | PolynomialFunction(const PolynomialFunction &p); 34 | virtual ~PolynomialFunction(); 35 | PolynomialFunction &operator=(const PolynomialFunction &p); 36 | 37 | virtual double operator()(double x) override; 38 | 39 | private: 40 | std::vector m_coeficients; 41 | }; 42 | 43 | 44 | #endif /* MathFunction_hpp */ 45 | -------------------------------------------------------------------------------- /CppOptions/blas_samp.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // blas_samp.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #include "blas_samp.hpp" 12 | 13 | #include "Matrix.h" 14 | 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace ublas = boost::numeric::ublas; 21 | 22 | std::vector preMultiply(const std::vector &v, Matrix &m) 23 | { 24 | using namespace ublas; 25 | ublas::vector vec; 26 | std::copy(v.begin(), v.end(), vec.end()); 27 | 28 | int d1 = m.numRows(); 29 | int d2 = (int)m[0].size(); 30 | ublas::matrix M(d1, d2); 31 | 32 | for (int i = 0; i < d1; ++i) 33 | { 34 | for (int j = 0; j < d2; ++j) 35 | { 36 | M(i,j) = m[i][j]; 37 | } 38 | } 39 | 40 | vector pv = prod(vec, M); 41 | 42 | std::vector res; 43 | std::copy(pv.begin(), pv.end(), res.end()); 44 | return res; 45 | } 46 | -------------------------------------------------------------------------------- /CppOptions/Matrix.h: -------------------------------------------------------------------------------- 1 | // 2 | // Matrix.h 3 | // 4 | // 5 | // (c) 2020 Carlos Oliveira 6 | // This code is part of the book 7 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 8 | // by Carlos Oliveira, Apress, 2020. 9 | // For more information, visit http://coliveira.net 10 | 11 | 12 | #ifndef __FinancialSamples__Matrix__ 13 | #define __FinancialSamples__Matrix__ 14 | 15 | #include 16 | 17 | class Matrix { 18 | public: 19 | typedef std::vector Row; 20 | 21 | Matrix(int size); 22 | Matrix(int size1, int size2); 23 | Matrix(const Matrix &s); 24 | ~Matrix(); 25 | Matrix &operator=(const Matrix &s); 26 | 27 | void transpose(); 28 | double trace(); 29 | void add(const Matrix &s); 30 | void subtract(const Matrix &s); 31 | void multiply(const Matrix &s); 32 | void multiply(double num); 33 | 34 | Row & operator[](int pos); 35 | int numRows() const; 36 | private: 37 | std::vector m_rows; 38 | }; 39 | 40 | // free operators 41 | // 42 | Matrix operator+(const Matrix &s1, const Matrix &s2); 43 | Matrix operator-(const Matrix &s1, const Matrix &s2); 44 | Matrix operator*(const Matrix &s1, const Matrix &s2); 45 | 46 | #endif /* defined(__FinancialSamples__Matrix__) */ 47 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Freeware License, some rights reserved 2 | 3 | Copyright (c) 2020 Carlos Oliveira 4 | 5 | Permission is hereby granted, free of charge, to anyone obtaining a copy 6 | of this software and associated documentation files (the "Software"), 7 | to work with the Software within the limits of freeware distribution and fair use. 8 | This includes the rights to use, copy, and modify the Software for personal use. 9 | Users are also allowed and encouraged to submit corrections and modifications 10 | to the Software for the benefit of other users. 11 | 12 | It is not allowed to reuse, modify, or redistribute the Software for 13 | commercial use in any way, or for a user’s educational materials such as books 14 | or blog articles without prior permission from the copyright holder. 15 | 16 | The above copyright notice and this permission notice need to be included 17 | in all copies or substantial portions of the software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | 27 | 28 | -------------------------------------------------------------------------------- /CppOptions/DataSource.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // DataSource.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #include "DataSource.hpp" 12 | 13 | 14 | DataSource::DataSource(const std::string &name) 15 | : m_dataName(name) 16 | { 17 | } 18 | 19 | DataSource::DataSource(const DataSource &p) 20 | : m_dataName(p.m_dataName) 21 | { 22 | } 23 | 24 | DataSource &DataSource::operator=(const DataSource &p) 25 | { 26 | if (this != &p) 27 | { 28 | m_dataName = p.m_dataName; 29 | } 30 | return *this; 31 | } 32 | 33 | DataSource::~DataSource() 34 | { 35 | } 36 | 37 | 38 | DataSource *DataSource::createInstance() 39 | { 40 | std::string sourceName; 41 | // complex method used here to find sourceName and other construction parameters .... 42 | DataSource *ds = new DataSource(sourceName); 43 | return ds; 44 | } 45 | 46 | void DataSource::readData() 47 | { 48 | // read data here ... 49 | } 50 | 51 | 52 | void useDataSource() 53 | { 54 | // DataSource *source = new DataSource(""); // this will not work! 55 | DataSource *source = DataSource::createInstance(); 56 | source->readData(); 57 | // do something else with data 58 | delete source; 59 | } 60 | -------------------------------------------------------------------------------- /CppOptions/CDS.h: -------------------------------------------------------------------------------- 1 | // 2 | // CDS.hpp 3 | // CppOptions 4 | // 5 | // (c) 2020 Carlos Oliveira 6 | // This code is part of the book 7 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 8 | // by Carlos Oliveira, Apress, 2020. 9 | // For more information, visit http://coliveira.net 10 | 11 | 12 | #ifndef CDS_hpp 13 | #define CDS_hpp 14 | 15 | #include 16 | 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | // 24 | // CDSSolver class, incorporates the solution to Credit Default 25 | class CDSSolver : boost::noncopyable { 26 | public: 27 | 28 | // constructor 29 | CDSSolver(double val, double sigma, double divYield, 30 | double rf, double strike, double barrier, double rebate); 31 | 32 | // solve the model 33 | std::pair 34 | solve(QuantLib::Date maturity_date); 35 | 36 | // generate a grid 37 | void generateGrid(QuantLib::BarrierOption &option, 38 | QuantLib::BlackScholesMertonProcess &process, 39 | const std::vector &grid); 40 | 41 | private: 42 | 43 | double cur_val; 44 | double sigma; 45 | double divYield; 46 | double rf; 47 | double strike; 48 | double barrier; 49 | double rebate; 50 | }; 51 | 52 | 53 | #endif /* CDS_hpp */ 54 | -------------------------------------------------------------------------------- /CppOptions/Prototype.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Prototype.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #include "Prototype.hpp" 12 | 13 | Prototype *Prototype::s_prototype = nullptr; 14 | 15 | 16 | Prototype::Prototype() 17 | { 18 | } 19 | 20 | Prototype::Prototype(const Prototype &p) 21 | : m_var1(p.m_var1) 22 | { 23 | } 24 | 25 | Prototype::~Prototype() 26 | { 27 | 28 | } 29 | 30 | void Prototype::setVar1(int v) 31 | { 32 | m_var1 = v; 33 | } 34 | 35 | const Prototype &Prototype::getPrototype() 36 | { 37 | if (!s_prototype) 38 | { 39 | s_prototype = new Prototype(); 40 | } 41 | return *s_prototype; 42 | } 43 | 44 | Prototype &Prototype::operator=(const Prototype &p) 45 | { 46 | if (this != &p) 47 | { 48 | m_var1 = p.m_var1; 49 | } 50 | return *this; 51 | } 52 | 53 | Prototype *Prototype::clone() const 54 | { 55 | Prototype *a = new Prototype(*this); 56 | return a; 57 | } 58 | 59 | 60 | void usePrototype() 61 | { 62 | const Prototype &p = Prototype::getPrototype(); 63 | 64 | Prototype *pnew = p.clone(); 65 | pnew->setVar1(22); 66 | 67 | Prototype *pn2 = pnew->clone(); 68 | pn2->setVar1(43); 69 | 70 | delete pnew; 71 | delete pn2; 72 | } 73 | 74 | 75 | -------------------------------------------------------------------------------- /CppOptions/RandomWalkGenerator.h: -------------------------------------------------------------------------------- 1 | // 2 | // RandomWalkGenerator.h 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef __CppOptions__RandomWalkGenerator__ 12 | #define __CppOptions__RandomWalkGenerator__ 13 | 14 | // the class uses a vector to hold the elements 15 | // of the random walk, so they can be later plotted. 16 | #include 17 | 18 | // 19 | // Simple random walk generating class. This class can be 20 | // used for price simulation purposes. 21 | // 22 | class RandomWalkGenerator { 23 | public: 24 | // 25 | // class constructors 26 | RandomWalkGenerator(int size, double start, double step); 27 | RandomWalkGenerator(const RandomWalkGenerator &p); 28 | 29 | // destructor 30 | ~RandomWalkGenerator(); 31 | 32 | // assignment operator 33 | RandomWalkGenerator &operator=(const RandomWalkGenerator &p); 34 | 35 | // main method that returns a vector with values of the random walk 36 | std::vector generateWalk(); 37 | 38 | // returns a single step of the random walk 39 | double computeRandomStep(double currentPrice); 40 | 41 | private: 42 | int m_numSteps; // the number of steps 43 | double m_stepSize; // size of each step (in percentage points) 44 | double m_initialPrice; // starting price 45 | }; 46 | 47 | 48 | #endif /* defined(__CppOptions__RandomWalkGenerator__) */ 49 | -------------------------------------------------------------------------------- /CppOptions/Observer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Observer.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef Observer_hpp 12 | #define Observer_hpp 13 | 14 | #include 15 | #include 16 | 17 | 18 | class Observer { 19 | public: 20 | Observer(); 21 | Observer(const Observer &p); 22 | ~Observer(); 23 | Observer &operator=(const Observer &p); // not implemented 24 | 25 | virtual void notify() = 0; 26 | 27 | private: 28 | 29 | }; 30 | 31 | class Trade { 32 | // .... 33 | }; 34 | 35 | class TradingLedger; 36 | 37 | class TradeObserver : public Observer { 38 | public: 39 | TradeObserver(TradingLedger *t); 40 | TradeObserver(const TradeObserver &p); 41 | ~TradeObserver(); 42 | TradeObserver &operator=(const TradeObserver &p); 43 | 44 | void notify(); 45 | void processNewTrade(); 46 | private: 47 | Trade m_trade; 48 | TradingLedger *m_ledger; 49 | }; 50 | 51 | 52 | class TradingLedger { 53 | public: 54 | TradingLedger(); 55 | TradingLedger(const TradingLedger &p); 56 | ~TradingLedger(); 57 | TradingLedger &operator=(const TradingLedger &p); 58 | 59 | void addObserver(std::shared_ptr observer); 60 | void removeObserver(std::shared_ptr observer); 61 | void triggerNotifications(); 62 | 63 | void addTrade(const Trade &t); 64 | const Trade &getLastTrade(); 65 | 66 | private: 67 | std::set> m_observers; 68 | Trade m_trade; 69 | }; 70 | 71 | 72 | 73 | 74 | #endif /* Observer_hpp */ 75 | -------------------------------------------------------------------------------- /CppOptions/templates.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // templates.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef templates_hpp 12 | #define templates_hpp 13 | 14 | #include 15 | #include 16 | 17 | 18 | template 19 | class Factorial { 20 | public: 21 | enum { 22 | Argument = N 23 | }; 24 | static long value(); 25 | }; 26 | 27 | template 28 | long Factorial::value() 29 | { 30 | return N * Factorial::value(); 31 | } 32 | 33 | 34 | template <> 35 | long Factorial<0>::value() 36 | { 37 | return 1; 38 | } 39 | 40 | void array_normalize(std::vector &array); 41 | 42 | void set_normalize(std::set &set); 43 | 44 | template 45 | class Normalization { 46 | public: 47 | typedef T Type; 48 | static void normalize(T &arg); 49 | }; 50 | 51 | template <> 52 | void Normalization>::normalize(std::vector &a) 53 | { 54 | array_normalize(a); 55 | } 56 | 57 | template <> 58 | void Normalization>::normalize(std::set &a) 59 | { 60 | set_normalize(a); 61 | } 62 | 63 | template 64 | void normalize(T &val) { 65 | Normalization::normalize(val); 66 | } 67 | 68 | void use_normalize() 69 | { 70 | std::set set; 71 | std::vector array; 72 | 73 | 74 | 75 | normalize(set); 76 | normalize(array); 77 | } 78 | 79 | void array_normalize(std::vector &array) 80 | { 81 | 82 | } 83 | 84 | void set_normalize(std::set &set) 85 | { 86 | 87 | } 88 | 89 | 90 | #endif /* templates_hpp */ 91 | -------------------------------------------------------------------------------- /CppOptions/LAVectors.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // LAVectors.hpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #ifndef LAVectors_hpp 12 | #define LAVectors_hpp 13 | 14 | 15 | #include 16 | 17 | typedef std::vector Vector; 18 | 19 | // scalar by vector operations 20 | 21 | Vector add(double num, const Vector &v); 22 | Vector multiply(double num, const Vector &v); 23 | 24 | void in_place_add(double num, Vector &v); 25 | void in_place_multiply(double num, Vector &v); 26 | 27 | inline Vector operator +(double num, const Vector &v) 28 | { 29 | return add(num, v); 30 | } 31 | 32 | inline Vector operator *(double num, const Vector &v) 33 | { 34 | return multiply(num, v); 35 | } 36 | 37 | inline void operator +=(double num, Vector &v) 38 | { 39 | in_place_add(num, v); 40 | } 41 | 42 | inline void operator *=(double num, Vector &v) 43 | { 44 | in_place_multiply(num, v); 45 | } 46 | 47 | // vector to vector operations 48 | 49 | Vector add(const Vector &v1, const Vector &v2); 50 | void in_place_add(Vector &v1, const Vector &v2); 51 | 52 | double product(const Vector &v1, const Vector &v2); 53 | void in_place_product(Vector &v1, const Vector &v2); 54 | 55 | 56 | inline Vector operator +(const Vector &v1, const Vector &v2) 57 | { 58 | return add(v1, v2); 59 | } 60 | 61 | inline void operator +=(Vector &v1, const Vector &v2) 62 | { 63 | in_place_add(v1, v2); 64 | } 65 | 66 | inline double operator *(const Vector &v1, const Vector &v2) 67 | { 68 | return product(v1, v2); 69 | } 70 | 71 | inline void operator *=(Vector &v1, const Vector &v2) 72 | { 73 | in_place_add(v1, v2); 74 | } 75 | 76 | double norm(const Vector &v); 77 | 78 | 79 | #include 80 | 81 | #endif /* LAVectors_hpp */ 82 | -------------------------------------------------------------------------------- /CppOptions/EulersMethod.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // EulersMethod.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #include "EulersMethod.hpp" 12 | 13 | 14 | #include 15 | 16 | using std::cout; 17 | using std::endl; 18 | 19 | 20 | EulersMethod::EulersMethod(DEMathFunction &f) 21 | : m_f(f) 22 | { 23 | } 24 | 25 | EulersMethod::EulersMethod(const EulersMethod &p) 26 | : m_f(p.m_f) 27 | { 28 | } 29 | 30 | EulersMethod::~EulersMethod() 31 | { 32 | } 33 | 34 | EulersMethod &EulersMethod::operator=(const EulersMethod &p) 35 | { 36 | if (this != &p) 37 | { 38 | m_f = p.m_f; 39 | } 40 | return *this; 41 | } 42 | 43 | double EulersMethod::solve(int n, double x0, double y0, double c) 44 | { 45 | // problem : y' = f(x,y) ; y(x0) = y0 46 | 47 | auto x = x0; 48 | auto y = y0; 49 | auto h = (c - x0)/n; 50 | 51 | cout << " h is " << h << endl; 52 | 53 | for (int i=0; i 15 | 16 | enum DayOfTheWeek { 17 | DayOfTheWeek_Sunday, 18 | DayOfTheWeek_Monday, 19 | DayOfTheWeek_Tuesday, 20 | DayOfTheWeek_Wednesday, 21 | DayOfTheWeek_Thursday, 22 | DayOfTheWeek_Friday, 23 | DayOfTheWeek_Saturday, 24 | DayOfTheWeek_UNKNOWN 25 | }; 26 | 27 | enum Month { 28 | Month_January = 1, 29 | Month_February, 30 | Month_March, 31 | Month_April, 32 | Month_May, 33 | Month_June, 34 | Month_July, 35 | Month_August, 36 | Month_September, 37 | Month_October, 38 | Month_November, 39 | Month_December, 40 | }; 41 | 42 | class Date { 43 | public: 44 | Date(int year, int month, int day); 45 | Date(const Date &p); 46 | ~Date(); 47 | Date &operator=(const Date &p); 48 | 49 | void setHolidays(const std::vector &days); 50 | std::string month(); 51 | std::string dayOfWeek(); 52 | 53 | void add(int numDays); 54 | void addTradingDays(int numDays); 55 | void subtract(int numDays); 56 | void subtractTradingDays(int numDays); 57 | int dateDifference(const Date &date); 58 | int tradingDateDifference(const Date &date); 59 | DayOfTheWeek dayOfTheWeek(); 60 | bool isHoliday(); 61 | bool isWeekDay(); 62 | Date nextTradingDay(); 63 | bool isLeapYear(); 64 | bool isTradingDay(); 65 | void print(); 66 | 67 | Date &operator ++(); 68 | Date &operator --(); 69 | bool operator<(const Date &d) const; 70 | bool operator==(const Date &d); 71 | private: 72 | int m_year; 73 | int m_month; 74 | int m_day; 75 | DayOfTheWeek m_weekDay; 76 | std::vector m_holidays; 77 | }; 78 | 79 | 80 | #endif /* defined(__CppOptions__Date__) */ 81 | -------------------------------------------------------------------------------- /CppOptions/OOExamples.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // OOExamples.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #include "OOExamples.h" 12 | 13 | 14 | double GeneralDerivative::strike() 15 | { 16 | return m_strike; 17 | } 18 | 19 | 20 | double CDSContract::kStandardPayoff = 1000.0; 21 | 22 | void CDSContract::setCounterpart(const std::string &s) 23 | { 24 | m_counterpart = s; 25 | setPayoff(kStandardPayoff); 26 | } 27 | 28 | double CDSContract::computeCurrentValue(const Date &d) 29 | { 30 | if (!counterpart().empty()) 31 | { 32 | processCreditEvent(); // make sure there is no credit event; 33 | } 34 | return 0; //calculateInternalValue(); 35 | } 36 | 37 | void LoanOnlyCDSContract::processCreditEvent() 38 | { 39 | } 40 | 41 | 42 | double LoanOnlyCDSContract::computeCurrentValue(const Date &d) 43 | { 44 | return 0; 45 | } 46 | 47 | CDSContract *createSimpeleContract() 48 | { 49 | CDSContract *contract = new LoanOnlyCDSContract(); 50 | contract->setCounterpart("IBM"); 51 | return contract; 52 | } 53 | 54 | 55 | void useContract(bool isLOContract, Date ¤tDate) 56 | { 57 | CDSContract *contract = nullptr; 58 | if (isLOContract) 59 | { 60 | contract = new LoanOnlyCDSContract(); 61 | } 62 | else 63 | { 64 | //contract = new CDSContract(); // normal CDS contract 65 | } 66 | 67 | contract->computeCurrentValue(currentDate); 68 | delete contract; 69 | } 70 | 71 | void useBasePtr(CDSContract *contract, Date ¤tDate) 72 | { 73 | contract->computeCurrentValue(currentDate); 74 | delete contract; 75 | } 76 | 77 | void callBasePtr() 78 | { 79 | Date date(1,1,2010); 80 | useBasePtr(new LoanOnlyCDSContract(), date); 81 | } 82 | 83 | int main_ooe() 84 | { 85 | Date date(1,1,2010); 86 | //useContract(true, date); 87 | useBasePtr(new LoanOnlyCDSContract(), date); 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /CppOptions/RandomWalk.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // RandomWalk.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | #include "RandomWalk.hpp" 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | using std::vector; 18 | using std::cout; 19 | using std::endl; 20 | 21 | 22 | std::default_random_engine engine; 23 | 24 | 25 | RandomWalkModel::RandomWalkModel(int size, double start, double step) 26 | : m_numSteps(size), 27 | m_stepSize(step), 28 | m_startPrice(start) 29 | { 30 | } 31 | 32 | RandomWalkModel::RandomWalkModel(const RandomWalkModel &p) 33 | : m_numSteps(p.m_numSteps), 34 | m_stepSize(p.m_stepSize), 35 | m_startPrice(p.m_startPrice) 36 | { 37 | } 38 | 39 | RandomWalkModel::~RandomWalkModel() 40 | { 41 | } 42 | 43 | RandomWalkModel &RandomWalkModel::operator=(const RandomWalkModel &p) 44 | { 45 | if (this != &p) 46 | { 47 | m_numSteps = p.m_numSteps; 48 | m_stepSize = p.m_stepSize; 49 | m_startPrice = p.m_startPrice; 50 | } 51 | return *this; 52 | } 53 | 54 | int RandomWalkModel::random_integer(int max) 55 | { 56 | 57 | std::uniform_int_distribution unif(0, max); 58 | return unif(engine); 59 | } 60 | 61 | std::vector RandomWalkModel::getWalk() 62 | { 63 | vector walk; 64 | double prev = m_startPrice; 65 | 66 | for (int i=0; i walk = rw.getWalk(); 83 | for (int i=0; i 15 | 16 | using std::cout; 17 | using std::endl; 18 | 19 | RungeKuttaMethod::RungeKuttaMethod(DEMathFunction &f) 20 | : m_func(f) 21 | { 22 | } 23 | 24 | RungeKuttaMethod::RungeKuttaMethod(const RungeKuttaMethod &p) 25 | : m_func(p.m_func) 26 | { 27 | } 28 | 29 | RungeKuttaMethod::~RungeKuttaMethod() 30 | { 31 | } 32 | 33 | RungeKuttaMethod &RungeKuttaMethod::operator=(const RungeKuttaMethod &p) 34 | { 35 | if (this != &p) 36 | { 37 | m_func = p.m_func; 38 | } 39 | return *this; 40 | } 41 | 42 | // Runge-Kutta method with fourth order approximation 43 | // 44 | double RungeKuttaMethod::solve(int n, double x0, double y0, double c) 45 | { 46 | // initial conditions 47 | auto x = x0; 48 | auto y = y0; 49 | auto h = (c - x0)/n; 50 | 51 | for (int i=0; i 14 | #include 15 | 16 | template 17 | T generic_max(T a, T b) 18 | { 19 | if (a > b) 20 | { 21 | return a; 22 | } 23 | else 24 | { 25 | return b; 26 | } 27 | } 28 | 29 | template <> 30 | const char * generic_max(const char *a, const char *b) 31 | { 32 | if (strcmp(a, b) > 0) 33 | { 34 | return a; 35 | } 36 | else 37 | { 38 | return b; 39 | } 40 | } 41 | 42 | 43 | template 44 | void printNumberPlusOne() 45 | { 46 | int a = N + 1; 47 | std::cout << a << std::endl; 48 | } 49 | 50 | void usePrintTemplate() 51 | { 52 | printNumberPlusOne<10>(); 53 | } 54 | 55 | template 56 | void printNumberRecursive() // general case 57 | { 58 | std::cout << N << " "; 59 | printNumberRecursive(); 60 | } 61 | 62 | template<> 63 | void printNumberRecursive<0>() // base case 64 | { 65 | std::cout << std::endl; 66 | } 67 | 68 | void usePrintRecursive() 69 | { 70 | printNumberRecursive<10>(); 71 | } 72 | 73 | template 74 | int intSum() 75 | { 76 | return N + intSum(); 77 | } 78 | 79 | template <> 80 | int intSum<0>() 81 | { 82 | return 0; 83 | } 84 | 85 | void useIntSum() 86 | { 87 | std::cout << intSum<20>() << std::endl; 88 | } 89 | 90 | void useFactorial() 91 | { 92 | Factorial<8> fact; 93 | std::cout << " factorial for argument " << fact.Argument << " is " << fact.value() << std::endl; 94 | } 95 | 96 | int int_max(int a, int b) 97 | { 98 | if (a > b) 99 | { 100 | return a; 101 | } 102 | else 103 | { 104 | return b; 105 | } 106 | } 107 | 108 | void use_template() 109 | { 110 | int res = 0; 111 | int a = 15, b = 32; 112 | 113 | res = generic_max(a, b); 114 | 115 | 116 | generic_max("test1", "test2"); 117 | } 118 | 119 | 120 | 121 | 122 | int main_templat() 123 | { 124 | usePrintRecursive(); 125 | useIntSum(); 126 | useFactorial(); 127 | return 0; 128 | } 129 | -------------------------------------------------------------------------------- /CppOptions/boosttest.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // boosttest.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | 12 | #include "boosttest.hpp" 13 | 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | using namespace std; 21 | using namespace boost::numeric::odeint; 22 | 23 | const double sigma = 10.0; 24 | const double R = 28.0; 25 | const double b = 8.0 / 3.0; 26 | 27 | typedef boost::array< double , 3 > state_type; 28 | 29 | void lorenz( const state_type &x , state_type &dxdt , double t ) 30 | { 31 | dxdt[0] = sigma * ( x[1] - x[0] ); 32 | dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; 33 | dxdt[2] = -b * x[2] + x[0] * x[1]; 34 | } 35 | 36 | void write_lorenz( const state_type &x , const double t ) 37 | { 38 | cout << t << '\t' << x[0] << '\t' << x[1] << '\t' << x[2] << endl; 39 | } 40 | 41 | void main2(int argc, char **argv) 42 | { 43 | state_type x = { 10.0 , 1.0 , 1.0 }; // initial conditions 44 | integrate(lorenz , x , 0.0 , 25.0 , 0.1 , write_lorenz ); 45 | } 46 | 47 | 48 | 49 | // 50 | // This is the equation at the right side of the ODE y' = f(x,y) 51 | // It is evaluated in the inner steps of the algorithm. 52 | // 53 | void right_side_equation(double y, double &dydx, double x) 54 | { 55 | dydx = 3.0/(2.5*x*x) + y/(1.5*x); 56 | } 57 | 58 | // this function simply prints the current value of the interactive 59 | // solution steps. 60 | void write_cout( const double &x , const double t ) 61 | { 62 | cout << t << '\t' << x << endl; 63 | } 64 | 65 | // A stepper based on Runge-Kutta algorithm. 66 | // the state_type use is 'double' 67 | typedef runge_kutta_dopri5 stepper_type; 68 | 69 | 70 | // This solves the ODE described above with initial condition x(1) = 0. 71 | 72 | 73 | int main_boost() 74 | { 75 | double x = 0.0; 76 | auto n = integrate_adaptive( 77 | make_controlled(1E-12, 1E-12, stepper_type()), // instantiate the stepper 78 | right_side_equation, // equation 79 | x, // initial state 80 | 1.0 , 10.0 , 0.1 , // start x, end x, and step size 81 | write_cout ); 82 | cout << " process completed after " << n << " steps \n"; 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /CppOptions/Integration.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Integration.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #include "Integration.hpp" 12 | 13 | 14 | #include "MathFunction.hpp" 15 | 16 | #include 17 | #include 18 | 19 | using std::cout; 20 | using std::endl; 21 | 22 | namespace { 23 | const int DEFAULT_NUM_INTERVALS = 100; 24 | } 25 | 26 | SimpsonsIntegration::SimpsonsIntegration(MathFunction &f) 27 | : m_f(f), 28 | m_numIntervals(DEFAULT_NUM_INTERVALS) 29 | { 30 | } 31 | 32 | SimpsonsIntegration::SimpsonsIntegration(const SimpsonsIntegration &p) 33 | : m_f(p.m_f), 34 | m_numIntervals(p.m_numIntervals) 35 | { 36 | } 37 | 38 | SimpsonsIntegration::~SimpsonsIntegration() 39 | { 40 | } 41 | 42 | SimpsonsIntegration &SimpsonsIntegration::operator=(const SimpsonsIntegration &p) 43 | { 44 | if (this != &p) 45 | { 46 | m_f = p.m_f; 47 | m_numIntervals = p.m_numIntervals; 48 | } 49 | return *this; 50 | } 51 | 52 | double SimpsonsIntegration::getIntegral(double a, double b) 53 | { 54 | double S = 0; 55 | double intSize = (b - a)/m_numIntervals; 56 | double x = a; 57 | 58 | for (int i=0; i 15 | #include 16 | #include "Date.h" 17 | 18 | class GeneralDerivative { 19 | 20 | virtual double strike(); 21 | private: 22 | double m_strike; 23 | }; 24 | 25 | 26 | /// abstract classes 27 | 28 | class AbstractDerivative { 29 | public: 30 | virtual double calculatePriceAtExpiration() = 0; 31 | virtual void setExpiration(int year, int month, int day); 32 | virtual double getcurrentPrice() = 0; 33 | }; 34 | 35 | 36 | class PartialDerivative { 37 | public: 38 | PartialDerivative(); 39 | virtual ~PartialDerivative(); 40 | PartialDerivative(const PartialDerivative &p); 41 | PartialDerivative &operator=(const PartialDerivative &p); 42 | 43 | private: 44 | 45 | }; 46 | 47 | enum CDSUnderlying { 48 | CDSUnderlying_Bond, 49 | CDSUnderlying_Cash 50 | }; 51 | 52 | class Date; 53 | class MathIntegration; 54 | 55 | class CDSContract { 56 | public: 57 | CDSContract() {} 58 | CDSContract(MathIntegration *mipt); 59 | CDSContract(const CDSContract &p); 60 | virtual ~CDSContract() { std::cout << " base delete " << std::endl; } 61 | CDSContract &operator=(const CDSContract &p); 62 | 63 | std::string counterpart() { return m_counterpart; } 64 | void setCounterpart(const std::string &s); 65 | double payoff() { return m_payoff; } 66 | void setPayoff(double payoff) { m_payoff = payoff; } 67 | virtual double computeCurrentValue(const Date &d); 68 | 69 | virtual void processCreditEvent() = 0; 70 | 71 | private: 72 | std::string m_counterpart; 73 | CDSUnderlying m_underlying; 74 | double m_payoff; 75 | int m_term; 76 | double m_spreadCost; 77 | MathIntegration *m_mipt; 78 | 79 | static double kStandardPayoff; 80 | }; 81 | 82 | 83 | class LoanOnlyCDSContract : public CDSContract { 84 | public: 85 | LoanOnlyCDSContract() { std::cout << " derived class delete " << std::endl; } 86 | // constructors go here 87 | void changeLoanSource(const std::string &s); 88 | virtual double computeCurrentValue(const Date &d); 89 | 90 | virtual void processCreditEvent(); 91 | 92 | private: 93 | std::string m_loanSource; 94 | }; 95 | 96 | 97 | 98 | 99 | 100 | #endif /* OOExamples_hpp */ 101 | -------------------------------------------------------------------------------- /CppOptions/MathFunction.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // MathFunction.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | #include "MathFunction.hpp" 11 | 12 | #include 13 | 14 | using std::cout; 15 | using std::endl; 16 | 17 | 18 | PolynomialFunction::PolynomialFunction(const std::vector &coef) 19 | : m_coeficients(coef) 20 | { 21 | } 22 | 23 | PolynomialFunction::PolynomialFunction(const PolynomialFunction &p) 24 | : m_coeficients(p.m_coeficients) 25 | { 26 | } 27 | 28 | PolynomialFunction::~PolynomialFunction() 29 | { 30 | } 31 | 32 | PolynomialFunction &PolynomialFunction::operator=(const PolynomialFunction &p) 33 | { 34 | if (this != &p) 35 | { 36 | m_coeficients = p.m_coeficients; 37 | } 38 | return *this; 39 | } 40 | 41 | double PolynomialFunction::operator()(double x) 42 | { 43 | int n = (int)m_coeficients.size(); 44 | double y = 0; 45 | int i; 46 | for (i=0; i 79 | namespace boost{ namespace math{ 80 | 81 | //template // = policies::policy<> > 83 | //class chi_squared_distribution; 84 | 85 | typedef chi_squared_distribution<> chi_squared; 86 | 87 | template 88 | class chi_squared_distribution 89 | { 90 | public: 91 | typedef RealType value_type; 92 | typedef Policy policy_type; 93 | 94 | // Constructor: 95 | chi_squared_distribution(RealType i); 96 | 97 | // Accessor to parameter: 98 | RealType degrees_of_freedom()const; 99 | 100 | // Parameter estimation: 101 | static RealType find_degrees_of_freedom( 102 | RealType difference_from_mean, 103 | RealType alpha, 104 | RealType beta, 105 | RealType sd, 106 | RealType hint = 100); 107 | }; 108 | 109 | }} // namespaces 110 | 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /CppOptions/RandomWalkGenerator.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // RandomWalkGenerator.cpp 3 | // 4 | // Simple random walk implementation. 5 | // 6 | // (c) 2020 Carlos Oliveira 7 | // This code is part of the book 8 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 9 | // by Carlos Oliveira, Apress, 2020. 10 | // For more information, visit http://coliveira.net 11 | 12 | 13 | #include "RandomWalkGenerator.h" 14 | 15 | #include 16 | #include 17 | 18 | using std::vector; 19 | using std::cout; 20 | using std::endl; 21 | 22 | // 23 | // Constructor. The supplied parameters represent the number of elements in the 24 | // random walk, the initial price, and the step size for the random walk. 25 | // 26 | RandomWalkGenerator::RandomWalkGenerator(int size, double start, double step) 27 | : m_numSteps(size), 28 | m_stepSize(step), 29 | m_initialPrice(start) 30 | { 31 | } 32 | 33 | RandomWalkGenerator::RandomWalkGenerator(const RandomWalkGenerator &p) 34 | : m_numSteps(p.m_numSteps), 35 | m_stepSize(p.m_stepSize), 36 | m_initialPrice(p.m_initialPrice) 37 | { 38 | } 39 | 40 | RandomWalkGenerator::~RandomWalkGenerator() 41 | { 42 | } 43 | 44 | RandomWalkGenerator &RandomWalkGenerator::operator=(const RandomWalkGenerator &p) 45 | { 46 | if (this != &p) 47 | { 48 | m_numSteps = p.m_numSteps; 49 | m_stepSize = p.m_stepSize; 50 | m_initialPrice = p.m_initialPrice; 51 | } 52 | return *this; 53 | } 54 | 55 | // 56 | // returns a single step of the random walk 57 | // 58 | double RandomWalkGenerator::computeRandomStep(double currentPrice) 59 | { 60 | int r = rand() % 3; 61 | double val = currentPrice; 62 | if (r == 0) 63 | { 64 | val += (m_stepSize * val); 65 | } 66 | else if (r == 1) 67 | { 68 | val -= (m_stepSize * val); 69 | } 70 | return val; 71 | } 72 | 73 | 74 | // 75 | // This is the main method. It will generate random numbers within 76 | // the constraints set in the constructor. 77 | // 78 | std::vector RandomWalkGenerator::generateWalk() 79 | { 80 | vector walk; 81 | double prev = m_initialPrice; 82 | 83 | for (auto i=0; i walk = rw.generateWalk(); 100 | for (int i=0; i 14 | 15 | using std::cout; 16 | using std::endl; 17 | 18 | GenericOption::GenericOption(double strike, OptionType type, double cost) 19 | : m_strike(strike), 20 | m_type(type), 21 | m_cost(cost) 22 | { 23 | 24 | } 25 | 26 | GenericOption::GenericOption(const GenericOption &p) 27 | : m_strike(p.m_strike), 28 | m_type(p.m_type), 29 | m_cost(p.m_cost) 30 | { 31 | 32 | } 33 | 34 | GenericOption::~GenericOption() 35 | { 36 | } 37 | 38 | GenericOption &GenericOption::operator=(const GenericOption &p) 39 | { 40 | if (this != &p) 41 | { 42 | m_type = p.m_type; 43 | m_strike = p.m_strike; 44 | m_cost = p.m_cost; 45 | } 46 | return *this; 47 | } 48 | 49 | // 50 | // Computes the value of the option at expiration date. 51 | // Value depends on the type of option (CALL or PUT) and strike. 52 | // 53 | double GenericOption::valueAtExpiration(double underlyingAtExpiration) 54 | { 55 | double value = 0.0; 56 | 57 | if (m_type == OptionType_Call) 58 | { 59 | if (m_strike < underlyingAtExpiration) 60 | { 61 | value = underlyingAtExpiration - m_strike; 62 | } 63 | } 64 | else // it is an OptionType_Put 65 | { 66 | if (m_strike > underlyingAtExpiration) 67 | { 68 | value = m_strike - underlyingAtExpiration; 69 | } 70 | } 71 | return value; 72 | } 73 | 74 | // 75 | // return the profit (value at expiration minus option cost) 76 | // 77 | double GenericOption::profitAtExpiration(double underlyingAtExpiration) 78 | { 79 | 80 | double finalValue = valueAtExpiration(underlyingAtExpiration); 81 | 82 | return finalValue - m_cost; 83 | } 84 | 85 | int main_go() 86 | { 87 | GenericOption option(100.0, OptionType_Put, 1.1); 88 | double price1 = 120.0; 89 | double value = option.valueAtExpiration(price1); 90 | cout << " For 100PUT, value at expiration for price " << price1 << " is " << value << endl; 91 | double price2 = 85.0; 92 | value = option.valueAtExpiration(85.0); 93 | cout << " For 100PUT, value at expiration for price " << price2 << " is " << value << endl; 94 | 95 | auto limit = 120.0; 96 | for (auto price = 80.0; price <= limit; price += 0.1) 97 | { 98 | value = option.profitAtExpiration(price); 99 | cout << price << ", " << value << endl; 100 | } 101 | 102 | 103 | 104 | return 0; 105 | } 106 | -------------------------------------------------------------------------------- /CppOptions/NewtonMethod.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // NewtonMethod.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #include "NewtonMethod.hpp" 12 | 13 | 14 | #include 15 | #include 16 | 17 | using std::endl; 18 | using std::cout; 19 | 20 | namespace { 21 | const double DEFAULT_ERROR = 0.0001; 22 | } 23 | 24 | NewtonMethod::NewtonMethod(MathFunction &f, MathFunction &derivative) 25 | : m_f(f), 26 | m_derivative(derivative), 27 | m_error(DEFAULT_ERROR) 28 | { 29 | } 30 | 31 | NewtonMethod::NewtonMethod(MathFunction &f, MathFunction &derivative, double error) 32 | : m_f(f), 33 | m_derivative(derivative), 34 | m_error(error) 35 | { 36 | } 37 | 38 | NewtonMethod::NewtonMethod(const NewtonMethod &p) 39 | : m_f(p.m_f), 40 | m_derivative(p.m_derivative), 41 | m_error(p.m_error) 42 | { 43 | } 44 | 45 | NewtonMethod::~NewtonMethod() 46 | { 47 | } 48 | 49 | NewtonMethod &NewtonMethod::operator=(const NewtonMethod &p) 50 | { 51 | if (this != &p) 52 | { 53 | m_f = p.m_f; 54 | m_derivative = p.m_derivative; 55 | m_error = p.m_error; 56 | } 57 | return *this; 58 | } 59 | 60 | double NewtonMethod::getFunctionRoot(double x0) 61 | { 62 | double x1 = x0; 63 | do 64 | { 65 | x0 = x1; 66 | cout << " x0 is " << x0 << endl; // this line just for demonstration 67 | double d = m_derivative(x0); 68 | double y = m_f(x0); 69 | x1 = x0 - y / d; 70 | } 71 | while (std::abs(x0 - x1) > m_error); 72 | return x1; 73 | } 74 | 75 | // ---- A function used as example 76 | 77 | namespace { 78 | 79 | class SampleFunction : public MathFunction { 80 | public: 81 | virtual ~SampleFunction(); 82 | virtual double operator()(double value); 83 | }; 84 | 85 | SampleFunction::~SampleFunction() 86 | { 87 | } 88 | 89 | double SampleFunction::operator ()(double x) 90 | { 91 | return (x-1)*(x-1)*(x-1); 92 | } 93 | 94 | class Derivative : public MathFunction { 95 | public: 96 | virtual ~Derivative(); 97 | virtual double operator()(double value); 98 | }; 99 | 100 | // represents the derivative of the sample function 101 | Derivative::~Derivative() 102 | { 103 | } 104 | 105 | double Derivative::operator ()(double x) 106 | { 107 | return 3*(x-1)*(x-1); 108 | } 109 | 110 | } 111 | 112 | int main_newton() 113 | { 114 | SampleFunction f; 115 | Derivative df; 116 | NewtonMethod nm(f, df); 117 | cout << " the root of the function is " << nm.getFunctionRoot(100) << endl; 118 | return 0; 119 | } 120 | 121 | -------------------------------------------------------------------------------- /CppOptions/LAVectors.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // LAVectors.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #include "LAVectors.hpp" 12 | 13 | #include 14 | 15 | // 16 | // adds a scalar number to a vector "v" 17 | // 18 | Vector add(double num, const Vector &v) 19 | { 20 | int n = (int)v.size(); 21 | Vector result(n); 22 | for (int i=0; i 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using std::string; 15 | using std::vector; 16 | using std::set; 17 | using std::map; 18 | using std::cout; 19 | using std::endl; 20 | using std::cerr; 21 | 22 | struct AA { 23 | int a, b; 24 | }; 25 | 26 | extern "C" 27 | { 28 | int testfunc(int); 29 | int add_to_n(int); 30 | int add_numbers(int *, int); 31 | int access_st(AA *s); 32 | } 33 | 34 | Dictionary::Dictionary(int wordSize) 35 | : m_values(), 36 | m_valuePositions(), 37 | m_adjacencyList(), 38 | m_wordSize(wordSize) 39 | { 40 | int a = testfunc(33); 41 | cout << " **** tfunc val: " << a << endl; 42 | int b = add_to_n(10); 43 | cout << " **** sum val: " << b << endl; 44 | int v[] = {1, 2, 3, 4, 5, 6, 7, 2}; 45 | int c = add_numbers(v, sizeof(v)/sizeof(v[0])); 46 | cout << " **** add val: " << c << endl; 47 | AA d; 48 | d.a = 5; 49 | d.b = 7; 50 | int e = access_st(&d); 51 | cout << " **** vals: " << d.a << " " << e << endl; 52 | } 53 | 54 | const std::vector > &Dictionary::adjList() 55 | { 56 | return m_adjacencyList; 57 | } 58 | 59 | Dictionary &Dictionary::operator=(const Dictionary &p) 60 | { 61 | 62 | if (&p != this) 63 | { 64 | m_adjacencyList = p.m_adjacencyList; 65 | m_valuePositions = p.m_valuePositions; 66 | m_values = p.m_values; 67 | m_wordSize = p.m_wordSize; 68 | } 69 | return *this; 70 | } 71 | 72 | // 73 | // true if the words a and b differ by just one character 74 | // 75 | bool diffByOne(const string &a, const string &b) 76 | { 77 | if (a.size() != b.size()) return false; 78 | int ndiff = 0; 79 | for (unsigned i=0; i(n)); 119 | for (int j=0; j PObserver; 16 | typedef shared_ptr PTradeObserver; 17 | 18 | Observer::Observer() 19 | { 20 | } 21 | 22 | Observer::Observer(const Observer &p) 23 | { 24 | } 25 | 26 | Observer::~Observer() 27 | { 28 | } 29 | 30 | void Observer::notify() 31 | { 32 | } 33 | 34 | TradeObserver::TradeObserver(TradingLedger *t) 35 | : m_ledger(t) 36 | { 37 | } 38 | 39 | TradeObserver::TradeObserver(const TradeObserver &p) 40 | : m_trade(p.m_trade), 41 | m_ledger(p.m_ledger) 42 | { 43 | } 44 | 45 | TradeObserver::~TradeObserver() 46 | { 47 | } 48 | 49 | TradeObserver &TradeObserver::operator=(const TradeObserver &p) 50 | { 51 | if (this != &p) 52 | { 53 | m_trade = p.m_trade; 54 | m_ledger = p.m_ledger; 55 | } 56 | return *this; 57 | } 58 | 59 | void TradeObserver::notify() 60 | { 61 | this->processNewTrade(); 62 | } 63 | 64 | void TradeObserver::processNewTrade() 65 | { 66 | m_trade = m_ledger->getLastTrade(); 67 | // do trading processing here 68 | } 69 | 70 | 71 | // 72 | 73 | TradingLedger::TradingLedger() 74 | { 75 | } 76 | 77 | TradingLedger::TradingLedger(const TradingLedger &p) 78 | : m_observers(p.m_observers), 79 | m_trade(p.m_trade) 80 | { 81 | } 82 | 83 | TradingLedger::~TradingLedger() 84 | { 85 | } 86 | 87 | TradingLedger &TradingLedger::operator=(const TradingLedger &p) 88 | { 89 | if (this != &p) 90 | { 91 | m_observers = p.m_observers; 92 | m_trade = p.m_trade; 93 | } 94 | return *this; 95 | } 96 | 97 | void TradingLedger::addObserver(PObserver observer) 98 | { 99 | m_observers.insert(observer); 100 | } 101 | 102 | void TradingLedger::removeObserver(PObserver observer) 103 | { 104 | if (m_observers.find(observer) != m_observers.end()) 105 | { 106 | m_observers.erase(observer); 107 | } 108 | } 109 | 110 | void TradingLedger::triggerNotifications() 111 | { 112 | for (auto i : m_observers) 113 | { 114 | i->notify(); 115 | } 116 | } 117 | 118 | void TradingLedger::addTrade(const Trade &t) 119 | { 120 | m_trade = t; 121 | this->triggerNotifications(); 122 | } 123 | 124 | const Trade &TradingLedger::getLastTrade() 125 | { 126 | return m_trade; 127 | } 128 | 129 | int main_obs() 130 | { 131 | TradingLedger tl; 132 | PTradeObserver observer1 = PTradeObserver(new TradeObserver(&tl)); 133 | PTradeObserver observer2 = PTradeObserver(new TradeObserver(&tl)); 134 | tl.addObserver(observer1); 135 | tl.addObserver(observer2); 136 | 137 | // perform trading system here 138 | 139 | Trade aTrade; 140 | tl.addTrade(aTrade); 141 | 142 | // observers should receive a notification at this point 143 | return 0; 144 | } 145 | -------------------------------------------------------------------------------- /CppOptions/MonteCarlo.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // MonteCarlo.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #include "MonteCarlo.hpp" 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | using std::cout; 20 | using std::endl; 21 | using std::vector; 22 | 23 | std::default_random_engine generator; 24 | 25 | 26 | int get_uniform_int(int max) 27 | { 28 | if (max < 1) 29 | { 30 | cout << "invalid parameter max " << max << endl; 31 | throw std::runtime_error("invalid parameter max"); 32 | } 33 | std::uniform_int_distribution uint(0,max); 34 | 35 | return uint(generator); 36 | } 37 | 38 | 39 | vector coin_toss_experiment(int num_experiments) 40 | { 41 | if (num_experiments < 1) 42 | { 43 | cout << "invalid number of experiments " << num_experiments << endl; 44 | throw std::runtime_error("invalid number of experiments"); 45 | } 46 | 47 | std::bernoulli_distribution bernoulli(0.5); 48 | 49 | vector results; 50 | for (int i=0; i num_customers_experiment(double mean, int max, int ntries) 58 | { 59 | std::default_random_engine generator; 60 | 61 | vector occurrences(max, 0); 62 | std::poisson_distribution poisson(mean); 63 | 64 | for (int i=0; i get_normal_observations(int n, double mean, double stdev) 77 | { 78 | std::default_random_engine generator; 79 | 80 | 81 | vector values; 82 | std::normal_distribution normaldist(mean, stdev); 83 | 84 | for (int i=0; i nv = get_normal_observations(1000, 8, 2); 104 | 105 | auto res = std::minmax_element(nv.begin(), nv.end()); 106 | double min = *(res.first); 107 | double max = *(res.second); 108 | 109 | int N = 100; 110 | double h = (max - min)/double(N); 111 | vector values(N, 0); 112 | 113 | for (int i=0; i 15 | 16 | #include 17 | 18 | 19 | // 20 | // The BlackScholesPricer class provides an interface to the ODEINT 21 | // pricer component 22 | // 23 | class BlackScholesPricer { 24 | public: 25 | BlackScholesPricer(bool call, double price, double strike, double tau, double r, double fr, double vol); 26 | BlackScholesPricer(const BlackScholesPricer &p); 27 | ~BlackScholesPricer(); 28 | BlackScholesPricer &operator=(const BlackScholesPricer &p); 29 | 30 | double value(); 31 | 32 | double delta(); 33 | double gamma(); 34 | double theta(); 35 | double vega(); 36 | private: 37 | double m_price; 38 | double m_strike; 39 | double m_tau; 40 | double m_rate; 41 | double m_frate; 42 | double m_vol; 43 | double m_isCall; 44 | 45 | boost::shared_ptr m_calc; 46 | }; 47 | 48 | 49 | BlackScholesPricer::BlackScholesPricer(bool call, double price, double strike, double tau, double r, double fr, double vol) 50 | :m_price(price), 51 | m_strike(strike), 52 | m_tau(tau), 53 | m_rate(r), 54 | m_frate(fr), 55 | m_vol(vol), 56 | m_isCall(call) 57 | { 58 | boost::shared_ptr 59 | m_option (new QuantLib::PlainVanillaPayoff(call ? QuantLib::Option::Call : QuantLib::Option::Put, strike)); 60 | 61 | // compute discount rates 62 | double cur_disc = std::exp(-m_rate * m_tau); // current discount rate 63 | double for_disc = std::exp(-m_frate * m_tau); // foward discount rate 64 | double stdev = m_vol * std::sqrt(m_tau); // standard deviation 65 | 66 | m_calc.reset(new QuantLib::BlackScholesCalculator(m_option, m_price, for_disc, stdev, cur_disc)); 67 | } 68 | 69 | BlackScholesPricer::BlackScholesPricer(const BlackScholesPricer &p) 70 | :m_price(p.m_price), 71 | m_strike(p.m_strike), 72 | m_tau(p.m_tau), 73 | m_rate(p.m_rate), 74 | m_frate(p.m_frate), 75 | m_vol(p.m_vol), 76 | m_isCall(p.m_isCall), 77 | m_calc(p.m_calc) 78 | {} 79 | 80 | BlackScholesPricer::~BlackScholesPricer() {} 81 | 82 | BlackScholesPricer &BlackScholesPricer::operator=(const BlackScholesPricer &p) 83 | { 84 | if (this != &p) 85 | { 86 | m_price = p.m_price; 87 | m_strike = p.m_strike; 88 | m_tau = p.m_tau; 89 | m_rate = p.m_rate; 90 | m_frate = p.m_frate; 91 | m_vol = p.m_vol; 92 | m_isCall = p.m_isCall; 93 | m_calc = p.m_calc; 94 | } 95 | return *this; 96 | } 97 | 98 | double BlackScholesPricer::value() 99 | { 100 | return m_calc->value(); 101 | } 102 | 103 | double BlackScholesPricer::delta() 104 | { 105 | return m_calc->delta(); 106 | } 107 | 108 | double BlackScholesPricer::gamma() 109 | { 110 | return m_calc->gamma(); 111 | } 112 | 113 | double BlackScholesPricer::theta() 114 | { 115 | return m_calc->theta(m_tau); 116 | } 117 | 118 | double BlackScholesPricer::vega() 119 | { 120 | return m_calc->vega(m_tau); 121 | } 122 | 123 | 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /CppOptions.xcodeproj/xcuserdata/carlosoliveira.xcuserdatad/xcschemes/CppOptions.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /CppOptions/DateCompact.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // DateCompact.cpp 3 | // 4 | // Implementation for the DateCompact class 5 | // 6 | // (c) 2020 Carlos Oliveira 7 | // This code is part of the book 8 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 9 | // by Carlos Oliveira, Apress, 2020. 10 | // For more information, visit http://coliveira.net 11 | 12 | 13 | #include "DateCompact.h" 14 | 15 | #include 16 | #include 17 | 18 | using std::cout; 19 | using std::endl; 20 | 21 | DateCompact::DateCompact(int year, int month, int day) 22 | { 23 | setYear(year); 24 | setMonth(month); 25 | setDay(day); 26 | } 27 | 28 | DateCompact::DateCompact(const DateCompact &p) 29 | { 30 | strcpy(m_date, p.m_date); 31 | } 32 | 33 | DateCompact::~DateCompact() 34 | { 35 | } 36 | 37 | DateCompact &DateCompact::operator=(const DateCompact &p) 38 | { 39 | if (&p != this) 40 | { 41 | strcpy(m_date, p.m_date); 42 | } 43 | return *this; 44 | } 45 | 46 | // 47 | // Use string comparison to determine if the dates are equal 48 | // 49 | bool DateCompact::operator==(const DateCompact &d) const 50 | { 51 | return strncmp(m_date, d.m_date, 8) == 0; 52 | } 53 | 54 | // Use the strncmp function to determine if a date is less than the other. 55 | bool DateCompact::operator<(const DateCompact &d) const 56 | { 57 | // strcmp returns negative values if the first argument is less than the second. 58 | return strncmp(m_date, d.m_date, 8) < 0; 59 | } 60 | 61 | // 62 | // Functions to calculate the year, month, and days as an integers, 63 | // based on the characters contained in the string 'm_date'. 64 | // 65 | 66 | int DateCompact::year() 67 | { 68 | // (x - '0') computes the numeric value corresponding to the each character. 69 | return 1000 * (m_date[0] - '0') + 100 * (m_date[1] - '0') + 10 * (m_date[2] - '0') + (m_date[3] - '0'); 70 | } 71 | 72 | int DateCompact::month() 73 | { 74 | return 10 * (m_date[4] - '0') + (m_date[5] - '0'); 75 | } 76 | 77 | int DateCompact::day() 78 | { 79 | return 10 * (m_date[6] - '0') + (m_date[7] - '0'); 80 | } 81 | 82 | void DateCompact::print() 83 | { 84 | // copy the m_date string into a NULL terminated string (with 9 characters). 85 | char s[9]; 86 | strncpy(s, m_date, 8); 87 | s[8] = '\0'; // properly terminate the string 88 | cout << s << endl; 89 | } 90 | 91 | // 92 | // calculate the string corresponding to the given numeric parameter. 93 | // 94 | 95 | void DateCompact::setYear(int year) 96 | { 97 | m_date[3] = '0' + (year % 10); 98 | year /= 10; 99 | m_date[2] = '0' + (year % 10); 100 | year /= 10; 101 | m_date[1] = '0' + (year % 10); 102 | year /= 10; 103 | m_date[0] = '0' + (year % 10); 104 | } 105 | 106 | void DateCompact::setMonth(int month) 107 | { 108 | m_date[5] = '0' + (month % 10); month /= 10; 109 | m_date[4] = '0' + (month % 10); 110 | 111 | } 112 | 113 | void DateCompact::setDay(int day) 114 | { 115 | m_date[7] = '0' + (day % 10); day /= 10; 116 | m_date[6] = '0' + (day % 10); 117 | } 118 | 119 | 120 | #include "Date.h" 121 | 122 | 123 | int main_dtc() 124 | //int main() 125 | { 126 | DateCompact d(2008, 3, 17); 127 | DateCompact e(2008, 5, 11); 128 | cout << " size of DateCompact: " << sizeof(DateCompact) << endl; 129 | 130 | d.print(); 131 | e.print(); 132 | 133 | if (d < e) 134 | { 135 | cout << " d is less than e " << endl; 136 | } 137 | else 138 | { 139 | cout << " d is not less than e " << endl; 140 | } 141 | 142 | Date date(2008, 3, 17); 143 | cout << " size of Date: " << sizeof(Date) << endl; 144 | 145 | return 0; 146 | } 147 | 148 | -------------------------------------------------------------------------------- /CppOptions/BlackScholes.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // BlackScholes.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #include "BlackScholes.hpp" 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | using std::vector; 21 | using std::cout; 22 | using std::endl; 23 | using std::setw; 24 | 25 | BlackScholesMethod::BlackScholesMethod(double expiration, double maxPrice, 26 | double strike, double intRate) 27 | : m_expiration(expiration), 28 | m_maxPrice(maxPrice), 29 | m_strike(strike), 30 | m_intRate(intRate) 31 | { 32 | } 33 | 34 | BlackScholesMethod::BlackScholesMethod(const BlackScholesMethod &p) 35 | : m_expiration(p.m_expiration), 36 | m_maxPrice(p.m_maxPrice), 37 | m_strike(p.m_strike), 38 | m_intRate(p.m_intRate) 39 | { 40 | } 41 | 42 | BlackScholesMethod::~BlackScholesMethod() 43 | { 44 | } 45 | 46 | BlackScholesMethod &BlackScholesMethod::operator=(const BlackScholesMethod &p) 47 | { 48 | if (this != &p) 49 | { 50 | m_expiration = p.m_expiration; 51 | m_maxPrice = p.m_maxPrice; 52 | m_strike = p.m_strike; 53 | m_intRate = p.m_intRate; 54 | } 55 | return *this; 56 | } 57 | 58 | vector BlackScholesMethod::solve(double volatility, int nx, int timeSteps) 59 | { 60 | double dt = m_expiration /(double)timeSteps; 61 | double dx = m_maxPrice /(double)nx; 62 | 63 | vector a(nx-1); 64 | vector b(nx-1); 65 | vector c(nx-1); 66 | 67 | int i; 68 | for (i = 0; i < nx - 1; i++) 69 | { 70 | b[i] = 1.0 - m_intRate * dt - dt * pow(volatility * (i+1), 2); 71 | } 72 | 73 | for (i = 0; i < nx - 2; i++) 74 | { 75 | c[i] = 0.5 * dt * pow(volatility * (i+1), 2) + 0.5 * dt * m_intRate * (i+1); 76 | } 77 | 78 | for (i = 1; i < nx - 1; i++) 79 | { 80 | a[i] = 0.5 * dt * pow(volatility * (i+1), 2) - 0.5 * dt * m_intRate * (i+1); 81 | } 82 | 83 | vector u((nx-1)*(timeSteps+1)); 84 | 85 | double u0 = 0.0; 86 | for (i = 0; i < nx - 1; i++) 87 | { 88 | u0 += dx; 89 | u[i+0*(nx-1)] = std::max(u0 - m_strike, 0.0); 90 | } 91 | 92 | for (int j = 0; j < timeSteps; j++) 93 | { 94 | double t = (double)(j) * m_expiration /(double)timeSteps; 95 | 96 | double p = 0.5 * dt * (nx - 1) * (volatility*volatility * (nx-1) + m_intRate) 97 | * (m_maxPrice-m_strike * exp(-m_intRate*t ) ); 98 | 99 | for (i = 0; i < nx - 1; i++) 100 | { 101 | u[i+(j+1)*(nx-1)] = b[i] * u[i+j*(nx-1)]; 102 | } 103 | for (i = 0; i < nx - 2; i++) 104 | { 105 | u[i+(j+1)*(nx-1)] += c[i] * u[i+1+j*(nx-1)]; 106 | } 107 | for (i = 1; i < nx - 1; i++) 108 | { 109 | u[i+(j+1)*(nx-1)] += a[i] * u[i-1+j*(nx-1)]; 110 | } 111 | u[nx-2+(j+1)*(nx-1)] += p; 112 | } 113 | 114 | return u; 115 | } 116 | 117 | int main_bsmeth() 118 | { 119 | auto strike = 5.0; 120 | auto intRate = 0.03; 121 | auto sigma = 0.50; 122 | auto t1 = 1.0; 123 | auto numSteps = 11; 124 | auto numDays = 29; 125 | auto maxPrice = 10.0; 126 | 127 | 128 | BlackScholesMethod blackScholes(t1, maxPrice, strike, intRate); 129 | vector u = blackScholes.solve(sigma, numSteps, numDays); 130 | 131 | double minPrice = .0; 132 | for (int i=0; i < numSteps-1; i++) 133 | { 134 | double s = ((numSteps-i-2) * minPrice+(i+1)*maxPrice)/ (double)(numSteps-1); 135 | cout << " " << s << " " << u[i+numDays*(numSteps-1)] << endl; 136 | } 137 | return 0; 138 | } 139 | -------------------------------------------------------------------------------- /CppOptions/mymod.py: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by SWIG (http://www.swig.org). 2 | # Version 3.0.5 3 | # 4 | # Do not make changes to this file unless you know what you are doing--modify 5 | # the SWIG interface file instead. 6 | 7 | 8 | 9 | 10 | 11 | from sys import version_info 12 | if version_info >= (2, 6, 0): 13 | def swig_import_helper(): 14 | from os.path import dirname 15 | import imp 16 | fp = None 17 | try: 18 | fp, pathname, description = imp.find_module('_mymod', [dirname(__file__)]) 19 | except ImportError: 20 | import _mymod 21 | return _mymod 22 | if fp is not None: 23 | try: 24 | _mod = imp.load_module('_mymod', fp, pathname, description) 25 | finally: 26 | fp.close() 27 | return _mod 28 | _mymod = swig_import_helper() 29 | del swig_import_helper 30 | else: 31 | import _mymod 32 | del version_info 33 | try: 34 | _swig_property = property 35 | except NameError: 36 | pass # Python < 2.2 doesn't have 'property'. 37 | 38 | 39 | def _swig_setattr_nondynamic(self, class_type, name, value, static=1): 40 | if (name == "thisown"): 41 | return self.this.own(value) 42 | if (name == "this"): 43 | if type(value).__name__ == 'SwigPyObject': 44 | self.__dict__[name] = value 45 | return 46 | method = class_type.__swig_setmethods__.get(name, None) 47 | if method: 48 | return method(self, value) 49 | if (not static): 50 | if _newclass: 51 | object.__setattr__(self, name, value) 52 | else: 53 | self.__dict__[name] = value 54 | else: 55 | raise AttributeError("You cannot add attributes to %s" % self) 56 | 57 | 58 | def _swig_setattr(self, class_type, name, value): 59 | return _swig_setattr_nondynamic(self, class_type, name, value, 0) 60 | 61 | 62 | def _swig_getattr_nondynamic(self, class_type, name, static=1): 63 | if (name == "thisown"): 64 | return self.this.own() 65 | method = class_type.__swig_getmethods__.get(name, None) 66 | if method: 67 | return method(self) 68 | if (not static): 69 | return object.__getattr__(self, name) 70 | else: 71 | raise AttributeError(name) 72 | 73 | def _swig_getattr(self, class_type, name): 74 | return _swig_getattr_nondynamic(self, class_type, name, 0) 75 | 76 | 77 | def _swig_repr(self): 78 | try: 79 | strthis = "proxy of " + self.this.__repr__() 80 | except: 81 | strthis = "" 82 | return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) 83 | 84 | try: 85 | _object = object 86 | _newclass = 1 87 | except AttributeError: 88 | class _object: 89 | pass 90 | _newclass = 0 91 | 92 | 93 | class Matrix(_object): 94 | __swig_setmethods__ = {} 95 | __setattr__ = lambda self, name, value: _swig_setattr(self, Matrix, name, value) 96 | __swig_getmethods__ = {} 97 | __getattr__ = lambda self, name: _swig_getattr(self, Matrix, name) 98 | __repr__ = _swig_repr 99 | 100 | def __init__(self, *args): 101 | this = _mymod.new_Matrix(*args) 102 | try: 103 | self.this.append(this) 104 | except: 105 | self.this = this 106 | __swig_destroy__ = _mymod.delete_Matrix 107 | __del__ = lambda self: None 108 | 109 | def transpose(self): 110 | return _mymod.Matrix_transpose(self) 111 | 112 | def trace(self): 113 | return _mymod.Matrix_trace(self) 114 | 115 | def add(self, s): 116 | return _mymod.Matrix_add(self, s) 117 | 118 | def subtract(self, s): 119 | return _mymod.Matrix_subtract(self, s) 120 | 121 | def multiply(self, *args): 122 | return _mymod.Matrix_multiply(self, *args) 123 | 124 | def numRows(self): 125 | return _mymod.Matrix_numRows(self) 126 | Matrix_swigregister = _mymod.Matrix_swigregister 127 | Matrix_swigregister(Matrix) 128 | 129 | # This file is compatible with both classic and new-style classes. 130 | 131 | 132 | -------------------------------------------------------------------------------- /CppOptions/Matrix.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Matrix.cpp 3 | // 4 | // 5 | // (c) 2020 Carlos Oliveira 6 | // This code is part of the book 7 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 8 | // by Carlos Oliveira, Apress, 2020. 9 | // For more information, visit http://coliveira.net 10 | 11 | 12 | #include "Matrix.h" 13 | 14 | #include 15 | 16 | Matrix::Matrix(int size) 17 | { 18 | for (int i=0; i row(size, 0); 21 | m_rows.push_back(row); 22 | } 23 | } 24 | 25 | Matrix::Matrix(int size, int size2) 26 | { 27 | for (int i=0; i row(size2, 0); 30 | m_rows.push_back(row); 31 | } 32 | } 33 | 34 | Matrix::Matrix(const Matrix &s) 35 | : m_rows(s.m_rows) 36 | { 37 | } 38 | 39 | Matrix::~Matrix() 40 | { 41 | } 42 | 43 | Matrix &Matrix::operator=(const Matrix &s) 44 | { 45 | if (this != &s) 46 | { 47 | m_rows = s.m_rows; 48 | } 49 | return *this; 50 | } 51 | 52 | Matrix::Row &Matrix::operator[](int pos) 53 | { 54 | return m_rows[pos]; 55 | } 56 | 57 | void Matrix::transpose() 58 | { 59 | std::vector rows; 60 | for (unsigned i=0;i row; 63 | for (unsigned j=0; j rows; 125 | for (unsigned i=0; i row; 128 | for (unsigned j=0; j 16 | 17 | // include classes from QuantLib 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | using namespace QuantLib; 30 | 31 | using std::cout; 32 | using std::vector; 33 | using std::pair; 34 | 35 | using boost::shared_ptr; 36 | 37 | 38 | 39 | CDSSolver::CDSSolver(double val, double sigma, double divYield, double rf, 40 | double strike, double barrier, double rebate) 41 | : 42 | cur_val(val), 43 | sigma(sigma), 44 | divYield(divYield), 45 | rf(rf), 46 | strike(strike), 47 | barrier(barrier), 48 | rebate(rebate) 49 | { 50 | } 51 | 52 | // solve the valuation problem using the barrier technique, from today to the maturity date 53 | pair 54 | CDSSolver::solve(Date maturity_date) 55 | { 56 | Handle quote(boost::shared_ptr(new SimpleQuote(cur_val))); 57 | Date today = Date::todaysDate(); 58 | 59 | 60 | shared_ptr ts1(new FlatForward(today, divYield, Thirty360())); 61 | shared_ptr ts2(new FlatForward(today, rf, Thirty360())); 62 | shared_ptr vs(new BlackConstantVol(today, NullCalendar(),sigma, Thirty360())); 63 | 64 | auto process = BlackScholesMertonProcess(quote, 65 | Handle(ts1), 66 | Handle(ts2), 67 | Handle(vs)); 68 | 69 | 70 | shared_ptr payoff(new PlainVanillaPayoff(Option::Type::Call, strike)); 71 | shared_ptr exercise(new EuropeanExercise(maturity_date)); 72 | 73 | auto option = BarrierOption(Barrier::Type::UpIn, 74 | barrier, rebate, 75 | payoff, 76 | exercise); 77 | 78 | auto pproc = shared_ptr(&process); 79 | 80 | option.setPricingEngine(shared_ptr(new AnalyticBarrierEngine(pproc))); 81 | 82 | return std::make_pair(option, process); 83 | } 84 | 85 | void CDSSolver::generateGrid(BarrierOption &option, BlackScholesMertonProcess &process, const vector &grid) 86 | { 87 | double value = option.NPV(); 88 | Size maxG = grid[grid.size()-1]; // find maximum grid value 89 | 90 | for (auto g : grid) 91 | { 92 | FdBlackScholesBarrierEngine be(shared_ptr(&process), maxG, g); 93 | option.setPricingEngine(shared_ptr(&be)); 94 | 95 | cout << std::abs(option.NPV()/value -1); 96 | 97 | FdBlackScholesBarrierEngine be1(shared_ptr(&process), g, maxG); 98 | option.setPricingEngine(shared_ptr(&be1)); 99 | 100 | cout << std::abs(option.NPV()/value -1); 101 | } 102 | } 103 | 104 | void test_CDSSolver() 105 | { 106 | // use a few test values 107 | 108 | double cur_val = 50.0; 109 | double sigma = 0.2; 110 | double divYield = 0.01; 111 | double rf = 0.05; 112 | double strike = 104.0; 113 | double barrier = 85.0; 114 | double rebate = 0.0; 115 | 116 | CDSSolver solver(cur_val, sigma, divYield, rf, strike, barrier, rebate); 117 | 118 | Date date(10, Month::August, 2016); 119 | 120 | auto result = solver.solve(date); 121 | 122 | std::vector grid = { 5, 10, 25, 50, 100, 1000, 2000 }; 123 | solver.generateGrid(result.first, result.second, grid); 124 | } 125 | 126 | 127 | int main_cds() 128 | { 129 | test_CDSSolver(); 130 | return 0; 131 | } 132 | 133 | 134 | 135 | 136 | class CDSContract { 137 | public: 138 | CDSContract(); 139 | CDSContract(const CDSContract &p); 140 | ~CDSContract(); 141 | CDSContract &operator=(const CDSContract &p); 142 | 143 | double notional() { return m_notional; } 144 | double spread() { return m_spread; } 145 | int timePeriod() { return m_timePeriod; } 146 | bool payAtDefault() { return m_payAtDefault; } 147 | bool isLong() { return m_isLong; } 148 | 149 | private: 150 | 151 | double m_notional; 152 | double m_spread; 153 | int m_timePeriod; 154 | bool m_payAtDefault; 155 | bool m_isLong; 156 | 157 | }; 158 | 159 | #endif 160 | -------------------------------------------------------------------------------- /CppOptions/Functional.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Functional.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #include "Functional.hpp" 12 | 13 | #include 14 | #include 15 | 16 | #include // for functional STL code 17 | 18 | 19 | // 20 | // Class SimpleOption 21 | // 22 | 23 | double SimpleOption::getInTheMoneyProbability(int numDays, double currentUnderlyingPrice) const 24 | { 25 | return 0; // implementation here 26 | } 27 | 28 | 29 | // 30 | // Class OptionComparison 31 | // 32 | 33 | OptionComparison::OptionComparison(bool directionLess) 34 | : m_directionLess(directionLess) 35 | { 36 | } 37 | 38 | OptionComparison::OptionComparison(const OptionComparison &p) 39 | : m_directionLess(p.m_directionLess) 40 | { 41 | } 42 | 43 | OptionComparison::~OptionComparison() 44 | { 45 | } 46 | 47 | OptionComparison &OptionComparison::operator=(const OptionComparison &p) 48 | { 49 | if (this != &p) 50 | { 51 | m_directionLess = p.m_directionLess; 52 | } 53 | return *this; 54 | } 55 | 56 | bool OptionComparison::operator()(const SimpleOption &o1, const SimpleOption &o2) 57 | { 58 | bool result = false; 59 | 60 | // check components of opt1 and opt2. In practice this could be more complex. 61 | if (m_directionLess) 62 | { 63 | result = o1.daysToExpiration() < o2.daysToExpiration(); 64 | } 65 | else 66 | { 67 | result = o1.daysToExpiration() > o2.daysToExpiration(); 68 | } 69 | return result; 70 | } 71 | 72 | 73 | void test_compare() 74 | { 75 | OptionComparison comparison(true); 76 | 77 | SimpleOption a, b; 78 | // ... 79 | 80 | if (comparison(a, b)) 81 | { 82 | std::cout << " a is less than b " << std::endl; 83 | } 84 | else 85 | { 86 | std::cout << " b is less than a " << std::endl; 87 | } 88 | } 89 | 90 | 91 | void test_operator() 92 | { 93 | using namespace std; 94 | 95 | vector numbers = { 3, 4, 2, 1, 6 }; 96 | 97 | sort(numbers.begin(), numbers.end(), greater() ); 98 | 99 | } 100 | 101 | 102 | 103 | void test_transform() 104 | { 105 | using namespace std; 106 | 107 | auto list1 = { 3, 4, 2, 1, 6 }; 108 | auto list2 = { 4, 1, 5, 3, 2 }; 109 | 110 | vector result(list1.size()); 111 | 112 | transform(list1.begin(), list1.end(), list2.begin(), result.begin(), plus() ); 113 | 114 | // use transformed list here... 115 | 116 | copy(result.begin(), result.end(), std::ostream_iterator(cout, ", ")); 117 | 118 | // prints 7, 5, 7, 4, 8, 119 | } 120 | 121 | void use_bind() 122 | { 123 | using namespace std; 124 | using namespace std::placeholders; 125 | 126 | auto list1 = { 3, 4, 2, 1, 6 }; 127 | 128 | vector result(list1.size()); 129 | 130 | // add 3 to each element of the list 131 | transform(list1.begin(), list1.end(), result.begin(), bind(plus(), _1, 3)); 132 | 133 | copy(result.begin(), result.end(), std::ostream_iterator(cout, ", ")); 134 | 135 | // prints 6, 7, 5, 4, 9, 136 | } 137 | 138 | 139 | auto computeInTheMoneyProblExample(const std::vector &options) -> std::vector 140 | { 141 | using namespace std; 142 | using namespace std::placeholders; 143 | 144 | double currentPrice = 100.0; 145 | 146 | vector probabilities(options.size()); 147 | 148 | auto inTheMoneyCalc = bind(&SimpleOption::getInTheMoneyProbability, _1, 2, currentPrice); 149 | 150 | 151 | transform(options.begin(), options.end(), probabilities.begin(), inTheMoneyCalc); 152 | 153 | return probabilities; 154 | } 155 | 156 | 157 | void use_lambda() 158 | { 159 | auto fun = [](double x, double y) -> double { return x + y; }; 160 | 161 | double res = fun(4, 5); 162 | 163 | std::cout << " result is " << res << std::endl; 164 | } 165 | 166 | void use_lambda2() 167 | { 168 | int offset = 5; 169 | 170 | auto fun1 = [ offset](double x, double y) -> double { return x + y + offset; }; 171 | auto fun2 = [&offset](double x, double y) -> double { return x + y + offset; }; 172 | 173 | double res = fun1(4, 5); 174 | 175 | std::cout << " result is " << res << std::endl; 176 | 177 | offset = 10; 178 | std::cout << " result of fun1 is " << fun1(4, 5) << std::endl; 179 | std::cout << " result of fun2 is " << fun2(4, 5) << std::endl; 180 | } 181 | 182 | 183 | void use_function(std::function f) 184 | { 185 | auto res = f(2,3); 186 | 187 | std::cout << " the function returns the value " << res << std::endl; 188 | } 189 | 190 | void test_use_function() 191 | { 192 | auto f1 = [] (int a, int b) { return a + b; }; 193 | auto f2 = [] (int a, int b) { return a * b; }; 194 | 195 | use_function(f1); 196 | use_function(f2); 197 | } 198 | 199 | int main_fun() 200 | //int main() 201 | { 202 | test_use_function(); 203 | return 0; 204 | } 205 | 206 | 207 | 208 | -------------------------------------------------------------------------------- /CppOptions/qlibsample.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // qlibsample.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #if 0 12 | 13 | #include "qlibsample.hpp" 14 | 15 | typedef double Real; 16 | 17 | using std::cout; 18 | using std::endl; 19 | 20 | using namespace QuantLib; 21 | 22 | 23 | 24 | void testingBlackScholesCalculator () 25 | { 26 | Real S0=100.0, K=105.0; 27 | Real rd =0.034 , rf =0.021 , tau =0.5 , vol =0.177; 28 | Real domDisc=std::exp(-rd*tau), forDisc=std::exp(-rf*tau); Real stdDev=vol*std::sqrt(tau); 29 | boost::shared_ptr vanillaPayoffPut( 30 | new QuantLib::PlainVanillaPayoff(Option::Put,K)); 31 | boost::shared_ptr aonPayoffCall( 32 | new AssetOrNothingPayoff(QuantLib::Option::Call,K)); 33 | QuantLib::BlackScholesCalculator vanillaPutPricer(vanillaPayoffPut,S0,forDisc,stdDev,domDisc); 34 | QuantLib::BlackScholesCalculator aonCallPricer(aonPayoffCall,S0,forDisc,stdDev,domDisc); 35 | std::cout << "--------------Vanilla Values -------------" << std::endl; 36 | std::cout << "Value:" << vanillaPutPricer.value() << std::endl; 37 | std::cout << "Delta:" << vanillaPutPricer.delta() << std::endl; 38 | std::cout << "Gamma:" << vanillaPutPricer.gamma() << std::endl; 39 | std::cout << "Vega:" << vanillaPutPricer.vega(tau) << std::endl; 40 | std::cout << "Theta:" << vanillaPutPricer.theta(tau) << std::endl; 41 | std::cout << "Delta Fwd:" << vanillaPutPricer.deltaForward() << std::endl; 42 | std::cout << "Gamma Fwd:" << vanillaPutPricer.gammaForward() << std::endl; 43 | std::cout << "-------------- AON Values-------------" << std::endl; 44 | std::cout << "Value:" << aonCallPricer.value() << std::endl; 45 | std::cout << "Delta:" << aonCallPricer.delta() << std::endl; 46 | std::cout << "Gamma:" << aonCallPricer.gamma() << std::endl; 47 | std::cout << "Vega:" << aonCallPricer.vega(tau) << std::endl; 48 | std::cout << "Theta:" << aonCallPricer.theta(tau) << std::endl; 49 | std::cout << "Delta Fwd:" << aonCallPricer.deltaForward() << std::endl; 50 | std::cout << "Gamma Fwd:" << aonCallPricer.gammaForward() << std::endl; 51 | 52 | 53 | } 54 | 55 | struct BlackScholesPrameters { 56 | double S0; 57 | double K; 58 | double rd; 59 | double rf; 60 | double tau; 61 | double vol; 62 | }; 63 | 64 | 65 | void callBlackScholes(BlackScholesPrameters &bp) 66 | { 67 | // create a vanilla option (standard option type) 68 | boost::shared_ptr 69 | vanillaPut(new QuantLib::PlainVanillaPayoff(Option::Put,bp.K)); 70 | 71 | // compute discount rates 72 | double cur_disc = std::exp(-bp.rd * bp.tau); // current discount rate 73 | double for_disc = std::exp(-bp.rf * bp.tau); // foward discount rate 74 | double stdev = bp.vol * std::sqrt(bp.tau); // standard deviation 75 | 76 | BlackScholesCalculator putPricer(vanillaPut, bp.S0, for_disc, stdev, cur_disc); 77 | 78 | // Print options greeks 79 | cout << "value:" << putPricer.value() << endl; 80 | cout << "delta:" << putPricer.delta() << endl; 81 | cout << "gamma:" << putPricer.gamma() << endl; 82 | cout << "vega:" << putPricer.vega(bp.tau) << endl; 83 | cout << "theta:" << putPricer.theta(bp.tau) << endl; 84 | cout << "delta Fwd:" << putPricer.deltaForward() << endl; 85 | cout << "gamma Fwd:" << putPricer.gammaForward() << endl; 86 | 87 | } 88 | 89 | void testBlackScholes() 90 | { 91 | BlackScholesPrameters bp; 92 | 93 | bp.S0 = 95.0; // current price 94 | bp.K = 100.0; // strike 95 | bp.rd = 0.026; // current rate of return 96 | bp.rf = 0.017; // forward rate of return 97 | bp.tau= 0.62; // tau (time greek) 98 | bp.vol= 0.193; // volatility 99 | 100 | callBlackScholes(bp); 101 | } 102 | 103 | 104 | 105 | void testDates() 106 | { 107 | Date date(10, Month::April, 2010); 108 | cout << "original date: " << date << endl; 109 | 110 | date += 2 * Days; 111 | cout << "after 2 days: " << date << endl; 112 | 113 | date += 3 * Months; 114 | cout << "after 3 months: " << date << endl; 115 | } 116 | 117 | void nextAndPreviousDay() 118 | { 119 | Date date(28, Month::February, 2010); 120 | cout << "original date: " << date << endl; 121 | 122 | date++; 123 | cout << "next day: " << date << endl; 124 | 125 | date--; 126 | cout << "previous day: " << date << endl; 127 | } 128 | 129 | void dateQuestions() 130 | { 131 | Date date(20, Month::February, 2010); 132 | 133 | 134 | cout << "weekday: " << date.weekday() << endl; 135 | 136 | cout << "is leap year? " << Date::isLeap(date.year()) << endl; 137 | 138 | cout << "is end of month? " << Date::isEndOfMonth(date) << endl; 139 | } 140 | 141 | void useCalendar() 142 | { 143 | Calendar cal = UnitedStates(UnitedStates::NYSE); 144 | 145 | cout << " list of holidays " << endl; 146 | for (auto date : Calendar::holidayList(cal, Date(1, Month::Jan, 2010), Date(1, Month::Jan, 2012))) 147 | { 148 | cout << " " << date; 149 | } 150 | 151 | cout << " is Jan 1 2010 a business day? " 152 | << cal.isBusinessDay(Date(1, Month::Jan, 2010)) << endl; 153 | cout << " is Jan 1 2010 a holiday? " 154 | << cal.isHoliday(Date(1, Month::Jan, 2010)) << endl; 155 | cout << " is Jan 1 2010 end of month? " 156 | << cal.isEndOfMonth(Date(1, Month::Jan, 2010)) << endl; 157 | } 158 | 159 | Calendar createNewCalendar() 160 | { 161 | Calendar newCal = UnitedStates(UnitedStates::NYSE); 162 | 163 | // Remove winter holiday 164 | newCal.removeHoliday(Date(25, Month::December, 2016)); 165 | 166 | // Add international worker's day 167 | newCal.addHoliday (Date(1, Month::May, 2016)); 168 | 169 | cout << " list of holidays " << endl; 170 | for (auto date : Calendar::holidayList(newCal, Date(1, Month::Jan, 2016), Date(1, Month::Jan, 2016))) 171 | { 172 | cout << " " << date; 173 | } 174 | 175 | return newCal; 176 | } 177 | 178 | int getNumberOfDays(Date d1, Date d2) 179 | { 180 | Calendar usCal = UnitedStates(UnitedStates::NYSE); 181 | 182 | int nDays = usCal.businessDaysBetween(d1, d2); 183 | 184 | cout << " the interval size is " << nDays << endl; 185 | 186 | return nDays; 187 | } 188 | 189 | 190 | int main_qlib() 191 | { 192 | 193 | cout << " hello \n" ; 194 | return 0; 195 | //testingBlackScholesCalculator(); 196 | } 197 | 198 | #endif 199 | -------------------------------------------------------------------------------- /CppOptions/LatticeModel.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // (c) 2020 Carlos Oliveira 4 | // This code is part of the book 5 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 6 | // by Carlos Oliveira, Apress, 2020. 7 | // For more information, visit http://coliveira.net 8 | 9 | 10 | #include "LatticeModel.hpp" 11 | 12 | #include 13 | #include 14 | 15 | using vec = std::vector; 16 | 17 | 18 | double computePO(int ptype, double S, double X) 19 | { 20 | if (ptype == 0) 21 | { 22 | return std::max(0.0, S - X); 23 | } 24 | else 25 | { 26 | return std::max(0.0, X - S); 27 | } 28 | } 29 | 30 | 31 | //void dolatice(int N, 32 | // double S0, 33 | // double rr, 34 | // double sigma, 35 | // int k, int T, double X, int ptype) 36 | //{ 37 | // vec this_s(2*N); 38 | // vec this_o(2*N); 39 | // vec next_s(2*N); 40 | // vec next_o(2*N); 41 | // 42 | // double dt = T / N; 43 | // double drift = (rr - 0.5 * sigma * sigma) * T; 44 | // double vol = sigma * sqrt(k * dt); 45 | // double disc_dt = exp(-rr * dt); 46 | // double scale_s = exp(-drift / N); 47 | // 48 | // for (int i=0; i<2*N; ++i) 49 | // { 50 | // this_s[i] = S0 * exp(drift + (i-N) * vol); 51 | // this_o[i] = computePO(ptype, this_s[i], X); 52 | // } 53 | // 54 | // vec probs(3); 55 | // probs[0] = 0.5 / k; 56 | // probs[1] = (k-1)/k; 57 | // probs[2] = probs[0]; 58 | // 59 | // int interval = 10; 60 | // 61 | // for (int i=N-1; i>=0; --i) 62 | // { 63 | // if (i % interval == 0) 64 | // { 65 | // 66 | // } 67 | // for (int j=0; j<2*N; ++j) 68 | // { 69 | // double v =0; 70 | // v += probs[0] * this_o[j]; 71 | // v += probs[1] * this_o[j+1]; 72 | // v += probs[2] * this_o[j+2]; 73 | // 74 | // next_o[i] = disc_dt * v; // discounted value 75 | // } 76 | // 77 | // this_o = next_o; 78 | // 79 | // if (1) 80 | // { // american option only 81 | // for (int j=0; j<2*N; ++j) 82 | // { 83 | // next_s[j] = scale_s * this_s[j]; 84 | // } 85 | // 86 | // this_s = next_s; 87 | // 88 | // double payoff; 89 | // for (int j=0; j<2*N; ++j) 90 | // { 91 | // payoff = computePO(ptype, this_s[j], X); 92 | //// this_o = 93 | // } 94 | // } 95 | // } 96 | // 97 | //} 98 | 99 | 100 | class BinomialModel { 101 | public: 102 | BinomialModel(const BinomialModel &p); 103 | ~BinomialModel(); 104 | BinomialModel &operator=(const BinomialModel &p); 105 | 106 | BinomialModel(double T, // expiration time 107 | double S, // stock price 108 | double r, // interest rate 109 | double sigma, 110 | double q, // dividend yield 111 | int n, // numer of steps 112 | bool call 113 | ); 114 | 115 | double optionPriceForStrike(double K); 116 | virtual void computePriceStep(int i, int j, double K, vec &prices, 117 | double p_u, double p_d, double u); 118 | 119 | 120 | protected: 121 | double getStockPrice() { return m_S; } 122 | private: 123 | double m_T; // expiration time 124 | double m_S; // stock price 125 | double m_r; // interest rate 126 | double m_sigma; // volatility 127 | double m_q; // dividend yield 128 | int m_n; // numer of steps 129 | bool m_call; // true = call, false = put 130 | 131 | }; 132 | 133 | 134 | class AmericanBinomialModel : public BinomialModel { 135 | AmericanBinomialModel(const BinomialModel &p); 136 | ~AmericanBinomialModel(); 137 | AmericanBinomialModel &operator=(const BinomialModel &p); 138 | 139 | AmericanBinomialModel(double T, // expiration time 140 | double S, // stock price 141 | double r, // interest rate 142 | double sigma, 143 | double q, // dividend yield 144 | int n, // numer of steps 145 | bool call 146 | ); 147 | 148 | virtual void computePriceStep(int i, int j, double K, vec &prices, 149 | double p_u, double p_d, double u); 150 | }; 151 | 152 | 153 | 154 | AmericanBinomialModel::AmericanBinomialModel(const BinomialModel &p) 155 | : BinomialModel(p) 156 | { 157 | } 158 | 159 | AmericanBinomialModel::~AmericanBinomialModel() 160 | { 161 | } 162 | 163 | AmericanBinomialModel &AmericanBinomialModel::operator=(const BinomialModel &p) 164 | { 165 | BinomialModel::operator=(p); // no new data members in this calss 166 | return *this; 167 | } 168 | 169 | AmericanBinomialModel::AmericanBinomialModel(double T, // expiration time 170 | double S, // stock price 171 | double r, // interest rate 172 | double sigma, 173 | double q, // dividend yield 174 | int n, // numer of steps 175 | bool call) 176 | : BinomialModel(T, S, r, sigma, q, n, call) 177 | { 178 | } 179 | 180 | void AmericanBinomialModel::computePriceStep(int i, int j, double K, vec &prices, double p_u, double p_d, double u) 181 | { 182 | BinomialModel::computePriceStep(i, j, K, prices, p_u, p_d, u); 183 | 184 | // compute exercise price for American option 185 | // 186 | double exercise = K - getStockPrice() * pow(u, 2*i - j); 187 | if (prices[i] < exercise) 188 | { 189 | prices[i] = exercise; 190 | } 191 | } 192 | 193 | 194 | // ------------ 195 | 196 | BinomialModel::BinomialModel(double T, double S, double r, 197 | double sigma, 198 | double q, 199 | int n, bool call) 200 | : m_T(T), 201 | m_S(S), 202 | m_r(r), 203 | m_sigma(sigma), 204 | m_n(n), 205 | m_q(q), 206 | m_call(call) 207 | { 208 | } 209 | 210 | BinomialModel::BinomialModel(const BinomialModel &p) 211 | : m_T(p.m_T), 212 | m_S(p.m_S), 213 | m_r(p.m_r), 214 | m_sigma(p.m_sigma), 215 | m_n(p.m_n), 216 | m_q(p.m_q), 217 | m_call(p.m_call) 218 | { 219 | } 220 | 221 | BinomialModel::~BinomialModel() 222 | { 223 | } 224 | 225 | BinomialModel &BinomialModel::operator=(const BinomialModel &p) 226 | { 227 | if (this != &p) 228 | { 229 | m_T = p.m_T; 230 | m_S = p.m_S; 231 | m_r = p.m_r; 232 | m_sigma = p.m_sigma; 233 | m_n = p.m_n; 234 | m_q = p.m_q; 235 | m_call = p.m_call; 236 | } 237 | return *this; 238 | } 239 | 240 | void BinomialModel::computePriceStep(int i, int j, double K, 241 | vec &prices, double p_u, double p_d, double u) 242 | { 243 | prices[i] = p_u * prices[i] + p_d * prices[i+1]; 244 | } 245 | 246 | double BinomialModel::optionPriceForStrike(double K) 247 | { 248 | 249 | double delta = m_T / m_n; // size of each step 250 | double u = exp(m_sigma * sqrt(delta)); 251 | 252 | double p_u = (u * exp(-m_r * delta) - exp(-m_q * delta)) * u / (u*u - 1); 253 | double p_d = exp(-m_r * delta) - p_u; 254 | 255 | vec prices(m_n); 256 | 257 | // compute last day values (leafs of the tree) 258 | for (int i= 0; i=0; --j) 271 | { 272 | for (int i = 0; i 15 | #include 16 | 17 | using std::cout; 18 | using std::endl; 19 | 20 | using std::string; 21 | 22 | Date::Date(int year, int month, int day) 23 | : m_year(year), 24 | m_month(month), 25 | m_day(day), 26 | m_weekDay(DayOfTheWeek_UNKNOWN) 27 | { 28 | } 29 | 30 | Date::~Date() 31 | { 32 | } 33 | 34 | Date::Date(const Date &p) 35 | : m_year(p.m_year), 36 | m_month(p.m_month), 37 | m_day(p.m_day), 38 | m_weekDay(p.m_weekDay), 39 | m_holidays(p.m_holidays) 40 | { 41 | } 42 | 43 | Date &Date::operator=(const Date &p) 44 | { 45 | if (&p != this) 46 | { 47 | m_day = p.m_day; 48 | m_month = p.m_month; 49 | m_year = p.m_year; 50 | m_weekDay = p.m_weekDay; 51 | m_holidays = p.m_holidays; 52 | } 53 | return *this; 54 | } 55 | 56 | bool Date::operator<(const Date &d) const 57 | { 58 | if (m_year < d.m_year) return true; 59 | if (m_year == d.m_year && m_month < d.m_month) return true; 60 | if (m_year == d.m_year && m_month == d.m_month && m_day < d.m_day) return true; 61 | return false; 62 | } 63 | 64 | bool Date::operator==(const Date &d) 65 | { 66 | return d.m_day == m_day && d.m_month == m_month && d.m_year == m_year; 67 | } 68 | 69 | void Date::setHolidays(const std::vector &days) 70 | { 71 | m_holidays = days; 72 | } 73 | 74 | bool Date::isHoliday() 75 | { 76 | return std::find(m_holidays.begin(), m_holidays.end(), *this) != m_holidays.end(); 77 | } 78 | 79 | std::string Date::month() 80 | { 81 | switch (m_month) { 82 | case Month_January: return "January"; 83 | case Month_February: return "February"; 84 | case Month_March: return "March"; 85 | case Month_April: return "April"; 86 | case Month_May: return "May"; 87 | case Month_June: return "June"; 88 | case Month_July: return "July"; 89 | case Month_August: return "August"; 90 | case Month_September: return "September"; 91 | case Month_October: return "October"; 92 | case Month_November: return "November"; 93 | case Month_December: return "December"; 94 | default: throw std::runtime_error("unknown month"); 95 | } 96 | return ""; 97 | } 98 | 99 | std::string Date::dayOfWeek() 100 | { 101 | switch (this->dayOfTheWeek()) { 102 | case DayOfTheWeek_Sunday: return "Sunday"; 103 | case DayOfTheWeek_Monday: return "Monday"; 104 | case DayOfTheWeek_Tuesday: return "Tuesday"; 105 | case DayOfTheWeek_Wednesday: return "Wednesday"; 106 | case DayOfTheWeek_Thursday: return "Thursday"; 107 | case DayOfTheWeek_Friday: return "Friday"; 108 | case DayOfTheWeek_Saturday: return "Saturday"; 109 | default: throw std::runtime_error("unknown day of week"); 110 | } 111 | } 112 | 113 | void Date::add(int numDays) 114 | { 115 | for (int i=0; i(day); 224 | return m_weekDay; 225 | } 226 | 227 | bool Date::isWeekDay() 228 | { 229 | DayOfTheWeek dayOfWeek = dayOfTheWeek(); 230 | if (dayOfWeek == DayOfTheWeek_Sunday || dayOfWeek == DayOfTheWeek_Saturday) 231 | { 232 | return false; 233 | } 234 | return true; 235 | } 236 | 237 | bool Date::isTradingDay() 238 | { 239 | if (!isWeekDay()) return false; 240 | if (m_holidays.size() == 0) return true; 241 | if (isHoliday()) return false; 242 | return true; 243 | } 244 | 245 | Date Date::nextTradingDay() 246 | { 247 | Date d = *this; 248 | if (d.isTradingDay()) 249 | { 250 | return ++d; 251 | } 252 | while (!d.isTradingDay()) 253 | { 254 | ++d; 255 | } 256 | return d; 257 | } 258 | 259 | bool Date::isLeapYear() 260 | { 261 | if (m_year % 4 != 0) return false; 262 | if (m_year % 100 != 0) return true; 263 | if (m_year % 400 != 0) return false; 264 | return true; 265 | } 266 | 267 | Date &Date::operator--() 268 | { 269 | if (m_weekDay != DayOfTheWeek_UNKNOWN) // update weekday 270 | { 271 | if (m_weekDay == DayOfTheWeek_Sunday) 272 | m_weekDay = DayOfTheWeek_Saturday; 273 | else 274 | m_weekDay = static_cast(m_weekDay - 1); 275 | } 276 | 277 | if (m_day > 1) 278 | { 279 | m_day--; 280 | return *this; 281 | } 282 | 283 | if (m_month == Month_January) 284 | { 285 | m_month = Month_December; 286 | m_day = 31; 287 | m_year--; 288 | return *this; 289 | } 290 | 291 | m_month--; 292 | 293 | if (m_month == Month_February) 294 | { 295 | m_day = isLeapYear() ? 29 : 28; 296 | return *this; 297 | } 298 | 299 | // list of months with 31 days 300 | std::vector monthsWithThirtyOneDays = { 1, 3, 5, 7, 8, 10, 12 }; 301 | if (std::find(monthsWithThirtyOneDays.begin(), 302 | monthsWithThirtyOneDays.end(), m_month) 303 | != monthsWithThirtyOneDays.end()) 304 | { 305 | m_day = 31; 306 | } 307 | else 308 | { 309 | m_day = 30; 310 | } 311 | return *this; 312 | } 313 | 314 | Date &Date::operator++() 315 | { 316 | // list of months with 31 days 317 | std::vector monthsWithThirtyOneDays = { 1, 3, 5, 7, 8, 10, 12 }; 318 | 319 | if (m_day == 31) 320 | { 321 | m_day = 1; 322 | m_month++; 323 | } 324 | else if (m_day == 30 && 325 | std::find(monthsWithThirtyOneDays.begin(), 326 | monthsWithThirtyOneDays.end(), m_month) 327 | == monthsWithThirtyOneDays.end()) 328 | { 329 | m_day = 1; 330 | m_month++; 331 | } 332 | else if (m_day == 29 && m_month == 2) 333 | { 334 | m_day = 1; 335 | m_month++; 336 | } 337 | else if (m_day == 28 && m_month == 2 && !isLeapYear()) 338 | { 339 | m_day = 1; 340 | m_month++; 341 | } 342 | else 343 | { 344 | m_day++; 345 | } 346 | 347 | if (m_month > 12) 348 | { 349 | m_month = 1; 350 | m_year++; 351 | } 352 | 353 | if (m_weekDay != DayOfTheWeek_UNKNOWN) // update weekday 354 | { 355 | if (m_weekDay == DayOfTheWeek_Saturday) 356 | m_weekDay = DayOfTheWeek_Sunday; 357 | else 358 | m_weekDay = static_cast(m_weekDay + 1); 359 | } 360 | return *this; 361 | } 362 | 363 | void Date::print() 364 | { 365 | cout << m_year << "/" << m_month << "/" << m_day << endl; 366 | } 367 | 368 | 369 | //int main() 370 | int main_date() 371 | { 372 | Date d(2015, 9, 12); 373 | DayOfTheWeek wd = d.dayOfTheWeek(); 374 | cout << " day of the week: " << wd << " " << d.dayOfWeek() << endl; 375 | d.print(); 376 | 377 | d.add(25); 378 | d.print(); 379 | 380 | d.addTradingDays(120); 381 | d.print(); 382 | cout << " day of the week: " << d.dayOfTheWeek() << " " << d.dayOfWeek() << endl; 383 | 384 | Date dd(2020, 5, 3); 385 | cout << " dow 2 : " << dd.dayOfWeek() << endl; 386 | 387 | return 0; 388 | } 389 | -------------------------------------------------------------------------------- /CppOptions/stl_alg.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // stl_alg.cpp 3 | // 4 | // (c) 2020 Carlos Oliveira 5 | // This code is part of the book 6 | // "Options and Derivatives Programming in C++20: Algorithms and Programming Techniques for the Financial Industry 2nd Edition" 7 | // by Carlos Oliveira, Apress, 2020. 8 | // For more information, visit http://coliveira.net 9 | 10 | 11 | #include "stl_alg.hpp" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | using std::vector; 20 | using std::cout; 21 | using std::endl; 22 | using std::pair; 23 | using std::list; 24 | 25 | class Date { 26 | public: 27 | // other public methods here 28 | bool operator<(const Date &d); 29 | 30 | int year() const { return m_year; } 31 | int month() const { return m_month; } 32 | int day() const { return m_day; } 33 | private: 34 | int m_day; 35 | int m_month; 36 | int m_year; 37 | }; 38 | 39 | bool Date::operator<(const Date &d) 40 | { 41 | if (m_year < d.m_year) 42 | { 43 | return true; 44 | } 45 | if (m_year == d.m_year and m_month < d.m_month) 46 | { 47 | return true; 48 | } 49 | if (m_year == d.m_year and m_month == d.m_month and m_day < d.m_day) 50 | { 51 | return true; 52 | } 53 | return false; 54 | } 55 | 56 | bool operator<(const Date &a, const Date &b) 57 | { 58 | return a < b; 59 | } 60 | 61 | bool year_comparison(const Date &a, const Date &b) 62 | { 63 | return a.year() < b.year(); 64 | } 65 | 66 | void sort_dates() 67 | { 68 | vector dates; 69 | // .... 70 | 71 | 72 | std::sort(dates.begin(), dates.end()); // normal comparison 73 | 74 | std::sort(dates.begin(), dates.end(), year_comparison); // comparison by year 75 | } 76 | 77 | void compute_frequency(vector &prices, double start, double end, double step) 78 | { 79 | 80 | int nbins = int(std::abs(end-start)/step); 81 | 82 | vector> count(nbins, std::make_pair(0,0)); 83 | for (int i=0; i ivector(100, 1); 113 | vector dvector(100); 114 | 115 | std::copy(ivector.begin(), ivector.end(), dvector.begin()); 116 | } 117 | 118 | void print_prices() 119 | { 120 | vector prices(100); 121 | 122 | // initialize prices here 123 | 124 | std::copy(prices.begin(), prices.end(), std::ostream_iterator(cout)); 125 | } 126 | 127 | void from_list_to_vector(const list &l) 128 | { 129 | vector values; 130 | 131 | // copy contents to destination array values 132 | std::copy(l.begin(), l.end(), values.begin()); 133 | } 134 | 135 | template 136 | typename T::const_iterator find(const T &a, S val) { 137 | return std::find (a.begin(), a.end(), val); 138 | } 139 | 140 | void find_value() 141 | { 142 | vector values; 143 | // ... initialize the vector 144 | 145 | 146 | vector::const_iterator aresult = find (values, 42); 147 | if (aresult == values.end()) 148 | { 149 | return; 150 | } 151 | 152 | vector::iterator result = std::find(values.begin(), values.end(), 42); 153 | if (result == values.end()) 154 | { 155 | cout << " the value was not found " << endl; 156 | } 157 | else 158 | { 159 | cout << " the value found is " << *result << endl; 160 | } 161 | } 162 | 163 | bool greater_than_100(int num) 164 | { 165 | return num > 100; 166 | } 167 | 168 | 169 | void conditional_find() 170 | { 171 | vector values; 172 | // ... initialize the vector 173 | 174 | vector::iterator result = std::find_if(values.begin(), values.end(), greater_than_100); 175 | if (result == values.end()) 176 | { 177 | cout << " the value was not found " << endl; 178 | } 179 | else 180 | { 181 | cout << " the value found is " << *result << endl; 182 | } 183 | } 184 | 185 | 186 | class StandardOption { 187 | public: 188 | StandardOption() : m_daysToExpiration() {} 189 | StandardOption(int days); 190 | StandardOption(const StandardOption &p); 191 | ~StandardOption(); 192 | StandardOption &operator=(const StandardOption &p); 193 | 194 | int daysToExpiration() const { return m_daysToExpiration; } 195 | 196 | // other function members here ... 197 | private: 198 | int m_daysToExpiration; 199 | // other data members here ... 200 | }; 201 | 202 | StandardOption::StandardOption(int days) 203 | : m_daysToExpiration(days) 204 | { 205 | } 206 | 207 | StandardOption::StandardOption(const StandardOption &p) 208 | : m_daysToExpiration(p.m_daysToExpiration) 209 | { 210 | } 211 | 212 | StandardOption::~StandardOption() 213 | { 214 | } 215 | 216 | StandardOption &StandardOption::operator=(const StandardOption &p) 217 | { 218 | if (this != &p) 219 | { 220 | m_daysToExpiration = p.m_daysToExpiration; 221 | } 222 | return *this; 223 | } 224 | 225 | 226 | 227 | bool is_expiring(const StandardOption &opt) 228 | { 229 | return opt.daysToExpiration() < 10; 230 | } 231 | 232 | vector find_expiring_options(vector &options) 233 | { 234 | vector result(options.size()); 235 | std::copy_if(options.begin(), options.end(), result.begin(), is_expiring); 236 | if (result.size()) 237 | { 238 | cout << " no expiring option was found " << endl; 239 | } 240 | return result; 241 | } 242 | 243 | 244 | int main_stlalg() 245 | { 246 | vector prices = //{32.3, 34, 35.6, 39.2, 38.7, 31.17, 33.14 }; 247 | { 42.78184445930497,43.67760039111022,42.03826375399276,47.91999821950942,49.93858797561979,42.13542043645291, 248 | 38.30163313879867,38.50027414977689,37.7250636004348,43.70213348996104,36.38765415703016,47.25755355070849, 249 | 35.56734542552674,35.99168991528921,37.50304207091226,38.51564887862568,44.87803633063664,39.85416161118745, 250 | 47.44804469670797,48.02670819457711,37.28933459695028,40.41342291119492,38.2241431256981,44.62217947447723, 251 | 41.03013931222591,35.26208364477185,39.29846553276695,40.65633985086487,47.0228452753842,45.34835153322644, 252 | 39.39700907758517,52.27811213309643,42.63383425974795,40.89249700685397,41.10156246193978,39.47450552642528, 253 | 45.59502602477541,37.32130193926878,36.10652743201731,36.83751340467555,38.22808121445735,40.7856881669989, 254 | 31.36116897916119,33.11108500567489,38.86526465282272,42.33702645101733,39.2742471198834,41.61902173680947, 255 | 32.49702576258007,40.02264414256337,34.85704183624394,35.15089912484926,36.77881561140303,45.72989880475985, 256 | 44.43533847264153,29.27318209468997,44.97598111118879,35.97246951040285,41.73849359918691,30.68554286551367, 257 | 34.66388957398927,43.80717757989846,39.7612215330862,47.03770824841743,44.92093808726787,48.11052662262456, 258 | 36.4622802991489,31.3763438464966,35.09788668863187,31.09792864705171,42.1708919897512,40.02911731364738, 259 | 39.46342929025483,45.81695148690243,43.63955234200387,42.17909414196498,37.60123847103494,43.25668427477181, 260 | 41.03317096943389,46.97461970715167,44.91857530250557,37.0296330565591,36.09364032256888,37.33186444898434, 261 | 38.37820863425179,42.128977451259,33.12287928040585,28.13889923699566,46.93552821004177,39.08490400296763, 262 | 41.40965593696255,40.39683039643357,48.26282345158097,41.38851709709769,47.37773643923619,39.93781367520791, 263 | 39.11047037239822,43.87488862041591,41.84229452562683,39.11307544315284,37.12839597652669,44.45813941412536, 264 | 46.73377993985634,40.11521346072037,34.02015829573072,39.21151096244717,42.5561533675194,36.66359384121515, 265 | 41.03770604517,37.58841778747188,37.36556871510344,30.77799770440181,42.64301727420439,46.26442977570423, 266 | 35.33601025545288,46.31322886198627,37.01799127095718,38.99354811415017,32.79446899107094,41.70857533970244, 267 | 40.87126425385425,32.85178742653525,37.55174479960902,47.18768755976919,42.21866580998352,41.63945505098134, 268 | 36.61444201381163,29.64780175729441,40.77940730811751,39.46542059833772,42.89910948035585,40.12317371206829, 269 | 42.43411461262851,35.88329424968147,29.01277874836401,38.56417020122005,36.50605380753814,40.55350429022879, 270 | 45.36041676143943,38.87427624108659,36.75057400908258,34.80509783081789,46.38341144819815,30.97062663171186, 271 | 39.46841998395084,26.10220881020765,34.20563388133634,40.71062702993218,40.12931797110947,31.38512872543786, 272 | 33.13674967978706,39.62942685602963,46.36085067393131,39.80501033808399,38.15726700221849,44.39924363525626, 273 | 33.2093433391518,31.69765959365117,42.33574480376637,37.33957414264603,45.33505715441738,47.15451393845362, 274 | 34.26571594660756,39.26995986487044,40.48923994719119,28.03197363217081,42.03042938796098,48.29611813824376, 275 | 32.65568118134725,33.03599145413803,38.77497405042885,37.54218522530394,36.73257681618899,31.74650042342772, 276 | 43.70466470964404,43.95509640314371,40.47615133493548,46.43657359714938,42.15964554414583,35.68711681489874, 277 | 42.41889757076655,44.52894333095128,38.23053461983582,33.54328535346639,39.20584181138072,38.46221246681366, 278 | 40.16257848097431,34.87088841002296,44.46483772617439,42.24668745434034,47.84207775896748,44.97672876224185, 279 | 34.50511961621996,36.25259304044854,48.70433158530048,38.65071818129881,41.12872526425293,36.8081868413574, 280 | 39.16674403418639,42.36081001508734,29.91648554931484,40.79507104027888,35.21155198669553,39.86467636572654, 281 | 34.16312678619537,44.28402670706689,32.2972327479956,49.71775839494127,31.85655354085528,42.69305364709465, 282 | 35.31978746186365,38.39450080730782,51.25056893970791,34.72778805729362,36.32614446260754,33.43739285911308, 283 | 38.54791259888807,34.49410615577555,44.75187351018732,45.39390925523594,35.96500752668668,41.54084212999258, 284 | 47.06467445316652,38.39843558787609,34.89666625244398,47.16228016827771,32.04148221250703,35.31171527834899, 285 | 40.42768570708395,42.98450221591088,34.95534551402104,45.56143682645318,43.67081394265119,37.30970243365253, 286 | 47.33704387524431,40.49347008302541,46.93380934436018,41.85656677613047,43.79909661106802,34.70490035774502, 287 | 36.56227975761775,35.99756822956058,40.31782436791381,41.47620622591621,47.39499139910249,29.76361427786139, 288 | 47.51448580510061,52.90916098669709,40.90020357863639,37.43710357613011,37.90639383683421,29.5225427825027, 289 | 45.10107112650064,42.81735023814488,38.56173403457683,28.71518973969216,35.4745320400253,38.1960900110268, 290 | 43.08875563412099,42.65915013188986,40.20701390247016,47.34133201355534,36.32572334393589,35.01705113251843, 291 | 35.5712158922518,38.39474522298454,28.81977157422747,45.55283128685715,37.67622910978037,41.46910993158829, 292 | 37.12918278792814,37.97333496653032,43.36143751335894,33.18434874172782,45.11338835476703,43.06015372494461, 293 | 30.80180131883006,34.50602074468794,45.17317489203142,33.7276490034627,49.53753463483577,45.85841071421091, 294 | 43.02365361972821,46.58265545026941,31.32267887691327,30.84752111873338,48.31335443087461,44.45394196493817, 295 | 42.76587932441861,44.4780979288028,42.26632945954473,33.50331196186566,38.79403203262196,38.69960822121119, 296 | 36.32280301539119,32.40982007652114,44.75746173057647,40.45497946850615,44.69217800086803,41.36346719520907, 297 | 36.85109237756015,39.96877678729342,40.35461240877066,40.91148989776364,35.26240177760784,35.48287092375762, 298 | 38.58465950042369,43.84253921028062,34.51879591594815,40.64679267671642,40.53928342449839,39.18602482572086, 299 | 36.01912495449452,35.34399985569668,38.96216402722161,36.43618650109931,38.52661462890424,38.95256437398413, 300 | 39.70645200370718,40.89035907475167,30.35549814699446,40.41779590913442,40.15272957970845,33.07259054852572, 301 | 38.87556911017958,38.34240699043298,37.90850080011717,36.89488047726263,53.22072610927503,42.67238777483797, 302 | 41.0412322196039,44.5538879373734,32.71162481918658,37.3528249148507,41.79667763835875,42.8961194793476, 303 | 43.8709213919598,39.58930822003997,54.1117190718699,49.5526479474614,38.10265766021563,38.3328362883291, 304 | 43.16194670143282,48.32865145554413,49.77219291224301,37.3563694900509,46.25511476472802,42.16008139722462, 305 | 40.13524190936413,38.98346514030116,34.35142142925718,30.01386924975923,37.89573116126832,43.70972077192636, 306 | 37.27034973834047,39.31443471387625,44.07161877381326,45.80342255388998,35.87713938023972,39.91225256774336, 307 | 41.3959892114833,46.0725782312095,42.77872322109898,31.11185961679133,40.45032983311206,43.9421772825232, 308 | 40.15968817379245,38.16683344854705,49.55977034103568,43.45626420932511,37.55532667654142,41.3907819459214, 309 | 39.90979226272548,35.60428341330544,45.35212021797298,42.52938644602645,38.55952972080569,40.29431115502922, 310 | 40.41342092411278,50.52770393302511,41.2319887087997,44.91666684917468,37.13675226533199,35.3562573099391, 311 | 32.84725721979154,35.29073977284445,42.34288305769034,25.84026261785755,39.62245050708788,44.84604915217371, 312 | 40.11578341866193,39.09919559200785,42.06175050871919,36.02303037427221,37.82331197692943,35.05942720028779, 313 | 36.88813138017978,36.03711817827941,43.98757052666639,35.77717057739348 }; 314 | compute_frequency(prices, 30.0, 50.0, 0.8); 315 | return 0; 316 | } 317 | 318 | -------------------------------------------------------------------------------- /CppOptions.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 731476451C6F729900EE2366 /* MathFunction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 731476431C6F729900EE2366 /* MathFunction.cpp */; }; 11 | 731476481C6FDA1B00EE2366 /* NewtonMethod.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 731476461C6FDA1B00EE2366 /* NewtonMethod.cpp */; }; 12 | 7314764B1C70315C00EE2366 /* Integration.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 731476491C70315C00EE2366 /* Integration.cpp */; }; 13 | 731E3AD51C20B782006C8170 /* Prototype.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 731E3AD31C20B782006C8170 /* Prototype.cpp */; }; 14 | 731E3AD81C21D17A006C8170 /* DataSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 731E3AD61C21D17A006C8170 /* DataSource.cpp */; }; 15 | 731E3ADB1C22256E006C8170 /* Observer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 731E3AD91C22256E006C8170 /* Observer.cpp */; }; 16 | 7330EBA71CCC7BED00814B79 /* qlibsample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7330EBA51CCC7BED00814B79 /* qlibsample.cpp */; }; 17 | 7330EBAA1CD5982800814B79 /* BlackScholesPricer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7330EBA81CD5982800814B79 /* BlackScholesPricer.cpp */; }; 18 | 733690561CDC480600A3DC25 /* CDS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 733690541CDC480600A3DC25 /* CDS.cpp */; }; 19 | 7339ED3A1CBAFC6600D853D0 /* boosttest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7339ED381CBAFC6600D853D0 /* boosttest.cpp */; }; 20 | 73754BF91C94A7B40029D2C6 /* RungeKutta.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73754BF71C94A7B40029D2C6 /* RungeKutta.cpp */; }; 21 | 73754BFC1C94A7D40029D2C6 /* stl_alg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73754BFA1C94A7D40029D2C6 /* stl_alg.cpp */; }; 22 | 73754BFF1C94A7F10029D2C6 /* templates.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73754BFD1C94A7F10029D2C6 /* templates.cpp */; }; 23 | 73754C021C95A9AB0029D2C6 /* LatticeModel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73754C001C95A9AB0029D2C6 /* LatticeModel.cpp */; }; 24 | 73754C051C990E2E0029D2C6 /* BlackScholes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73754C031C990E2D0029D2C6 /* BlackScholes.cpp */; }; 25 | 737DAF081CA5844A000BE28D /* MonteCarlo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 737DAF061CA5844A000BE28D /* MonteCarlo.cpp */; }; 26 | 737DAF0B1CA7954B000BE28D /* RandomWalk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 737DAF091CA7954B000BE28D /* RandomWalk.cpp */; }; 27 | 737FB2D41C1E361800D801D2 /* DesignPatterns.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 737FB2D21C1E361700D801D2 /* DesignPatterns.cpp */; }; 28 | 738BCB131B6BF8B400E894F1 /* GericDerivative.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 738BCB111B6BF8B300E894F1 /* GericDerivative.cpp */; }; 29 | 738BCB161B75095A00E894F1 /* RandomWalkGenerator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 738BCB141B75095A00E894F1 /* RandomWalkGenerator.cpp */; }; 30 | 739299C31B9DEE71000D14D1 /* Date.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 739299C11B9DEE71000D14D1 /* Date.cpp */; }; 31 | 739299C61BA219AF000D14D1 /* DateCompact.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 739299C41BA219AF000D14D1 /* DateCompact.cpp */; }; 32 | 739EFE7C1C65A6A40069A59A /* Matrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 739EFE7A1C65A6A40069A59A /* Matrix.cpp */; }; 33 | 739EFE7F1C66432E0069A59A /* LAVectors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 739EFE7D1C66432E0069A59A /* LAVectors.cpp */; }; 34 | 739EFE821C682C630069A59A /* blas_samp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 739EFE801C682C630069A59A /* blas_samp.cpp */; }; 35 | 739F954D1B50186700966A6F /* GenericOption.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 739F954B1B50186700966A6F /* GenericOption.cpp */; }; 36 | 73DD3E3A1C7EB94100B48D57 /* EulersMethod.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73DD3E381C7EB94100B48D57 /* EulersMethod.cpp */; }; 37 | 73EBC5DC1BC1DD5C0091F9BB /* OOExamples.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73EBC5DA1BC1DD5C0091F9BB /* OOExamples.cpp */; }; 38 | 73EBFBEA24DF77EA00E7C85A /* hist.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73EBFBE824DF77EA00E7C85A /* hist.cpp */; }; 39 | 73F06B5D1C502C5D002A744C /* Functional.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73F06B5B1C502C5D002A744C /* Functional.cpp */; }; 40 | 73FFC60B244AD4050064C47E /* c20test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73FFC609244AD4050064C47E /* c20test.cpp */; }; 41 | /* End PBXBuildFile section */ 42 | 43 | /* Begin PBXCopyFilesBuildPhase section */ 44 | 739F953F1B50183A00966A6F /* CopyFiles */ = { 45 | isa = PBXCopyFilesBuildPhase; 46 | buildActionMask = 2147483647; 47 | dstPath = /usr/share/man/man1/; 48 | dstSubfolderSpec = 0; 49 | files = ( 50 | ); 51 | runOnlyForDeploymentPostprocessing = 1; 52 | }; 53 | /* End PBXCopyFilesBuildPhase section */ 54 | 55 | /* Begin PBXFileReference section */ 56 | 731476431C6F729900EE2366 /* MathFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathFunction.cpp; sourceTree = ""; }; 57 | 731476441C6F729900EE2366 /* MathFunction.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = MathFunction.hpp; sourceTree = ""; }; 58 | 731476461C6FDA1B00EE2366 /* NewtonMethod.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewtonMethod.cpp; sourceTree = ""; }; 59 | 731476471C6FDA1B00EE2366 /* NewtonMethod.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = NewtonMethod.hpp; sourceTree = ""; }; 60 | 731476491C70315C00EE2366 /* Integration.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Integration.cpp; sourceTree = ""; }; 61 | 7314764A1C70315C00EE2366 /* Integration.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Integration.hpp; sourceTree = ""; }; 62 | 731E3AD31C20B782006C8170 /* Prototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Prototype.cpp; sourceTree = ""; }; 63 | 731E3AD41C20B782006C8170 /* Prototype.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Prototype.hpp; sourceTree = ""; }; 64 | 731E3AD61C21D17A006C8170 /* DataSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DataSource.cpp; sourceTree = ""; }; 65 | 731E3AD71C21D17A006C8170 /* DataSource.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = DataSource.hpp; sourceTree = ""; }; 66 | 731E3AD91C22256E006C8170 /* Observer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Observer.cpp; sourceTree = ""; }; 67 | 731E3ADA1C22256E006C8170 /* Observer.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Observer.hpp; sourceTree = ""; }; 68 | 7330EBA51CCC7BED00814B79 /* qlibsample.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = qlibsample.cpp; sourceTree = ""; }; 69 | 7330EBA61CCC7BED00814B79 /* qlibsample.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = qlibsample.hpp; sourceTree = ""; }; 70 | 7330EBA81CD5982800814B79 /* BlackScholesPricer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BlackScholesPricer.cpp; sourceTree = ""; }; 71 | 7330EBA91CD5982800814B79 /* BlackScholesPricer.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = BlackScholesPricer.hpp; sourceTree = ""; }; 72 | 733690541CDC480600A3DC25 /* CDS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CDS.cpp; sourceTree = ""; }; 73 | 733690551CDC480600A3DC25 /* CDS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDS.h; sourceTree = ""; }; 74 | 7339ED381CBAFC6600D853D0 /* boosttest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = boosttest.cpp; sourceTree = ""; }; 75 | 7339ED391CBAFC6600D853D0 /* boosttest.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = boosttest.hpp; sourceTree = ""; }; 76 | 73754BF71C94A7B40029D2C6 /* RungeKutta.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RungeKutta.cpp; sourceTree = ""; }; 77 | 73754BF81C94A7B40029D2C6 /* RungeKutta.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = RungeKutta.hpp; sourceTree = ""; }; 78 | 73754BFA1C94A7D40029D2C6 /* stl_alg.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = stl_alg.cpp; sourceTree = ""; }; 79 | 73754BFB1C94A7D40029D2C6 /* stl_alg.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = stl_alg.hpp; sourceTree = ""; }; 80 | 73754BFD1C94A7F10029D2C6 /* templates.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = templates.cpp; sourceTree = ""; }; 81 | 73754BFE1C94A7F10029D2C6 /* templates.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = templates.hpp; sourceTree = ""; }; 82 | 73754C001C95A9AB0029D2C6 /* LatticeModel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LatticeModel.cpp; sourceTree = ""; }; 83 | 73754C011C95A9AB0029D2C6 /* LatticeModel.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = LatticeModel.hpp; sourceTree = ""; }; 84 | 73754C031C990E2D0029D2C6 /* BlackScholes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BlackScholes.cpp; sourceTree = ""; }; 85 | 73754C041C990E2E0029D2C6 /* BlackScholes.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = BlackScholes.hpp; sourceTree = ""; }; 86 | 737DAF061CA5844A000BE28D /* MonteCarlo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MonteCarlo.cpp; sourceTree = ""; }; 87 | 737DAF071CA5844A000BE28D /* MonteCarlo.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = MonteCarlo.hpp; sourceTree = ""; }; 88 | 737DAF091CA7954B000BE28D /* RandomWalk.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RandomWalk.cpp; sourceTree = ""; }; 89 | 737DAF0A1CA7954B000BE28D /* RandomWalk.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = RandomWalk.hpp; sourceTree = ""; }; 90 | 737FB2D21C1E361700D801D2 /* DesignPatterns.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DesignPatterns.cpp; sourceTree = ""; }; 91 | 737FB2D31C1E361700D801D2 /* DesignPatterns.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = DesignPatterns.hpp; sourceTree = ""; }; 92 | 738BCB111B6BF8B300E894F1 /* GericDerivative.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GericDerivative.cpp; sourceTree = ""; }; 93 | 738BCB121B6BF8B400E894F1 /* GericDerivative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GericDerivative.h; sourceTree = ""; }; 94 | 738BCB141B75095A00E894F1 /* RandomWalkGenerator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RandomWalkGenerator.cpp; sourceTree = ""; }; 95 | 738BCB151B75095A00E894F1 /* RandomWalkGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RandomWalkGenerator.h; sourceTree = ""; }; 96 | 739299C11B9DEE71000D14D1 /* Date.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Date.cpp; sourceTree = ""; }; 97 | 739299C21B9DEE71000D14D1 /* Date.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Date.h; sourceTree = ""; }; 98 | 739299C41BA219AF000D14D1 /* DateCompact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DateCompact.cpp; sourceTree = ""; }; 99 | 739299C51BA219AF000D14D1 /* DateCompact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DateCompact.h; sourceTree = ""; }; 100 | 739EFE7A1C65A6A40069A59A /* Matrix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Matrix.cpp; sourceTree = ""; }; 101 | 739EFE7B1C65A6A40069A59A /* Matrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Matrix.h; sourceTree = ""; }; 102 | 739EFE7D1C66432E0069A59A /* LAVectors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LAVectors.cpp; sourceTree = ""; }; 103 | 739EFE7E1C66432E0069A59A /* LAVectors.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = LAVectors.hpp; sourceTree = ""; }; 104 | 739EFE801C682C630069A59A /* blas_samp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = blas_samp.cpp; sourceTree = ""; }; 105 | 739EFE811C682C630069A59A /* blas_samp.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = blas_samp.hpp; sourceTree = ""; }; 106 | 739F95411B50183A00966A6F /* CppOptions */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = CppOptions; sourceTree = BUILT_PRODUCTS_DIR; }; 107 | 739F954B1B50186700966A6F /* GenericOption.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GenericOption.cpp; sourceTree = ""; }; 108 | 739F954C1B50186700966A6F /* GenericOption.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GenericOption.h; sourceTree = ""; }; 109 | 73DD3E381C7EB94100B48D57 /* EulersMethod.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EulersMethod.cpp; sourceTree = ""; }; 110 | 73DD3E391C7EB94100B48D57 /* EulersMethod.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = EulersMethod.hpp; sourceTree = ""; }; 111 | 73EBC5DA1BC1DD5C0091F9BB /* OOExamples.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OOExamples.cpp; sourceTree = ""; }; 112 | 73EBC5DB1BC1DD5C0091F9BB /* OOExamples.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOExamples.h; sourceTree = ""; }; 113 | 73EBFBE824DF77EA00E7C85A /* hist.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = hist.cpp; path = CppOptions/hist.cpp; sourceTree = ""; }; 114 | 73EBFBE924DF77EA00E7C85A /* hist.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = hist.hpp; path = CppOptions/hist.hpp; sourceTree = ""; }; 115 | 73F06B5B1C502C5D002A744C /* Functional.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Functional.cpp; sourceTree = ""; }; 116 | 73F06B5C1C502C5D002A744C /* Functional.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Functional.hpp; sourceTree = ""; }; 117 | 73FFC609244AD4050064C47E /* c20test.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = c20test.cpp; sourceTree = ""; }; 118 | 73FFC60A244AD4050064C47E /* c20test.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = c20test.hpp; sourceTree = ""; }; 119 | /* End PBXFileReference section */ 120 | 121 | /* Begin PBXFrameworksBuildPhase section */ 122 | 739F953E1B50183A00966A6F /* Frameworks */ = { 123 | isa = PBXFrameworksBuildPhase; 124 | buildActionMask = 2147483647; 125 | files = ( 126 | ); 127 | runOnlyForDeploymentPostprocessing = 0; 128 | }; 129 | /* End PBXFrameworksBuildPhase section */ 130 | 131 | /* Begin PBXGroup section */ 132 | 739F95381B50183A00966A6F = { 133 | isa = PBXGroup; 134 | children = ( 135 | 73EBFBE824DF77EA00E7C85A /* hist.cpp */, 136 | 73EBFBE924DF77EA00E7C85A /* hist.hpp */, 137 | 739F95431B50183A00966A6F /* CppOptions */, 138 | 739F95421B50183A00966A6F /* Products */, 139 | ); 140 | sourceTree = ""; 141 | }; 142 | 739F95421B50183A00966A6F /* Products */ = { 143 | isa = PBXGroup; 144 | children = ( 145 | 739F95411B50183A00966A6F /* CppOptions */, 146 | ); 147 | name = Products; 148 | sourceTree = ""; 149 | }; 150 | 739F95431B50183A00966A6F /* CppOptions */ = { 151 | isa = PBXGroup; 152 | children = ( 153 | 737DAF091CA7954B000BE28D /* RandomWalk.cpp */, 154 | 7339ED381CBAFC6600D853D0 /* boosttest.cpp */, 155 | 7330EBA51CCC7BED00814B79 /* qlibsample.cpp */, 156 | 7330EBA81CD5982800814B79 /* BlackScholesPricer.cpp */, 157 | 733690541CDC480600A3DC25 /* CDS.cpp */, 158 | 733690551CDC480600A3DC25 /* CDS.h */, 159 | 7330EBA91CD5982800814B79 /* BlackScholesPricer.hpp */, 160 | 7330EBA61CCC7BED00814B79 /* qlibsample.hpp */, 161 | 7339ED391CBAFC6600D853D0 /* boosttest.hpp */, 162 | 737DAF0A1CA7954B000BE28D /* RandomWalk.hpp */, 163 | 73754BFD1C94A7F10029D2C6 /* templates.cpp */, 164 | 73FFC609244AD4050064C47E /* c20test.cpp */, 165 | 73FFC60A244AD4050064C47E /* c20test.hpp */, 166 | 73754BFE1C94A7F10029D2C6 /* templates.hpp */, 167 | 737DAF061CA5844A000BE28D /* MonteCarlo.cpp */, 168 | 737DAF071CA5844A000BE28D /* MonteCarlo.hpp */, 169 | 73754BFA1C94A7D40029D2C6 /* stl_alg.cpp */, 170 | 73754BFB1C94A7D40029D2C6 /* stl_alg.hpp */, 171 | 73754BF71C94A7B40029D2C6 /* RungeKutta.cpp */, 172 | 73754C001C95A9AB0029D2C6 /* LatticeModel.cpp */, 173 | 73754C011C95A9AB0029D2C6 /* LatticeModel.hpp */, 174 | 73754C031C990E2D0029D2C6 /* BlackScholes.cpp */, 175 | 73754C041C990E2E0029D2C6 /* BlackScholes.hpp */, 176 | 73754BF81C94A7B40029D2C6 /* RungeKutta.hpp */, 177 | 739EFE801C682C630069A59A /* blas_samp.cpp */, 178 | 739EFE811C682C630069A59A /* blas_samp.hpp */, 179 | 731476431C6F729900EE2366 /* MathFunction.cpp */, 180 | 731476441C6F729900EE2366 /* MathFunction.hpp */, 181 | 731476461C6FDA1B00EE2366 /* NewtonMethod.cpp */, 182 | 731476471C6FDA1B00EE2366 /* NewtonMethod.hpp */, 183 | 731476491C70315C00EE2366 /* Integration.cpp */, 184 | 73DD3E381C7EB94100B48D57 /* EulersMethod.cpp */, 185 | 73DD3E391C7EB94100B48D57 /* EulersMethod.hpp */, 186 | 7314764A1C70315C00EE2366 /* Integration.hpp */, 187 | 73EBC5DA1BC1DD5C0091F9BB /* OOExamples.cpp */, 188 | 73EBC5DB1BC1DD5C0091F9BB /* OOExamples.h */, 189 | 737FB2D21C1E361700D801D2 /* DesignPatterns.cpp */, 190 | 737FB2D31C1E361700D801D2 /* DesignPatterns.hpp */, 191 | 731E3AD31C20B782006C8170 /* Prototype.cpp */, 192 | 731E3AD41C20B782006C8170 /* Prototype.hpp */, 193 | 731E3AD61C21D17A006C8170 /* DataSource.cpp */, 194 | 731E3AD71C21D17A006C8170 /* DataSource.hpp */, 195 | 731E3AD91C22256E006C8170 /* Observer.cpp */, 196 | 73F06B5B1C502C5D002A744C /* Functional.cpp */, 197 | 73F06B5C1C502C5D002A744C /* Functional.hpp */, 198 | 739EFE7A1C65A6A40069A59A /* Matrix.cpp */, 199 | 739EFE7D1C66432E0069A59A /* LAVectors.cpp */, 200 | 739EFE7E1C66432E0069A59A /* LAVectors.hpp */, 201 | 739EFE7B1C65A6A40069A59A /* Matrix.h */, 202 | 731E3ADA1C22256E006C8170 /* Observer.hpp */, 203 | 739F954C1B50186700966A6F /* GenericOption.h */, 204 | 739F954B1B50186700966A6F /* GenericOption.cpp */, 205 | 739299C11B9DEE71000D14D1 /* Date.cpp */, 206 | 739299C21B9DEE71000D14D1 /* Date.h */, 207 | 739299C41BA219AF000D14D1 /* DateCompact.cpp */, 208 | 739299C51BA219AF000D14D1 /* DateCompact.h */, 209 | 738BCB121B6BF8B400E894F1 /* GericDerivative.h */, 210 | 738BCB111B6BF8B300E894F1 /* GericDerivative.cpp */, 211 | 738BCB141B75095A00E894F1 /* RandomWalkGenerator.cpp */, 212 | 738BCB151B75095A00E894F1 /* RandomWalkGenerator.h */, 213 | ); 214 | path = CppOptions; 215 | sourceTree = ""; 216 | }; 217 | /* End PBXGroup section */ 218 | 219 | /* Begin PBXNativeTarget section */ 220 | 739F95401B50183A00966A6F /* CppOptions */ = { 221 | isa = PBXNativeTarget; 222 | buildConfigurationList = 739F95481B50183A00966A6F /* Build configuration list for PBXNativeTarget "CppOptions" */; 223 | buildPhases = ( 224 | 739F953D1B50183A00966A6F /* Sources */, 225 | 739F953E1B50183A00966A6F /* Frameworks */, 226 | 739F953F1B50183A00966A6F /* CopyFiles */, 227 | ); 228 | buildRules = ( 229 | ); 230 | dependencies = ( 231 | ); 232 | name = CppOptions; 233 | productName = CppOptions; 234 | productReference = 739F95411B50183A00966A6F /* CppOptions */; 235 | productType = "com.apple.product-type.tool"; 236 | }; 237 | /* End PBXNativeTarget section */ 238 | 239 | /* Begin PBXProject section */ 240 | 739F95391B50183A00966A6F /* Project object */ = { 241 | isa = PBXProject; 242 | attributes = { 243 | LastUpgradeCheck = 0710; 244 | ORGANIZATIONNAME = "Carlos Oliveira"; 245 | TargetAttributes = { 246 | 739F95401B50183A00966A6F = { 247 | CreatedOnToolsVersion = 6.4; 248 | }; 249 | }; 250 | }; 251 | buildConfigurationList = 739F953C1B50183A00966A6F /* Build configuration list for PBXProject "CppOptions" */; 252 | compatibilityVersion = "Xcode 3.2"; 253 | developmentRegion = English; 254 | hasScannedForEncodings = 0; 255 | knownRegions = ( 256 | English, 257 | en, 258 | ); 259 | mainGroup = 739F95381B50183A00966A6F; 260 | productRefGroup = 739F95421B50183A00966A6F /* Products */; 261 | projectDirPath = ""; 262 | projectRoot = ""; 263 | targets = ( 264 | 739F95401B50183A00966A6F /* CppOptions */, 265 | ); 266 | }; 267 | /* End PBXProject section */ 268 | 269 | /* Begin PBXSourcesBuildPhase section */ 270 | 739F953D1B50183A00966A6F /* Sources */ = { 271 | isa = PBXSourcesBuildPhase; 272 | buildActionMask = 2147483647; 273 | files = ( 274 | 731476451C6F729900EE2366 /* MathFunction.cpp in Sources */, 275 | 739EFE821C682C630069A59A /* blas_samp.cpp in Sources */, 276 | 739EFE7C1C65A6A40069A59A /* Matrix.cpp in Sources */, 277 | 737DAF081CA5844A000BE28D /* MonteCarlo.cpp in Sources */, 278 | 73EBC5DC1BC1DD5C0091F9BB /* OOExamples.cpp in Sources */, 279 | 737DAF0B1CA7954B000BE28D /* RandomWalk.cpp in Sources */, 280 | 731476481C6FDA1B00EE2366 /* NewtonMethod.cpp in Sources */, 281 | 7314764B1C70315C00EE2366 /* Integration.cpp in Sources */, 282 | 73754C051C990E2E0029D2C6 /* BlackScholes.cpp in Sources */, 283 | 73754C021C95A9AB0029D2C6 /* LatticeModel.cpp in Sources */, 284 | 737FB2D41C1E361800D801D2 /* DesignPatterns.cpp in Sources */, 285 | 738BCB161B75095A00E894F1 /* RandomWalkGenerator.cpp in Sources */, 286 | 73DD3E3A1C7EB94100B48D57 /* EulersMethod.cpp in Sources */, 287 | 739F954D1B50186700966A6F /* GenericOption.cpp in Sources */, 288 | 731E3AD51C20B782006C8170 /* Prototype.cpp in Sources */, 289 | 73754BF91C94A7B40029D2C6 /* RungeKutta.cpp in Sources */, 290 | 738BCB131B6BF8B400E894F1 /* GericDerivative.cpp in Sources */, 291 | 73FFC60B244AD4050064C47E /* c20test.cpp in Sources */, 292 | 731E3AD81C21D17A006C8170 /* DataSource.cpp in Sources */, 293 | 731E3ADB1C22256E006C8170 /* Observer.cpp in Sources */, 294 | 739EFE7F1C66432E0069A59A /* LAVectors.cpp in Sources */, 295 | 73754BFF1C94A7F10029D2C6 /* templates.cpp in Sources */, 296 | 73EBFBEA24DF77EA00E7C85A /* hist.cpp in Sources */, 297 | 7339ED3A1CBAFC6600D853D0 /* boosttest.cpp in Sources */, 298 | 73754BFC1C94A7D40029D2C6 /* stl_alg.cpp in Sources */, 299 | 7330EBA71CCC7BED00814B79 /* qlibsample.cpp in Sources */, 300 | 73F06B5D1C502C5D002A744C /* Functional.cpp in Sources */, 301 | 739299C61BA219AF000D14D1 /* DateCompact.cpp in Sources */, 302 | 7330EBAA1CD5982800814B79 /* BlackScholesPricer.cpp in Sources */, 303 | 739299C31B9DEE71000D14D1 /* Date.cpp in Sources */, 304 | 733690561CDC480600A3DC25 /* CDS.cpp in Sources */, 305 | ); 306 | runOnlyForDeploymentPostprocessing = 0; 307 | }; 308 | /* End PBXSourcesBuildPhase section */ 309 | 310 | /* Begin XCBuildConfiguration section */ 311 | 739F95461B50183A00966A6F /* Debug */ = { 312 | isa = XCBuildConfiguration; 313 | buildSettings = { 314 | ALWAYS_SEARCH_USER_PATHS = NO; 315 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 316 | CLANG_CXX_LIBRARY = "libc++"; 317 | CLANG_ENABLE_MODULES = YES; 318 | CLANG_ENABLE_OBJC_ARC = YES; 319 | CLANG_WARN_BOOL_CONVERSION = YES; 320 | CLANG_WARN_CONSTANT_CONVERSION = YES; 321 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 322 | CLANG_WARN_EMPTY_BODY = YES; 323 | CLANG_WARN_ENUM_CONVERSION = YES; 324 | CLANG_WARN_INT_CONVERSION = YES; 325 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 326 | CLANG_WARN_UNREACHABLE_CODE = YES; 327 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 328 | COPY_PHASE_STRIP = NO; 329 | DEBUG_INFORMATION_FORMAT = dwarf; 330 | ENABLE_STRICT_OBJC_MSGSEND = YES; 331 | ENABLE_TESTABILITY = YES; 332 | GCC_C_LANGUAGE_STANDARD = gnu99; 333 | GCC_DYNAMIC_NO_PIC = NO; 334 | GCC_NO_COMMON_BLOCKS = YES; 335 | GCC_OPTIMIZATION_LEVEL = 0; 336 | GCC_PREPROCESSOR_DEFINITIONS = ( 337 | "DEBUG=1", 338 | "$(inherited)", 339 | ); 340 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 341 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 342 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 343 | GCC_WARN_UNDECLARED_SELECTOR = YES; 344 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 345 | GCC_WARN_UNUSED_FUNCTION = YES; 346 | GCC_WARN_UNUSED_VARIABLE = YES; 347 | HEADER_SEARCH_PATHS = /opt/local/include/; 348 | LIBRARY_SEARCH_PATHS = /opt/local/lib; 349 | MACOSX_DEPLOYMENT_TARGET = 10.10; 350 | MTL_ENABLE_DEBUG_INFO = YES; 351 | ONLY_ACTIVE_ARCH = YES; 352 | OTHER_LDFLAGS = " -lboost_signals-mt"; 353 | SDKROOT = macosx; 354 | }; 355 | name = Debug; 356 | }; 357 | 739F95471B50183A00966A6F /* Release */ = { 358 | isa = XCBuildConfiguration; 359 | buildSettings = { 360 | ALWAYS_SEARCH_USER_PATHS = NO; 361 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 362 | CLANG_CXX_LIBRARY = "libc++"; 363 | CLANG_ENABLE_MODULES = YES; 364 | CLANG_ENABLE_OBJC_ARC = YES; 365 | CLANG_WARN_BOOL_CONVERSION = YES; 366 | CLANG_WARN_CONSTANT_CONVERSION = YES; 367 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 368 | CLANG_WARN_EMPTY_BODY = YES; 369 | CLANG_WARN_ENUM_CONVERSION = YES; 370 | CLANG_WARN_INT_CONVERSION = YES; 371 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 372 | CLANG_WARN_UNREACHABLE_CODE = YES; 373 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 374 | COPY_PHASE_STRIP = NO; 375 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 376 | ENABLE_NS_ASSERTIONS = NO; 377 | ENABLE_STRICT_OBJC_MSGSEND = YES; 378 | GCC_C_LANGUAGE_STANDARD = gnu99; 379 | GCC_NO_COMMON_BLOCKS = YES; 380 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 381 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 382 | GCC_WARN_UNDECLARED_SELECTOR = YES; 383 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 384 | GCC_WARN_UNUSED_FUNCTION = YES; 385 | GCC_WARN_UNUSED_VARIABLE = YES; 386 | HEADER_SEARCH_PATHS = /opt/local/include/; 387 | LIBRARY_SEARCH_PATHS = /opt/local/lib; 388 | MACOSX_DEPLOYMENT_TARGET = 10.10; 389 | MTL_ENABLE_DEBUG_INFO = NO; 390 | OTHER_LDFLAGS = " -lboost_signals-mt"; 391 | SDKROOT = macosx; 392 | }; 393 | name = Release; 394 | }; 395 | 739F95491B50183A00966A6F /* Debug */ = { 396 | isa = XCBuildConfiguration; 397 | buildSettings = { 398 | CLANG_CXX_LANGUAGE_STANDARD = "c++2a"; 399 | HEADER_SEARCH_PATHS = /usr/local/include/; 400 | LIBRARY_SEARCH_PATHS = /usr/local/lib; 401 | OTHER_LDFLAGS = ""; 402 | PRODUCT_NAME = "$(TARGET_NAME)"; 403 | }; 404 | name = Debug; 405 | }; 406 | 739F954A1B50183A00966A6F /* Release */ = { 407 | isa = XCBuildConfiguration; 408 | buildSettings = { 409 | CLANG_CXX_LANGUAGE_STANDARD = "c++2a"; 410 | HEADER_SEARCH_PATHS = /usr/local/include/; 411 | LIBRARY_SEARCH_PATHS = /usr/local/lib; 412 | OTHER_LDFLAGS = ""; 413 | PRODUCT_NAME = "$(TARGET_NAME)"; 414 | }; 415 | name = Release; 416 | }; 417 | /* End XCBuildConfiguration section */ 418 | 419 | /* Begin XCConfigurationList section */ 420 | 739F953C1B50183A00966A6F /* Build configuration list for PBXProject "CppOptions" */ = { 421 | isa = XCConfigurationList; 422 | buildConfigurations = ( 423 | 739F95461B50183A00966A6F /* Debug */, 424 | 739F95471B50183A00966A6F /* Release */, 425 | ); 426 | defaultConfigurationIsVisible = 0; 427 | defaultConfigurationName = Release; 428 | }; 429 | 739F95481B50183A00966A6F /* Build configuration list for PBXNativeTarget "CppOptions" */ = { 430 | isa = XCConfigurationList; 431 | buildConfigurations = ( 432 | 739F95491B50183A00966A6F /* Debug */, 433 | 739F954A1B50183A00966A6F /* Release */, 434 | ); 435 | defaultConfigurationIsVisible = 0; 436 | defaultConfigurationName = Release; 437 | }; 438 | /* End XCConfigurationList section */ 439 | }; 440 | rootObject = 739F95391B50183A00966A6F /* Project object */; 441 | } 442 | --------------------------------------------------------------------------------