refactor: 新增 DirectionRatio 方向因子纯函数, 替换7处三元式
多空方向(PositionType==Long?1:-1)和收付方向(xxx==收取?1:-1) 在两个上帝类里重复 15+处, +1/-1 写反是常见 bug 源。 新增 ReturnLegs/DirectionRatio.cs: - LongShort(positionType): 多头=+1, 空头=-1 - ReceivePay(direction): 收取=+1, 支付=-1 替换: - SwapEodPositionService: 6处 shortRatio 三元式(含注释1处) - SwapDealService: 1处 shortRatio + 1处 directionRatio 验证: 编译0错误, 全量511测试7失败(基线一致)。
This commit is contained in:
@@ -1693,7 +1693,7 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
payQty = Math.Abs(payQty);
|
||||
int ratio = eventFlow.PayDirection == (int)SwapDirectionEnum.收取 ? 1 : -1;//收取为正,支付为负
|
||||
int shortRatio = newEodPayPosition.PositionType == (int)PositionTypeFlag.Long ? 1 : -1;//多空方向
|
||||
int shortRatio = DirectionRatio.LongShort(newEodPayPosition.PositionType);
|
||||
newEodPayPosition.ValueDate = eventFlow.PayDate.Value;
|
||||
newEodPayPosition.PositionId = eventFlow.PositionId;
|
||||
newEodPayPosition.ClientId = td.ClientId;
|
||||
@@ -1791,7 +1791,7 @@ namespace YLErp.Modules.SwapModule
|
||||
return curretEod;
|
||||
}
|
||||
var dealDate = curretEod.ValueDate;
|
||||
int shortRatio = eod.PositionType == (int)PositionTypeFlag.Long ? 1 : -1;
|
||||
int shortRatio = DirectionRatio.LongShort(eod.PositionType);
|
||||
int directionRatio = eod.PosiDirection == (int)SwapDirectionEnum.收取 ? 1 : -1;
|
||||
curretEod.PosiStatus = curretEod.PosiQuantity == 0 ? 1 : 0;
|
||||
var price = GetSwapValuationPrice(eod.UnderlyingCode, dealDate, out decimal vobp);
|
||||
@@ -1883,7 +1883,7 @@ namespace YLErp.Modules.SwapModule
|
||||
return curretEod;
|
||||
}
|
||||
var dealDate = curretEod.ValueDate;
|
||||
int shortRatio = eod.PositionType == (int)PositionTypeFlag.Long ? 1 : -1;
|
||||
int shortRatio = DirectionRatio.LongShort(eod.PositionType);
|
||||
int directionRatio = eod.PosiDirection == (int)SwapDirectionEnum.收取 ? 1 : -1;
|
||||
var price = GetSwapValuationPrice(eod.UnderlyingCode, dealDate, out decimal vobp);
|
||||
var todayConsumedDividend = CalcConsumedDividend(curretEod, unwindEvents);
|
||||
@@ -1971,7 +1971,7 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
return;
|
||||
}
|
||||
int shortRatio = eod.PositionType == (int)PositionTypeFlag.Long ? 1 : -1;
|
||||
int shortRatio = DirectionRatio.LongShort(eod.PositionType);
|
||||
int directionRatio = eod.PosiDirection == (int)SwapDirectionEnum.收取 ? 1 : -1;
|
||||
var unwindFlowEvents = unwindEvents.Where(x => x.EventType == (int)SwapFlowEventTypeEnum.平仓).ToList();
|
||||
var openFlowEvents = unwindEvents.Where(x => x.EventType == (int)SwapFlowEventTypeEnum.开仓).ToList();
|
||||
@@ -2052,7 +2052,7 @@ namespace YLErp.Modules.SwapModule
|
||||
curretEod.SwapTradeId = td.id;
|
||||
curretEod.PositionId = position.id;
|
||||
curretEod.ClientId = td.ClientId;
|
||||
int shortRatio = position.PositionType == (int)PositionTypeFlag.Long ? 1 : -1;
|
||||
int shortRatio = DirectionRatio.LongShort(position.PositionType);
|
||||
int directionRatio = position.PosiDirection == (int)SwapDirectionEnum.收取 ? 1 : -1;
|
||||
curretEod.PositionType = position.PositionType;
|
||||
var eod = new eod_swap_position()
|
||||
|
||||
Reference in New Issue
Block a user