|
|
|
@@ -1,10 +1,12 @@
|
|
|
|
|
using BaseOUDAL;
|
|
|
|
|
using ClosedXML.Report.Utils;
|
|
|
|
|
using Confluent.Kafka;
|
|
|
|
|
using CsvHelper;
|
|
|
|
|
using Dapper;
|
|
|
|
|
using DocumentFormat.OpenXml.Office.CustomUI;
|
|
|
|
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
|
|
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
|
|
|
using Org.BouncyCastle.Asn1.Ocsp;
|
|
|
|
|
using Qdp.Foundation.Utilities;
|
|
|
|
|
using Qdp.Pricing.Ecosystem.Trade.FixedIncome;
|
|
|
|
|
using Qdp.Pricing.Library.Base.Utilities;
|
|
|
|
@@ -19,6 +21,7 @@ using YLErp.Abstract.DataProviders;
|
|
|
|
|
using YLErp.BLL;
|
|
|
|
|
using YLErp.BLL.Calculation;
|
|
|
|
|
using YLErp.BLL.Eod;
|
|
|
|
|
using YLErp.BLL.EodSettlement;
|
|
|
|
|
using YLErp.BLL.Hedge;
|
|
|
|
|
using YLErp.Commons;
|
|
|
|
|
using YLErp.DataBase;
|
|
|
|
@@ -81,11 +84,12 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
var req = new QuotaMonitorReq
|
|
|
|
|
{
|
|
|
|
|
PvPercent = PS.Config.ErpElement.EodVarPvPercent,
|
|
|
|
|
UseCalcCreditExposure = true
|
|
|
|
|
UseCalcCreditExposure = true,
|
|
|
|
|
ValueDate= settlementDate
|
|
|
|
|
};
|
|
|
|
|
//全局
|
|
|
|
|
{
|
|
|
|
|
var list = QueryGlobalFromCalc(req);
|
|
|
|
|
var list = QueryEodGlobalFromCalc(req);
|
|
|
|
|
list.ForEach(O =>
|
|
|
|
|
{
|
|
|
|
|
O.id = 0;
|
|
|
|
@@ -165,130 +169,9 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
});
|
|
|
|
|
DbContext.QuotaMonitor_Global.AddRange(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//资产汇总
|
|
|
|
|
{
|
|
|
|
|
var list = QueryAssetFromCalc(req);
|
|
|
|
|
list.ForEach(O =>
|
|
|
|
|
{
|
|
|
|
|
O.id = 0;
|
|
|
|
|
O.ValueDate = settlementDate;
|
|
|
|
|
O.UnderlyingCode ??= "";
|
|
|
|
|
O.StockEqvNotional = O.StockEqvNotional.IsNormalize() ? O.StockEqvNotional : null;
|
|
|
|
|
O.Quota_StockEqvNotional_Upper = O.Quota_StockEqvNotional_Upper.IsNormalize() ? O.Quota_StockEqvNotional_Upper : null;
|
|
|
|
|
O.Quota_StockEqvNotional_Lower = O.Quota_StockEqvNotional_Lower.IsNormalize() ? O.Quota_StockEqvNotional_Lower : null;
|
|
|
|
|
O.Quota_StockEqvNotional_wUpper = O.Quota_StockEqvNotional_wUpper.IsNormalize() ? O.Quota_StockEqvNotional_wUpper : null;
|
|
|
|
|
O.Quota_StockEqvNotional_wLower = O.Quota_StockEqvNotional_wLower.IsNormalize() ? O.Quota_StockEqvNotional_wLower : null;
|
|
|
|
|
O.DeltaExposure = O.DeltaExposure.IsNormalize() ? O.DeltaExposure : null;
|
|
|
|
|
O.Quota_DeltaExposure_Upper = O.Quota_DeltaExposure_Upper.IsNormalize() ? O.Quota_DeltaExposure_Upper : null;
|
|
|
|
|
O.Quota_DeltaExposure_Lower = O.Quota_DeltaExposure_Lower.IsNormalize() ? O.Quota_DeltaExposure_Lower : null;
|
|
|
|
|
O.Quota_DeltaExposure_wUpper = O.Quota_DeltaExposure_wUpper.IsNormalize() ? O.Quota_DeltaExposure_wUpper : null;
|
|
|
|
|
O.Quota_DeltaExposure_wLower = O.Quota_DeltaExposure_wLower.IsNormalize() ? O.Quota_DeltaExposure_wLower : null;
|
|
|
|
|
O.DeltaNetExposure = O.DeltaNetExposure.IsNormalize() ? O.DeltaNetExposure : null;
|
|
|
|
|
O.Quota_DeltaNetExposure_Upper = O.Quota_DeltaNetExposure_Upper.IsNormalize() ? O.Quota_DeltaNetExposure_Upper : null;
|
|
|
|
|
O.Quota_DeltaNetExposure_Lower = O.Quota_DeltaNetExposure_Lower.IsNormalize() ? O.Quota_DeltaNetExposure_Lower : null;
|
|
|
|
|
O.Quota_DeltaNetExposure_wUpper = O.Quota_DeltaNetExposure_wUpper.IsNormalize() ? O.Quota_DeltaNetExposure_wUpper : null;
|
|
|
|
|
O.Quota_DeltaNetExposure_wLower = O.Quota_DeltaNetExposure_wLower.IsNormalize() ? O.Quota_DeltaNetExposure_wLower : null;
|
|
|
|
|
O.DeltaCash = O.DeltaCash.IsNormalize() ? O.DeltaCash : null;
|
|
|
|
|
O.Quota_DeltaCash_Upper = O.Quota_DeltaCash_Upper.IsNormalize() ? O.Quota_DeltaCash_Upper : null;
|
|
|
|
|
O.Quota_DeltaCash_Lower = O.Quota_DeltaCash_Lower.IsNormalize() ? O.Quota_DeltaCash_Lower : null;
|
|
|
|
|
O.Quota_DeltaCash_wUpper = O.Quota_DeltaCash_wUpper.IsNormalize() ? O.Quota_DeltaCash_wUpper : null;
|
|
|
|
|
O.Quota_DeltaCash_wLower = O.Quota_DeltaCash_wLower.IsNormalize() ? O.Quota_DeltaCash_wLower : null;
|
|
|
|
|
O.GammaCash = O.GammaCash.IsNormalize() ? O.GammaCash : null;
|
|
|
|
|
O.Quota_GammaCash_Upper = O.Quota_GammaCash_Upper.IsNormalize() ? O.Quota_GammaCash_Upper : null;
|
|
|
|
|
O.Quota_GammaCash_Lower = O.Quota_GammaCash_Lower.IsNormalize() ? O.Quota_GammaCash_Lower : null;
|
|
|
|
|
O.Quota_GammaCash_wUpper = O.Quota_GammaCash_wUpper.IsNormalize() ? O.Quota_GammaCash_wUpper : null;
|
|
|
|
|
O.Quota_GammaCash_wLower = O.Quota_GammaCash_wLower.IsNormalize() ? O.Quota_GammaCash_wLower : null;
|
|
|
|
|
O.Vega = O.Vega.IsNormalize() ? O.Vega : null;
|
|
|
|
|
O.Quota_Vega_Upper = O.Quota_Vega_Upper.IsNormalize() ? O.Quota_Vega_Upper : null;
|
|
|
|
|
O.Quota_Vega_Lower = O.Quota_Vega_Lower.IsNormalize() ? O.Quota_Vega_Lower : null;
|
|
|
|
|
O.Quota_Vega_wUpper = O.Quota_Vega_wUpper.IsNormalize() ? O.Quota_Vega_wUpper : null;
|
|
|
|
|
O.Quota_Vega_wLower = O.Quota_Vega_wLower.IsNormalize() ? O.Quota_Vega_wLower : null;
|
|
|
|
|
O.VegaCash = O.VegaCash.IsNormalize() ? O.VegaCash : null;
|
|
|
|
|
O.Quota_VegaCash_Upper = O.Quota_VegaCash_Upper.IsNormalize() ? O.Quota_VegaCash_Upper : null;
|
|
|
|
|
O.Quota_VegaCash_Lower = O.Quota_VegaCash_Lower.IsNormalize() ? O.Quota_VegaCash_Lower : null;
|
|
|
|
|
O.Quota_VegaCash_wUpper = O.Quota_VegaCash_wUpper.IsNormalize() ? O.Quota_VegaCash_wUpper : null;
|
|
|
|
|
O.Quota_VegaCash_wLower = O.Quota_VegaCash_wLower.IsNormalize() ? O.Quota_VegaCash_wLower : null;
|
|
|
|
|
O.Concentration = O.Concentration.IsNormalize() ? O.Concentration : null;
|
|
|
|
|
O.Quota_Concentration_Upper = O.Quota_Concentration_Upper.IsNormalize() ? O.Quota_Concentration_Upper : null;
|
|
|
|
|
O.Quota_Concentration_Lower = O.Quota_Concentration_Lower.IsNormalize() ? O.Quota_Concentration_Lower : null;
|
|
|
|
|
O.Quota_Concentration_wUpper = O.Quota_Concentration_wUpper.IsNormalize() ? O.Quota_Concentration_wUpper : null;
|
|
|
|
|
O.Quota_Concentration_wLower = O.Quota_Concentration_wLower.IsNormalize() ? O.Quota_Concentration_wLower : null;
|
|
|
|
|
O.PositionPnl = O.PositionPnl.IsNormalize() ? O.PositionPnl : null;
|
|
|
|
|
O.Quota_PositionPnl_Upper = O.Quota_PositionPnl_Upper.IsNormalize() ? O.Quota_PositionPnl_Upper : null;
|
|
|
|
|
O.Quota_PositionPnl_Lower = O.Quota_PositionPnl_Lower.IsNormalize() ? O.Quota_PositionPnl_Lower : null;
|
|
|
|
|
O.Quota_PositionPnl_wUpper = O.Quota_PositionPnl_wUpper.IsNormalize() ? O.Quota_PositionPnl_wUpper : null;
|
|
|
|
|
O.Quota_PositionPnl_wLower = O.Quota_PositionPnl_wLower.IsNormalize() ? O.Quota_PositionPnl_wLower : null;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
DbContext.QuotaMonitor_Asset.AddRange(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//品种汇总
|
|
|
|
|
{
|
|
|
|
|
var list = QueryVarietyFromCalc(req);
|
|
|
|
|
list.ForEach(O =>
|
|
|
|
|
{
|
|
|
|
|
O.id = 0;
|
|
|
|
|
O.ValueDate = settlementDate;
|
|
|
|
|
O.UnderlyingCode ??= "";
|
|
|
|
|
O.StockEqvNotional = O.StockEqvNotional.IsNormalize() ? O.StockEqvNotional : null;
|
|
|
|
|
O.Quota_StockEqvNotional_Upper = O.Quota_StockEqvNotional_Upper.IsNormalize() ? O.Quota_StockEqvNotional_Upper : null;
|
|
|
|
|
O.Quota_StockEqvNotional_Lower = O.Quota_StockEqvNotional_Lower.IsNormalize() ? O.Quota_StockEqvNotional_Lower : null;
|
|
|
|
|
O.Quota_StockEqvNotional_wUpper = O.Quota_StockEqvNotional_wUpper.IsNormalize() ? O.Quota_StockEqvNotional_wUpper : null;
|
|
|
|
|
O.Quota_StockEqvNotional_wLower = O.Quota_StockEqvNotional_wLower.IsNormalize() ? O.Quota_StockEqvNotional_wLower : null;
|
|
|
|
|
O.DeltaExposure = O.DeltaExposure.IsNormalize() ? O.DeltaExposure : null;
|
|
|
|
|
O.Quota_DeltaExposure_Upper = O.Quota_DeltaExposure_Upper.IsNormalize() ? O.Quota_DeltaExposure_Upper : null;
|
|
|
|
|
O.Quota_DeltaExposure_Lower = O.Quota_DeltaExposure_Lower.IsNormalize() ? O.Quota_DeltaExposure_Lower : null;
|
|
|
|
|
O.Quota_DeltaExposure_wUpper = O.Quota_DeltaExposure_wUpper.IsNormalize() ? O.Quota_DeltaExposure_wUpper : null;
|
|
|
|
|
O.Quota_DeltaExposure_wLower = O.Quota_DeltaExposure_wLower.IsNormalize() ? O.Quota_DeltaExposure_wLower : null;
|
|
|
|
|
O.DeltaNetExposure = O.DeltaNetExposure.IsNormalize() ? O.DeltaNetExposure : null;
|
|
|
|
|
O.Quota_DeltaNetExposure_Upper = O.Quota_DeltaNetExposure_Upper.IsNormalize() ? O.Quota_DeltaNetExposure_Upper : null;
|
|
|
|
|
O.Quota_DeltaNetExposure_Lower = O.Quota_DeltaNetExposure_Lower.IsNormalize() ? O.Quota_DeltaNetExposure_Lower : null;
|
|
|
|
|
O.Quota_DeltaNetExposure_wUpper = O.Quota_DeltaNetExposure_wUpper.IsNormalize() ? O.Quota_DeltaNetExposure_wUpper : null;
|
|
|
|
|
O.Quota_DeltaNetExposure_wLower = O.Quota_DeltaNetExposure_wLower.IsNormalize() ? O.Quota_DeltaNetExposure_wLower : null;
|
|
|
|
|
O.DeltaCash = O.DeltaCash.IsNormalize() ? O.DeltaCash : null;
|
|
|
|
|
O.Quota_DeltaCash_Upper = O.Quota_DeltaCash_Upper.IsNormalize() ? O.Quota_DeltaCash_Upper : null;
|
|
|
|
|
O.Quota_DeltaCash_Lower = O.Quota_DeltaCash_Lower.IsNormalize() ? O.Quota_DeltaCash_Lower : null;
|
|
|
|
|
O.Quota_DeltaCash_wUpper = O.Quota_DeltaCash_wUpper.IsNormalize() ? O.Quota_DeltaCash_wUpper : null;
|
|
|
|
|
O.Quota_DeltaCash_wLower = O.Quota_DeltaCash_wLower.IsNormalize() ? O.Quota_DeltaCash_wLower : null;
|
|
|
|
|
O.GammaCash = O.GammaCash.IsNormalize() ? O.GammaCash : null;
|
|
|
|
|
O.Quota_GammaCash_Upper = O.Quota_GammaCash_Upper.IsNormalize() ? O.Quota_GammaCash_Upper : null;
|
|
|
|
|
O.Quota_GammaCash_Lower = O.Quota_GammaCash_Lower.IsNormalize() ? O.Quota_GammaCash_Lower : null;
|
|
|
|
|
O.Quota_GammaCash_wUpper = O.Quota_GammaCash_wUpper.IsNormalize() ? O.Quota_GammaCash_wUpper : null;
|
|
|
|
|
O.Quota_GammaCash_wLower = O.Quota_GammaCash_wLower.IsNormalize() ? O.Quota_GammaCash_wLower : null;
|
|
|
|
|
O.Vega = O.Vega.IsNormalize() ? O.Vega : null;
|
|
|
|
|
O.Quota_Vega_Upper = O.Quota_Vega_Upper.IsNormalize() ? O.Quota_Vega_Upper : null;
|
|
|
|
|
O.Quota_Vega_Lower = O.Quota_Vega_Lower.IsNormalize() ? O.Quota_Vega_Lower : null;
|
|
|
|
|
O.Quota_Vega_wUpper = O.Quota_Vega_wUpper.IsNormalize() ? O.Quota_Vega_wUpper : null;
|
|
|
|
|
O.Quota_Vega_wLower = O.Quota_Vega_wLower.IsNormalize() ? O.Quota_Vega_wLower : null;
|
|
|
|
|
O.VegaCash = O.VegaCash.IsNormalize() ? O.VegaCash : null;
|
|
|
|
|
O.Quota_VegaCash_Upper = O.Quota_VegaCash_Upper.IsNormalize() ? O.Quota_VegaCash_Upper : null;
|
|
|
|
|
O.Quota_VegaCash_Lower = O.Quota_VegaCash_Lower.IsNormalize() ? O.Quota_VegaCash_Lower : null;
|
|
|
|
|
O.Quota_VegaCash_wUpper = O.Quota_VegaCash_wUpper.IsNormalize() ? O.Quota_VegaCash_wUpper : null;
|
|
|
|
|
O.Quota_VegaCash_wLower = O.Quota_VegaCash_wLower.IsNormalize() ? O.Quota_VegaCash_wLower : null;
|
|
|
|
|
O.Concentration = O.Concentration.IsNormalize() ? O.Concentration : null;
|
|
|
|
|
O.Quota_Concentration_Upper = O.Quota_Concentration_Upper.IsNormalize() ? O.Quota_Concentration_Upper : null;
|
|
|
|
|
O.Quota_Concentration_Lower = O.Quota_Concentration_Lower.IsNormalize() ? O.Quota_Concentration_Lower : null;
|
|
|
|
|
O.Quota_Concentration_wUpper = O.Quota_Concentration_wUpper.IsNormalize() ? O.Quota_Concentration_wUpper : null;
|
|
|
|
|
O.Quota_Concentration_wLower = O.Quota_Concentration_wLower.IsNormalize() ? O.Quota_Concentration_wLower : null;
|
|
|
|
|
O.PositionPnl = O.PositionPnl.IsNormalize() ? O.PositionPnl : null;
|
|
|
|
|
O.Quota_PositionPnl_Upper = O.Quota_PositionPnl_Upper.IsNormalize() ? O.Quota_PositionPnl_Upper : null;
|
|
|
|
|
O.Quota_PositionPnl_Lower = O.Quota_PositionPnl_Lower.IsNormalize() ? O.Quota_PositionPnl_Lower : null;
|
|
|
|
|
O.Quota_PositionPnl_wUpper = O.Quota_PositionPnl_wUpper.IsNormalize() ? O.Quota_PositionPnl_wUpper : null;
|
|
|
|
|
O.Quota_PositionPnl_wLower = O.Quota_PositionPnl_wLower.IsNormalize() ? O.Quota_PositionPnl_wLower : null;
|
|
|
|
|
O.Theta = O.Theta.IsNormalize() ? O.Theta : null;
|
|
|
|
|
O.Quota_Theta_Upper = O.Quota_Theta_Upper.IsNormalize() ? O.Quota_Theta_Upper : null;
|
|
|
|
|
O.Quota_Theta_Lower = O.Quota_Theta_Lower.IsNormalize() ? O.Quota_Theta_Lower : null;
|
|
|
|
|
O.Quota_Theta_wUpper = O.Quota_Theta_wUpper.IsNormalize() ? O.Quota_Theta_wUpper : null;
|
|
|
|
|
O.Quota_Theta_wLower = O.Quota_Theta_wLower.IsNormalize() ? O.Quota_Theta_wLower : null;
|
|
|
|
|
});
|
|
|
|
|
DbContext.QuotaMonitor_Variety.AddRange(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//标的汇总
|
|
|
|
|
{
|
|
|
|
|
var list = QueryUnderlyingFromCalc(req);
|
|
|
|
|
var list = QueryEodUnderlyingFromCalc(req);
|
|
|
|
|
list.ForEach(O =>
|
|
|
|
|
{
|
|
|
|
|
O.id = 0;
|
|
|
|
@@ -356,7 +239,7 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
|
|
|
|
|
//客户汇总
|
|
|
|
|
{
|
|
|
|
|
var list = QueryClientFromCalc(req);
|
|
|
|
|
var list = QueryEodClientFromCalc(req);
|
|
|
|
|
list.ForEach(O =>
|
|
|
|
|
{
|
|
|
|
|
O.id = 0;
|
|
|
|
@@ -387,7 +270,7 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
|
|
|
|
|
//单笔交易
|
|
|
|
|
{
|
|
|
|
|
var list = QueryTradeFromCalc(req);
|
|
|
|
|
var list = QueryEodTradeFromCalc(req);
|
|
|
|
|
list.ForEach(O =>
|
|
|
|
|
{
|
|
|
|
|
O.id = 0;
|
|
|
|
@@ -437,8 +320,6 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
#region 落库
|
|
|
|
|
|
|
|
|
|
DbContext.BulkDelete<QuotaMonitor_Global>($"{nameof(QuotaMonitorBase.ValueDate)}='{settlementDate.ToString("yyyy-MM-dd")}'");
|
|
|
|
|
DbContext.BulkDelete<QuotaMonitor_Asset>($"{nameof(QuotaMonitorBase.ValueDate)}='{settlementDate.ToString("yyyy-MM-dd")}'");
|
|
|
|
|
DbContext.BulkDelete<QuotaMonitor_Variety>($"{nameof(QuotaMonitorBase.ValueDate)}='{settlementDate.ToString("yyyy-MM-dd")}'");
|
|
|
|
|
DbContext.BulkDelete<QuotaMonitor_Underlying>($"{nameof(QuotaMonitorBase.ValueDate)}='{settlementDate.ToString("yyyy-MM-dd")}'");
|
|
|
|
|
DbContext.BulkDelete<QuotaMonitor_Client>($"{nameof(QuotaMonitorBase.ValueDate)}='{settlementDate.ToString("yyyy-MM-dd")}'");
|
|
|
|
|
DbContext.BulkDelete<QuotaMonitor_Trade>($"{nameof(QuotaMonitorBase.ValueDate)}='{settlementDate.ToString("yyyy-MM-dd")}'");
|
|
|
|
@@ -696,7 +577,16 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
{
|
|
|
|
|
//SetDebugSqlLog();
|
|
|
|
|
var list = QueryFromDb<QuotaMonitor_Global>(req);
|
|
|
|
|
list.Reverse();
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
item.StockEqvNotional = item.StockEqvNotional.Normalize();
|
|
|
|
|
item.Quota_StockEqvNotional_Upper = item.Quota_StockEqvNotional_Upper?? double.NaN;
|
|
|
|
|
item.Quota_StockEqvNotional_Lower = item.Quota_StockEqvNotional_Lower?? double.NaN;
|
|
|
|
|
item.Quota_StockEqvNotional_wUpper = item.Quota_StockEqvNotional_wUpper?? double.NaN;
|
|
|
|
|
item.Quota_StockEqvNotional_wLower = item.Quota_StockEqvNotional_wLower?? double.NaN;
|
|
|
|
|
item.DeltaExposure = item.DeltaExposure.Normalize();
|
|
|
|
|
}
|
|
|
|
|
// list.Reverse();
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -719,6 +609,16 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
var clientName = DataCacheProvider.GetClientDataSource().GetData(req.ClientNumber)?.Name;
|
|
|
|
|
list = list.Where(O => O.ClientName == clientName).ToList();
|
|
|
|
|
}
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
item.StockEqvNotional = item.StockEqvNotional.Normalize();
|
|
|
|
|
item.Quota_StockEqvNotional_Upper = item.Quota_StockEqvNotional_Upper ?? double.NaN;
|
|
|
|
|
item.Quota_StockEqvNotional_Lower = item.Quota_StockEqvNotional_Lower ?? double.NaN;
|
|
|
|
|
item.Quota_StockEqvNotional_wUpper = item.Quota_StockEqvNotional_wUpper ?? double.NaN;
|
|
|
|
|
item.Quota_StockEqvNotional_wLower = item.Quota_StockEqvNotional_wLower ?? double.NaN;
|
|
|
|
|
item.PositionMargin = item.PositionMargin.Normalize();
|
|
|
|
|
item.AvailableFund = item.AvailableFund.Normalize();
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -753,7 +653,7 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
var list = QueryFromDb<QuotaMonitor_Trade>(req);
|
|
|
|
|
var tradeNumberList = list.Select(O => O.TradeNumber);
|
|
|
|
|
var query = DbContext.trade.Where(O => tradeNumberList.Contains(O.TradeNumber));
|
|
|
|
|
if (!req.TradeNumber.IsNullOrWhiteSpace())
|
|
|
|
|
if (!string.IsNullOrEmpty(req.TradeNumber))
|
|
|
|
|
{
|
|
|
|
|
queryStatus = true;
|
|
|
|
|
query = query.Where(O => O.TradeNumber == req.TradeNumber);
|
|
|
|
@@ -776,7 +676,7 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
on q.UnderlyingCode equals um.UnderlyingCode
|
|
|
|
|
select q;
|
|
|
|
|
}
|
|
|
|
|
if (!req.TradeType.IsNullOrWhiteSpace())
|
|
|
|
|
if (!string.IsNullOrEmpty(req.TradeType))
|
|
|
|
|
{
|
|
|
|
|
queryStatus = true;
|
|
|
|
|
query = query.Where(O => req.TradeType == O.TradeType || req.TradeType == O.StructureType);
|
|
|
|
@@ -801,27 +701,12 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
}
|
|
|
|
|
query = query.Where(O => date >= O.TradeDate);
|
|
|
|
|
}
|
|
|
|
|
if (!req.TradeStatus.IsNullOrWhiteSpace())
|
|
|
|
|
if (!string.IsNullOrEmpty(req.TradeStatus))
|
|
|
|
|
{
|
|
|
|
|
queryStatus = true;
|
|
|
|
|
query = query.Where(O => req.TradeStatus == O.TradeStatus);
|
|
|
|
|
}
|
|
|
|
|
if (req.ActualSubject != null && req.ActualSubject.Any())
|
|
|
|
|
{
|
|
|
|
|
queryStatus = true;
|
|
|
|
|
var clientDb = DbContextFactory.GetClientDbContext(OptUser);
|
|
|
|
|
var dict = clientDb.ClientMeta.Where(O => O.MetaKey == "同一主体").Select(O => new { O.ClientId, O.MetaValue });
|
|
|
|
|
var clientId = new List<int>();
|
|
|
|
|
foreach (var item in dict)
|
|
|
|
|
{
|
|
|
|
|
var arr = item.MetaValue.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
if (req.ActualSubject.Intersect(arr).Any())
|
|
|
|
|
{
|
|
|
|
|
clientId.Add(item.ClientId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
query = query.Where(O => clientId.Contains(O.ClientId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (req.TagIds != null && req.TagIds.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var tradeTagIdQuery = from tt in DbContext.trade_tag
|
|
|
|
@@ -852,6 +737,20 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
{
|
|
|
|
|
list = list.Where(O => req.UnderlyingId.Contains(O.UnderlyingId)).ToList();
|
|
|
|
|
}
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
item.StockEqvNotional = item.StockEqvNotional.Normalize();
|
|
|
|
|
item.Quota_StockEqvNotional_Upper = item.Quota_StockEqvNotional_Upper ?? double.NaN;
|
|
|
|
|
item.Quota_StockEqvNotional_Lower = item.Quota_StockEqvNotional_Lower ?? double.NaN;
|
|
|
|
|
item.Quota_StockEqvNotional_wUpper = item.Quota_StockEqvNotional_wUpper ?? double.NaN;
|
|
|
|
|
item.Quota_StockEqvNotional_wLower = item.Quota_StockEqvNotional_wLower ?? double.NaN;
|
|
|
|
|
item.DeltaExposure = item.DeltaExposure.Normalize();
|
|
|
|
|
item.Concentration= item.Concentration.Normalize();
|
|
|
|
|
item.Quota_Concentration_Lower = item.Quota_Concentration_Lower ?? double.NaN;
|
|
|
|
|
item.Quota_Concentration_Upper = item.Quota_Concentration_Upper ?? double.NaN;
|
|
|
|
|
item.Quota_Concentration_wUpper = item.Quota_Concentration_wUpper ?? double.NaN;
|
|
|
|
|
item.Quota_Concentration_wLower = item.Quota_Concentration_wLower ?? double.NaN;
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1055,6 +954,75 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询限额监控-全局数据-收盘
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<QuotaMonitor_Global> QueryEodGlobalFromCalc(QuotaMonitorReq req)
|
|
|
|
|
{
|
|
|
|
|
var posiQuery = DbContext.eod_swap_position.Where(O =>O.ValueDate==req.ValueDate&&O.PosiQuantity>0);
|
|
|
|
|
|
|
|
|
|
req.PvPercent = 1 - req.PvPercent;
|
|
|
|
|
|
|
|
|
|
var setValue = new Action<QuotaMonitor_Global, List<QuotaSetting>>((obj, settings) =>
|
|
|
|
|
{
|
|
|
|
|
obj.StockEqvNotional = Convert.ToDouble(posiQuery.Sum(s => s.PosiNotionalValue));
|
|
|
|
|
obj.DeltaExposure = posiQuery.Sum(O => Convert.ToDouble(O.PosiQuantity*(O.PositionType==(int)PositionTypeFlag.Long?1:-1)));
|
|
|
|
|
|
|
|
|
|
var stockEqvNotionalSettings = settings.Where(O => O.IsValid && O.Status == QuotaSettingApprovalStatus.Valid && O.QuotaRange == 0 && O.QuotaIndex == "名义本金").FirstOrDefault()?.Clone();
|
|
|
|
|
stockEqvNotionalSettings?.ConvertToAbs(valuedateBLL.SystemDate.BusinessTotalScale ?? 0);
|
|
|
|
|
obj.Quota_StockEqvNotional_Upper = stockEqvNotionalSettings?.QuotaUpperLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_StockEqvNotional_Lower = stockEqvNotionalSettings?.QuotaLowerLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_StockEqvNotional_wUpper = stockEqvNotionalSettings?.WarningUpperLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_StockEqvNotional_wLower = stockEqvNotionalSettings?.WarningLowerLimit ?? double.NaN;
|
|
|
|
|
|
|
|
|
|
var deltaExposureSettings = settings.Where(O => O.IsValid && O.Status == QuotaSettingApprovalStatus.Valid && O.QuotaRange == 0 && O.QuotaIndex == "Delta敞口(多空比)").FirstOrDefault()?.Clone();
|
|
|
|
|
obj.Quota_DeltaExposure_Upper = deltaExposureSettings?.QuotaUpperLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_DeltaExposure_Lower = deltaExposureSettings?.QuotaLowerLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_DeltaExposure_wUpper = deltaExposureSettings?.WarningUpperLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_DeltaExposure_wLower = deltaExposureSettings?.WarningLowerLimit ?? double.NaN;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var allSetting = QueryCurrentQuotaSetting(QuotaTypeEnum.GLOBAL_ALL);
|
|
|
|
|
allSetting = MargeQuotaSetting(allSetting, 0, 0);
|
|
|
|
|
var swapSetting = QueryCurrentQuotaSetting(QuotaTypeEnum.GLOBAL_SWAP);
|
|
|
|
|
swapSetting = MargeQuotaSetting(swapSetting, 0, 0);
|
|
|
|
|
var swap = new QuotaMonitor_Global()
|
|
|
|
|
{
|
|
|
|
|
ParentKey = "场外",
|
|
|
|
|
BusinessType = "互换",
|
|
|
|
|
};
|
|
|
|
|
setValue(swap, swapSetting);
|
|
|
|
|
var underly = GetEodTradePositionPnl(req.ValueDate);
|
|
|
|
|
var unTrade = new QuotaMonitor_Global()
|
|
|
|
|
{
|
|
|
|
|
ParentKey = "场外",
|
|
|
|
|
BusinessType = "未簿记合约",
|
|
|
|
|
StockEqvNotional = 0,
|
|
|
|
|
DeltaExposure = 0
|
|
|
|
|
};
|
|
|
|
|
var all = new QuotaMonitor_Global()
|
|
|
|
|
{
|
|
|
|
|
BusinessType = "全局",
|
|
|
|
|
StockEqvNotional = swap.StockEqvNotional,
|
|
|
|
|
PositionPnl = underly.PositionPnl + swap.PositionPnl,
|
|
|
|
|
DeltaExposure = swap.DeltaExposure+ underly.DeltaExposure
|
|
|
|
|
};
|
|
|
|
|
var list = new List<QuotaMonitor_Global>
|
|
|
|
|
{
|
|
|
|
|
swap,
|
|
|
|
|
underly,
|
|
|
|
|
unTrade,
|
|
|
|
|
all
|
|
|
|
|
};
|
|
|
|
|
for (var i = 0; i < list.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
list[i].id = -1 - i;
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void GuangFaOnOptionHandleGammaAndTheta(trade t, realtime_trade_risk risk)
|
|
|
|
|
{
|
|
|
|
|
if (t.ExerciseDate.HasValue)
|
|
|
|
@@ -1190,6 +1158,88 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询限额监控-客户数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<QuotaMonitor_Client> QueryEodClientFromCalc(QuotaMonitorReq req)
|
|
|
|
|
{
|
|
|
|
|
var clientIds = DbContext.eod_swap.Where(x => x.NotionalValue > 0&&x.ValueDate==req.ValueDate).AsNoTracking().Select(s=>s.ClientId).Distinct().ToList();
|
|
|
|
|
var setValue = new Action<QuotaMonitor_Client, List<QuotaSetting>>((obj, settings) =>
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
stockEqvNotionalSettings = stockEqvNotionalSettingsClient.Clone();
|
|
|
|
|
}
|
|
|
|
|
stockEqvNotionalSettings?.ConvertToAbs(obj.ProductScale.GetValueOrDefault());
|
|
|
|
|
obj.Quota_StockEqvNotional_Upper = stockEqvNotionalSettings?.QuotaUpperLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_StockEqvNotional_Lower = stockEqvNotionalSettings?.QuotaLowerLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_StockEqvNotional_wUpper = stockEqvNotionalSettings?.WarningUpperLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_StockEqvNotional_wLower = stockEqvNotionalSettings?.WarningLowerLimit ?? double.NaN;
|
|
|
|
|
});
|
|
|
|
|
var list = new List<QuotaMonitor_Client>();
|
|
|
|
|
|
|
|
|
|
var setting = QueryCurrentQuotaSetting(QuotaTypeEnum.CLIENT);
|
|
|
|
|
|
|
|
|
|
var creditList = DbContext.credit.Where(t =>
|
|
|
|
|
t.ProcessStatus == "已审批" &&
|
|
|
|
|
(!t.CreditDeadLine.HasValue ||
|
|
|
|
|
t.CreditDeadLine >= req.ValueDate) &&
|
|
|
|
|
(!t.CreditStartDate.HasValue ||
|
|
|
|
|
t.CreditStartDate <= req.ValueDate))
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var creditExposureDict = new Dictionary<int, double>();
|
|
|
|
|
var todayClientBalance = ClientBalanceUtility.GetClientBanlances(clientIds, DateTime.MinValue, req.ValueDate).ToList();
|
|
|
|
|
foreach (var item in todayClientBalance)
|
|
|
|
|
{
|
|
|
|
|
var c = new QuotaMonitor_Client();
|
|
|
|
|
var client = DataCacheProvider.GetClientDataSource().GetData(item.ClientId);
|
|
|
|
|
c.ClientId = item.ClientId;
|
|
|
|
|
c.ClientName = client.Name;
|
|
|
|
|
c.ClientNumber = client.Number;
|
|
|
|
|
c.AvailableFund = item.AvailableAmount;
|
|
|
|
|
c.Credit = item.TotalCredit;
|
|
|
|
|
c.PayableFund = item.PayableFund;
|
|
|
|
|
c.PositionMargin = item.MinusPayableMargin;
|
|
|
|
|
c.StockEqvNotional = item.PositionNotionalPrincipal;
|
|
|
|
|
var credits = creditList.Where(O => O.ClientId == item.ClientId && O.StockEqvNotional.IsNormalize()).Select(O => O.StockEqvNotional).ToArray();
|
|
|
|
|
c.StockEqvNotionalScale = credits.Any() ? (credits.Sum() ?? double.NaN) : double.NaN;
|
|
|
|
|
c.AvailableStockEqvNotional = c.StockEqvNotionalScale - c.StockEqvNotional;
|
|
|
|
|
c.CreditExposure = creditExposureDict.ContainsKey(item.ClientId) ? creditExposureDict[item.ClientId] : null;
|
|
|
|
|
list.Add(c);
|
|
|
|
|
}
|
|
|
|
|
var totalProductScale = list.Sum(O => O.ProductScale) ?? 0;
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
setValue(item, setting);
|
|
|
|
|
}
|
|
|
|
|
var totalscale = list.Where(O => O.StockEqvNotionalScale.IsNormalize()).Select(O => O.StockEqvNotionalScale);
|
|
|
|
|
var total = new QuotaMonitor_Client()
|
|
|
|
|
{
|
|
|
|
|
ClientNumber = "合计",
|
|
|
|
|
StockEqvNotionalScale = totalscale.Any() ? totalscale.Sum() : double.NaN,
|
|
|
|
|
StockEqvNotional = list.Sum(O => O.StockEqvNotional),
|
|
|
|
|
PositionMargin = list.Sum(O => O.PositionMargin),
|
|
|
|
|
AvailableFund = list.Sum(O => O.AvailableFund),
|
|
|
|
|
Credit = list.Sum(O => O.Credit),
|
|
|
|
|
PayableFund = list.Sum(O => O.PayableFund),
|
|
|
|
|
ProductScale = list.Sum(O => O.ProductScale),
|
|
|
|
|
HoldingFund = list.Sum(O => O.HoldingFund),
|
|
|
|
|
ClientId = 0
|
|
|
|
|
};
|
|
|
|
|
total.HoldingRate = (total.HoldingFund / total.ProductScale).Normalize();
|
|
|
|
|
total.AvailableStockEqvNotional = total.StockEqvNotionalScale - total.StockEqvNotional;
|
|
|
|
|
setValue(total, setting);
|
|
|
|
|
list.Add(total);
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询限额监控-单笔交易数据
|
|
|
|
|
/// </summary>
|
|
|
|
@@ -1201,7 +1251,7 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
req.sidx = "TradeNumber";
|
|
|
|
|
req.sord = "asc";
|
|
|
|
|
var predicate = PredicateBuilder.True<trade>().And(t => ConsTrade.PositionTradeStatusList.Contains(t.TradeStatus) && t.ValidState != "InValid" && t.ExerciseDate >= SystemValueDate);
|
|
|
|
|
if (!req.TradeNumber.IsNullOrWhiteSpace())
|
|
|
|
|
if (!string.IsNullOrEmpty(req.TradeNumber))
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(O => O.TradeNumber.Contains(req.TradeNumber));
|
|
|
|
|
}
|
|
|
|
@@ -1218,7 +1268,7 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(O => req.UnderlyingId.Contains(O.UnderlyingId));
|
|
|
|
|
}
|
|
|
|
|
if (!req.TradeType.IsNullOrWhiteSpace())
|
|
|
|
|
if (!string.IsNullOrEmpty(req.TradeType))
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(O => req.TradeType == O.TradeType || req.TradeType == O.StructureType);
|
|
|
|
|
}
|
|
|
|
@@ -1239,7 +1289,7 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
}
|
|
|
|
|
predicate = predicate.And(O => date >= O.TradeDate);
|
|
|
|
|
}
|
|
|
|
|
if (!req.TradeStatus.IsNullOrWhiteSpace())
|
|
|
|
|
if (!string.IsNullOrEmpty(req.TradeStatus))
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(O => req.TradeStatus == O.TradeStatus);
|
|
|
|
|
}
|
|
|
|
@@ -1304,7 +1354,113 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询限额监控-单笔交易数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<QuotaMonitor_Trade> QueryEodTradeFromCalc(QuotaMonitorReq req)
|
|
|
|
|
{
|
|
|
|
|
var result = new List<QuotaMonitor_Trade>();
|
|
|
|
|
req.sidx = "TradeNumber";
|
|
|
|
|
req.sord = "asc";
|
|
|
|
|
var eodPredicate = PredicateBuilder.True<eod_swap>().And(t => t.NotionalValue>0&&t.ValueDate==req.ValueDate);
|
|
|
|
|
var predicate = PredicateBuilder.True<trade>().And(t => t.ValidState != "InValid" && t.ExerciseDate >= req.ValueDate);
|
|
|
|
|
if (!string.IsNullOrEmpty(req.TradeNumber))
|
|
|
|
|
{
|
|
|
|
|
eodPredicate = eodPredicate.And(O => O.SwapTradeNo.Contains(req.TradeNumber));
|
|
|
|
|
predicate = predicate.And(O => O.TradeNumber.Contains(req.TradeNumber));
|
|
|
|
|
}
|
|
|
|
|
if (req.ClientId != 0)
|
|
|
|
|
{
|
|
|
|
|
eodPredicate = eodPredicate.And(O => O.ClientId==req.ClientId);
|
|
|
|
|
predicate = predicate.And(O => req.ClientId == O.ClientId);
|
|
|
|
|
}
|
|
|
|
|
if (req.UnderlyingId?.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(O => req.UnderlyingId.Contains(O.UnderlyingId));
|
|
|
|
|
}
|
|
|
|
|
if (req.AssetId != 0)
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(O => req.AssetId == O.AssetId);
|
|
|
|
|
}
|
|
|
|
|
if (req.TradeDateStart != default)
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(O => req.TradeDateStart <= O.TradeDate);
|
|
|
|
|
}
|
|
|
|
|
if (req.TradeDateEnd != default)
|
|
|
|
|
{
|
|
|
|
|
var date = req.TradeDateEnd;
|
|
|
|
|
if (date < DateTime.MaxValue.Date)
|
|
|
|
|
{
|
|
|
|
|
date = date.AddDays(1);
|
|
|
|
|
}
|
|
|
|
|
predicate = predicate.And(O => date >= O.TradeDate);
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(req.TradeStatus))
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(O => req.TradeStatus == O.TradeStatus);
|
|
|
|
|
}
|
|
|
|
|
var posiQuery = from t in DbContext.trade.Where(predicate)
|
|
|
|
|
join p in DbContext.eod_swap.Where(eodPredicate) on t.id equals p.SwapTradeId
|
|
|
|
|
select new QuotaMonitor_TradeDto()
|
|
|
|
|
{
|
|
|
|
|
trade = t,
|
|
|
|
|
ClientId = t.ClientId,
|
|
|
|
|
TradeNumber = t.TradeNumber,
|
|
|
|
|
ClientName = t.ClientName,
|
|
|
|
|
StockEqvNotional = Convert.ToDouble(p.NotionalValue),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var list = posiQuery.ToList();
|
|
|
|
|
|
|
|
|
|
var setValue = new Action<QuotaMonitor_Trade, List<QuotaSetting>>((obj, settings) =>
|
|
|
|
|
{
|
|
|
|
|
var temp = settings.Where(O => O.IsValid && O.Status == QuotaSettingApprovalStatus.Valid && O.QuotaRange == 0);
|
|
|
|
|
var stockEqvNotionalSetting = temp.Where(O => O.QuotaIndex == "名义本金").FirstOrDefault()?.Clone();
|
|
|
|
|
stockEqvNotionalSetting?.ConvertToAbs(valuedateBLL.SystemDate.BusinessTotalScale ?? 0);
|
|
|
|
|
obj.Quota_StockEqvNotional_Upper = stockEqvNotionalSetting?.QuotaUpperLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_StockEqvNotional_Lower = stockEqvNotionalSetting?.QuotaLowerLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_StockEqvNotional_wUpper = stockEqvNotionalSetting?.WarningUpperLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_StockEqvNotional_wLower = stockEqvNotionalSetting?.WarningLowerLimit ?? double.NaN;
|
|
|
|
|
var swapPercentSetting = temp.Where(O => O.QuotaIndex == "互换价格偏离比例").FirstOrDefault()?.Clone();
|
|
|
|
|
obj.Quota_SwapPercent_Upper = swapPercentSetting?.QuotaUpperLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_SwapPercent_Lower = swapPercentSetting?.QuotaLowerLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_SwapPercent_wUpper = swapPercentSetting?.WarningUpperLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_SwapPercent_wLower = swapPercentSetting?.WarningLowerLimit ?? double.NaN;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var setting = QueryCurrentQuotaSetting(QuotaTypeEnum.TRADE);
|
|
|
|
|
setting = MargeQuotaSetting(setting, 0, 0);
|
|
|
|
|
var ccrDict = new Dictionary<int, double>();
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
setValue(item, setting);
|
|
|
|
|
var sportPrice = item.trade.SpotPrice ?? 0;
|
|
|
|
|
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);
|
|
|
|
|
item.Quota_SwapPercent = pricePercent;
|
|
|
|
|
var obj = new QuotaMonitor_Trade();
|
|
|
|
|
ObjectHelper.MapValues(obj, item);
|
|
|
|
|
result.Add(obj);
|
|
|
|
|
}
|
|
|
|
|
var total = new QuotaMonitor_Trade()
|
|
|
|
|
{
|
|
|
|
|
TradeNumber = "合计",
|
|
|
|
|
StockEqvNotional = result.Sum(O => O.StockEqvNotional),
|
|
|
|
|
DeltaCash = result.Sum(O => O.DeltaCash),
|
|
|
|
|
GammaCash = result.Sum(O => O.GammaCash),
|
|
|
|
|
Vega = result.Sum(O => O.Vega),
|
|
|
|
|
VegaCash = result.Sum(O => O.VegaCash),
|
|
|
|
|
Quota_CCR = result.Sum(O => O.Quota_CCR),
|
|
|
|
|
PnL = result.Sum(O => O.PnL),
|
|
|
|
|
};
|
|
|
|
|
result.Add(total);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询限额监控-资产汇总数据
|
|
|
|
|
/// </summary>
|
|
|
|
@@ -1984,6 +2140,96 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询限额监控-标的汇总数据-收盘
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<QuotaMonitor_Underlying> QueryEodUnderlyingFromCalc(QuotaMonitorReq req)
|
|
|
|
|
{
|
|
|
|
|
var result = new List<QuotaMonitor_Underlying>();
|
|
|
|
|
var clientPositions = DbContext.eod_swap_position.Where(s=>s.ValueDate==req.ValueDate&&s.PosiQuantity>0).AsNoTracking().AsEnumerable();
|
|
|
|
|
List<QuotaMonitor_UnderlyingModel> underlyingModels = new List<QuotaMonitor_UnderlyingModel>();
|
|
|
|
|
foreach (var item in clientPositions)
|
|
|
|
|
{
|
|
|
|
|
var model = new QuotaMonitor_UnderlyingModel()
|
|
|
|
|
{
|
|
|
|
|
UnderlyingCode = item.UnderlyingCode,
|
|
|
|
|
StockEqvNotional = Convert.ToDouble(item.PosiNotionalValue),
|
|
|
|
|
PositionType = item.PositionType,
|
|
|
|
|
Qty = item.PosiQuantity,
|
|
|
|
|
};
|
|
|
|
|
underlyingModels.Add(model);
|
|
|
|
|
}
|
|
|
|
|
var queryGroup = underlyingModels.GroupBy(g => g.UnderlyingCode).ToList();
|
|
|
|
|
var qutoList = new List<QuotaMonitor_UnderlyingDto>();
|
|
|
|
|
foreach (var item in queryGroup)
|
|
|
|
|
{
|
|
|
|
|
QuotaMonitor_UnderlyingDto dto = new QuotaMonitor_UnderlyingDto();
|
|
|
|
|
dto.UnderlyingCode = item.Key;
|
|
|
|
|
dto.StockEqvNotional = Math.Abs(item.Sum(s => s.StockEqvNotional * (s.PositionType == (int)PositionTypeFlag.Long ? 1 : -1)));
|
|
|
|
|
qutoList.Add(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var underlyingCodes = qutoList.Select(s => s.UnderlyingCode).ToList();
|
|
|
|
|
var underlyings = DbContext.underlying_manager.Where(x => underlyingCodes.Contains(x.UnderlyingCode)).AsNoTracking().ToList();
|
|
|
|
|
foreach (var item in qutoList)
|
|
|
|
|
{
|
|
|
|
|
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.UnderlyingId = um?.id ?? 0;
|
|
|
|
|
if (um != null && um.IsBond())
|
|
|
|
|
{
|
|
|
|
|
var bond = JsonHelper.Deserialize<UnderlyingBond>(um.ExJson);
|
|
|
|
|
quotaMonitor.Circulation = Convert.ToDouble((bond.IssueSize * 100000000m) ?? 0);
|
|
|
|
|
}
|
|
|
|
|
result.Add(quotaMonitor);
|
|
|
|
|
}
|
|
|
|
|
if (req.UnderlyingId != null && req.UnderlyingId.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
result = result.Where(O => req.UnderlyingId.Contains(O.UnderlyingId)).ToList();
|
|
|
|
|
}
|
|
|
|
|
var setValue = new Action<QuotaMonitor_Underlying, IEnumerable<QuotaSetting>, double>((obj, settings, tStockEqvNotional) =>
|
|
|
|
|
{
|
|
|
|
|
obj.Concentration = obj.Circulation == 0 ? double.NaN : obj.StockEqvNotional / obj.Circulation;
|
|
|
|
|
|
|
|
|
|
var stockEqvNotionalSetting = settings.Where(O => O.QuotaIndex == "轧差名义本金" && O.QuotaRange == obj.UnderlyingId).FirstOrDefault()?.Clone();
|
|
|
|
|
if (stockEqvNotionalSetting == null)
|
|
|
|
|
{
|
|
|
|
|
stockEqvNotionalSetting = settings.Where(O => O.QuotaIndex == "轧差名义本金" && O.QuotaRange == 0).FirstOrDefault()?.Clone();
|
|
|
|
|
}
|
|
|
|
|
stockEqvNotionalSetting?.ConvertToAbs(valuedateBLL.SystemDate.BusinessTotalScale ?? 0);
|
|
|
|
|
obj.Quota_StockEqvNotional_Upper = stockEqvNotionalSetting?.QuotaUpperLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_StockEqvNotional_Lower = stockEqvNotionalSetting?.QuotaLowerLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_StockEqvNotional_wUpper = stockEqvNotionalSetting?.WarningUpperLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_StockEqvNotional_wLower = stockEqvNotionalSetting?.WarningLowerLimit ?? double.NaN;
|
|
|
|
|
|
|
|
|
|
var concentrationSetting = settings.Where(O => O.QuotaIndex == "轧差集中度" && O.QuotaRange == obj.UnderlyingId).FirstOrDefault()?.Clone();
|
|
|
|
|
if (concentrationSetting == null)
|
|
|
|
|
{
|
|
|
|
|
concentrationSetting = settings.Where(O => O.QuotaIndex == "轧差集中度" && O.QuotaRange == 0).FirstOrDefault()?.Clone();
|
|
|
|
|
}
|
|
|
|
|
obj.Quota_Concentration_Upper = concentrationSetting?.QuotaUpperLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_Concentration_Lower = concentrationSetting?.QuotaLowerLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_Concentration_wUpper = concentrationSetting?.WarningUpperLimit ?? double.NaN;
|
|
|
|
|
obj.Quota_Concentration_wLower = concentrationSetting?.WarningLowerLimit ?? double.NaN;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var totalStockEqvNotional = result.Sum(s => s.StockEqvNotional ?? 0);
|
|
|
|
|
var setting = QueryCurrentQuotaSetting(QuotaTypeEnum.UNDERLYING);
|
|
|
|
|
var codeList = new List<string>();
|
|
|
|
|
foreach (var item in result)
|
|
|
|
|
{
|
|
|
|
|
var tempSetting = setting.Where(O => O.IsValid && O.Status == QuotaSettingApprovalStatus.Valid && (O.QuotaRange == item.UnderlyingId || O.QuotaRange == 0));
|
|
|
|
|
setValue(item, tempSetting, totalStockEqvNotional);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.Sort((X, Y) => X.UnderlyingCode.CompareTo(Y.UnderlyingCode));
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询限额监控-簿记汇总数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req"></param>
|
|
|
|
@@ -5014,11 +5260,55 @@ namespace YLErp.Modules.RiskModule
|
|
|
|
|
}
|
|
|
|
|
quotaMonitor_Global.PositionPnl += lastPrice * item.Position - item.PositionCost;
|
|
|
|
|
quotaMonitor_Global.StockEqvNotional += item.PositionCost;
|
|
|
|
|
quotaMonitor_Global.DeltaExposure += (item.PositionType == PositionTypeFlag.Long ? -1 : 1) * item.Position;
|
|
|
|
|
quotaMonitor_Global.DeltaExposure += (item.PositionType == PositionTypeFlag.Long ? 1 : -1) * item.Position;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return quotaMonitor_Global;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 计算日终标的交易盈亏
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="valueDate"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private QuotaMonitor_Global GetEodTradePositionPnl(DateTime valueDate)
|
|
|
|
|
{
|
|
|
|
|
QuotaMonitor_Global quotaMonitor_Global = new QuotaMonitor_Global()
|
|
|
|
|
{
|
|
|
|
|
ParentKey = "场外",
|
|
|
|
|
BusinessType = "标的交易",
|
|
|
|
|
PositionPnl = 0,
|
|
|
|
|
DeltaExposure = 0,
|
|
|
|
|
StockEqvNotional = 0
|
|
|
|
|
};
|
|
|
|
|
List<string> tradetypes = new List<string> { "利率债", "信用债", "其它债券" };
|
|
|
|
|
var tposis = DbContext.eod_trade_position.Where(x => tradetypes.Contains(x.TradeType)&&x.ValueDate==valueDate).AsNoTracking().ToList();
|
|
|
|
|
var umCodes = tposis.Select(x => x.UnderlyingCode).Distinct().ToList();
|
|
|
|
|
var ums = DataCacheProvider.GetUnderlyingDataSource().AsQueryable().Where(x => umCodes.Contains(x.UnderlyingCode));
|
|
|
|
|
foreach (var item in tposis)
|
|
|
|
|
{
|
|
|
|
|
double lastPrice = 0;
|
|
|
|
|
var um = ums.FirstOrDefault(x => x.UnderlyingCode == item.UnderlyingCode);
|
|
|
|
|
double contractSize = 0;
|
|
|
|
|
if (um != null)
|
|
|
|
|
{
|
|
|
|
|
contractSize = um.ContractSize;
|
|
|
|
|
if (!um.IsBond())
|
|
|
|
|
{
|
|
|
|
|
lastPrice = EodPriceQueryService.GetClosePrice(valuedateBLL.ValueDate, item.UnderlyingCode);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var bondPrice = EodPriceQueryService.GetBondPrice(valuedateBLL.ValueDate, item.UnderlyingCode);
|
|
|
|
|
lastPrice = bondPrice != null ? bondPrice.ClosePrice : (um.Price ?? 0) * Convert.ToDouble(ConsGlobal.bondPriceMultiple);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
quotaMonitor_Global.PositionPnl += item.PositionPnL;
|
|
|
|
|
quotaMonitor_Global.StockEqvNotional += item.Cost;
|
|
|
|
|
quotaMonitor_Global.DeltaExposure += item.Amount;
|
|
|
|
|
}
|
|
|
|
|
quotaMonitor_Global.StockEqvNotional = Math.Abs(quotaMonitor_Global.StockEqvNotional??0);
|
|
|
|
|
return quotaMonitor_Global;
|
|
|
|
|
}
|
|
|
|
|
private List<string> checkGlobal(List<CheckQuotaMoitorModel> positionList, List<CheckQuotaMoitorModel> posiList, string tag_prefix, QuotaSetting[] settings, bool warning)
|
|
|
|
|
{
|
|
|
|
|
var messageList = new List<string>();
|
|
|
|
|