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
@@ -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;
}