using Qdp.Foundation.Implementations; using Qdp.Pricing.Base.Enums; using Qdp.Pricing.Base.Implementations; using YLErp.Enums; using YLErp.QdpModule; using YLErp.ThirdParty.CaculatePrice.DongZheng.Dto; namespace YLErp.Modules.CalculationModule { #region----基类---- /// /// 期权交易要素 /// public abstract class OptionTradeParamBase { /// /// 交易类型 /// public abstract string tradeType { get; } /// /// 标的代码 /// public string[] underlyingTickers { get; set; } /// /// 行权价 /// public double strike { get; set; } /// /// 开始日期 /// public Date startDate { get; set; } Date _tradeDate; /// /// tradeDate(未赋值时返回startDate) /// public Date tradeDate { get => _tradeDate ?? startDate; set => _tradeDate = value; } /// /// 标的到期日 /// endDate必须有值否则QDP会报错 /// public Date endDate { get; set; } /// /// 行权期日 /// public Date exerciseDate { get; set; } /// /// 行权期日(原始值) /// public Date originalExerciseDate { get => _originalExerciseDate ?? exerciseDate; set => _originalExerciseDate = value; } /// /// 结算日期 /// public Date settlementDate { get; set; } /// /// 行权类型(European|American) /// public virtual string exerciseType { get; set; } private string _buySell = "Buy"; /// /// trade.BuySell的转换处理 /// public string buysell { get => _buySell; set => _buySell = value == "Buy" || value == "买入" || string.IsNullOrWhiteSpace(value) ? "Buy" : "Sell"; } /// /// 无风险利率 /// public double riskFreeRate { get; set; } /// /// 分红率 /// public double dividendRate { get; set; } string _underlyingInstrumentType; private Date _originalExerciseDate; /// /// 标的资产类型 /// public string underlyingInstrumentType { get => _underlyingInstrumentType; set => _underlyingInstrumentType = ConsGlobal.InstrumentType.ConvertCalcType(value,true); } /// /// 看涨看跌(Call|Put) /// public virtual OptionType optionType { get; set; } /// /// 看涨看跌(Call|Put) /// optionType的别名 /// public OptionType callput { get => optionType; set => optionType = value; } /// /// 份额 /// public double notional { get; set; } /// /// 行权价是否百分比格式(有可能trade上是true但这个值取false,比如处理累计期权就固定取了false) /// public bool isMoneynessOption { get; set; } /// /// 行权价是否百分比格式() /// internal bool isMoneynessOptionOrigianl { get; set; } /// /// 期初标的价格 /// public double initialSpotPrice { get; set; } /// /// 是否有夜盘 /// public bool hasNightMarket { get; set; } /// /// 参与率 /// public double participationRate { get; set; } = 1.0; /// /// 保底收益率 /// public double principalRate { get; set; } /// /// 是否期权年化 /// public virtual bool isAnnualized { get; set; } /// /// 期权年化系数 /// public double annualizedFactor { get; set; } = 1.0; /// /// 是否使用精确时间模式 /// public bool preciseTimeMode { get; set; } /// /// 交易ID /// public string tradeId { get; set; } /// /// 交易编号 /// public string tradeNumber { get; set; } /// /// ttmDays /// public double timeToMaturityDays { get; set; } = double.NaN; /// /// /// public Dictionary dividends { get; set; } /// /// /// public string[] volSurfaceNames { get; set; } /// /// 是否合成远期交易(除香草和合成价差外其他都应该是false) /// public bool isForwardTrade { get; set; } public override string ToString() { return tradeType; } /// /// 对象克隆 /// public OptionTradeParamBase Clone() { return (OptionTradeParamBase)MemberwiseClone(); } /// /// 获取绝对行权价 /// public double GetAbsStrike() { return isMoneynessOption ? strike * initialSpotPrice : strike; } } #endregion #region----香草期权---- /// /// 香草期权 /// public class VanillaOptionTradeParam : OptionTradeParamBase { public override string tradeType => "香草期权"; } #endregion #region----合成价差期权---- /// /// 合成价差期权 /// public class SSpreadOptionTradeParam : OptionTradeParamBase { public override string tradeType => "合成价差期权"; /// /// 合约系数 /// public double[] coefficients { get; set; } } #endregion #region----彩虹期权---- /// /// 彩虹期权 /// public class RainbowOptionTradeParam : OptionTradeParamBase { public override string tradeType => "彩虹期权"; public double[] strikes { get; set; } public string rainbowType { get; set; } public double cashAmount { get; set; } public double correlation { get; set; } } #endregion #region----亚式期权---- /// /// 亚式期权 /// public class AsianOptionTradeParam : OptionTradeParamBase { public override string tradeType => "亚式期权"; /// /// 亚式期权类型 /// public string payoffType { get; set; } /// /// 结算类型 /// public string settleMode { get; set; } /// /// 行权价类型 /// public string strikeStyle { get; set; } /// /// 杠杆率 /// public double strikeGearingFactor { get; set; } = 1; /// /// fixing /// public string fixings { get; set; } /// /// 起算日 /// public Date averagingPeriodStartDate { get; set; } /// /// /// public string observationDateStr { get; set; } /// /// 增强价格 /// public double enhancedPrice { get; set; } } #endregion #region----障碍期权---- /// /// 障碍期权 /// public class BarrierOptionTradeParam : OptionTradeParamBase { public override string tradeType => "障碍期权"; /// /// 障碍类型 /// public string barrierType { get; set; } /// /// 障碍价格 /// public double barrierPrice { get; set; } /// /// 高障碍价格 /// public double upperBarrierPrice { get; set; } /// /// 是否离散观察 /// public bool isDiscrete { get; set; } /// /// 敲入观察频率 /// public string observationDateStr { get; set; } /// /// 补偿金额 /// public double rebate { get; set; } /// /// 高障碍补偿金额 /// public double rebateHigh { get; set; } /// /// 补偿支付类型 /// public string rebateType { get; set; } = string.Empty; /// /// 障碍偏移 /// public double barrierShift { get; set; } /// /// 敲入状态 /// public string barrierStatus { get; set; } = "Monitoring"; /// /// 补偿按敲出日年化 /// public bool rebateAnnualizedAtKO { get; set; } /// /// 补偿计息规则 /// public string rebateDayCount { get; set; } } #endregion #region----二元期权---- /// /// 二元期权 /// public class BinaryOptionTradeParam : OptionTradeParamBase { public override string tradeType => "二元期权"; /// /// 看涨看跌 /// public override OptionType optionType { get => ConsGlobal.ExerciseMode.IsAmerican(exerciseType) ? OptionType.Call : base.optionType; set => base.optionType = value; } /// /// 二元类型 /// public string payoffType { get; set; } /// /// 高障碍价格 /// public double upperBarrier { get; set; } = double.NaN; /// /// 补偿金额 /// public double cashOrNothingAmount { get; set; } /// /// 高障碍补偿金额 /// public double cashOrNothingAmountHigh { get; set; } = double.NaN; /// /// 是否离散观察 /// public bool isDiscreteMonitored { get; set; } /// /// 敲入观察频率 /// public string observationDateStr { get; set; } /// /// 补偿支付 /// public string binaryRebateType { get; set; } = "AtEnd"; /// /// /// public string binaryOptionReplicationStrategy { get; set; } = "None"; /// /// /// public double replicationShiftSize { get; set; } /// /// 补偿按敲出日年化 /// public bool rebateAnnualizedAtKO { get; set; } /// /// 补偿计息规则 /// public string rebateDayCount { get; set; } } #endregion #region----价差期权---- /// /// 价差期权 /// public class SpreadOptionTradeParam : OptionTradeParamBase { public override string tradeType => "价差期权"; /// /// /// public double[] weights { get; set; } /// /// /// public SpreadType spreadType { get; set; } /// /// /// public double[] correlations { get; set; } /// /// /// public double[] dividendRates { get; set; } } #endregion #region----双鲨期权---- /// /// 双鲨期权 /// public class DoubleSharkFinOptionTradeParam : OptionTradeParamBase { public override string tradeType => "双鲨期权"; /// /// 低行权价 /// public double strikeLow { get; set; } /// /// 高行权价 /// public double strikeHigh { get; set; } /// /// 高障碍价格 /// public double barrierHigh { get; set; } /// /// 低障碍价格 /// public double barrierLow { get; set; } /// /// 高参与率 /// public double callParticipationRate { get; set; } /// /// 低参与率 /// public double putParticipationRate { get; set; } /// /// 补偿金额 /// public double rebate { get; set; } /// /// 高补偿金额 /// public double rebateHigh { get; set; } = double.NaN; /// /// 补偿支付方式 /// public string rebateType { get; set; } = string.Empty; /// /// 是否离散观察 /// public bool isDiscrete { get; set; } /// /// 敲入观察频率 /// public string observationDateStr { get; set; } /// /// 敲入敲出状态 /// public string barrierStatus { get; set; } = "Monitoring"; } #endregion #region----凤凰期权---- /// /// 凤凰期权 /// public class AutocallOptionTradeParam : OptionTradeParamBase { public override string tradeType => "凤凰期权"; /// /// 行权类型(European|American) /// public override string exerciseType { get => "European"; set { } } /// /// 票息 /// public double coupon { get; set; } /// /// 票息年化 /// public bool isFixedCoupon { get; set; } /// /// 票息日历规则 /// public string couponDayCount { get; set; } /// /// 票息障碍价格 /// public double couponBarrier { get; set; } /// /// 票息当期支付 /// public bool couponPayAtMaturity { get; set; } /// /// 敲出障碍价格 /// public double koBarrier { get; set; } /// /// 敲出观察频率 /// public string koObservationDateStr { get; set; } /// /// 敲入障碍价格 /// public double kiBarrier { get; set; } /// /// 敲入观察频率 /// public string observationDateStr { get; set; } /// /// 敲入未敲出仍支付票息 /// public bool includeCouponAfterKI { get; set; } /// /// 敲入期权行权价2 /// public double spreadStrike { get; set; } /// /// 敲入期权类型(默认:Put) /// public string kiOptionType { get; set; } = "Put"; /// /// /// public string barrierStatus { get; set; } = "Monitoring"; /// /// /// public List happenedObservations { get; set; } /// /// 期权年化 /// public override bool isAnnualized { get => annualizedOptionPayoff; set => annualizedOptionPayoff = value; } /// /// 期权年化 /// public bool annualizedOptionPayoff { get; set; } } #endregion #region----雪球期权---- /// /// 雪球期权 /// public class SnowballOptionTradeParam : OptionTradeParamBase { public override string tradeType => "雪球期权"; /// /// 行权类型(European|American) /// public override string exerciseType { get => "European"; set { } } #region 敲出设置 /// /// 敲出障碍价格 /// public double koBarrier { get; set; } /// /// 敲出观察日期 /// public string koObservationDateStr { get; set; } /// /// 票息支付日期 /// public string couponPaymentDateStr { get; set; } /// /// 敲出票息率 /// public double koRebate { get; set; } /// /// 票息日历规则 /// public string couponDayCount { get; set; } /// /// 是否固定票息 /// public bool isFixedCoupon { get; set; } /// /// 是否敲出转期权 /// public bool useOptionPayoffAtKO { get; set; } /// /// 敲出转期权类型(默认:Call) /// public OptionType koOptionType { get; set; } = OptionType.Call; /// /// 敲出期权行权价1(敲出转期权时使用) /// public double koStrike { get; set; } = double.NaN; /// /// 敲出期权行权价2(敲出装价差期权时使用) /// public double spreadStrikeAtKO { get; set; } /// /// 已经被废弃(界面已经没有可输入的地方) /// public double koBarrierAdjustStep { get; set; } #endregion #region 敲入设置 /// /// 敲入转期权类型(默认:Put) /// public OptionType kiOptionType { get; set; } = OptionType.Put; /// /// 敲入障碍价格 /// public double kiBarrier { get; set; } /// /// 敲入观察频率 /// public string observationDateStr { get; set; } /// /// 未敲出转期权 /// public bool useOptionPayoffAtMaturity { get; set; } /// /// 敲入期权行权价2 /// public double spreadStrikeAtMaturity { get; set; } #endregion /// /// 红利票息 /// public double coupon { get; set; } /// /// 年化期权费率(用于年化权利金模式的保本雪球) /// public double? annualizedPremiumRate { get; set; } /// /// 敲入敲出状态 /// public string barrierStatus { get; set; } = "Monitoring"; /// /// 期权年化 /// public override bool isAnnualized { get => annualizedOptionPayoff; set => annualizedOptionPayoff = value; } /// /// 期权年化 /// public bool annualizedOptionPayoff { get; set; } } /// /// 专业版雪球 /// public class SnowballSpecialistOptionTradeParam : SnowballOptionTradeParam { public override string tradeType => "专业雪球期权"; /// /// 行权类型(European|American) /// public override string exerciseType { get => "European"; set { } } /// /// 预付金是否参与定价 /// public bool PrepaymentUsed { get; set; } /// /// 预付金比例 /// public double PrepaymentRatio { get; set; } /// /// 预付金返息率 /// public double PrepaymentInterestRate { get; set; } /// /// 预付金折现率 /// public double? PrepaymentConvertCashRate { get; set; } /// /// 终日是否计息 /// public bool CouponIncludeEndDate { get; set; } /// /// 增强参与率 /// public double EnhancedParticipationRate { get; set; } /// /// 敲入参与率 /// public double KIParticipationRate { get; set; } /// /// 保本比率 /// public double PrincipalProtectionRate { get; set; } /// /// 敲入观察设置,0:手动,1:每日观察,2:仅到期日观察 /// public KIObservationType KIObservationType { get; set; } } #endregion #region---气囊结构---- /// /// 气囊结构 /// public class AirBagOptionTradeParam : OptionTradeParamBase { public override string tradeType => "气囊结构"; /// /// 障碍价格 /// public double barrier { get; set; } /// /// 高行权价 /// public double highStrike { get; set; } /// /// 敲入参与率 /// public double kiParticipationRate { get; set; } /// /// 是否收益封顶 /// public bool hasPayoffLimit { get; set; } /// /// 是否离散观察 /// public bool isDiscrete { get; set; } /// /// /// public string observationDateStr { get; set; } /// /// 敲入敲出状态 /// public string barrierStatus { get; set; } = "Monitoring"; /// /// 看涨看跌 /// public override OptionType optionType { get => OptionType.Call; set { } } } #endregion #region----收益增强结构---- /// /// 收益增强结构 /// public class UnderlyingEnhanceTradeParam : OptionTradeParamBase { public override string tradeType => "收益增强结构"; /// /// 看涨看跌 /// public override OptionType optionType { get => OptionType.Call; set { } } public double annualizedEnhanceRate { get; set; } } #endregion #region----区间累积---- /// /// 区间累积结构 /// public class RangeAccrualTradeParam : OptionTradeParamBase { public override string tradeType => "区间累积期权"; /// /// 行权类型(European|American) /// public override string exerciseType { get => "European"; set { } } /// /// 看涨看跌 /// public override OptionType optionType { get => OptionType.Call; set { } } public double lowerRange { get; set; } public double upperRange { get; set; } public double bonusRate { get; set; } public string observationDateStr { get; set; } public string fixings { get; set; } public List happenedObservations { get; set; } } #endregion #region----累计期权---- /// /// 标准累计期权 /// public class AccumulatorOptionTradeParam : OptionTradeParamBase { public override string tradeType => "累计期权"; /// /// 看涨乘数 /// public double CallMultiplier { get; set; } /// /// 看跌乘数 /// public double PutMultiplier { get; set; } /// /// 敲出是否终止 /// public bool EarlyTerminate { get; set; } /// /// 是否支付票息 /// public bool PayCoupon { get; set; } /// /// 票息支付日期 /// public string couponPaymentDateStr { get; set; } /// /// 票息日历规则 /// public string couponDayCount { get; set; } /// /// 是否固定票息 /// public bool isFixedCoupon { get; set; } /// /// 是否首日计息 /// public bool includeStartDateCoupon { get; set; } /// /// 累计类型 /// public string AccumuType { get; set; } /// /// 结算方式(现金当日/现金期末/实物交割) /// public string SettlementMode { get; set; } /// /// 障碍价格 /// public double Barrier { get; set; } /// /// 票息金额 /// public double Coupon { get; set; } /// /// 观察日列表 /// public string KOObservationDates { get; set; } /// /// 上下限价格模式:等于上下限价格时敲出或买方赔付 /// public bool updownPriceMode { get; set; } /// /// /// public List happenedObservations { get; set; } } /// /// 三段式累计期权 /// public class SegmentedAccumulatorOptionTradeParam : AccumulatorOptionTradeParam { public override string tradeType => "三段式累计期权"; private new double CallMultiplier { get; set; } private new double PutMultiplier { get; set; } /// /// (20221008)票息金额2 /// 三段式有效 /// public double Coupon2 { get; set; } /// /// 乘数1 /// 标准累购:put /// 标准累沽:put /// 三段式累购:put /// 三段式累沽:put 1 /// public double Multiplier1 { get; set; } /// /// 乘数2 /// 标准累购:call /// 标准累沽:call /// 三段式累购:call 1 /// 三段式累沽:put 2 /// public double Multiplier2 { get; set; } /// /// (20221008)乘数3 /// 三段式有效 /// 三段累购:call 2 /// 三段累沽:call /// public double Multiplier3 { get; set; } /// /// (20221008)结算方式2(现金当日/现金期末/实物交割) /// 三段式不支持现金期末 /// public string SettleMode2 { get; set; } /// /// (20221008)结算方式3(现金当日/现金期末/实物交割) /// 三段式不支持现金期末 /// public string SettleMode3 { get; set; } /// /// (20221008)行权价2 /// public double Strike2 { get; set; } /// /// (20221008)行权价3 /// 三段式有效 /// public double Strike3 { get; set; } } #endregion #region----现金流交易---- public class CashFlowTradeParam : OptionTradeParamBase { public override string tradeType => "现金流交易"; /// /// 利率 /// public double ProfitRate { get; set; } /// /// 利率类型 /// public CashFlowRateTypeEnum RateType { get; set; } /// /// 资金类型 /// public CashflowDepositTypeEnum DepositType { get; set; } /// /// 预付比例 /// public double PrepayRatio { get; set; } /// /// 计息日历规则 /// public string ProfitDayCount { get; set; } } #endregion #region ----结构化产品 public class StructProductTradeParam { public StructureRequest Request { get; set; } public VolSurface VolSurface { get; set; } } public class ExpireDto { public double Days { get; set; } public string DayStr { get; set; } } #endregion /// /// 期权计算参数 /// public class OptionCalcParam where T : OptionTradeParamBase { public OptionCalcParam(T tradeParam) { TradeParam = tradeParam ?? throw new ArgumentNullException(nameof(tradeParam)); } public T TradeParam { get; } /// /// [非必需]期权计算场景 /// public CalcScenarioEnum calcScenario { get; set; } /// /// [必需]标的价格 /// public double[] spotPrices { get; set; } /// /// [非必需]引擎名称 /// public string engineName { get; set; } /// /// 计算枚举,默认:BASIC_GREEKS /// public PricingRequest pricingRequest { get; set; } = QdpPricingRequest.BASIC_GREEKS; /// /// 急速模式?? /// public bool quadratureFastMode { get; set; } /// /// 是否计算T+1日的Delta /// public bool CalcDeltaT1 { get; set; } /// /// [只读]标的集合 /// public string[] underlyingTickers => TradeParam.underlyingTickers; /// /// [只读]波动率曲面名称 /// public string[] volSurfaceNames => TradeParam.volSurfaceNames; } }