#EQD-5618 国联民生-【TRS】【交易确认书】- 追保线梯度配置,新增平仓线与预警线、授信现金比例
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using YLErp.BLL;
|
||||||
using YLErp.Core.Helpers;
|
using YLErp.Core.Helpers;
|
||||||
using YLErp.DBModels;
|
using YLErp.DBModels;
|
||||||
using YLErp.DBModels.Consts;
|
using YLErp.DBModels.Consts;
|
||||||
@@ -315,9 +316,40 @@ namespace YLErp.Plugins.GuoLian.DocumentGenerator
|
|||||||
dic["初始保障金率"] = ((double)initRate * 100).ToString("N4");
|
dic["初始保障金率"] = ((double)initRate * 100).ToString("N4");
|
||||||
dic["维持保障金率"] = ((double)maintainRate * 100).ToString("N4");
|
dic["维持保障金率"] = ((double)maintainRate * 100).ToString("N4");
|
||||||
|
|
||||||
// 期初预付比例和金额
|
// 期初预付/期初现金交换:预付=初始预付金腿合计(模板口径:可全部或部分授信替代),
|
||||||
dic["期初预付比例"] = ((double)initRate * 100).ToString("0.##");
|
// 现金=资金记录实付现金(ClientCashInCashOut:Action=应付预付金且 Money<0 即客户期初实付;
|
||||||
dic["期初预付金额"] = ((trade.OriginalStockEqvNotional ?? 0) * (double)initRate).ToString("N2");
|
// 授信部分不产生资金流水,平仓返还为正数、追加保证金是独立Action,均不落入该口径)
|
||||||
|
var notional = trade.OriginalStockEqvNotional ?? 0;
|
||||||
|
var initialLegs = swapPositions.Where(x => x.InterestMode == (int)InterestModeEnum.初始预付金).ToList();
|
||||||
|
var initialLegIds = initialLegs.Select(x => x.id).ToList();
|
||||||
|
double cashPaid;
|
||||||
|
using (var db = new YLContext())
|
||||||
|
{
|
||||||
|
cashPaid = db.ClientCashInCashOut
|
||||||
|
.Where(x => x.TradeId == trade.id && x.Action == ClientCashInCashOut.系统操作_应付预付金
|
||||||
|
&& x.ValidState != ConsGlobal.InValid && x.Money < 0
|
||||||
|
&& (x.Deal == 0 || initialLegIds.Contains(x.Deal)))
|
||||||
|
.Sum(x => x.Money) ?? 0;
|
||||||
|
}
|
||||||
|
var cashRatio = notional == 0 ? 0 : -cashPaid / notional * 100;
|
||||||
|
dic["期初现金交换比例"] = cashRatio.ToString("0.##");
|
||||||
|
dic["期初现金交换金额"] = (-cashPaid).ToString("N2");
|
||||||
|
|
||||||
|
// 期初预付比例和金额:有应付腿取腿合计(合约录入值),无应付腿(无预付金模板/合约维度盯市)走模板率兜底
|
||||||
|
var totalPayable = initialLegs
|
||||||
|
.Select(x => x.InterestPrincipalFix * (x.InterestDirection == 1 ? 1m : -1m))
|
||||||
|
.Where(x => x > 0)
|
||||||
|
.Sum();
|
||||||
|
if (totalPayable > 0)
|
||||||
|
{
|
||||||
|
dic["期初预付比例"] = (notional == 0 ? 0 : (double)totalPayable / notional * 100).ToString("0.##");
|
||||||
|
dic["期初预付金额"] = ((double)totalPayable).ToString("N2");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dic["期初预付比例"] = ((double)initRate * 100).ToString("0.##");
|
||||||
|
dic["期初预付金额"] = (notional * (double)initRate).ToString("N2");
|
||||||
|
}
|
||||||
bool posiLong = IsCustomerLong(swapPosition);
|
bool posiLong = IsCustomerLong(swapPosition);
|
||||||
var maintainRatePercent = (double)maintainRate * 100; // A(%)
|
var maintainRatePercent = (double)maintainRate * 100; // A(%)
|
||||||
|
|
||||||
@@ -441,9 +473,7 @@ namespace YLErp.Plugins.GuoLian.DocumentGenerator
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 期初预付金利率(InterestMode == 初始预付金)
|
// 期初预付金利率(InterestMode == 初始预付金)
|
||||||
var initialMarginPosition = swapPositions
|
var initialMarginPosition = initialLegs.FirstOrDefault();
|
||||||
.Where(x => x.InterestMode == (int)InterestModeEnum.初始预付金)
|
|
||||||
.FirstOrDefault();
|
|
||||||
dic["期初预付金利率"] = initialMarginPosition != null
|
dic["期初预付金利率"] = initialMarginPosition != null
|
||||||
? ((double)initialMarginPosition.InterestRateDefault * 100).ToString("N4")
|
? ((double)initialMarginPosition.InterestRateDefault * 100).ToString("N4")
|
||||||
: "0.0000";
|
: "0.0000";
|
||||||
@@ -507,18 +537,9 @@ namespace YLErp.Plugins.GuoLian.DocumentGenerator
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 基本费率 = PosiTradingFeePending / 名义本金 * 100
|
// 基本费率 = PosiTradingFeePending / 名义本金 * 100
|
||||||
var notional = trade.OriginalStockEqvNotional ?? 0;
|
|
||||||
var tradingFee = (double)swapPosition.PosiTradingFeePending;
|
var tradingFee = (double)swapPosition.PosiTradingFeePending;
|
||||||
var basicFeeRate = notional == 0 ? 0 : tradingFee / notional * 100;
|
var basicFeeRate = notional == 0 ? 0 : tradingFee / notional * 100;
|
||||||
dic["基本费率"] = basicFeeRate.ToString("0.####");
|
dic["基本费率"] = basicFeeRate.ToString("0.####");
|
||||||
|
|
||||||
// 期初现金交换比例和金额(使用初始预付金数据)
|
|
||||||
dic["期初现金交换比例"] = initialMarginPosition != null
|
|
||||||
? ((double)initialMarginPosition.InterestRateDefault * 100).ToString("N4")
|
|
||||||
: "0.0000";
|
|
||||||
dic["期初现金交换金额"] = initialMarginPosition != null
|
|
||||||
? ((double)initialMarginPosition.InterestPrincipalFix).ToString("N2")
|
|
||||||
: "0.00";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user