82 lines
3.4 KiB
C#
82 lines
3.4 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using YLErp.BLL.MarginCalculation;
|
|
using YLErp.Modules.DataProviderModule;
|
|
using GTJAMarginCalculationNew = YLErp.BLL.MarginCalculation.GTJAMarginCalculation;
|
|
//using GTJAMarginCalculationOld = YLErp.BLL.MarginCalculationBak.GTJAMarginCalculation;
|
|
|
|
namespace YLErp.Modules.MarginModule
|
|
{
|
|
[TestClass]
|
|
public class GTJAMarginTest : UnitTestBase
|
|
{
|
|
[TestMethod("国君保证金比较新方法和老方法")]
|
|
public void TestOldNew()
|
|
{
|
|
var req = new RunMarginCalculationReq
|
|
{
|
|
forOtherSide = false,
|
|
forSingleTrade = true,
|
|
hasOptionInfo = false,
|
|
//isEodSettle = false,
|
|
//isInitialMargin = false,
|
|
settleDate = DateTime.Today,
|
|
userId = 1,
|
|
userName = "系统用户",
|
|
volType = "交易"
|
|
};
|
|
|
|
using (var db = DbContextFactory.GetYLDbContext())
|
|
{
|
|
req.tradeList = db.trade.Where(n => n.id == 106969)
|
|
.Where(t => t.ValidState != ConsGlobal.InValid && t.ClientId > 0
|
|
&& t.TradeType != "结构化交易" && t.TradeStatus == "确认成交" && t.SpotPrice != null)
|
|
.OrderByDescending(n => n.id).Take(100).ToList();
|
|
}
|
|
|
|
var priceDic = new Dictionary<string, double>();
|
|
|
|
foreach (var t in req.tradeList)
|
|
{
|
|
if (!priceDic.ContainsKey(t.UnderlyingCode))
|
|
{
|
|
priceDic[t.UnderlyingCode] = t.SpotPrice.Value * 1.08;
|
|
}
|
|
}
|
|
|
|
req.PriceProvider = (ManualPriceProvider)priceDic;
|
|
|
|
var resultNew = GTJAMarginCalculationNew.Instance.RunMarginCalculation(req.Clone())
|
|
.ToDictionary(n => n.TradeId);
|
|
|
|
//var resultOld = GTJAMarginCalculationOld.Instance.RunMarginCalculation(
|
|
// req.userId, req.userName, req.tradeList, req.settleDate, priceDic, req.hasOptionInfo, req.isEodSettle, req.forOtherSide, req.volType, req.forOtherSide
|
|
// );
|
|
|
|
//foreach (var ro in resultOld)
|
|
//{
|
|
// if (resultNew.TryGetValue(ro.TradeId, out var rn))
|
|
// {
|
|
// Console.WriteLine("trade id: " + ro.TradeId);
|
|
// Assert.IsTrue(Math.Abs((ro.Spv1 ?? 0) - (rn.Spv1 ?? 0)) < 1e-6);
|
|
// Assert.IsTrue(Math.Abs((ro.Spv2 ?? 0) - (rn.Spv2 ?? 0)) < 1e-6);
|
|
// Assert.IsTrue(Math.Abs((ro.Spv3 ?? 0) - (rn.Spv3 ?? 0)) < 1e-6);
|
|
// Assert.IsTrue(Math.Abs((ro.Spv4 ?? 0) - (rn.Spv4 ?? 0)) < 1e-6);
|
|
// Assert.IsTrue(Math.Abs((ro.Spv5 ?? 0) - (rn.Spv5 ?? 0)) < 1e-6);
|
|
// Assert.IsTrue(Math.Abs((ro.Spv6 ?? 0) - (rn.Spv6 ?? 0)) < 1e-6);
|
|
// Assert.IsTrue(Math.Abs((ro.Spv7 ?? 0) - (rn.Spv7 ?? 0)) < 1e-6);
|
|
// Assert.IsTrue(Math.Abs((ro.Spv8 ?? 0) - (rn.Spv8 ?? 0)) < 1e-6);
|
|
// Assert.IsTrue(Math.Abs((ro.WorstCastClientPayable ?? 0) - (rn.WorstCastClientPayable ?? 0)) < 1e-6);
|
|
// }
|
|
// else
|
|
// {
|
|
// Assert.Fail();
|
|
// System.Diagnostics.Debug.WriteLine("没有取到新保证金");
|
|
// }
|
|
//}
|
|
}
|
|
}
|
|
}
|