using System.Runtime.CompilerServices; using YLErp.Models; namespace YLErp { /// /// 全局常量定义 /// public static class ConsGlobal { /// /// 默认波动率 /// public const double DefaultVol = 0.3; /// /// 默认日历 /// public const string DefaultCalendar = "chn"; /// /// 日期格式:yyyy-MM-dd /// public const string DateFormat = "yyyy-MM-dd"; /// /// 日期时间格式:yyyy-MM-dd HH:mm:ss /// public const string DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; /// /// 系统 /// public const string XiTong = "系统"; /// /// 参考价标的代码前缀 /// public const string RefPricePrefix = "\a[R1]"; /// /// 债券价格乘数 /// public const decimal bondPriceMultiple = 0.01m; /// /// 债券价格展示乘数 /// public const decimal bondShowPriceMultiple = 100m; /// /// 限额监控系数 /// public const double quotaMonitorMultiple = 0.0001; /// /// 互换结算岗组 /// public const string SwapSettlementConfigGroup = "SwapSettlement"; /// /// 互换计算岗邮件配置key /// public const string SwapSettlementConfigEmail = "SettlementEmail"; /// /// 价格四舍五入保留位数 /// public const int PriceRound = 11; /// /// 互换期初、期末交割价四舍五入保留位数 /// public const int SwapDeliveryPriceRound = 9; /// /// 金额四舍五入保留位数 /// public const int MoneyRound = 2; #region----有效Valid/无效InValid---- public const string Valid = "Valid"; public const string InValid = "InValid"; /// /// /// public static bool IsValid(string validState) { return !InValid.Equals(validState, StringComparison.OrdinalIgnoreCase); } public static IList ValidStates() { return new List { new SelectItem {Text = "有效", Value = Valid }, new SelectItem {Text = "无效", Value = InValid}, }; } public static string GetValidDesc(string validState) { return InValid.Equals(validState, StringComparison.OrdinalIgnoreCase) || validState == "2" ? "无效" : "有效"; } #endregion #region----资产类型InstrumentType---- /// /// 资产类型 /// public static class InstrumentType { public const string Stock = "Stock"; // 股票 public const string StockIndex = "StockIndex"; // 股指 public const string StockIF = "StockIF"; // 股指期货 public const string CommoditySpot = "CommoditySpot"; // 商品现货 public const string CommodityFutures = "CommodityFutures"; // 商品期货 public const string NewOtcStock = "NewOtcStock"; // 新三板挂牌股票 public const string HKStock = "HKStock"; // 香港股票 public const string HKStockIndex = "HKStockIndex"; // 香港股指 public const string Fund = "Fund"; // 基金及基金专户 public const string TBonds = "TBonds"; // 利率债 public const string CreditBonds = "CreditBonds"; // 信用债 public const string OtherBonds = "OtherBonds"; // 其它债券 public const string Bonds = "Bond"; // 债券 public const string GoldFutures = "GoldFutures"; // 黄金期货 public const string TBFutures = "TBFutures"; // 国债期货 public const string OtherFutures = "OtherFutures"; // 其他期货 public const string GoldSpot = "GoldSpot"; // 黄金现货 public const string OtherSpot = "OtherSpot"; // 其他现货 public const string AbroadFutures = "AbroadFutures"; // 境外期货 public const string AbroadSpot = "AbroadSpot"; // 境外现货 public const string AbroadStock = "AbroadStock"; // 境外股票 public const string AbroadStockIndex = "AbroadStockIndex"; // 境外股指 public const string ExRate = "ExRate"; // 汇率 public const string Shibor = "Shibor"; // Shibor public const string FixingRepoRate = "FixingRepoRate"; // 银行间回购定盘 public const string OtherRate = "OtherRate"; // 其他利率 public const string RateYield = "RateYield"; // 利率收益率 public const string BondIndex = "BondIndex"; // 债券指数 //public const string OtherUnderlying = "OtherUnderlying"; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string GetDesc(string instType) { switch (instType) { case Stock: return "股票"; case StockIndex: return "股指"; case StockIF: return "股指期货"; case CommoditySpot: return "商品现货"; case CommodityFutures: return "商品期货"; case NewOtcStock: return "新三板挂牌股票"; case HKStock: return "香港股票"; case HKStockIndex: return "香港股指"; case Fund: return "基金及基金专户"; case TBonds: return "利率债"; case GoldFutures: return "黄金期货"; case TBFutures: return "国债期货"; case OtherFutures: return "其他期货"; case GoldSpot: return "黄金现货"; case OtherSpot: return "其他现货"; case AbroadFutures: return "境外期货"; case AbroadSpot: return "境外现货"; case AbroadStock: return "境外股票"; case AbroadStockIndex: return "境外股指"; case ExRate: return "汇率"; case Shibor: return "Shibor"; case FixingRepoRate: return "银行间回购定盘"; case OtherRate: return "其他利率"; //case OtherUnderlying: return "其他标的"; case CreditBonds: return "信用债"; case OtherBonds: return "其它债券"; case RateYield: return "利率收益率"; case BondIndex: return "债券指数"; default: return instType; } } public static string GetFromDesc(string CnName) { switch (CnName) { case "股票": return Stock; case "股指": return StockIndex; case "股指期货": return StockIF; case "商品现货": return CommoditySpot; case "商品期货": return CommodityFutures; case "新三板挂牌股票": return NewOtcStock; case "香港股票": return HKStock; case "香港股指": return HKStockIndex; case "基金及基金专户": return Fund; case "国债": return TBonds; case "利率债": return TBonds; case "黄金期货": return GoldFutures; case "国债期货": return TBFutures; case "其他期货": return OtherFutures; case "黄金现货": return GoldSpot; case "其他现货": return OtherSpot; case "境外期货": return AbroadFutures; case "境外现货": return AbroadSpot; case "境外股票": return AbroadStock; case "境外股指": return AbroadStockIndex; case "汇率": return ExRate; case "Shibor": return Shibor; case "银行间回购定盘": return FixingRepoRate; case "其他利率": return OtherRate; //case "其他标的": return OtherUnderlying; case "信用债": return CreditBonds; case "其它债券": return OtherBonds; case "利率收益率": return RateYield; case "债券指数": return BondIndex; default: throw new ServiceException("资产类型不存在"); } } public static IEnumerable SelectItems() { if (PS.Config.Company == Configuration.CompanyEnum.中金) { return new[] { new SelectItem { Text = "股票", Value = Stock }, new SelectItem { Text = "股指", Value = StockIndex }, new SelectItem { Text = "股指期货", Value = StockIF }, new SelectItem { Text = "新三板挂牌股票" ,Value = NewOtcStock}, new SelectItem { Text = "香港股票" ,Value = HKStock}, new SelectItem { Text = "香港股指" ,Value = HKStockIndex}, new SelectItem { Text = "基金及基金专户" ,Value = Fund}, new SelectItem { Text = "国债" ,Value = TBonds}, new SelectItem { Text = "黄金期货" ,Value = GoldFutures}, new SelectItem { Text = "国债期货" ,Value = TBFutures}, new SelectItem { Text = "其他期货" ,Value = OtherFutures}, new SelectItem { Text = "黄金现货" ,Value = GoldSpot}, new SelectItem { Text = "其他现货" ,Value = OtherSpot}, new SelectItem { Text = "境外期货" ,Value = AbroadFutures}, new SelectItem { Text = "境外现货" ,Value = AbroadSpot}, new SelectItem { Text = "境外股票" ,Value = AbroadStock}, new SelectItem { Text = "境外股指" ,Value = AbroadStockIndex}, new SelectItem { Text = "汇率" ,Value = ExRate }, new SelectItem { Text = "Shibor" ,Value = Shibor}, new SelectItem { Text = "银行间回购定盘" ,Value = FixingRepoRate}, new SelectItem { Text = "其他利率" ,Value = OtherRate}, //new SelectItem { Text = "其他标的" ,Value = OtherUnderlying} }; } return new[] { new SelectItem { Text = "股票", Value = Stock }, new SelectItem { Text = "股指", Value = StockIndex }, new SelectItem { Text = "股指期货", Value = StockIF }, new SelectItem { Text = "商品期货", Value = CommodityFutures }, new SelectItem { Text = "商品现货", Value = CommoditySpot }, new SelectItem { Text = "新三板挂牌股票" ,Value = NewOtcStock}, new SelectItem { Text = "香港股票" ,Value = HKStock}, new SelectItem { Text = "香港股指" ,Value = HKStockIndex}, new SelectItem { Text = "基金及基金专户" ,Value = Fund}, new SelectItem { Text = "利率债" ,Value = TBonds}, new SelectItem { Text = "信用债" ,Value = CreditBonds}, new SelectItem { Text = "其它债券" ,Value = OtherBonds}, new SelectItem { Text = "黄金期货" ,Value = GoldFutures}, new SelectItem { Text = "国债期货" ,Value = TBFutures}, new SelectItem { Text = "其他期货" ,Value = OtherFutures}, new SelectItem { Text = "黄金现货" ,Value = GoldSpot}, new SelectItem { Text = "其他现货" ,Value = OtherSpot}, new SelectItem { Text = "境外期货" ,Value = AbroadFutures}, new SelectItem { Text = "境外现货" ,Value = AbroadSpot}, new SelectItem { Text = "境外股票" ,Value = AbroadStock}, new SelectItem { Text = "境外股指" ,Value = AbroadStockIndex}, new SelectItem { Text = "汇率" ,Value = ExRate }, new SelectItem { Text = "Shibor" ,Value = Shibor}, new SelectItem { Text = "银行间回购定盘" ,Value = FixingRepoRate}, new SelectItem { Text = "利率收益率" ,Value = RateYield}, new SelectItem { Text = "债券指数" ,Value = BondIndex}, //new SelectItem { Text = "其他利率" ,Value = OtherRate}, //new SelectItem { Text = "其他标的" ,Value = OtherUnderlying} }; } public static IEnumerable FutureTypes() { return new[] { CommodityFutures, StockIF, GoldFutures, TBFutures, OtherFutures, AbroadFutures, RateYield, BondIndex }; } /// /// 权益类 /// /// public static IEnumerable EquityTypes() { return new[] { Stock, StockIndex, StockIF, NewOtcStock, HKStock, HKStockIndex, AbroadStock, AbroadStockIndex }; } //------------IS----------------------- /// /// 是否股票资产类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsStock(string instType) { return Stock.Equals(instType, StringComparison.OrdinalIgnoreCase); } /// /// 是否股指资产类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsStockIndex(string instType) { return StockIndex.Equals(instType, StringComparison.OrdinalIgnoreCase); } /// /// 是否股票指数期货资产类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsStockIF(string instType) { return StockIF.Equals(instType, StringComparison.OrdinalIgnoreCase); } /// /// 是否商品现货资产类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsCommoditySpot(string instType) { return CommoditySpot.Equals(instType, StringComparison.OrdinalIgnoreCase); } /// /// 是否商品期货资产类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsCommodityFutures(string instType) { return CommodityFutures.Equals(instType, StringComparison.OrdinalIgnoreCase); } /// /// 是否债券资产类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBond(string instType) { switch (instType) { case Bonds: case TBonds: case CreditBonds: case OtherBonds: return true; default: return false; } } //------------CalcType----------------------- /// /// 是否期货资产类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool CalcTypeIsFutures(string instType) { return IsCommodityFutures(ConvertCalcType(instType)); } /// /// 计算方式是否是股票类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool CalcTypeIsStock(string instType) { return IsStock(ConvertCalcType(instType)); } /// /// 类型转换为计算所用类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ConvertCalcType(string instType,bool pringScene = false) { if (pringScene && PS.Config.Company == Configuration.CompanyEnum.国联) { return Bonds; } switch (instType) { case Stock: case StockIndex: case NewOtcStock: case HKStock: case HKStockIndex: case AbroadStock: case AbroadStockIndex: case Shibor: return Stock; case StockIF: case CommodityFutures: case GoldFutures: case TBFutures: case OtherFutures: case AbroadFutures: case RateYield: case BondIndex: return CommodityFutures; case CommoditySpot: case GoldSpot: case OtherSpot: case AbroadSpot: return CommoditySpot; case TBonds: case CreditBonds: case OtherBonds: return Bonds; default: return instType; } } //------------LinkType----------------------- /// /// 期货类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string[] GetFutureTypes() { return new[] { CommodityFutures, StockIF, GoldFutures, TBFutures, AbroadFutures, OtherFutures,RateYield,BondIndex }; } /// /// 股票类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string[] GetStockTypes() { return new[] { Stock, StockIndex, NewOtcStock, HKStock, HKStockIndex, AbroadStock, AbroadStockIndex }; } /// /// 现货类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string[] GetSpotTypes() { return new[] { CommoditySpot, GoldSpot, OtherSpot, AbroadSpot }; } /// /// 债券类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string[] GetBondTypes() { return new[] { Bonds, TBonds, CreditBonds, OtherBonds, }; } } #endregion public static class MainCategory { public const string Equity = "Equity"; public const string BulkCommodity = "BulkCommodity"; public const string InterestRate = "InterestRate";//利率 public const string Credit = "Credit";//信用类 public const string ExchangeRate = "ExchangeRate";//汇率 public const string Other = "Other"; public static string GetDesc(string instType) { switch (instType) { case Equity: return "权益类"; case BulkCommodity: return "大宗商品"; case InterestRate: return "利率"; case Credit: return "信用类"; case ExchangeRate: return "汇率"; case Other: return "其他"; default: return instType; } } public static string GetFromDesc(string CnName) { switch (CnName) { case "权益类": return Equity; case "大宗商品": return BulkCommodity; case "利率": return InterestRate; case "信用类": return Credit; case "汇率": return ExchangeRate; case "其他": return Other; default: throw new ServiceException("主类型不存在"); } } public static IEnumerable SelectItems() { return new[] { new SelectItem { Text = "权益类", Value = Equity }, new SelectItem { Text = "大宗商品", Value = BulkCommodity }, new SelectItem { Text = "利率", Value = InterestRate }, new SelectItem { Text = "信用类", Value = Credit }, new SelectItem { Text = "汇率", Value = ExchangeRate }, new SelectItem { Text = "其他" ,Value = Other}, }; } } #region----看涨看跌CallPut---- /// /// 看涨看跌 /// public static class CallPut { public const string Call = "Call"; public const string Call_CN = "看涨"; public const string Put = "Put"; public const string Put_CN = "看跌"; public static bool IsCall(string value) { return Call.Equals(value, StringComparison.OrdinalIgnoreCase) || value == Call_CN; } public static bool IsPut(string value) { return Put.Equals(value, StringComparison.OrdinalIgnoreCase) || value == Put_CN; } public static string ConvertToCN(string value) { switch (value?.ToLowerInvariant()) { case "call": return Call_CN; case "put": return Put_CN; default: return value; } } /// /// 获取CallPut /// public static string GetCallPut(string OptionType) { switch (OptionType) { case "看涨": case "Call": case "多头": return "Call"; case "看跌": case "Put": case "空头": return "Put"; default: return OptionType; } } } #endregion #region----交易方向TradeSide---- /// /// 交易方向 /// public static class TradeSide { public const string 多头开仓 = "多头开仓"; public const string 多头平仓 = "多头平仓"; public const string 空头开仓 = "空头开仓"; public const string 空头平仓 = "空头平仓"; public static IEnumerable SelectItems() { return new[] { new SelectItem { Text = "多头开仓", Value = 多头开仓 }, new SelectItem { Text = "多头平仓", Value = 多头平仓 }, new SelectItem { Text = "空头开仓", Value = 空头开仓 }, new SelectItem { Text = "空头平仓", Value = 空头平仓 } }; } public static bool IsValid(string value) { return SelectItems().Any(n => n.Value == value); } } #endregion #region----行权方式ExerciseMode---- /// /// 行权方式 /// public static class ExerciseMode { public const string American = "American"; public const string European = "European"; public static string GetDesc(string exerciseMode) { switch (exerciseMode) { case American: return "美式"; case European: return "欧式"; default: return exerciseMode; } } public static IEnumerable SelectItems() { return new[] { new SelectItem { Text = "美式", Value = American }, new SelectItem { Text = "欧式", Value = European}, }; } public static bool IsAmerican(string exerciseMode) { return American.Equals(exerciseMode, StringComparison.OrdinalIgnoreCase); } public static bool IsEuropean(string exerciseMode) { return European.Equals(exerciseMode, StringComparison.OrdinalIgnoreCase); } } #endregion #region----结算价模式SettlePriceMode---- /// /// 结算价模式 /// public static class SettlePriceMode { public const string 结算价 = "结算价"; public const string 收盘价 = "收盘价"; /// /// 如果mode不等于结算价就使用收盘价 /// public static bool UseClosePrice(string mode) { return mode != 结算价; } /// /// 如果mode等于结算价就使用结算价 /// public static bool UseSettlePrice(string mode) { return mode == 结算价; } /// /// 根据结算价类型中文描述获取枚举值 /// public static DBModels.SettlementTypeEnum GetSettlementType(string mode) { if (mode == 结算价) { return DBModels.SettlementTypeEnum.SettlePrice; } //这个方法不会涉及到参考价,如果要增加参考价逻辑,建议另开方法 return DBModels.SettlementTypeEnum.ClosePrice; } } #endregion #region----价格是否为0---- public const double TooSmallValue = 1e-6; /// /// 把过小值变为0; /// public static double IgnoreTSV(double price) { return Math.Abs(price) < TooSmallValue ? 0 : price; } #endregion #region----交易类型---- public static class TradeType { /// /// 远期 /// public const string Forward = "远期"; /// /// 收益互换 /// public const string PayoffSwap = "收益互换"; /// /// 自定义交易 /// public const string Custom = "自定义交易"; /// /// 自定义交易(和Custom同义) /// public const string Manual = "自定义交易"; /// /// 现金流交易 /// public const string CashFlow = "现金流交易"; /// /// 结构化交易 /// public const string Structure = "结构化交易"; /// /// 区间累积期权 /// public const string RangeAcc = "区间累积期权"; /// /// 是否期权交易(采用反证法) /// public static bool IsOptionTrade(string tradeType) { return tradeType != Forward && tradeType != PayoffSwap && tradeType != Custom && tradeType != CashFlow; } } #endregion #region ----客户文件类型---- public static class ClientFileType { /// /// ---- /// public const string NoType = ""; /// /// 适当性文件 /// public const string Suitably = "适应性文件"; /// /// 双录视频文件 /// public const string BookRadio = "双录视频文件"; /// /// 主协议附件 /// public const string MainProtocol = "主协议附件(PDF)"; /// /// 补充协议附件 /// public const string EnhanceProtocol = "补充协议附件(PDF)"; /// /// 履约预付金附件 /// public const string DateMargin = "履约协议附件(PDF)"; /// /// 代签产品附件 /// public const string AllographProduct = "代签产品附件(PDF)"; } #endregion #region----波动率类型---- /// /// 波动率类型 /// public static class VolType { /// /// 开仓 /// public const string OpeningVol = "开仓"; /// /// 持仓 /// public const string PositionVol = "持仓"; /// /// 对冲 /// public const string HedgingVol = "对冲"; public static bool IsPositionVol(string volType) { return string.IsNullOrWhiteSpace(volType) || volType == PositionVol; } } #endregion #region----交易所类型---- public static class MarketType { public static readonly List ChineseMarketCode = new List { "SHFE", "INE", "CFFEX", "CZCE", "DCE" }; } #endregion #region----货币类型---- public static class Currency { public const string CNH = "CNH"; public const string CNY = "CNY"; public const string USD = "USD"; public const string EUR = "EUR"; public static readonly string[] CNCurrencies; static Currency() { CNCurrencies = new[] { CNH, CNY }; } /// /// 是否中国货币 /// public static bool IsCnCurrency(string currency) { return CNCurrencies.Contains(currency, StringComparer.OrdinalIgnoreCase); } } #endregion public static class ReportMainNode { //{ "A1001", "A1002","A1003","A1004", "A1005", "A1006" ,"A1007", //"A1008", "A1009","A1010", "A1011", "A1012","A1013","A1014","A1015","A1016","A1017" } public static string GetMaxDpethNode(string BusiDataType) { switch (BusiDataType) { case "A1005": case "A1006": return "SwapConfirmation"; default: return "OtherReport"; } } public static string GetKeyNode(string BusiDataType) { switch (BusiDataType) { case "A1005": case "A1006": return "ConfirmationNo"; default: return "ExceID"; } } } /// /// 收盘状态值 /// public static class EodStatusVlue { public const string Success = "已收盘"; } } }