Skip to content

Commit

Permalink
cleaned entire include/src by adding better alignments and spaces for…
Browse files Browse the repository at this point in the history
… namespace
  • Loading branch information
anthonymakarewicz committed Aug 13, 2024
1 parent 0c0ab6a commit 4d6fac0
Show file tree
Hide file tree
Showing 45 changed files with 214 additions and 194 deletions.
2 changes: 2 additions & 0 deletions include/market_data/interface_market_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "market_data_observer.h"

namespace OptionPricer {

// Interface injection for production and mock object for unit test
class IMarketData {
public:
Expand All @@ -19,6 +20,7 @@ namespace OptionPricer {
[[nodiscard]] virtual double getR() const = 0;
virtual void setR(const double& r) = 0;
};

}

#endif //INTERFACE_MARKET_DATA_H
11 changes: 0 additions & 11 deletions include/market_data/market_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ namespace OptionPricer {
// Declare MarketData as Singleton
class MarketData final: public IMarketData {
public:
/** @brief MarketData Singleton class
*
* This class serves as a centralized location where all MarketData object will be stored
* and updated and acces by all MarketDataObserver subclasses instances.
* Specifically, only 1 instance of the MarketData object will be created when our program
* will execute be stored as a shared_ptr that all our Options will own the adress of it.
*
* This MarketData data will notify all the Option when StockData used for those Options
* will change.
*
*/
static std::shared_ptr<MarketData> getInstance();
~MarketData() override;

Expand Down
3 changes: 2 additions & 1 deletion include/market_data/market_data_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string>

namespace OptionPricer {
// Observer of MarketData

class MarketDataObserver {
public:
explicit MarketDataObserver(const std::string& id);
Expand All @@ -16,6 +16,7 @@ namespace OptionPricer {
protected:
std::string id_;
};

}

#endif //MARKET_DATA_OBSERVER_H
2 changes: 1 addition & 1 deletion include/market_data/stock_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ namespace OptionPricer {
const double& sigma,
const std::optional<double>& c = std::nullopt);

// Prefix guetters with nodiscard C++17
[[nodiscard]] double getPrice() const;
[[nodiscard]] double getSigma() const;
[[nodiscard]] std::optional<double> getCoupon() const;

friend std::ostream& operator<<(std::ostream& os, const StockData& stockData);
bool operator==(const StockData& other) const;
bool operator!=(const StockData& other) const;
Expand Down
2 changes: 2 additions & 0 deletions include/option/path_dependent/american_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "base_path_dependent_option.h"

namespace OptionPricer {

class AmericanOption final: public PathDependentOption {
public:
~AmericanOption() override;
Expand All @@ -14,6 +15,7 @@ namespace OptionPricer {
std::shared_ptr<IMarketData> marketData);
friend class AmericanOptionFactory;
};

}

#endif //AMERICAN_OPTION_H
7 changes: 5 additions & 2 deletions include/option/path_dependent/asian_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "option/path_dependent/base_path_dependent_option.h"

namespace OptionPricer {

// Base Asian
class AsianOption: public PathDependentOption {
public:
~AsianOption() override;
Expand All @@ -12,7 +14,7 @@ namespace OptionPricer {
using PathDependentOption::PathDependentOption;
};


// Arithmetic Asian
class ArithmeticAsianOption final: public AsianOption {
public:
~ArithmeticAsianOption() override;
Expand All @@ -23,7 +25,7 @@ namespace OptionPricer {
friend class ArithmeticAsianOptionFactory;
};


// Geometric Asian
class GeometricAsianOption final: public AsianOption {
public:
~GeometricAsianOption() override;
Expand All @@ -33,6 +35,7 @@ namespace OptionPricer {
using AsianOption::AsianOption;
friend class GeometricAsianOptionFactory;
};

}

#endif //BASE_ASIAN_OPTION_H
40 changes: 14 additions & 26 deletions include/option/path_dependent/barrier_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,55 @@
#include "base_path_dependent_option.h"

namespace OptionPricer {

enum class BarrierDirection {
Up, Down
};

// Base Barrier
class BarrierOption : public PathDependentOption {
public:
~BarrierOption() override = default;
~BarrierOption() override;

virtual bool isActive(const double& S) const {
if (direction_ == BarrierDirection::Up) {
return S >= B_;
}
return S <= B_; // BarrierDirection::Down
}
virtual bool isActive(const double& S) const;

protected:
BarrierOption(const std::string& ticker, std::unique_ptr<Payoff> payoff, const double& T, const double& B,
BarrierDirection direction, std::shared_ptr<IMarketData> marketData)
: PathDependentOption(ticker, std::move(payoff), T, std::move(marketData)),
B_(B), direction_(direction) {}
BarrierDirection direction, std::shared_ptr<IMarketData> marketData);

double B_; // Barrier level
BarrierDirection direction_;
std::unique_ptr<Payoff> payoff_;
};


// Knock-In Barrier
class KnockInBarrierOption final: public BarrierOption {
public:
~KnockInBarrierOption() override = default;
~KnockInBarrierOption() override;

bool isActive(const double& S) const override {
return BarrierOption::isActive(S);
}
bool isActive(const double& S) const override;

double calc_price() const override {
return 0.0;
}
double calc_price() const override;

private:
using BarrierOption::BarrierOption;
friend class KnockInBarrierOptionFactory;
};


// Knock-Out Barrier
class KnockOutBarrierOption final: public BarrierOption {
public:
~KnockOutBarrierOption() override = default;
~KnockOutBarrierOption() override;

bool isActive(const double& S) const override {
return !BarrierOption::isActive(S);
}
bool isActive(const double& S) const override;

double calc_price() const override {
return 0.0;
}
double calc_price() const override;

private:
using BarrierOption::BarrierOption;
friend class KnockOutBarrierOptionFactory;
};

};

#endif //BASE_BARRIER_OPTION_H
8 changes: 6 additions & 2 deletions include/option/path_dependent/base_path_dependent_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
#include "../base_option.h"

namespace OptionPricer {

class PathDependentOption : public Option {
public:
~PathDependentOption() override;

protected:
// Protected parameterized constructor to enforce creation through factory method
PathDependentOption(const std::string& ticker, std::unique_ptr<Payoff> payoff, const double& T,
std::shared_ptr<IMarketData> marketData);
PathDependentOption(const std::string& ticker,
std::unique_ptr<Payoff> payoff,
const double& T,
std::shared_ptr<IMarketData> marketData);
};

}

#endif //BASE_PATH_DEPENDENT_OPTION_H
9 changes: 6 additions & 3 deletions include/option/path_dependent/factory_american_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
#include "option/path_dependent/american_option.h"

namespace OptionPricer {

class AmericanOptionFactory final: public OptionFactory<AmericanOption> {
std::unique_ptr<Payoff> createSpecificPayoff(const ParameterObject& params, const PayoffType& type) override;
std::unique_ptr<Payoff> createSpecificPayoff(const ParameterObject& params,
const PayoffType& type) override;

std::shared_ptr<AmericanOption> createSpecificOption(const ParameterObject& params,
std::unique_ptr<Payoff> payoff,
const std::shared_ptr<IMarketData>& marketData) override;
std::unique_ptr<Payoff> payoff,
const std::shared_ptr<IMarketData>& marketData) override;

std::string getType(const PayoffType& type) const override;
};

}

#endif //FACTORY_AMERICAN_OPTION_H
2 changes: 2 additions & 0 deletions include/option/path_dependent/factory_asian_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace OptionPricer {

// ArithmeticAsianOptionFactory
class ArithmeticAsianOptionFactory final: public OptionFactory<ArithmeticAsianOption> {
std::unique_ptr<Payoff> createSpecificPayoff(const ParameterObject& params, const PayoffType& type) override;
std::shared_ptr<ArithmeticAsianOption> createSpecificOption(const ParameterObject& params,
Expand All @@ -14,6 +15,7 @@ namespace OptionPricer {
std::string getType(const PayoffType& type) const override;
};

// GeometricAsianOptionFactory
class GeometricAsianOptionFactory final: public OptionFactory<GeometricAsianOption> {
std::unique_ptr<Payoff> createSpecificPayoff(const ParameterObject& params, const PayoffType& type) override;
std::shared_ptr<GeometricAsianOption> createSpecificOption(const ParameterObject& params,
Expand Down
21 changes: 12 additions & 9 deletions include/option/path_dependent/factory_barrier_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,31 @@
#include "option/path_dependent/barrier_option.h"

namespace OptionPricer {

// Knock-In Barrier Factory
class KnockInBarrierOptionFactory final: public OptionFactory<KnockInBarrierOption> {
std::unique_ptr<Payoff> createSpecificPayoff(const ParameterObject& params, const PayoffType& type) override;

std::shared_ptr<KnockInBarrierOption> createSpecificOption(const ParameterObject& params,
std::unique_ptr<Payoff> payoff,
const std::shared_ptr<IMarketData>& marketData) override;
std::shared_ptr<KnockInBarrierOption> createSpecificOption(
const ParameterObject& params,
std::unique_ptr<Payoff> payoff,
const std::shared_ptr<IMarketData>& marketData) override;

std::string getType(const PayoffType& type) const override;
};


// Knock-Out Barrier Factory
class KnockOutBarrierOptionFactory final: public OptionFactory<KnockOutBarrierOption> {
std::unique_ptr<Payoff> createSpecificPayoff(const ParameterObject& params, const PayoffType& type) override;

std::shared_ptr<KnockOutBarrierOption> createSpecificOption(const ParameterObject& params,
std::unique_ptr<Payoff> payoff,
const std::shared_ptr<IMarketData>& marketData) override;
std::shared_ptr<KnockOutBarrierOption> createSpecificOption(
const ParameterObject& params,
std::unique_ptr<Payoff> payoff,
const std::shared_ptr<IMarketData>& marketData) override;

std::string getType(const PayoffType& type) const override;
};
}


}

#endif //FACTORY_BARRIER_OPTION_H
2 changes: 2 additions & 0 deletions include/option/path_dependent/factory_lookback_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace OptionPricer {

// Floating Strike Lookback Factory
class FloatingStrikeLookbackOptionFactory final: public OptionFactory<FloatingStrikeLookbackOption> {
public:
std::unique_ptr<Payoff> createSpecificPayoff(const ParameterObject& params, const PayoffType& type) override;
Expand All @@ -15,6 +16,7 @@ namespace OptionPricer {
std::string getType(const PayoffType& type) const override;
};

// Fixed Strike Lookback Factory
class FixedStrikeLookbackOptionFactory final: public OptionFactory<FixedStrikeLookbackOption> {
public:
std::unique_ptr<Payoff> createSpecificPayoff(const ParameterObject& params, const PayoffType& type) override;
Expand Down
4 changes: 3 additions & 1 deletion include/option/path_dependent/lookback_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace OptionPricer {

// Base class for Lookback options
// Base Lookback
class LookbackOption: public PathDependentOption {
public:
~LookbackOption() override;
Expand All @@ -14,6 +14,7 @@ namespace OptionPricer {
using PathDependentOption::PathDependentOption;
};

// Floating Strike Lookback
class FloatingStrikeLookbackOption final: public LookbackOption {
public:
~FloatingStrikeLookbackOption() override;
Expand All @@ -24,6 +25,7 @@ namespace OptionPricer {
friend class FloatingStrikeLookbackOptionFactory;
};

// Fixed Strike Lookback
class FixedStrikeLookbackOption final: public LookbackOption {
public:
~FixedStrikeLookbackOption() override;
Expand Down
2 changes: 2 additions & 0 deletions include/option/single_path/digital_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "base_single_path_option.h"

namespace OptionPricer {

class DigitalOption final : public SinglePathOption {
public:
~DigitalOption() override;
Expand All @@ -14,6 +15,7 @@ namespace OptionPricer {
std::shared_ptr<IMarketData> marketData);
friend class DigitalOptionFactory;
};

}

#endif //DIGITAL_OPTION_H
8 changes: 4 additions & 4 deletions include/solver/monte_carlo/mc_american.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ namespace OptionPricer {
class AmericanMCPricer final: public PathDependentMCPricer {
public:
AmericanMCPricer(std::shared_ptr<AmericanOption> option,
std::shared_ptr<IMarketData> marketData,
std::shared_ptr<StockPriceModel> stockModel,
std::shared_ptr<NumberGenerarator> generator,
const unsigned int& steps);
std::shared_ptr<IMarketData> marketData,
std::shared_ptr<StockPriceModel> stockModel,
std::shared_ptr<NumberGenerarator> generator,
const unsigned int& steps);
//std::shared_ptr<RegressionStrategy> regressionStrategy,
//std::shared_ptr<BasisFunctionStrategy> basisFunctionStrategy);

Expand Down
Loading

0 comments on commit 4d6fac0

Please sign in to comment.