187 lines
5.7 KiB
C#
187 lines
5.7 KiB
C#
using Qdp.ComputeServiceV2.Data.CommonModels.TradeInfos;
|
|
using Qdp.Pricing.Base.Enums;
|
|
|
|
namespace YLErp.QdpModule
|
|
{
|
|
/// <summary>
|
|
/// 转换为QDP定义
|
|
/// </summary>
|
|
public static class QdpConverter
|
|
{
|
|
/// <summary>
|
|
/// 转换OTC看涨看跌到QDP枚举
|
|
/// </summary>
|
|
public static OptionType ConvertOptionType(string value)
|
|
{
|
|
if (string.IsNullOrEmpty(value))
|
|
{
|
|
return OptionType.Call;
|
|
}
|
|
|
|
switch (value?.ToUpperInvariant())
|
|
{
|
|
case "看涨":
|
|
case "CALL":
|
|
return OptionType.Call;
|
|
case "看跌":
|
|
case "PUT":
|
|
return OptionType.Put;
|
|
default:
|
|
throw new NotImplementedException("ToOptionType:" + value);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转换OTC看涨看跌到QDP枚举
|
|
/// </summary>
|
|
public static OptionType ConvertCallPut(string value)
|
|
{
|
|
return ConvertOptionType(value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转换OTC买卖方向到QDP买卖方向
|
|
/// </summary>
|
|
public static TradeType ConvertTradeType(string value)
|
|
{
|
|
if (string.IsNullOrEmpty(value))
|
|
{
|
|
return TradeType.Buy;
|
|
}
|
|
|
|
switch (value.ToUpperInvariant())
|
|
{
|
|
case "卖出":
|
|
case "SELL":
|
|
return TradeType.Sell;
|
|
case "买入":
|
|
case "BUY":
|
|
return TradeType.Buy;
|
|
default:
|
|
throw new NotImplementedException("ToTradeType:" + value);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转换OTC行权方式到QDP行权方式
|
|
/// </summary>
|
|
public static OptionExercise ConvertExerciseType(string exerciseType)
|
|
{
|
|
if (string.IsNullOrEmpty(exerciseType))
|
|
{
|
|
return OptionExercise.European;
|
|
}
|
|
|
|
switch (exerciseType.ToUpperInvariant())
|
|
{
|
|
case "美式":
|
|
case "AMERICAN":
|
|
return OptionExercise.American;
|
|
default:
|
|
return OptionExercise.European;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转换OTC买卖方向到QDP买卖方向
|
|
/// </summary>
|
|
public static Position ConvertPosition(string tradeType)
|
|
{
|
|
if (tradeType == null)
|
|
{
|
|
return Position.Buy;
|
|
}
|
|
|
|
switch (tradeType.ToUpperInvariant())
|
|
{
|
|
case "卖出":
|
|
case "SELL":
|
|
return Position.Sell;
|
|
default:
|
|
return Position.Buy;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转换OTC敲入敲出状态到QDP敲入敲出状态
|
|
/// </summary>
|
|
public static BarrierStatus ConvertBarrierStatus(string barrierStatus)
|
|
{
|
|
if (barrierStatus == null)
|
|
{
|
|
return BarrierStatus.Monitoring;
|
|
}
|
|
|
|
switch (barrierStatus.ToUpperInvariant())
|
|
{
|
|
case "敲入":
|
|
case "KNOCKEDIN":
|
|
return BarrierStatus.KnockedIn;
|
|
case "敲出":
|
|
case "KNOCKEDOUT":
|
|
return BarrierStatus.KnockedOut;
|
|
default:
|
|
return BarrierStatus.Monitoring;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转换OTC敲入敲出状态到QDP敲入敲出状态
|
|
/// </summary>
|
|
public static BinaryOptionReplicationStrategy ConvertReplicationStrategy(string replicationStrategy)
|
|
{
|
|
switch (replicationStrategy)
|
|
{
|
|
case "Down":
|
|
return BinaryOptionReplicationStrategy.Down;
|
|
case "Middle":
|
|
return BinaryOptionReplicationStrategy.Middle;
|
|
default:
|
|
return BinaryOptionReplicationStrategy.None;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转换OTC敲入到期支付类别到QDP期权类型
|
|
/// </summary>
|
|
public static OptionType ConvertOptionType(KIPayoffTypeEnum kiPayoffType)
|
|
{
|
|
switch (kiPayoffType)
|
|
{
|
|
case KIPayoffTypeEnum.ToPutOption:
|
|
return OptionType.Put;
|
|
case KIPayoffTypeEnum.ToPutSpreadOption:
|
|
return OptionType.PutSpread;
|
|
case KIPayoffTypeEnum.ToCallOption:
|
|
return OptionType.Call;
|
|
case KIPayoffTypeEnum.ToCallSpreadOption:
|
|
return OptionType.CallSpread;
|
|
default:
|
|
return OptionType.Put;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 对于Autocall类期权结构(主要是雪球),根据期权看涨看跌和koType转换为KO的OptionType
|
|
/// </summary>
|
|
/// <param name="koType"></param>
|
|
/// <param name="optionType"></param>
|
|
/// <returns></returns>
|
|
public static OptionType ConvertAutocallKOOptionType(KOPayoffTypeEnum koType, OptionType optionType)
|
|
{
|
|
//3.13 请用下面的逻辑
|
|
if (koType == KOPayoffTypeEnum.Rebate)
|
|
return OptionType.Coupon;
|
|
|
|
if (optionType == OptionType.Put)
|
|
{
|
|
return koType == KOPayoffTypeEnum.ToSpreadOption ? OptionType.PutSpread : OptionType.Put;
|
|
}
|
|
else
|
|
{
|
|
return koType == KOPayoffTypeEnum.ToSpreadOption ? OptionType.CallSpread : OptionType.Call;
|
|
}
|
|
}
|
|
}
|
|
}
|