山证bug修复及功能 迁移
This commit is contained in:
@@ -1065,11 +1065,12 @@ namespace YLErp.Modules.RiskModule
|
||||
setValue(swap, swapSetting);
|
||||
|
||||
var positionList = new List<KeyValuePair<trade, realtime_trade_risk>>();
|
||||
var gloabDv01 = GetTradePositionDv01();
|
||||
double underPnl = 0;
|
||||
var gloabDv01 = GetTradePositionDv01(ref underPnl);
|
||||
if (dict.ContainsKey("互换"))
|
||||
{
|
||||
var swapPositionList = dict["互换"].Select(O => new KeyValuePair<trade, realtime_trade_risk>(O.t, O.risk));
|
||||
swap.TotalPnL = swapPositionList.Sum(O => O.Value.PositionPnl.Normalize() + O.Value.RealizedPnl.Normalize());
|
||||
swap.TotalPnL = swapPositionList.Sum(O => O.Value.PositionPnl.Normalize());
|
||||
if (PS.Config.Is国信金阳)
|
||||
{
|
||||
swap.PositionPnl = swapPositionList.Sum(O => O.Value.PositionPnl.Normalize() < 0 ? O.Value.PositionPnl.Normalize() : 0);
|
||||
@@ -1097,6 +1098,7 @@ namespace YLErp.Modules.RiskModule
|
||||
ParentKey = "场外",
|
||||
BusinessType = "标的交易",
|
||||
Quota_DV01 = gloabDv01,
|
||||
PositionPnl = underPnl
|
||||
};
|
||||
var unTrade = new QuotaMonitor_Global()
|
||||
{
|
||||
@@ -1109,6 +1111,7 @@ namespace YLErp.Modules.RiskModule
|
||||
{
|
||||
BusinessType = "全局",
|
||||
StockEqvNotional = Convert.ToDouble(posiStockEqvNotional),
|
||||
PositionPnl = underly.PositionPnl + swap.PositionPnl,
|
||||
Quota_DV01_Upper = dv01Settings?.QuotaUpperLimit ?? double.NaN,
|
||||
Quota_DV01_Lower = dv01Settings?.QuotaLowerLimit ?? double.NaN,
|
||||
Quota_DV01_wUpper = dv01Settings?.WarningUpperLimit ?? double.NaN,
|
||||
@@ -1221,7 +1224,7 @@ namespace YLErp.Modules.RiskModule
|
||||
var temp = settings.Where(O => O.IsValid && O.Status == QuotaSettingApprovalStatus.Valid && (O.QuotaRange == obj.ClientId || O.QuotaRange == 0));
|
||||
var stockEqvNotionalSettings = temp.Where(O => O.QuotaIndex == "名义本金" && O.QuotaRange == 0).FirstOrDefault()?.Clone();
|
||||
var stockEqvNotionalSettingsClient = temp.Where(O => O.QuotaIndex == "名义本金" && O.QuotaRange == obj.ClientId).FirstOrDefault()?.Clone();
|
||||
if (stockEqvNotionalSettingsClient!=null)
|
||||
if (stockEqvNotionalSettingsClient != null)
|
||||
{
|
||||
stockEqvNotionalSettings = stockEqvNotionalSettingsClient.Clone();
|
||||
}
|
||||
@@ -1433,7 +1436,7 @@ namespace YLErp.Modules.RiskModule
|
||||
GammaCash = risk.GammaCash ?? 0,
|
||||
Vega = risk.Vega ?? 0,
|
||||
VegaCash = risk.VegaCash ?? 0,
|
||||
PnL = (PS.Config.IsPVRounded ? risk.RoundedPositionPnl : risk.PositionPnl) ?? 0,
|
||||
PnL = (PS.Config.IsPVRounded ? risk.RoundedPositionPnl : risk.PositionPnl) ?? 0 + risk.RealizedPnl,
|
||||
Quota_DV01 = risk.DV01
|
||||
};
|
||||
|
||||
@@ -1505,8 +1508,7 @@ namespace YLErp.Modules.RiskModule
|
||||
if (item.trade.TradeType == "收益互换")
|
||||
{
|
||||
var sportPrice = item.trade.SpotPrice ?? 0;
|
||||
var valueDate = QdpCalendarHelper.GetNonHolidayDefore(valuedateBLL.ValueDate.AddDays(-1));
|
||||
var bondPrice = EodPriceQueryService.GetBondPrice(valueDate, item.trade.UnderlyingCode);
|
||||
var bondPrice = EodPriceQueryService.GetBondPrice(valuedateBLL.ValueDate, item.trade.UnderlyingCode);
|
||||
var basePrice = bondPrice == null ? 0 : bondPrice.ClosePrice;
|
||||
var vobp = bondPrice == null ? 0 : Convert.ToDouble(bondPrice.Vobp);
|
||||
var pricePercent = basePrice == 0 ? 0 : Math.Abs((sportPrice / basePrice) - 1);
|
||||
@@ -2145,7 +2147,7 @@ namespace YLErp.Modules.RiskModule
|
||||
QuotaMonitor_Underlying quotaMonitor = new QuotaMonitor_Underlying();
|
||||
var um = underlyings.FirstOrDefault(f => f.UnderlyingCode == item.UnderlyingCode);
|
||||
quotaMonitor.UnderlyingCode = item.UnderlyingCode;
|
||||
quotaMonitor.StockEqvNotional =Math.Abs(item.StockEqvNotional??0);
|
||||
quotaMonitor.StockEqvNotional = Math.Abs(item.StockEqvNotional ?? 0);
|
||||
quotaMonitor.UnderlyingId = um?.id ?? 0;
|
||||
if (um != null && um.IsBond())
|
||||
{
|
||||
@@ -3582,20 +3584,20 @@ namespace YLErp.Modules.RiskModule
|
||||
IsValid = true,
|
||||
Status = QuotaSettingApprovalStatus.Valid,
|
||||
});
|
||||
//交易-止损金额
|
||||
_quotaSettings.Add(new QuotaSetting()
|
||||
{
|
||||
QuotaType = QuotaTypeEnum.TRADE,
|
||||
QuotaRange = 0,
|
||||
QuotaIndex = "止损金额",
|
||||
QuotaLowerLimit = null,
|
||||
QuotaUpperLimit = null,
|
||||
WarningLowerLimit = null,
|
||||
WarningUpperLimit = null,
|
||||
Percent = false,
|
||||
IsValid = true,
|
||||
Status = QuotaSettingApprovalStatus.Valid,
|
||||
});
|
||||
////交易-止损金额
|
||||
//_quotaSettings.Add(new QuotaSetting()
|
||||
//{
|
||||
// QuotaType = QuotaTypeEnum.TRADE,
|
||||
// QuotaRange = 0,
|
||||
// QuotaIndex = "止损金额",
|
||||
// QuotaLowerLimit = null,
|
||||
// QuotaUpperLimit = null,
|
||||
// WarningLowerLimit = null,
|
||||
// WarningUpperLimit = null,
|
||||
// Percent = false,
|
||||
// IsValid = true,
|
||||
// Status = QuotaSettingApprovalStatus.Valid,
|
||||
//});
|
||||
//交易-Delta金额
|
||||
_quotaSettings.Add(new QuotaSetting()
|
||||
{
|
||||
@@ -4405,7 +4407,7 @@ namespace YLErp.Modules.RiskModule
|
||||
{
|
||||
List<ClientRiskCheckItem> clientRiskCheckResps = new List<ClientRiskCheckItem>();
|
||||
var allList = QueryPrecheckQuotaSetting(false);
|
||||
allList = allList.Where(x=>x.QuotaIndex!="DV01").ToList(); ;
|
||||
allList = allList.Where(x => x.QuotaIndex != "DV01").ToList(); ;
|
||||
var precheckQuotaSettingList = allList.Where(O => O.Precheck).ToList();
|
||||
List<string> quotaIndexs = new List<string>() { "名义本金", "轧差集中度", "轧差名义本金" };
|
||||
if (clientRiskCheckReq.isClient)
|
||||
@@ -4416,9 +4418,9 @@ namespace YLErp.Modules.RiskModule
|
||||
{
|
||||
return clientRiskCheckResps;
|
||||
}
|
||||
var clientPrecheckQuotaSettingList = precheckQuotaSettingList.Where(x=>x.QuotaRange== clientRiskCheckReq.clientId&&x.QuotaType==QuotaTypeEnum.CLIENT&&x.QuotaIndex=="名义本金").ToList();
|
||||
var allClientPrecheckQuotaSettingList= precheckQuotaSettingList.Where(x => x.QuotaRange == 0 && x.QuotaType == QuotaTypeEnum.CLIENT && x.QuotaIndex == "名义本金").ToList();
|
||||
if (clientPrecheckQuotaSettingList.Count>0)
|
||||
var clientPrecheckQuotaSettingList = precheckQuotaSettingList.Where(x => x.QuotaRange == clientRiskCheckReq.clientId && x.QuotaType == QuotaTypeEnum.CLIENT && x.QuotaIndex == "名义本金").ToList();
|
||||
var allClientPrecheckQuotaSettingList = precheckQuotaSettingList.Where(x => x.QuotaRange == 0 && x.QuotaType == QuotaTypeEnum.CLIENT && x.QuotaIndex == "名义本金").ToList();
|
||||
if (clientPrecheckQuotaSettingList.Count > 0)
|
||||
{
|
||||
foreach (var item in allClientPrecheckQuotaSettingList)
|
||||
{
|
||||
@@ -4430,16 +4432,26 @@ namespace YLErp.Modules.RiskModule
|
||||
{
|
||||
throw new ServiceException("未找到客户信息");
|
||||
}
|
||||
try
|
||||
{
|
||||
RealtimePnlCalc.RealtimeSwapPosition(new OptUserInfo(0, "互换实时持仓服务", OptUserFrom.Service));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogFactory.GetLogger("RealtimeSwapPosition").Error("风控调用实时持仓异常", ex);
|
||||
}
|
||||
|
||||
using var bondDb = new BondOmsDBContext();
|
||||
var clientPositions = bondDb.client_position.AsNoTracking().ToList();//所有持仓
|
||||
ClientPosition posi = new ClientPosition();
|
||||
posi.commission = clientRiskCheckReq.commission;
|
||||
posi.side = clientRiskCheckReq.side;
|
||||
posi.security_id = clientRiskCheckReq.securityId;
|
||||
posi.full_price_now = clientRiskCheckReq.price* ConsGlobal.bondShowPriceMultiple;
|
||||
posi.full_price_now = clientRiskCheckReq.price * ConsGlobal.bondShowPriceMultiple;
|
||||
posi.deal_full_price_avg = clientRiskCheckReq.price * ConsGlobal.bondShowPriceMultiple;
|
||||
posi.client_id = clientRiskCheckReq.clientId;
|
||||
posi.position_qty = clientRiskCheckReq.qty / 10000;
|
||||
posi.position_notional_principal = clientRiskCheckReq.qty;
|
||||
posi.direction = (int)SwapDirectionEnum.支付;
|
||||
clientPositions.Add(posi);
|
||||
var umCodes = clientPositions.Select(s => s.security_id).Distinct().ToList();
|
||||
@@ -4486,7 +4498,6 @@ namespace YLErp.Modules.RiskModule
|
||||
{
|
||||
checkQuotaMoitorModel.Price *= ConsGlobal.bondPriceMultiple;
|
||||
checkQuotaMoitorModel.NowPrice *= ConsGlobal.bondPriceMultiple;
|
||||
dealDate = QdpCalendarHelper.GetNonHolidayDefore(dealDate.AddDays(-1));
|
||||
var bondPrice = EodPriceQueryService.GetBondPrice(dealDate, item.security_id);
|
||||
lastPrice = bondPrice != null ? bondPrice.ClosePrice : (um.Price ?? 0) * Convert.ToDouble(ConsGlobal.bondPriceMultiple);
|
||||
vobp = bondPrice != null ? bondPrice.Vobp ?? 0 : 0;
|
||||
@@ -4533,7 +4544,6 @@ namespace YLErp.Modules.RiskModule
|
||||
{
|
||||
List<CheckQuotaMoitorModel> checkPoisiList = new List<CheckQuotaMoitorModel>();
|
||||
var dealDate = valuedateBLL.ValueDate;
|
||||
dealDate = QdpCalendarHelper.GetNonHolidayDefore(dealDate.AddDays(-1));
|
||||
using var bondDb = new BondOmsDBContext();
|
||||
var clientPositions = bondDb.client_position.AsNoTracking().ToList();//所有持仓
|
||||
Dictionary<string, EodPrice> eodPriceDic = new Dictionary<string, EodPrice>();
|
||||
@@ -4717,7 +4727,6 @@ namespace YLErp.Modules.RiskModule
|
||||
{
|
||||
checkQuotaMoitorModel.Price *= ConsGlobal.bondPriceMultiple;
|
||||
checkQuotaMoitorModel.NowPrice *= ConsGlobal.bondPriceMultiple;
|
||||
dealDate = QdpCalendarHelper.GetNonHolidayDefore(dealDate.AddDays(-1));
|
||||
var bondPrice = EodPriceQueryService.GetBondPrice(dealDate, item.security_id);
|
||||
lastPrice = bondPrice != null ? bondPrice.ClosePrice : (um.Price ?? 0) * Convert.ToDouble(ConsGlobal.bondPriceMultiple);
|
||||
vobp = bondPrice != null ? bondPrice.Vobp ?? 0 : 0;
|
||||
@@ -5121,7 +5130,7 @@ namespace YLErp.Modules.RiskModule
|
||||
tag_prefix = quota.QuotaRange == 0 ? "客户合计" : "当前客户";
|
||||
msgList.AddRange(checkClient(positionList, posiList, tag_prefix, new QuotaSetting[] { quota }, settingAll, warning));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -5217,10 +5226,11 @@ namespace YLErp.Modules.RiskModule
|
||||
currentValue = null;
|
||||
var tag = $"{tag_prefix}({settingItem.QuotaIndex})";
|
||||
CheckQuotaMoitorModel current = positionList.FirstOrDefault(x => x.Current);
|
||||
double pnl = 0;
|
||||
switch (settingItem.QuotaIndex)
|
||||
{
|
||||
case "DV01":
|
||||
var uDv = GetTradePositionDv01();
|
||||
var uDv = GetTradePositionDv01(ref pnl);
|
||||
currentValue = uDv;
|
||||
var tradePosiVal = posiList.Sum(s => s.DV01);
|
||||
var posiVal = positionList.Where(x => !x.Current).Sum(s => s.DV01);
|
||||
@@ -5240,10 +5250,11 @@ namespace YLErp.Modules.RiskModule
|
||||
{
|
||||
double? currentValue = null;
|
||||
double tradeValue = 0;
|
||||
double pnl = 0;
|
||||
switch (checkItem.quotaType)
|
||||
{
|
||||
case "DV01":
|
||||
tradeValue = GetTradePositionDv01();
|
||||
tradeValue = GetTradePositionDv01(ref pnl);
|
||||
currentValue = tradeValue + Convert.ToDouble(positionList.Sum(s => s.DV01));
|
||||
var posiVal = positionList.Where(x => !x.Current).Sum(s => s.DV01);
|
||||
if (!ValidateQuoteResult(checkItem, currentValue, Convert.ToDouble(posiVal) + tradeValue))
|
||||
@@ -5261,9 +5272,8 @@ namespace YLErp.Modules.RiskModule
|
||||
/// 算标的交易dv01
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private double GetTradePositionDv01()
|
||||
private double GetTradePositionDv01(ref double pnl)
|
||||
{
|
||||
var dealDate = QdpCalendarHelper.GetNonHolidayDefore(valuedateBLL.ValueDate.AddDays(-1));
|
||||
double currentValue = 0;
|
||||
List<string> tradetypes = new List<string> { "利率债", "信用债", "其它债券" };
|
||||
var tposis = DbContext.TradePosition.Where(x => tradetypes.Contains(x.TradeType)).AsNoTracking().ToList();
|
||||
@@ -5284,13 +5294,14 @@ namespace YLErp.Modules.RiskModule
|
||||
}
|
||||
else
|
||||
{
|
||||
var bondPrice = EodPriceQueryService.GetBondPrice(dealDate, item.UnderlyingCode);
|
||||
var bondPrice = EodPriceQueryService.GetBondPrice(valuedateBLL.ValueDate, item.UnderlyingCode);
|
||||
lastPrice = bondPrice != null ? bondPrice.ClosePrice : (um.Price ?? 0) * Convert.ToDouble(ConsGlobal.bondPriceMultiple);
|
||||
vobp = bondPrice != null ? bondPrice.Vobp ?? 0 : 0;
|
||||
}
|
||||
}
|
||||
var DV01 = Convert.ToDouble(vobp) * Math.Abs(item.Position) * contractSize * 0.01 * (item.PositionType == PositionTypeFlag.Long ? 1 : -1);
|
||||
var DV01 = Convert.ToDouble(vobp) * item.Position * contractSize * 0.01;
|
||||
currentValue += DV01;
|
||||
pnl += lastPrice * Math.Abs(item.Position) - Math.Abs(item.PositionCost);
|
||||
}
|
||||
return currentValue;
|
||||
}
|
||||
@@ -5513,7 +5524,7 @@ namespace YLErp.Modules.RiskModule
|
||||
return null;
|
||||
case "Delta金额":
|
||||
currentValue = Convert.ToDouble(current.Delta);
|
||||
|
||||
|
||||
if (!ValidateQuoteResult(checkItem))
|
||||
{
|
||||
return checkItem;
|
||||
@@ -5533,7 +5544,7 @@ namespace YLErp.Modules.RiskModule
|
||||
checkItem.currentValue = currentValue;
|
||||
if (!ValidateQuoteResult(checkItem))
|
||||
{
|
||||
|
||||
|
||||
return checkItem;
|
||||
}
|
||||
return null;
|
||||
@@ -5550,7 +5561,7 @@ namespace YLErp.Modules.RiskModule
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private List<string> checkUnderlying(List<CheckQuotaMoitorModel> positionList, List<CheckQuotaMoitorModel> posiList, string tag_prefix, QuotaSetting[] settings, List<QuotaSetting> settingAll, bool warning)
|
||||
@@ -5618,11 +5629,6 @@ namespace YLErp.Modules.RiskModule
|
||||
messageList.Add(SetQuotaMsg(tag, setting.QuotaIndex, currentValue, Convert.ToDouble(tradePosiVal), posiVal, Convert.ToDouble(current.Pv), Convert.ToDouble(noPosiVal), null, upperLimit, lowerLimit, setting.Percent, warning));
|
||||
break;
|
||||
case "轧差集中度":
|
||||
//if (current.Circulation == 0)
|
||||
//{
|
||||
// messageList.Add($"{tag}:{current.UnderlyingCode}发行规模数据未维护");
|
||||
// break;
|
||||
//}
|
||||
currentValue = current.Circulation == 0 ? 0 : currentValue / Convert.ToDouble(current.Circulation);
|
||||
tradePosiVal = current.Circulation == 0 ? 0 : tradePosiVal / current.Circulation;
|
||||
posiVal = current.Circulation == 0 ? 0 : posiVal / Convert.ToDouble(current.Circulation);
|
||||
@@ -5652,14 +5658,14 @@ namespace YLErp.Modules.RiskModule
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var noQuoteSetting = settingAll.FirstOrDefault(x => x.QuotaType == QuotaTypeEnum.UNDERLYING && x.QuotaRange == quotaRange && x.QuotaIndex== checkItem.quotaType&&!x.Precheck);//是否设置了不事前检查
|
||||
var noQuoteSetting = settingAll.FirstOrDefault(x => x.QuotaType == QuotaTypeEnum.UNDERLYING && x.QuotaRange == quotaRange && x.QuotaIndex == checkItem.quotaType && !x.Precheck);//是否设置了不事前检查
|
||||
if (noQuoteSetting != null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
currentPv = positionList.Where(s => s.UnderlyingCode == current.UnderlyingCode).Sum(s => s.Pv * (s.Side == 0 ? 1 : -1));
|
||||
currentValue = Convert.ToDouble(currentPv);
|
||||
currentValue = Math.Abs(currentValue??0);
|
||||
currentValue = Math.Abs(currentValue ?? 0);
|
||||
posiPv = positionList.Where(s => s.UnderlyingCode == current.UnderlyingCode && !s.Current).Sum(s => s.Pv * (s.Side == 0 ? 1 : -1));
|
||||
posiVal = Convert.ToDouble(posiPv);
|
||||
var tag = $"{tag_prefix}({checkItem.quotaType})";
|
||||
@@ -5673,10 +5679,6 @@ namespace YLErp.Modules.RiskModule
|
||||
}
|
||||
return null;
|
||||
case "轧差集中度":
|
||||
//if (current.Circulation == 0)
|
||||
//{
|
||||
// throw new Exception($"{tag}:{current.UnderlyingCode}发行规模数据未维护");
|
||||
//}
|
||||
currentValue = current.Circulation == 0 ? 0 : currentValue / Convert.ToDouble(current.Circulation);
|
||||
posiPv = positionList.Where(s => s.UnderlyingCode == current.UnderlyingCode && !s.Current).Sum(s => s.Pv);
|
||||
posiVal = current.Circulation == 0 ? 0 : Convert.ToDouble(posiPv / current.Circulation);
|
||||
@@ -5706,7 +5708,7 @@ namespace YLErp.Modules.RiskModule
|
||||
CheckQuotaMoitorModel current = positionList.FirstOrDefault(x => x.Current);
|
||||
//settings 可能包含全部
|
||||
var settingItem = settings.First();
|
||||
var noQuoteSetting = settingAll.FirstOrDefault(x => x.QuotaType == settingItem.QuotaType && x.QuotaRange == settingItem.QuotaRange &&x.QuotaIndex==settingItem.QuotaIndex && !x.Precheck);//是否设置了不事前检查
|
||||
var noQuoteSetting = settingAll.FirstOrDefault(x => x.QuotaType == settingItem.QuotaType && x.QuotaRange == settingItem.QuotaRange && x.QuotaIndex == settingItem.QuotaIndex && !x.Precheck);//是否设置了不事前检查
|
||||
if (noQuoteSetting != null)
|
||||
{
|
||||
return messageList;
|
||||
@@ -5780,7 +5782,7 @@ namespace YLErp.Modules.RiskModule
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var noQuoteSetting = settingAll.FirstOrDefault(x => x.QuotaType == QuotaTypeEnum.CLIENT && x.QuotaRange == quotaRange&&x.QuotaIndex== checkItem.quotaType && !x.Precheck);//是否设置了不事前检查
|
||||
var noQuoteSetting = settingAll.FirstOrDefault(x => x.QuotaType == QuotaTypeEnum.CLIENT && x.QuotaRange == quotaRange && x.QuotaIndex == checkItem.quotaType && !x.Precheck);//是否设置了不事前检查
|
||||
if (noQuoteSetting != null)
|
||||
{
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user