TRS-ZS-578 收盘增加风控存库

This commit is contained in:
shangzhongyuan
2025-08-05 13:18:03 +08:00
parent 69e1f0e995
commit 282554e2e9
9 changed files with 482 additions and 216 deletions
@@ -304,6 +304,7 @@ namespace YLErp.DBModels
/// <summary>
/// 标的发行量
/// </summary>
[NotMapped]
public double Circulation { get; set; }
/// <summary>
/// Theta
@@ -620,22 +621,18 @@ namespace YLErp.DBModels
/// <summary>
/// 名义本金限额
/// </summary>
[NotMapped]
public double? Quota_StockEqvNotional_Upper { get; set; } = double.NaN;
/// <summary>
/// 名义本金限额
/// </summary>
[NotMapped]
public double? Quota_StockEqvNotional_Lower { get; set; } = double.NaN;
/// <summary>
/// 名义本金限额
/// </summary>
[NotMapped]
public double? Quota_StockEqvNotional_wUpper { get; set; } = double.NaN;
/// <summary>
/// 名义本金限额
/// </summary>
[NotMapped]
public double? Quota_StockEqvNotional_wLower { get; set; } = double.NaN;
/// <summary>
@@ -1246,7 +1243,6 @@ namespace YLErp.DBModels
/// <summary>
/// 父节点代码
/// </summary>
[NotMapped]
public string ParentKey { get; set; }
public double? Theta { get; set; }
public double? Quota_Theta_Upper { get; set; } = double.NaN;
@@ -199,8 +199,6 @@ namespace YLErp.BLL.Eod
ProcessClientCash(lastSettletDate);
}
//计算winloss2
ProcessClientCash2(startDate);
//获取客户所有现存(抵押状态)抵押品信息
ProcessClientCashProduct();
@@ -496,6 +496,9 @@ namespace YLErp.Modules.CalculationModule
case "商品期货":
case "商品现货":
case "场内期权":
case "利率债":
case "信用债":
case "其它债券":
return BuySell.Contains("多头") ? "long" : "short";
case "股票":
default: return "long";
@@ -94,7 +94,7 @@ namespace YLErp.Modules.CalculationModule
var client = DataCacheProvider.GetClientDataSource().GetData(trade.ClientId);
var rate = new EodCurrencyRateService(OptUserInfo.SystemUser).GetCurrencyRate(trade.QuoteCurrency, trade.SettlementCurrency, valueDate, seekPreday: !isEodSettlement);
var rateTradeDate = new EodCurrencyRateService(OptUserInfo.SystemUser).GetCurrencyRate(trade.QuoteCurrency, trade.SettlementCurrency, trade.TradeDate.Value, seekPreday: !isEodSettlement);
var lastEodSwap = GetEodSwapData(trade, db);
var lastEodSwap = GetEodSwapData(trade, db,valueDate);
var pv = lastEodSwap.PostionValue;
var clientCashOut= db.ClientCashInCashOut.FirstOrDefault(x=>x.Action== "系统操作-期权费"&&x.TradeId== trade.id&&x.HappenDate<= valueDate) ;
var credit = db.credit.FirstOrDefault(x => x.CreditStartDate <= valueDate && x.CreditDeadLine >= valueDate && x.ClientId == trade.ClientId && x.ProcessStatus == "已审批");
@@ -149,23 +149,24 @@ namespace YLErp.Modules.CalculationModule
/// <param name="tradeId"></param>
/// <param name="db"></param>
/// <returns></returns>
private static eod_swap GetEodSwapData(OtcTradeBase trade, YLContext db)
private static eod_swap GetEodSwapData(OtcTradeBase trade, YLContext db,DateTime valueDate)
{
var eodSwap = new eod_swap();
var eodSwap = db.eod_swap.Where(x => x.SwapTradeId == trade.id && x.ValueDate == valueDate).FirstOrDefault();
if (eodSwap!=null)
{
return eodSwap;
}
eodSwap = new eod_swap();
var positions = db.swap_position.Where(x => x.PosiQuantity > 0 && !x.IsInitial && x.SwapTradeId == trade.id).ToList();
eodSwap.SwapTradeId = trade.id;
eodSwap.NotionalValueLong = positions.Where(x => x.PositionType == (int)PositionTypeFlag.Long).Sum(s => s.PosiNotionalValue);
eodSwap.NotionalValueShort = positions.Where(x => x.PositionType == (int)PositionTypeFlag.Short).Sum(s => s.PosiNotionalValue);
eodSwap.NotionalValue = eodSwap.NotionalValueLong + eodSwap.NotionalValueShort;
var lastEod = db.eod_swap.Where(x => x.SwapTradeId == trade.id && x.ValueDate <= valuedateBLL.ValueDate).OrderByDescending(o => o.ValueDate).FirstOrDefault();
eodSwap.RealizedPnL = lastEod?.RealizedPnL ?? 0;
eodSwap.InterestPnL = lastEod?.InterestPnL ?? 0;
foreach (var item in positions)
{
decimal shortRatio = item.PositionType == (int)PositionTypeFlag.Long ? 1 : -1;//多空方向
int directionRatio = item.PosiDirection == (int)SwapDirectionEnum. ? 1 : -1;
var pv = item.PosiQuantity * shortRatio * item.ContractSize;
var pvNoPrice = item.PosiQuantity * item.ContractSize;
var pv = item.PosiQuantity* shortRatio;
var data = DataCacheProvider.GetUnderlyingDataSource().GetData(item.UnderlyingCode);
if (data != null)
{
@@ -184,9 +185,8 @@ namespace YLErp.Modules.CalculationModule
{
eodSwap.MarketValueShort += pv;
}
eodSwap.NotionalValue += pvNoPrice;
}
eodSwap.PostionValue = lastEod?.PostionValue ?? 0;
eodSwap.PostionValue = eodSwap.NotionalValue;
return eodSwap;
}
@@ -548,12 +548,20 @@ where {nameof(t.TaskStartTime)}>'{startDateStr}' and {nameof(t.TaskState)}={(int
new EodClientBalanceCalc(_context).ClientBalanceCalc();
_context.LogInfo("结束任务:结算客户资金");
}
AddOrUpdateEodStatus(_request);
if (PS.Config.ErpElement.UseSettleDataAcquisition)
{
SetTaskStep("配合数据采集,限额监控数据落地");
var service = new QuotaMonitorService(_context.UserInfo);
service.EodSettlementExecute(_context.SettleDate);
_context.LogInfo("结束任务:限额监控数据落地");
}
_cancellationTokenSource.Token.ThrowIfCancellationRequested();
//if (!_request.IsPartialSettlement)
//{
AddOrUpdateEodStatus(_request);
//}
sw.Stop();
+442 -152
View File
@@ -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>();
+1 -30
View File
@@ -111,21 +111,10 @@
<span class="search-label">标的代码</span>
<select trade underlying data-placeholder="请选择 标的代码" id="UnderlyingId" name="UnderlyingId" multiple></select>
</div>
<div class="search-group">
<label class="search-label">百分比</label>
<input global class="text-box" type="text" value="@PS.Config.ErpElement.EodVarPvPercent" name="PvPercent" id="PvPercent">
</div>
@Html.SearchDateRange("TradeDate", "成交日期", htmlAttributes: new { trade = "" })
@Html.MyAceDropdownInput("AssetId", "簿记账户", AssetunitController.GetClientassetunit(), htmlAttributes: new { trade = "" ,assetunit="" })
@Html.MyAceDropdownInput("TradeStatus", "交易状态", GlobalData.GetSelectItems(ConsTrade.AllTradeStatus), true, htmlAttributes: new { trade = "" })
@if (PS.Config.Company == CompanyEnum.国海)
{
<div class="search-group">
<span class="search-label" for="UseCCR">计算CCR</span>
<input trade class="checkbox" id="UseCCR" name="UseCCR" type="checkbox" value="" autocomplete="off">
</div>
}
<div class="search-group">
<label class="search-label">限额维度</label>
<select setting class="selectpicker" data-actions-box="true" data-live-search="true" id="QuotaType" name="QuotaType">
@@ -154,17 +143,6 @@
<option value="false">否</option>
</select>
</div>
@if (PS.Config.Company == CompanyEnum.广发商贸)
{
<div class="search-group">
<label class="search-label">是否有持仓</label>
<select underlying assetunit data-actions-box="true" data-live-search="true" id="HasPosition" name="HasPosition">
<option value="">全部</option>
<option value="true" selected>是</option>
<option value="false">否</option>
</select>
</div>
}
@Html.MyAceDropdownInput("UseValid", "状态", new SelectListItem[]{ new SelectListItem(){ Text ="有效",Value="有效" },new SelectListItem(){ Text ="无效",Value="无效" },new SelectListItem(){ Text ="待生效",Value="待生效" },new SelectListItem(){ Text ="待删除",Value="待删除" }}.ToList())
@Html.MyAceDropdownInput("confriomStatus", "确认状态", pageObj.ApprovalStatusDict.Select(O=>new SelectListItem(){ Text = O.Value,Value =O.Key }).ToList())
@@ -181,18 +159,11 @@
<img src="~/Images/configure.png" />
</div>
</div>
@if (PS.Config.Company == CompanyEnum.广发商贸)
{
<div style="float: right;display:none;" class="gf-Setting">
@MyControls.Btn("批量操作", "showWindow('批量操作')")
@MyControls.Btn("导入限额指标", "showWindow('导入限额指标')")
</div>
}
</div>
</div>
<ul id="myTab" class="nav nav-tabs nav-main">
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">整体业务汇总</a>
<a class="nav-link" tag="global" href="javascript:void(0)">整体业务汇总</a>
</li>
<li class="nav-item">
<a class="nav-link" tag="underlying" href="javascript:void(0)">标的汇总</a>
@@ -9,8 +9,8 @@ $(function () {
$("#myTab li a").on("click", function (e) {
setSummaryType($(e.target).text());
});
FastVue.numberInput(document.getElementById('PvPercent'), { precision: 0, append: '%' });
new tradeHelper.UnderlyingSelectCtrl('#UnderlyingId').setFlag(tradeHelper.UnderlyingSelectFlag.OtcTrade);
main.setTradeDatePicker(moment(page.ValueDate));
$(".datepicker").datepicker({
changeMonth: true,
changeYear: true,
@@ -21,20 +21,20 @@ $(function () {
$("#DateValueDate").change(function () {
var dateVal = $(this).val();
valueDateShowStatus = page.ValueDate == dateVal;
var tab = $('#myTab .active a').text();
if (tab == "整体业务汇总") {
if (valueDateShowStatus) {
$("#PvPercent").parents('.search-group').show();
} else {
$("#PvPercent").parents('.search-group').hide();
}
}
SearchClick(true);
//var tab = $('#myTab .active a').text();
//if (tab == "整体业务汇总") {
// if (valueDateShowStatus) {
// $("#PvPercent").parents('.search-group').show();
// } else {
// $("#PvPercent").parents('.search-group').hide();
// }
//}
});
$("#UseValid,#confriomStatus").attr("setting", "");
setSummaryType(page.SummaryType)//这个方法应该在最后调用,否则可能会影响页面展示效果
if (getRequest().SummaryType != undefined) {
setSummaryType(getRequest().SummaryType);
SearchClick(true);
}
});
function getRequest() {
@@ -220,11 +220,11 @@ function getGrid(summaryType) {
switch (summaryType) {
case "整体业务汇总":
obj.colModel = colModel_global;
if (valueDateShowStatus) {
$("#PvPercent").parents('.search-group').show();
} else {
$("#PvPercent").parents('.search-group').hide();
}
//if (valueDateShowStatus) {
// $("#PvPercent").parents('.search-group').show();
//} else {
// $("#PvPercent").parents('.search-group').hide();
//}
break;
case "品种汇总":
obj.colModel = colModel_variety;
@@ -299,6 +299,7 @@ function setSummaryType(summaryType) {
//$("#TagIds").parents('.search-group').show();
if (typeof g_grid.GridUnload == 'function') { g_grid.GridUnload(); }
g_grid = getGrid(summaryType);
SearchClick(true);
}
function GetPostData() {
-1
View File
@@ -92,7 +92,6 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B454A6FB-CF27-4B00-AEDC-BA1F0ED2F6D1} = {15F732CE-6C51-48F0-BC50-3BEC018460E5}
{5981434D-792E-4528-AFC8-7EB8AFD9F80C} = {15F732CE-6C51-48F0-BC50-3BEC018460E5}
{C7E0F300-16D5-438B-97A2-79DC2311D1D5} = {F315B5D3-F4FE-43E5-AF22-AF92978A71BE}
{FEDA115A-88ED-42FE-A5FF-0AAE229DC4CF} = {F315B5D3-F4FE-43E5-AF22-AF92978A71BE}
{206EBAE4-AB3E-4F09-9428-DDC3E64CFC42} = {F315B5D3-F4FE-43E5-AF22-AF92978A71BE}