Class UnderlyingDataset
Defined in File underlying_dataset.hpp
Inheritance Relationships
Base Type
public std::enable_shared_from_this< UnderlyingDataset >
Class Documentation
-
class UnderlyingDataset : public std::enable_shared_from_this<UnderlyingDataset>
A comprehensive dataset for option pricing and analysis on an underlying security.
The UnderlyingDataset class provides a complete framework for managing, analyzing, and modeling option data for a specific underlying security. It stores and processes:
Underlying security price information
Dividend schedules and projections
Option expirations and strikes
Interest rate and borrowing cost curves
Volatility term structures and models
Stochastic processes for option pricing
Event schedules for market events
This class serves as the central repository for all data required for sophisticated option pricing, volatility surface modeling, and risk analysis.
Note
This class uses the POSIX time library for handling dates and times.
Note
It implements the enable_shared_from_this pattern for safe shared_ptr management.
Public Functions
-
UnderlyingDataset()
Default constructor.
-
size_t add_composite_stochastic_process_config(const CompositeStochasticProcessConfig &config)
Adds a composite stochastic process configuration.
- Parameters:
config – The composite stochastic process configuration.
- Returns:
The ID of the added configuration.
-
inline std::shared_ptr<CompositeStochasticProcess> get_composite_stochastic_process(size_t id)
Retrieves the composite stochastic process associated with the given ID.
- Parameters:
id – The ID of the stochastic process.
- Returns:
A shared pointer to the composite stochastic process.
-
inline std::vector<std::vector<double>> get_composite_stochastic_process_volatility_grid(size_t id)
Gets the volatility grid for the specified composite stochastic process.
- Parameters:
id – The ID of the stochastic process.
- Returns:
A 2D vector containing the volatility grid values.
-
inline int get_option_settlement_lag() const
Gets the option settlement lag.
- Returns:
The settlement lag in days.
-
inline void set_option_settlement_lag(int option_settlement_lag)
Sets the option settlement lag.
- Parameters:
option_settlement_lag – The settlement lag in days.
-
inline int get_underlying_settlement_lag() const
Gets the underlying asset settlement lag.
- Returns:
The settlement lag in days.
-
inline void set_underlying_settlement_lag(int underlying_settlement_lag)
Sets the underlying asset settlement lag.
- Parameters:
underlying_settlement_lag – The settlement lag in days.
-
inline void set_option_style(OptionStyle style)
Sets the option style (e.g., European, American).
- Parameters:
style – The option style to be set.
-
inline OptionStyle get_option_style() const
Gets the current option style.
- Returns:
The option style.
-
inline void set_exercise_settlement_lag(int lag)
Sets the exercise settlement lag.
- Parameters:
lag – The exercise settlement lag in days.
-
inline int get_exercise_settlement_lag() const
Gets the exercise settlement lag.
- Returns:
The exercise settlement lag in days.
-
inline std::vector<std::shared_ptr<CompositeStochasticProcess>> get_composite_stochastic_processes()
Retrieves all composite stochastic processes.
- Returns:
A vector of shared pointers to composite stochastic processes.
-
std::vector<std::shared_ptr<OptionExpiration>> get_option_expirations(const ObjectGetter<bool, OptionExpiration> &filter =
[](std::shared_ptr< OptionExpiration >) { return true;}
) const Retrieves option expirations that match a given filter.
- Parameters:
filter – A lambda function that determines which option expirations to include. Defaults to including all option expirations.
- Returns:
A vector of shared pointers to OptionExpiration objects.
-
inline std::shared_ptr<TenorCalculator> get_variance_tenor_calculator() const
Gets the variance tenor calculator.
- Returns:
A shared pointer to the TenorCalculator instance.
Sets the underlying security.
- Parameters:
und – A shared pointer to the underlying security.
-
inline std::shared_ptr<Security> get_underlying() const
Gets the underlying security.
- Returns:
A shared pointer to the underlying security.
Sets the variance tenor calculator.
- Parameters:
variance_tenor_calculator – A shared pointer to the TenorCalculator instance.
-
inline std::shared_ptr<TradingCalendar> get_trading_calendar() const
Gets the trading calendar used for variance tenor related calculations.
- Returns:
A shared pointer to the TradingCalendar instance.
-
void setup()
Performs setup operations for the object. Need to be called after all setters and before all getters.
-
std::tuple<std::vector<std::string>, std::vector<std::string>, std::vector<std::vector<double>>> get_option_pricing_dataframe() const
Retrieves the option pricing data in a structured format.
- Returns:
A tuple containing vectors of column names, row names, and a 2D vector of option pricing values.
-
std::tuple<std::vector<std::string>, std::vector<std::string>, std::vector<std::vector<double>>> get_option_bid_ask_implied_volatility_dataframe() const
Retrieves the bid-ask implied volatility data for options.
- Returns:
A tuple containing vectors of column names, row names, and a 2D vector of bid-ask implied volatilities.
Retrieves the stochastic process volatility grid for a given stochastic process.
- Parameters:
stochastic_process – A shared pointer to the stochastic process.
- Returns:
A tuple containing vectors of column names, row names, and a 2D vector of volatility values.
-
std::tuple<std::vector<boost::posix_time::ptime>, std::vector<std::string>, std::vector<std::vector<double>>> get_option_expiration_dataframe() const
Retrieves the option expiration data in a structured format.
- Returns:
A tuple containing vectors of expiration dates, labels, and a 2D vector of expiration-related values.
-
std::tuple<std::vector<boost::posix_time::ptime>, std::vector<std::string>, std::vector<std::vector<double>>> get_implied_interest_borrow_dataframe() const
Retrieves the implied interest and borrow rate data.
- Returns:
A tuple containing vectors of dates, labels, and a 2D vector of implied interest and borrow rate values.
Retrieves the volatility grid for option expirations of a stochastic process.
- Parameters:
stochastic_process – A shared pointer to the stochastic process.
- Returns:
A tuple containing vectors of expiration dates, labels, and a 2D vector of volatility values.
Computes the volatility grid for a given stochastic process.
- Parameters:
stochastic_process – A shared pointer to the stochastic process.
expirations – A vector of expiration times.
deltas – A vector of delta values.
- Returns:
A 2D vector representing the computed volatility grid.
Retrieves option strike volatilities for a given stochastic process.
- Parameters:
stochastic_process – A shared pointer to the stochastic process.
- Returns:
A map associating option strikes with their corresponding volatilities.
Retrieves the option expiration data for a stochastic process.
- Parameters:
stochastic_process – A shared pointer to the stochastic process.
- Returns:
A tuple containing vectors of expiration dates, labels, and a 2D vector of expiration-related values.
-
std::tuple<std::vector<boost::posix_time::ptime>, std::vector<std::string>, std::vector<std::vector<double>>> get_expiration_volatility_model_dataframe() const
Retrieves the expiration volatility model data.
- Returns:
A tuple containing vectors of expiration dates, labels, and a 2D vector of volatility model values.
-
void delete_expired(const boost::posix_time::ptime &expiration)
Deletes all expired data up to a given expiration date.
- Parameters:
expiration – The expiration date before which data will be deleted.
-
std::vector<boost::posix_time::ptime> get_expirations() const
Retrieves the list of option expiration datetime.
- Returns:
A vector of expiration datetime.
-
double get_variance_tenor(const boost::posix_time::ptime &expiration) const
Computes the variance tenor for a given expiration date.
- Parameters:
expiration – The expiration date.
- Returns:
The computed variance tenor.
-
double get_interest(const boost::posix_time::ptime &expiration) const
Retrieves the interest rate for a given expiration date.
- Parameters:
expiration – The expiration date.
- Returns:
The interest rate.
-
inline std::shared_ptr<PieceWiseTermStructure> get_atm_volatility_term_structure()
Retrieves the at-the-money volatility term structure.
- Returns:
A shared pointer to the ATM volatility term structure.
-
std::shared_ptr<OptionExpiration> get_option_expiration(const boost::posix_time::ptime &expiration) const
Retrieves the option expiration object for a given expiration datetime.
- Parameters:
expiration – The expiration datetime.
- Returns:
A shared pointer to the corresponding OptionExpiration object.
-
double short_term_volatility(const boost::posix_time::ptime &min_expiration = boost::posix_time::not_a_date_time) const
Computes the short-term volatility.
- Parameters:
min_expiration – The minimum expiration date considered. Defaults to not-a-date-time.
- Returns:
The computed short-term volatility.
-
double long_term_volatility(const boost::posix_time::ptime &max_expiration = boost::posix_time::not_a_date_time) const
Computes the long-term volatility.
- Parameters:
max_expiration – The maximum expiration date considered. Defaults to not-a-date-time.
- Returns:
The computed long-term volatility.
-
inline std::shared_ptr<Schedule<Dividend>> get_dividend_schedule()
Retrieves the dividend schedule.
- Returns:
A shared pointer to the schedule of dividends.
-
void add_projected_dividend(const boost::gregorian::date &ex_date, double fixed, double proportional = 0, int ex_date_uncertainty = 0)
Adds a projected dividend to the dataset.
- Parameters:
ex_date – The ex-dividend date.
fixed – The fixed dividend amount.
proportional – The proportional dividend amount (default: 0).
ex_date_uncertainty – The uncertainty in the ex-dividend date (default: 0).
-
std::shared_ptr<Option> create_option(const boost::posix_time::ptime &expiration, double strike, OptionType type)
Creates an option contract with the specified parameters.
- Parameters:
expiration – The expiration date of the option.
strike – The strike price of the option.
type – The type of option (call or put).
- Returns:
A shared pointer to the created option.
-
std::shared_ptr<Security> create_underlying()
Creates the underlying security.
- Returns:
A shared pointer to the created security.
-
std::vector<std::shared_ptr<Option>> get_options() const
Retrieves all option contracts associated with the dataset.
- Returns:
A vector of shared pointers to Option objects.
-
std::vector<std::shared_ptr<OptionStrike>> get_option_strikes() const
Retrieves all option strikes in the dataset.
- Returns:
A vector of shared pointers to OptionStrike objects.
-
inline void set_valuation_time(const boost::posix_time::ptime &valuation_time)
Sets the valuation time. Change of valuation time does NOT automatically change the settlement lags.
- Parameters:
valuation_time – The new valuation time.
-
inline boost::posix_time::ptime get_valuation_time() const
Retrieves the valuation time.
- Returns:
The valuation time.
-
inline double get_underlying_price() const
Retrieves the price of the underlying asset.
- Returns:
The underlying price.
-
inline std::shared_ptr<Schedule<Estimate>> get_variance_schedule() const
Retrieves the variance schedule.
- Returns:
A shared pointer to the variance schedule.
-
inline std::shared_ptr<PieceWiseYieldCurve> get_yield_curve() const
Retrieves the yield curve.
- Returns:
A shared pointer to the yield curve.
-
inline std::shared_ptr<Schedule<Estimate>> get_borrow_schedule() const
Retrieves the borrow rate schedule.
- Returns:
A shared pointer to the borrow schedule.
-
inline std::shared_ptr<PieceWiseYieldCurve> get_borrow_curve() const
Retrieves the borrow rate curve.
- Returns:
A shared pointer to the borrow curve.
-
inline std::shared_ptr<StochasticProcessPricer> get_stochastic_process_pricer() const
Retrieves the stochastic process pricer.
- Returns:
A shared pointer to the stochastic process pricer.
Sets the yield curve.
- Parameters:
yield_curve – A shared pointer to the new yield curve.
Sets the borrow curve.
- Parameters:
borrow_curve – A shared pointer to the new borrow curve.
-
inline std::shared_ptr<BumpModel> get_variance_term_structure_model() const
Retrieves the variance term structure model.
- Returns:
A shared pointer to the variance term structure model.
-
inline std::shared_ptr<BoundedSchedule<Event>> get_implied_event_schedule() const
Retrieves the implied event schedule.
- Returns:
A shared pointer to the implied event schedule.
-
inline std::shared_ptr<BoundedSchedule<std::shared_ptr<TimeBoundedBimodalGaussian>>> get_bounded_bimodal_gaussian()
Retrieves the bounded bimodal Gaussian model.
- Returns:
A shared pointer to the bounded bimodal Gaussian model.
-
void reset()
Resets the dataset.
-
inline std::vector<std::vector<std::vector<double>>> get_composite_stochastic_process_volatility_grids()
Retrieves the composite stochastic process volatility grids.
- Returns:
A 3D vector containing volatility grids. The first dimension is in stochastic processes. The second dimension is in tenors. The third dimension is in deltas.
-
std::vector<std::shared_ptr<OptionExpiration>> get_unexpired_option_expirations(const boost::posix_time::ptime &valuation_time) const
Retrieves all unexpired option expirations as of a given valuation time.
- Parameters:
valuation_time – The valuation time.
- Returns:
A vector of shared pointers to unexpired option expirations.
-
std::shared_ptr<OptionExpiration> get_first_unexpired_option_expiration(const boost::posix_time::ptime &valuation_time) const
Retrieves the first unexpired option expiration as of a given valuation time.
- Parameters:
valuation_time – The valuation time.
- Returns:
A shared pointer to the first unexpired option expiration.
Public Static Functions
-
static inline std::tuple<std::vector<std::string>, std::vector<double>> get_delta_grid()
Retrieves the delta grid used for volatility grid.
- Returns:
A tuple containing a vector of delta labels (e.g., “10D”, “20D”) and a vector of corresponding numerical delta values.
-
static inline std::tuple<std::vector<std::string>, std::vector<double>> get_tenor_grid()
Retrieves the tenor grid used for volatility grid.
- Returns:
A tuple containing a vector of tenor labels (e.g., “1w”, “1m”) and a vector of corresponding numerical tenor values in years.
Friends
-
friend std::ostream &operator<<(std::ostream &out, const UnderlyingDataset &rhs)
Overloads the stream output operator for the UnderlyingDataset.
- Parameters:
out – The output stream.
rhs – The UnderlyingDataset object to print.
- Returns:
A reference to the modified output stream.