chore(swap): 删除全部期货公司定制保证金计算死代码——36个厂商类+东吴DongWu子目录+调度器四处厂商switch收敛Default直调+MarginTypeEnum三个不可达枚举项;连带YLErpUnitTest厂商类历史快照副本与4个厂商测试(3个零断言草稿/1个招证金标准)。本分支Company=国联无专属case,厂商路径本就永不执行;顺带消除Debug配置残留的格林大华#if DEBUG两处编译错误。-23231行,Release/Debug/UnitTestProject三处构建0错误
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,40 +0,0 @@
|
||||
using YLErp.BLL.MarginCalculation;
|
||||
using YLErp.Modules.DataProviderModule;
|
||||
|
||||
namespace YLErp.Modules.CalcModules
|
||||
{
|
||||
[TestClass]
|
||||
public class SwapCalcTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void TestCalc1()
|
||||
{
|
||||
//var db = DbContextFactory.GetYLDbContext();
|
||||
//var td = db.trade.AsNoTracking().FirstOrDefault(n => n.TradeNumber == "SHBX-BX-21051203");
|
||||
//var tdswap = db.trade_swap.FirstOrDefault(n => n.TradeId == td.id);
|
||||
|
||||
//var priceProvidr = new ManualPriceProvider();
|
||||
//priceProvidr.SetPrice("AG00", 5262);
|
||||
//var optionValue = PayoffSwapCalcService.CalcValue(td, tdswap, new DateTime(2021, 5, 12), priceProvidr, true);
|
||||
//Console.WriteLine(optionValue.Pv);
|
||||
|
||||
//priceProvidr = new ManualPriceProvider();
|
||||
//priceProvidr.SetPrice("AG00", 5661.36);
|
||||
//optionValue = PayoffSwapCalcService.CalcValue(td, tdswap, new DateTime(2021, 5, 12), priceProvidr, true);
|
||||
//Console.WriteLine(optionValue.Pv);
|
||||
var db = DbContextFactory.GetYLDbContext();
|
||||
var td = db.trade.AsNoTracking().FirstOrDefault(n => n.TradeNumber == "CW20180051C3248");
|
||||
var date = new DateTime(2022, 5, 30);
|
||||
var priceProvider = new EodPriceProvider(date);
|
||||
var req = new RunMarginCalculationReq(OptUserInfo.SystemUser)
|
||||
{
|
||||
tradeList = new System.Collections.Generic.List<trade> { td },
|
||||
settleDate = date,
|
||||
PriceProvider = priceProvider.GetPriceProvider(),
|
||||
CalcMarginType = Enums.CalcMarginTypeEnum.EodMargin,
|
||||
volType = "持仓"
|
||||
};
|
||||
GuoTouMarginCalculation.TradeMargin(req, td);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
using CsvHelper;
|
||||
using CsvHelper.Configuration;
|
||||
using Org.BouncyCastle.Ocsp;
|
||||
using System.Globalization;
|
||||
using YLErp.Model.Enum;
|
||||
using static NPOI.HSSF.Util.HSSFColor;
|
||||
|
||||
namespace YLErp.Modules.MarginModule
|
||||
{
|
||||
[TestClass]
|
||||
public class HaiTongMarginTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void TestMethod1()
|
||||
{
|
||||
var csvFile = Path.Combine(AppContext.BaseDirectory, "Resources\\MarginModule\\tradespans.csv");
|
||||
|
||||
var config = new CsvConfiguration(CultureInfo.InvariantCulture) { HeaderValidated = null, MissingFieldFound=null };
|
||||
using var reader = new StreamReader(csvFile);
|
||||
using var csv = new CsvReader(reader, config);
|
||||
var tradeSpans = csv.GetRecords<trade_span>().Where(n => n.ValueDate.Day == 10).ToList();
|
||||
var clientSpanNews = new List<ClientSpan>();
|
||||
|
||||
if (tradeSpans != null && tradeSpans.Count > 0)
|
||||
{
|
||||
var tradeIds = tradeSpans.Select(t => t.TradeId).ToList();
|
||||
|
||||
//海通预付金保底收益率-用来计算名义本金
|
||||
double GuaranteedIncome = 0.01;
|
||||
|
||||
var clientGroups = tradeSpans.GroupBy(t => t.ClientId);
|
||||
|
||||
foreach (var clientGroup in clientGroups)
|
||||
{
|
||||
var clientRatio = 1.1;
|
||||
|
||||
var underlyingGroup = clientGroup.Where(x => x.IsSingleMargin != true).GroupBy(t => t.UnderlyingId).Select(t => new ClientSpan
|
||||
{
|
||||
UnderlyingId = t.Key,
|
||||
ClientId = clientGroup.Key ?? 0,
|
||||
ValueDate = DateTime.Today,
|
||||
//负数代表客户应缴预付金,正数代表客户应收预付金
|
||||
Spv1 = -t.Sum(g => g.Spv1),
|
||||
Spv2 = -t.Sum(g => g.Spv2),
|
||||
Spv3 = -t.Sum(g => g.Spv3),
|
||||
Spv4 = -t.Sum(g => g.Spv4),
|
||||
Spv5 = -t.Sum(g => g.Spv5),
|
||||
Spv6 = -t.Sum(g => g.Spv6),
|
||||
Spv7 = -t.Sum(g => g.Spv7),
|
||||
Spv8 = -t.Sum(g => g.Spv8),
|
||||
WorstCastClientPayable = -t.Sum(g => g.WorstCastClientPayable),
|
||||
OptId = 0,
|
||||
OptName = "ddd",
|
||||
OptDate = DateTime.Now,
|
||||
SpanType = 1
|
||||
}).ToList();
|
||||
|
||||
foreach (var item in underlyingGroup)
|
||||
{
|
||||
if (clientGroup.Count(m => m.UnderlyingId == item.UnderlyingId && m.ClientId == item.ClientId) > 1)
|
||||
{
|
||||
item.SetWorstCastClientPayableMin();
|
||||
|
||||
#region 更新tradeSpan,使得每笔交易的持仓预付金和客户预付金计算用的Spv组保持一致
|
||||
|
||||
var tradeIdList = clientGroup.Select(x => x.TradeId);
|
||||
var tradeSpansUpdate = new List<trade_span>();
|
||||
var tradeSpansReq = new List<trade_span>();
|
||||
|
||||
if (item.WorstCastClientPayable == item.Spv1)
|
||||
{
|
||||
tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv1);
|
||||
tradeSpansReq.ForEach(x => x.WorstCastClientPayable = x.Spv1);
|
||||
}
|
||||
else if (item.WorstCastClientPayable == item.Spv2)
|
||||
{
|
||||
tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv2);
|
||||
tradeSpansReq.ForEach(x => x.WorstCastClientPayable = x.Spv2);
|
||||
}
|
||||
else if (item.WorstCastClientPayable == item.Spv3)
|
||||
{
|
||||
tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv3);
|
||||
tradeSpansReq.ForEach(x => x.WorstCastClientPayable = x.Spv3);
|
||||
}
|
||||
else if (item.WorstCastClientPayable == item.Spv4)
|
||||
{
|
||||
tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv4);
|
||||
tradeSpansReq.ForEach(x => x.WorstCastClientPayable = x.Spv4);
|
||||
}
|
||||
else if (item.WorstCastClientPayable == item.Spv5)
|
||||
{
|
||||
tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv5);
|
||||
tradeSpansReq.ForEach(x => x.WorstCastClientPayable = x.Spv5);
|
||||
}
|
||||
else if (item.WorstCastClientPayable == item.Spv6)
|
||||
{
|
||||
tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv6);
|
||||
tradeSpansReq.ForEach(x => x.WorstCastClientPayable = x.Spv6);
|
||||
}
|
||||
else if (item.WorstCastClientPayable == item.Spv7)
|
||||
{
|
||||
tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv7);
|
||||
tradeSpansReq.ForEach(x => x.WorstCastClientPayable = x.Spv7);
|
||||
}
|
||||
else if (item.WorstCastClientPayable == item.Spv8)
|
||||
{
|
||||
tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv8);
|
||||
tradeSpansReq.ForEach(x => x.WorstCastClientPayable = x.Spv8);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
else
|
||||
{
|
||||
var tradeSpansUpdate = new List<trade_span>();
|
||||
tradeSpansUpdate.ForEach(x => x.Comment = "单笔计算");
|
||||
}
|
||||
|
||||
//客户信息中追保方向为“单向追保”或“双向追保”的客户: call 看涨
|
||||
//(1)Call净名义本金 = 客户Call卖方持仓名义本金 - 客户Call买方持仓名义本金;
|
||||
//(2)Put净名义本金 = 客户Put卖方持仓名义本金 - 客户Put买方持仓名义本金;
|
||||
//(3)单品种预付金占用 = max(0, max(∑逐笔交易持仓预付金,(Call净名义本金 + Put净名义本金)*1 % *1.1));
|
||||
//(4)预付金占用 =∑单品种预付金占用。
|
||||
//客户信息追保方向“对手方单向追保”或“其他”的客户:预付金占用 = 0。
|
||||
|
||||
//var callsale = clientGroup.Where(m => m.UnderlyingId == item.UnderlyingId && m.trade.BuySell == "买入" && m.trade.OptionType == "看涨").Select(m => m.trade.StockEqvNotional).Sum();
|
||||
//var callbuy = clientGroup.Where(m => m.UnderlyingId == item.UnderlyingId && m.trade.BuySell == "卖出" && m.trade.OptionType == "看涨").Select(m => m.trade.StockEqvNotional).Sum();
|
||||
//var putsale = clientGroup.Where(m => m.UnderlyingId == item.UnderlyingId && m.trade.BuySell == "买入" && m.trade.OptionType == "看跌").Select(m => m.trade.StockEqvNotional).Sum();
|
||||
//var putbuy = clientGroup.Where(m => m.UnderlyingId == item.UnderlyingId && m.trade.BuySell == "卖出" && m.trade.OptionType == "看跌").Select(m => m.trade.StockEqvNotional).Sum();
|
||||
|
||||
//var StockEqvNotional = (double)((callsale - callbuy + putsale - putbuy) * GuaranteedIncome * clientRatio);
|
||||
|
||||
//if (client.MarginOptionType != (int)MarginOptionEnum.双向追保)
|
||||
//{
|
||||
// item.WorstCastClientPayable = -Math.Max(0, Math.Max(-(double)item.WorstCastClientPayable, StockEqvNotional));
|
||||
//}
|
||||
}
|
||||
|
||||
var clientSpan = new ClientSpan
|
||||
{
|
||||
ClientId = clientGroup.Key ?? 0,
|
||||
ValueDate = DateTime.Now,
|
||||
Spv1 = underlyingGroup.Sum(g => g.Spv1),
|
||||
Spv2 = underlyingGroup.Sum(g => g.Spv2),
|
||||
Spv3 = underlyingGroup.Sum(g => g.Spv3),
|
||||
Spv4 = underlyingGroup.Sum(g => g.Spv4),
|
||||
Spv5 = underlyingGroup.Sum(g => g.Spv5),
|
||||
Spv6 = underlyingGroup.Sum(g => g.Spv6),
|
||||
Spv7 = underlyingGroup.Sum(g => g.Spv7),
|
||||
Spv8 = underlyingGroup.Sum(g => g.Spv8),
|
||||
//负数代表客户应缴预付金,正数代表客户应收预付金
|
||||
WorstCastClientPayable = underlyingGroup.Sum(g => g.WorstCastClientPayable),
|
||||
DeltaMargin = 0,
|
||||
TwoSideMargin = underlyingGroup.Sum(g => g.TwoSideMargin),
|
||||
OptId = 0,
|
||||
OptName = "ddd",
|
||||
OptDate = DateTime.Now,
|
||||
SpanType = 1,
|
||||
AdditionalWorstCastClientPayable = 0
|
||||
};
|
||||
|
||||
clientSpanNews.Add(clientSpan);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user