136 lines
6.6 KiB
C#
136 lines
6.6 KiB
C#
using YLErp.BLL.MarginCalculation;
|
|
using YLErp.Commons;
|
|
using YLErp.DBModels.Consts;
|
|
using YLErp.Model;
|
|
using YLErp.Modules;
|
|
using YLErp.Modules.DataProviderModule;
|
|
using YLErp.Modules.TradeModule;
|
|
|
|
namespace YLErp.BLL.GenerateDocument
|
|
{
|
|
public class GeneralGenerateUnwindReport : BaseGenerate
|
|
{
|
|
public GeneralGenerateUnwindReport(trade_contract_group tradeContractGroup, string docType, int optId, string optName) : base(tradeContractGroup, docType, optId, optName)
|
|
{
|
|
|
|
}
|
|
|
|
protected override string ContractType => ContractTypeEnum.UnWind;
|
|
|
|
public override string TemplateFile => $"提前终止确认书模板.{DocType.ToLower()}";
|
|
|
|
public override string ContractNOSeed => "GTJAUnWind";
|
|
|
|
public override ReturnInfo<Dictionary<string, string>> AppendDictionary()
|
|
{
|
|
var dic = CurrentContractDataSet.ModelDic;
|
|
var tradeContractGroup = CurrentContractDataSet.ContractGroup;
|
|
|
|
var trade = tradeContractGroup.trade;
|
|
var tradeCash = tradeContractGroup.trade_cash;
|
|
var contractDoc = tradeContractGroup.trade_contract_document;
|
|
|
|
var underlying = DataCacheProvider.GetUnderlyingDataSource().GetData(trade.UnderlyingCode);
|
|
var variety = DataCacheProvider.GetVarietyDataSource().GetData(underlying.UnderlyingTypeId);
|
|
|
|
string strUnit = variety.QuoteUnitSingle;
|
|
double tradeNotional = trade.Notional;
|
|
double unWindCount = trade.TradeStatus == ConsTrade.已平仓 || (trade.UnWindNotional > 0 && tradeCash.UnwindNotional > 0) ? (tradeCash.UnwindNotional).Value : trade.Notional;
|
|
string unWindCountPercent = ((tradeCash.UnwindPercentRate ?? 0) * 100).ToString("f2") + "%";
|
|
string unWindPricePercent = ((tradeCash.UnwindPricePercentRate ?? 0) * 100).ToString("f2") + "%";
|
|
|
|
dic["{{支付时间}}"] = "提前终止/到期时支付";
|
|
|
|
//期末价格
|
|
double endPrice = underlying.Price ?? 0;
|
|
//交割金额
|
|
double tradeCashAmount = 0;
|
|
if (tradeCash != null)
|
|
{
|
|
endPrice = tradeCash.FinalPrice ?? 0;
|
|
tradeCashAmount = tradeCash.Amount;
|
|
}
|
|
|
|
dic["{{名义本金}}"] = $"{(trade.OriginalStockEqvNotional ?? 0):f2}";
|
|
dic["{{期权费率}}"] = $"{(trade.PremiumRate ?? 0) * 100:f2}%";
|
|
dic["{{终止类型}}"] = tradeCash.Action == ClientCashInCashOut.系统操作_平仓费 ? "平仓" : "美式期权行权";
|
|
dic["{{执行价格}}"] = $"{(trade.ActualStrike ?? 0):f2}元/{strUnit}";
|
|
dic["{{期初价格}}"] = $"{(trade.SpotPrice ?? 0):f2}元/{strUnit}";
|
|
dic["{{期权收益}}"] = $"{Math.Abs(tradeCashAmount / tradeNotional):f2}元/{strUnit}";
|
|
dic["{{期末数量}}"] = $"{tradeNotional}{strUnit}";
|
|
dic["{{结算价}}"] = $"{Math.Abs(tradeCashAmount):f2}元";
|
|
dic["{{终止日}}"] = trade.UnWindDate?.ToString("yyyy年M月d日");
|
|
dic["{{终止数量}}"] = trade.IsUsePremiumRate == true ? unWindCountPercent : $"{unWindCount:f2}{strUnit}";
|
|
dic["{{标的终止日价格}}"] = $"{tradeCash.FinalPrice ?? 0:f2}元/{strUnit}";
|
|
|
|
dic["{{期末价格}}"] = $"{tradeCash.FinalPrice ?? 0:f2}元/{strUnit}";
|
|
var req = new RunMarginCalculationReq(GetOptUser())
|
|
{
|
|
tradeList = new List<trade> { trade },
|
|
settleDate = trade.UnWindDate.Value,
|
|
PriceProvider = new SinglePriceProvider(trade.UnderlyingCode, endPrice)
|
|
};
|
|
if (trade.IsGroup == 1)
|
|
{
|
|
req.tradeList = db.trade.Where(x => x.ParentTradeId == trade.id).ToList();
|
|
}
|
|
var tradeSpans = MarginDefault.RunMarginCalculation(req);
|
|
if (tradeSpans?.Count > 0)
|
|
{
|
|
var margin = trade.IsGroup == 1 ? tradeSpans.Sum(x => x.WorstCastClientPayable ?? 0) : (tradeSpans[0].WorstCastClientPayable ?? 0);
|
|
dic["{{预付金}}"] = $"{Math.Abs(margin):f2}元";
|
|
}
|
|
else
|
|
{
|
|
dic["{{预付金}}"] = "0元";
|
|
}
|
|
dic["{{期权平仓价格}}"] = tradeCash.Action == "系统操作-行权费" || tradeCash.UnwindType == "部分行权" ? "行权收益" : "期权平仓价格";
|
|
dic["{{平仓价格}}"] = trade.IsUsePremiumRate == true && tradeCash.Action == "系统操作-平仓费" ? unWindPricePercent : $"{Math.Abs(tradeCash.UnwindPrice ?? 0):f2}元/{strUnit}";
|
|
dic["{{提前终止款}}"] = $"{tradeCash.Amount:f2}元";
|
|
dic["{{结算价格}}"] = dic["{{平仓价格}}"];
|
|
|
|
var isGJBuyer = trade.BuySell == "买入";
|
|
|
|
if (isGJBuyer)
|
|
{
|
|
var incomes = tradeCash.Amount - trade.TradePrice.Value;
|
|
dic["{{结算净额}}"] = $"{Math.Abs(incomes):f2}元";
|
|
dic["{{结算方式}}"] = incomes > 0 ? "卖方向买方支付结算净额" : "买方向卖方支付结算净额";
|
|
dic["{{平仓盈亏}}"] = $"{Math.Abs(incomes):f2}元";
|
|
}
|
|
else
|
|
{
|
|
var incomes = tradeCash.Amount + trade.TradePrice.Value;
|
|
dic["{{结算净额}}"] = $"{Math.Abs(incomes):f2}元";
|
|
dic["{{结算方式}}"] = incomes > 0 ? "买方向卖方支付结算净额" : "卖方向买方支付结算净额";
|
|
dic["{{平仓盈亏}}"] = $"{Math.Abs(incomes):f2}元";
|
|
}
|
|
|
|
dic["{{确认书编号}}"] = contractDoc.Code;
|
|
dic["{{确认书时间}}"] = $"{contractDoc.ValueDate.Value:yyyy年M月d日}";
|
|
|
|
return Return.Success(dic);
|
|
}
|
|
|
|
protected override string GetContractIndex(trade_contract_group tradeContractGroup)
|
|
{
|
|
var contractBLL = new TradeContractBLL(OptId, OptName);
|
|
var contractIndex = contractBLL.GetContractNo(ContractNOSeed);
|
|
return contractIndex;
|
|
}
|
|
|
|
protected override string GetContractNO(trade_contract_group tradeContractGroup, string contractIndex)
|
|
{
|
|
var trade = tradeContractGroup.trade;
|
|
var client = DataCacheProvider.GetClientDataSource().GetData(trade.ClientId);
|
|
return $"{client?.Number}C{contractIndex} - 01";
|
|
}
|
|
|
|
protected override string GetOutputFileName(trade_contract_group tradeContractGroup, string contractIndex)
|
|
{
|
|
var trade = tradeContractGroup.trade;
|
|
return $"{trade.ClientName}提前终止确认书C{contractIndex}-01.docx";
|
|
}
|
|
}
|
|
}
|