83 lines
3.1 KiB
C#
83 lines
3.1 KiB
C#
using YLErp.Enums;
|
|
using YLErp.Modules.CalculationModule;
|
|
using YLErp.Modules.TradeModule;
|
|
|
|
namespace YLErp.BLL.MarginCalculation
|
|
{
|
|
/// <summary>
|
|
/// 国海预付金算法
|
|
/// </summary>
|
|
public class GuoHaiMarginCalculation : MarginCalculationBase
|
|
{
|
|
public static readonly GuoHaiMarginCalculation Instance;
|
|
|
|
static GuoHaiMarginCalculation()
|
|
{
|
|
Instance = new GuoHaiMarginCalculation();
|
|
}
|
|
|
|
protected GuoHaiMarginCalculation()
|
|
{
|
|
|
|
}
|
|
|
|
public override List<trade_span> RunMarginCalculation(RunMarginCalculationReq req)
|
|
{
|
|
List<trade_span> spanList = new List<trade_span>();
|
|
var config = valuedateBLL.SystemDate;
|
|
|
|
var clientId = req.tradeList.Select(O => O.ClientId).ToHashSet();
|
|
var tradeId = req.tradeList.Select(O => O.id).ToHashSet();
|
|
var tradeList = new List<trade>(req.tradeList);
|
|
using (var db = new YLContext())
|
|
{
|
|
tradeList.AddRange(
|
|
db.trade.Where(O =>
|
|
clientId.Contains(O.ClientId) &&
|
|
O.TradeType != "现金流交易" &&
|
|
O.TradeType != "远期" &&
|
|
O.ExerciseDate >= req.settleDate &&
|
|
O.TradeDate <= req.settleDate &&
|
|
ConsTrade.PositionTradeStatusList.Contains(O.TradeStatus) &&
|
|
O.ValidState != "InValid" &&
|
|
!tradeId.Contains(O.id) &&
|
|
O.MarginType == DBModels.Enums.MarginTypeEnum.DEFAULT));
|
|
new TradeExtendService(req.UserInfo).SetTradeExtend(tradeList, true);
|
|
}
|
|
var ccrService = new CCRService(req.UserInfo);
|
|
ccrService.IsRealtime = req.CalcMarginType != CalcMarginTypeEnum.EodMargin;
|
|
ccrService.SettlementDate = req.settleDate;
|
|
var ccrDict = ccrService.CalculationCCR(tradeList, config.MarginJ, config.MarginN);
|
|
foreach (var item in req.tradeList)
|
|
{
|
|
if (!ccrDict.ContainsKey(item.id))
|
|
{
|
|
//throw new Exception($"{item.id}预付金计算失败");
|
|
//结构化交易和自定义交易不计算
|
|
continue;
|
|
}
|
|
var ccr = ccrDict[item.id];
|
|
spanList.Add(new trade_span()
|
|
{
|
|
TradeId = item.id,
|
|
ClientId = item.ClientId,
|
|
ValueDate = req.settleDate,
|
|
Spv = ccr,
|
|
Spv1 = ccr,
|
|
Spv2 = ccr,
|
|
Spv3 = ccr,
|
|
Spv4 = ccr,
|
|
WorstCastClientPayable = ccr
|
|
});
|
|
}
|
|
return spanList;
|
|
}
|
|
|
|
public override double GetTradeMargin(GetTradeMarginReq req)
|
|
{
|
|
var margin = RunMarginCalculation(req.GetRunMarginCalculationReq());
|
|
return margin.Where(O => O.TradeId == req.trade.id).FirstOrDefault()?.WorstCastClientPayable ?? 0.0;
|
|
}
|
|
}
|
|
}
|