Ankit3445/options_pricing
0
1#pragma once2 3#include <string>4#include <vector>5#include <nlohmann/json.hpp>6 7#include "Common.hpp"8 9struct StrategyLeg {10 double strike;11 double expiry;12 OptionType type;13 int quantity; // +1 long, -1 short14 double entry_price = 0.0;15};16 17struct StrategyDef {18 std::string name;19 std::string ticker;20 double spot = 0.0;21 double rate = 0.04;22 std::vector<StrategyLeg> legs;23};24 25class StrategyBuilder {26public:27 static StrategyDef covered_call(const std::string& ticker, double spot, double strike, double expiry);28 static StrategyDef protective_put(const std::string& ticker, double spot, double strike, double expiry);29 static StrategyDef straddle(const std::string& ticker, double spot, double strike, double expiry);30 static StrategyDef strangle(const std::string& ticker, double spot, double low_strike, double high_strike, double expiry);31 static StrategyDef bull_call_spread(const std::string& ticker, double spot, double low_strike, double high_strike, double expiry);32 static StrategyDef bear_put_spread(const std::string& ticker, double spot, double low_strike, double high_strike, double expiry);33 static StrategyDef butterfly(const std::string& ticker, double spot, double low, double mid, double high, double expiry);34 static StrategyDef iron_condor(const std::string& ticker, double spot, double put_low, double put_high, double call_low, double call_high, double expiry);35 36 static nlohmann::json pnl_at_expiry(const StrategyDef& strat, double spot_min, double spot_max, int steps);37 static Greeks greeks_at_spot(const StrategyDef& strat, double spot);38 static nlohmann::json to_json(const StrategyDef& strat);39 static double bs_price(double S, double K, double T, double r, double sigma, OptionType type);40 static Greeks bs_greeks(double S, double K, double T, double r, double sigma, OptionType type);41 42private:43 static double norm_cdf(double x);44};45 