
gs-quant EqSynthetic 股票合成工具详解字段体系、双腿结构与定价实战【免费下载链接】gs-quantPython toolkit for quantitative finance项目地址: https://gitcode.com/GitHub_Trending/gs/gs-quantgs-quant 的EqSynthetic是面向股票合成类工具Synthetic/Total Return Swap、CFD 及 OET 变体的一站式建模入口本文以其官方 API 文档docs/classes/gs_quant.instrument.EqSynthetic.rst为骨架结合源码中该类的完整字段定义与配套子结构逐项讲解每个属性的语义、类型与默认值并给出从构造、序列化到解析定价的完整用法帮助你直接复用这套工具建模股票合成头寸。一、EqSynthetic 是什么一条腿建模股票合成工具EqSynthetic定义在 gs_quant/target/instrument.py继承自Instrument位于 gs_quant/instrument/core.py其asset_class固定为AssetClass.Equitytype_固定为AssetType.Synthetic也就是说无论具体选哪种合成结构它在资产分类上都归属“股票、合成工具”。它的swap_type字段默认取值为SwapType.Eq_Synthetic_OET即字符串Eq Synthetic OET。从SwapType枚举gs_quant/target/common.py可以看到该类可覆盖的合成结构全谱SwapType 枚举值序列化字符串含义Eq_CFD_StandardEq CFD Standard标准股票 CFDEq_SwapEq Swap股票总收益互换Eq_Swap_OET_AsymmetricEq Swap OET AsymmetricOET 非对称股票互换Eq_Swap_OET_SimpleEq Swap OET SimpleOET 简易股票互换Eq_Swap_TermEq Swap Term定期股票互换Eq_Synthetic_OETEq Synthetic OETOET 合成默认需要说明的是官方文档页面 gs_quant.instrument.EqSynthetic.rst 采用 Sphinxautoclass自动生成其“Properties”一节完整列举了该类对外暴露的全部属性约 35 项并注明其余方法继承自 gs_quant.base.Priceable。下文即按这份属性清单逐项展开。二、交易方向与规模buy_sell、quantity_ 与佣金这一类字段描述“谁、以多大头寸、花多少成本”参与这笔合成工具buy_sell交易方向取值BuySell.Buy/BuySell.Sell枚举定义于 gs_quant/target/common.py序列化为Buy/Sell。quantity_InstrumentBase提供的内部规模字段见 gs_quant/base.py默认值为1通过同名构造参数初始化对外由只读属性instrument_quantity暴露gs_quant/base.py。num_of_underlyers标的下方对应的“underlyer 数量”类型为float适用于一篮子多标的情形。commission / commission_type / commission_units交易佣金及其类型、单位三者配套使用类型分别为float/str/str默认均未设置None。三、标的信息underlier、underlier_type 与双币种underlier标的价格或标识符类型为Union[float, str]——既可以传数值固定价格也可以传字符串标识如代码、指数名。underlier_type标的标识符类型取自UnderlierType枚举gs_quant/target/common.py支持BBID、BID、CUSIP、ISIN、SEDOL、RIC、Ticker共七种。currency工具计价货币取Currency枚举gs_quant/target/common.py。settlement_currency结算货币可不同于计价货币用于跨币种结算场景。fx_data_source汇率数据源str类型用于涉及货币折算时的 FX 曲线选择。strike行权/参考价float类型对于含敲出或行权结构的合成工具定义执行水平。dividend_pay_ratio股利支付比率float类型控制股票腿中股利收益的传递比例。四、日期体系从生效日到交割延迟合成工具的现金流依赖一整套日期字段EqSynthetic对这些日期做了显式建模effective_date生效日datetime.date类型。expiry到期日Union[datetime.date, str]——既可直接给日期也可给相对期限字符串如3m。trade_date交易日str。initial_valuation_date初始估值日str。designated_maturity指定期限如1y、10y这类期限标签str类型用于描述工具的原始期限而非具体日历日。rate_tenor利率期限str用于确定 funding 腿的基准利率期限结构。settlement_delay / reset_delay / payment_delay结算、重置、支付三个环节的延迟天数均为str。valuation_bdc / payment_bdc估值与支付的营业日惯例Business Day Conventionfloat类型控制遇到节假日时日期如何顺延。schedule_type日程类型str用于驱动内部日程生成规则。五、经济条款与 OET 条款rate_option、oet_termsrate_option利率基准选项str例如常见的浮动利率索引标识用于 funding 腿计息。oet_termsOETOne Equity Trade / OET 交易条款参数集合类型为tuple[EqSyntheticOETTerms, ...]。EqSyntheticOETTerms定义于 gs_quant/target/instrument.py内含client_fee/client_notice/client_termsstr与client_fee_atfloat客户侧的费用、通知期、条款文本与费用触发点firm_fee/firm_notice/firm_termsstr与firm_fee_atfloat机构firm侧对应字段oet_typestrOET 结构类型。forwardstartingfixednotional / forwardstartingnotionalprecision / forwardstartingtype远期起始名义金额、名义精度与起始类型属于远期起始forward-starting结构的专属参数。六、双腿结构eq_leg 与 funding_legEqSynthetic采用“股票腿 融资腿”的双腿结构分别由两个EqSyntheticLeg元组承载eq_leg股票腿tuple[EqSyntheticLeg, ...]。funding_leg融资腿tuple[EqSyntheticLeg, ...]通常挂钩rate_option与rate_tenor描述的浮动基准。EqSyntheticLeg定义于 gs_quant/target/instrument.py其字段为字段类型说明schedule_typestr该腿的日程类型first_roll_datestr首次滚动/换仓日期first_roll_date_day_of_monthfloat首次滚动的月份内日payment_scheduletuple[EqSyntheticSchedule, ...]支付日程reset_scheduletuple[EqSyntheticSchedule, ...]重置日程valuation_scheduletuple[EqSyntheticSchedule, ...]估值日程而每条日程EqSyntheticSchedulegs_quant/target/instrument.py包含period周期、delay延迟、date_rule日期规则与datestuple[EqSyntheticDateInfo, ...]四个字段EqSyntheticDateInfogs_quant/target/instrument.py仅含一个date字段用于穷举法指定具体日期。七、元数据与框架属性name、metadata、type_、unresolved 等name工具名称str使用name_metadata序列化。metadata任意元数据字典由InstrumentBase管理gs_quant/base.pyclone时会被一并复制。type_固定为AssetType.Synthetic序列化字段名为typeNone时不输出excludeexclude_none。provider数据/定价提供方抽象属性见 gs_quant/base.py。unresolved / resolution_key解析前的原始快照与解析密钥resolve()之后由InstrumentBase.resolved()写入gs_quant/base.py。dataclass_json_configdataclass-json 框架注入的序列化配置。八、序列化与反序列化camelCase 与构造容错EqSynthetic类的三个装饰器源码 gs_quant/target/instrument.py 上方共同决定了其序列化行为handle_camel_case_args构造时自动兼容 camelCase 参数名例如可直接写underlierType、swapType与 Python 侧underlier_type、swap_type等价dataclass_json(letter_caseLetterCase.CAMEL)to_json()/from_json()时字段统一转为 camelCase与 Marquee 平台契约保持一致dataclass(unsafe_hashTrue, reprFalse)可哈希、自定义repr。典型用法from gs_quant.instrument import EqSynthetic # 构造股票腿 融资腿的合成互换 sw EqSynthetic( underlier.SPX, underlier_typeTicker, swap_typeEq Synthetic OET, buy_sellBuy, currencyUSD, expiry3m, ) # camelCase 参数同样被接受 sw2 EqSynthetic(underlierAAPL UW, underlierTypeTicker, buySellSell) # 序列化与回读 payload sw.to_json() restored EqSynthetic.from_json(payload)九、解析、定价与风险Priceable 能力集官方文档注明该类的其余方法继承自Priceabledocs/classes/gs_quant.base.Priceable.rst核心能力定义于 gs_quant/base.pyresolve(in_placeTrue)补齐未提供的属性。合成工具的固定利率、缺口日期等可在解析后自动算出。price()/dollar_price()返回本币现值 / 美元现值在PricingContext异步上下文中调用则返回 future可批量并行定价。calc(risk_measure, fnNone)计算任意风险度量如股票 Delta、Vega结果可为标量或 DataFrame。**clone(kwargs)复制工具并覆盖指定字段InstrumentBase.clone会保留unresolved、metadata与resolution_keygs_quant/base.py。在PricingContext中批量并行计算的完整模式参照 gs_quant/base.py 的示例范式from gs_quant.markets import PricingContext from gs_quant.risk import EqDelta, EqVega with PricingContext(): price_f sw.price() # 返回 future delta_f sw.calc(EqDelta) # 返回 future price price_f.result() # float本币现值 delta delta_f.result() # 风险度量结果十、小结EqSynthetic用一套统一、显式的字段体系覆盖了股票合成工具的完整生命周期从方向buy_sell、规模quantity_/num_of_underlyers、标的underlier/underlier_type、日期effective_date/expiry/ 各类delay与bdc到双腿结构eq_leg/funding_leg与 OET 条款oet_terms再经由 camelCase 序列化与Priceable的解析、定价、风险计算能力完成全链路使用。深入阅读 gs_quant/target/instrument.py 中EqSynthetic、EqSyntheticLeg、EqSyntheticSchedule、EqSyntheticOETTerms的定义以及 gs_quant/target/common.py 中的SwapType、UnderlierType、BuySell枚举即可在自身项目中精确复现这套建模语义。【免费下载链接】gs-quantPython toolkit for quantitative finance项目地址: https://gitcode.com/GitHub_Trending/gs/gs-quant创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考