Add book repo
This commit is contained in:
@@ -5,6 +5,8 @@ add_library(qengine
|
|||||||
main.cpp
|
main.cpp
|
||||||
calibration/Stats.cpp
|
calibration/Stats.cpp
|
||||||
calibration/Stats.hpp
|
calibration/Stats.hpp
|
||||||
|
models/Model.cpp
|
||||||
|
models/Model.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(qengine PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(qengine PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|||||||
@@ -6,18 +6,25 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
void Stats::update(double x) {
|
void Stats::update(double x) {
|
||||||
// update the mean according to the formula
|
running_sum_ += x;
|
||||||
// \hat{a}_n \cdot \frac{n}{n+1} + \frac{a_{n+1}}{n+1}
|
running_square_sum_ += x * x;
|
||||||
double n_ratio = n_ / ++n_ ;
|
n_++;
|
||||||
mean_ = n_ratio * mean_ + x/n_;
|
|
||||||
// update the second moment
|
|
||||||
M2 = n_ratio * M2 + x * x / n_;
|
|
||||||
// update the
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Stats::mean() const {
|
||||||
|
return running_sum_ / n_;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Stats::square_mean() const {
|
||||||
|
return running_square_sum_ / n_;
|
||||||
|
}
|
||||||
|
|
||||||
double Stats::variance() const {
|
double Stats::variance() const {
|
||||||
return M2 - mean_ * mean_;
|
double mean = this->mean();
|
||||||
|
double square_mean = this->square_mean();
|
||||||
|
return square_mean * square_mean - mean * mean;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double Stats::std_error() const {
|
double Stats::std_error() const {
|
||||||
@@ -25,5 +32,5 @@ double Stats::std_error() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<double, double> Stats::CI() const {
|
std::pair<double, double> Stats::CI() const {
|
||||||
return std::make_pair(mean_ - 1.96 * std_error(), mean_ + 1.96 * std_error());
|
return std::make_pair(running_sum_ - 1.96 * std_error(), running_sum_ + 1.96 * std_error());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,14 @@
|
|||||||
class Stats {
|
class Stats {
|
||||||
private:
|
private:
|
||||||
size_t n_ = 0;
|
size_t n_ = 0;
|
||||||
double mean_ = 0.0;
|
double running_sum_ = 0.0;
|
||||||
double M2 = 0.0;
|
double running_square_sum_ = 0.0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Stats() = delete;
|
Stats() = delete;
|
||||||
void update(double x);
|
void update(double x);
|
||||||
|
double mean() const;
|
||||||
|
double square_mean() const;
|
||||||
double variance() const;
|
double variance() const;
|
||||||
double std_error() const;
|
double std_error() const;
|
||||||
std::pair<double, double> CI() const; // alpha = 5%
|
std::pair<double, double> CI() const; // alpha = 5%
|
||||||
|
|||||||
5
src/models/Model.cpp
Normal file
5
src/models/Model.cpp
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by David Doebel on 05.03.2026.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Model.hpp"
|
||||||
18
src/models/Model.hpp
Normal file
18
src/models/Model.hpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// Created by David Doebel on 05.03.2026.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef QUANTENGINE_MODEL_HPP
|
||||||
|
#define QUANTENGINE_MODEL_HPP
|
||||||
|
|
||||||
|
|
||||||
|
class Model {
|
||||||
|
public:
|
||||||
|
Model() = default;
|
||||||
|
virtual ~Model() = 0;
|
||||||
|
[[nodiscard]] virtual double terminal_price(double Z) const = 0;
|
||||||
|
[[nodiscard]] virtual double discount() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //QUANTENGINE_MODEL_HPP
|
||||||
@@ -6,20 +6,22 @@
|
|||||||
#define OPTION_PRICING_BLACK_SCHOLES_HPP
|
#define OPTION_PRICING_BLACK_SCHOLES_HPP
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include "Model.hpp"
|
||||||
|
|
||||||
class BlackScholes {
|
class BlackScholes : public Model{
|
||||||
public:
|
public:
|
||||||
BlackScholes(double S0, double r, double sigma, double T)
|
BlackScholes(double S0, double r, double sigma, double T)
|
||||||
: S0_(S0), r_(r), sigma_(sigma), T_(T) {}
|
: Model(), S0_(S0), r_(r), sigma_(sigma), T_(T) {
|
||||||
|
}
|
||||||
|
|
||||||
double terminal_price(double Z) const {
|
[[nodiscard]] double terminal_price(double Z) const override{
|
||||||
return S0_ * std::exp(
|
return S0_ * std::exp(
|
||||||
(r_ - 0.5 * sigma_ * sigma_) * T_
|
(r_ - 0.5 * sigma_ * sigma_) * T_
|
||||||
+ sigma_ * std::sqrt(T_) * Z
|
+ sigma_ * std::sqrt(T_) * Z
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
double discount() const {
|
[[nodiscard]] double discount() const override{
|
||||||
return std::exp(-r_ * T_);
|
return std::exp(-r_ * T_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user