标的交易&风控

This commit is contained in:
吴方海
2025-04-25 15:50:51 +08:00
parent 428938cb6f
commit fe4b431faf
8 changed files with 60 additions and 97 deletions
@@ -901,6 +901,7 @@ namespace YLErp.Modules.RiskModule
{
return;
}
obj.DeltaExposure= dict[obj.BusinessType].Sum(O => O.risk.Delta.Normalize());
obj.DeltaCash = dict[obj.BusinessType].Sum(O => O.risk.DeltaCash.Normalize());
obj.Vega = dict[obj.BusinessType].Sum(O => O.risk.Vega.Normalize());
obj.VegaCash = dict[obj.BusinessType].Sum(O => O.risk.VegaCash.Normalize());
@@ -1015,41 +1016,30 @@ namespace YLErp.Modules.RiskModule
setValue(swap, swapSetting);
var positionList = new List<KeyValuePair<trade, realtime_trade_risk>>();
var gloabPnl = GetTradePositionPnl();
var underly = GetTradePositionPnl();
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());
if (PS.Config.Is国信金阳)
{
swap.PositionPnl = swapPositionList.Sum(O => O.Value.PositionPnl.Normalize() < 0 ? O.Value.PositionPnl.Normalize() : 0);
}
else
{
swap.PositionPnl = swapPositionList.Sum(O => O.Value.PositionPnl.Normalize());
}
swap.PositionPnl = swapPositionList.Sum(O => O.Value.PositionPnl.Normalize());
positionList.AddRange(swapPositionList);
}
swap.DeltaNetExposure = double.NaN;
var checkPosiList = GetCheckPosiList();
var posiStockEqvNotional = checkPosiList.Sum(s => s.Pv);
var underly = new QuotaMonitor_Global()
{
ParentKey = "场外",
BusinessType = "标的交易",
PositionPnl = gloabPnl
};
var delta = checkPosiList.Sum(s => s.Delta);
var unTrade = new QuotaMonitor_Global()
{
ParentKey = "场外",
BusinessType = "未簿记合约",
StockEqvNotional = Convert.ToDouble(posiStockEqvNotional) - swap.StockEqvNotional.Normalize()
StockEqvNotional = Convert.ToDouble(posiStockEqvNotional) - swap.StockEqvNotional.Normalize(),
DeltaExposure=(double)delta- (swap.DeltaExposure??0)
};
var all = new QuotaMonitor_Global()
{
BusinessType = "全局",
StockEqvNotional = Convert.ToDouble(posiStockEqvNotional),
PositionPnl = underly.PositionPnl + swap.PositionPnl
PositionPnl = underly.PositionPnl + swap.PositionPnl,
DeltaExposure=(double)delta+ underly.DeltaExposure
};
var list = new List<QuotaMonitor_Global>
{
@@ -4364,7 +4354,7 @@ namespace YLErp.Modules.RiskModule
checkQuotaMoitorModel.Commision = item.commission ?? 0;
checkQuotaMoitorModel.Direction = item.direction;
checkQuotaMoitorModel.ClientId = Convert.ToInt32(item.client_id ?? 0);
checkQuotaMoitorModel.Delta = (checkQuotaMoitorModel.Side == 0 ? checkQuotaMoitorModel.Price : -checkQuotaMoitorModel.Price) * checkQuotaMoitorModel.Qty;
checkQuotaMoitorModel.Delta = (checkQuotaMoitorModel.Side == 0 ? 1 : -1) * checkQuotaMoitorModel.Qty;
EodPrice bondPrice = null;
if (eodPriceDic.ContainsKey(checkQuotaMoitorModel.UnderlyingCode))
{
@@ -4990,9 +4980,16 @@ namespace YLErp.Modules.RiskModule
/// 算标的交易盈亏
/// </summary>
/// <returns></returns>
private double GetTradePositionPnl()
private QuotaMonitor_Global GetTradePositionPnl()
{
double currentValue = 0;
QuotaMonitor_Global quotaMonitor_Global = new QuotaMonitor_Global()
{
ParentKey= "场外",
BusinessType = "标的交易",
PositionPnl=0,
DeltaExposure=0,
StockEqvNotional=0
};
List<string> tradetypes = new List<string> { "利率债", "信用债", "其它债券" };
var tposis = DbContext.TradePosition.Where(x => tradetypes.Contains(x.TradeType)).AsNoTracking().ToList();
var umCodes = tposis.Select(x => x.UnderlyingCode).Distinct().ToList();
@@ -5015,9 +5012,12 @@ namespace YLErp.Modules.RiskModule
lastPrice = bondPrice != null ? bondPrice.ClosePrice : (um.Price ?? 0) * Convert.ToDouble(ConsGlobal.bondPriceMultiple);
}
}
currentValue += lastPrice * item.Position - item.PositionCost;
quotaMonitor_Global.PositionPnl += lastPrice * item.Position - item.PositionCost;
quotaMonitor_Global.StockEqvNotional += item.PositionCost;
quotaMonitor_Global.DeltaExposure += (item.PositionType == PositionTypeFlag.Long ? -1 : 1) * item.Position;
}
return currentValue;
return quotaMonitor_Global;
}
private List<string> checkGlobal(List<CheckQuotaMoitorModel> positionList, List<CheckQuotaMoitorModel> posiList, string tag_prefix, QuotaSetting[] settings, bool warning)
{