从山证v2.3.0拷贝
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
using YLErp.Configuration;
|
||||
using YLErp.Modules.EodModule.SettlementModule;
|
||||
using YLErp.Modules.TradeModule.DealModule;
|
||||
|
||||
namespace YLErp.Modules.EodModule
|
||||
{
|
||||
[TestClass]
|
||||
public class EodSettlementTaskTest : UnitTestBase
|
||||
{
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void TestEodTask()
|
||||
{
|
||||
var eodDate = new DateTime(2020, 9, 2);
|
||||
|
||||
var task = new EodTask
|
||||
{
|
||||
StartDate = eodDate,
|
||||
EndDate = eodDate,
|
||||
VolTypes = "持仓",//"持仓,开仓,对冲";
|
||||
PriceType = EodSettlePriceType.ClosePrice
|
||||
};
|
||||
EodTaskRunner.ExecuteDebugAsync(task).Wait();
|
||||
Assert.IsTrue(task.TaskState == EodTaskState.completed, task.TaskResult);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestReadTrade()
|
||||
{
|
||||
var date = new DateTime(2020, 07, 01);
|
||||
var eodArr = new YLContext().eod_trade.Where(O => O.ValueDate == date).ToArray();
|
||||
var tradeArr = eodArr.Select(O => O.trade).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GetFixingString 测试
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void GetFixingString()
|
||||
{
|
||||
var underlyingCode = "A00";
|
||||
var settlementType = 1;
|
||||
var futurePriceList = new YLContext().eod_commodity_future_price
|
||||
.Where(e => e.UnderlyingCode == underlyingCode)
|
||||
//.Where(e => e.ValueDate >= startDate)
|
||||
//.Where(e => e.ValueDate >= exerciseDate)
|
||||
.Select(e => new
|
||||
{
|
||||
e.ValueDate,
|
||||
e.ClosePrice,
|
||||
e.SettlePrice,
|
||||
e.ReferencePrice
|
||||
}).ToList();
|
||||
|
||||
var query = from e in futurePriceList
|
||||
orderby e.ValueDate
|
||||
select e.ValueDate + "," + GetPrice(settlementType, e.ClosePrice, e.SettlePrice, e.ReferencePrice);
|
||||
|
||||
var fixing = string.Join(";", query.ToArray());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// GetFixingString 测试
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void ClientBalanceCalc()
|
||||
{
|
||||
var request = new EodSettlementRequest(GetOptUser())
|
||||
{
|
||||
VolType = null,
|
||||
UseClosePrice = true,
|
||||
ClientIds = null,
|
||||
SettleDate = DateTime.Today
|
||||
};
|
||||
CancellationTokenSource cancellationTokenSource;
|
||||
EodSettlementContextV2 _context;
|
||||
cancellationTokenSource = new CancellationTokenSource();
|
||||
var settlementConfig = new SettlementConfig
|
||||
{
|
||||
Version = "V1",
|
||||
CalcPnlExplain = false,
|
||||
PriceType = 3,
|
||||
SupportPart = false,
|
||||
VolTypes = "持仓,开仓,对冲,光证,BidAskVol"
|
||||
};
|
||||
_context = new EodSettlementContextV2(request, settlementConfig, cancellationTokenSource.Token);
|
||||
new EodClientBalanceCalc(_context).ClientBalanceCalc();
|
||||
}
|
||||
|
||||
private double GetPrice(int settlementType, double closePrice, double settlePrice, double? referencePrice)
|
||||
{
|
||||
var price = closePrice;
|
||||
if (settlementType == (int)SettlementTypeEnum.SettlePrice)
|
||||
{
|
||||
price = settlePrice;
|
||||
}
|
||||
else if (settlementType == (int)SettlementTypeEnum.ReferencePrice)
|
||||
{
|
||||
price = referencePrice ?? closePrice;
|
||||
}
|
||||
return price;
|
||||
}
|
||||
|
||||
public enum SettlementTypeEnum
|
||||
{
|
||||
|
||||
ClosePrice = 0,
|
||||
|
||||
SettlePrice = 1,
|
||||
|
||||
|
||||
ReferencePrice = 2,
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestDividend()
|
||||
{
|
||||
var service = new DividendService(OptUserInfo.UnitTestUser);
|
||||
|
||||
var info = new ex_dividend_info()
|
||||
{
|
||||
UnderlyingCode = "002043.SZ",
|
||||
ExDividendDate = new DateTime(2020, 7, 6),
|
||||
GiveCashAmount = 2.5,
|
||||
GiveShareAmount = 0,
|
||||
RationedSharesAmount = 0,
|
||||
RationedSharesPrice = 0,
|
||||
};
|
||||
var price = service.GetPrice(8.8, info);
|
||||
Assert.IsTrue((price - 8.6126) < 1e-4);
|
||||
|
||||
info = new ex_dividend_info()
|
||||
{
|
||||
UnderlyingCode = "600406.SH",
|
||||
ExDividendDate = new DateTime(2020, 7, 8),
|
||||
GiveCashAmount = 2.9,
|
||||
GiveShareAmount = 0,
|
||||
RationedSharesAmount = 0,
|
||||
RationedSharesPrice = 0,
|
||||
};
|
||||
price = service.GetPrice(20.1893, info);
|
||||
Assert.IsTrue((price - 19.9785) < 1e-4);
|
||||
|
||||
info = new ex_dividend_info()
|
||||
{
|
||||
UnderlyingCode = "600406.SH",
|
||||
ExDividendDate = new DateTime(2020, 7, 8),
|
||||
GiveCashAmount = 2.9,
|
||||
GiveShareAmount = 0,
|
||||
RationedSharesAmount = 0,
|
||||
RationedSharesPrice = 0,
|
||||
};
|
||||
price = service.GetPrice(19.9454, info);
|
||||
Assert.IsTrue((price - 19.7371) < 1e-4);
|
||||
|
||||
info = new ex_dividend_info()
|
||||
{
|
||||
UnderlyingCode = "601021.SH",
|
||||
ExDividendDate = new DateTime(2020, 7, 8),
|
||||
GiveCashAmount = 2.0006,
|
||||
GiveShareAmount = 0,
|
||||
RationedSharesAmount = 0,
|
||||
RationedSharesPrice = 0,
|
||||
};
|
||||
price = service.GetPrice(37.13, info);
|
||||
Assert.IsTrue((price - 36.9776) < 1e-4);
|
||||
|
||||
info = new ex_dividend_info()
|
||||
{
|
||||
UnderlyingCode = "300001.SZ",
|
||||
ExDividendDate = new DateTime(2020, 7, 13),
|
||||
GiveCashAmount = 0.2,
|
||||
GiveShareAmount = 0,
|
||||
RationedSharesAmount = 0,
|
||||
RationedSharesPrice = 0,
|
||||
};
|
||||
price = service.GetPrice(20.381, info);
|
||||
Assert.IsTrue((price - 20.3681) < 1e-4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user