77 lines
2.9 KiB
C#
77 lines
2.9 KiB
C#
using NPOI.SS.Formula.Functions;
|
|
using YLErp.Modules.EodModule.SettlementModule;
|
|
|
|
namespace YLErp.Modules.EodModule
|
|
{
|
|
/// <summary>
|
|
/// 广发日终结算定制服务
|
|
/// </summary>
|
|
public class GuangFaService
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public static void EodExecute(EodSettlementContextV2 context)
|
|
{
|
|
if (context is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(context));
|
|
}
|
|
|
|
try
|
|
{
|
|
var reqClientIds = context.Request.ClientIds;
|
|
|
|
var _db = DbContextFactory.GetYLDbContext();
|
|
|
|
//日终持仓(对冲波动率)数据查询
|
|
var eodQuery = _db.eod_trade_position_hedgevol.Where(t => t.ValueDate == context.SettleDate && t.ClientId > 0);
|
|
if (reqClientIds != null && reqClientIds.Any())
|
|
{
|
|
eodQuery = eodQuery.Where(t => reqClientIds.Contains(t.ClientId));
|
|
}
|
|
|
|
var gQuery = from eod in eodQuery
|
|
group eod by eod.ClientId into g
|
|
select new
|
|
{
|
|
ClientId = g.Key,
|
|
PvSum = g.Sum(n => n.Pv),
|
|
RoundedPvSum = g.Sum(n => n.RoundedPv),
|
|
PositionPnLSum = g.Sum(n => n.PositionPnL),
|
|
RoundedPositionPnLSum = g.Sum(n => n.RoundedPositionPnL),
|
|
};
|
|
var eodpnlList = gQuery.ToList();
|
|
|
|
//客户结算资金数据查询
|
|
var cbQuery = _db.ClientBalanceDaily.Where(t => t.BalanceDate == context.SettleDate);
|
|
if (reqClientIds != null && reqClientIds.Any())
|
|
{
|
|
cbQuery = cbQuery.Where(t => reqClientIds.Contains(t.ClientId));
|
|
}
|
|
var clientBalanceDailyList = cbQuery.ToList();
|
|
|
|
//循环更新客户结算资金(从持仓波动率改为对冲波动率)
|
|
foreach (var item in clientBalanceDailyList)
|
|
{
|
|
var eodpnl = eodpnlList.FirstOrDefault(n => n.ClientId == item.ClientId);
|
|
|
|
if (eodpnl != null)
|
|
{
|
|
item.Pv = -eodpnl.PvSum;
|
|
item.RoundedPv = -eodpnl.RoundedPvSum;
|
|
item.PositionPnl = -eodpnl.PositionPnLSum;
|
|
item.RoundedPositionPnl = -eodpnl.RoundedPositionPnLSum;
|
|
}
|
|
}
|
|
|
|
_db.SaveChanges();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogFactory.GetLogger("广发商贸日终结算定制").Error(ex, "使用对冲波动率持仓数据更新持仓盈亏、持仓市值");
|
|
}
|
|
}
|
|
}
|
|
}
|