Files
zszq-trs/YLErpDAL/Modules/CalculationModule/StockTradeCalcHelper.cs
T
2024-05-09 14:06:26 +08:00

101 lines
4.0 KiB
C#

namespace YLErp.Modules.CalculationModule
{
/// <summary>
/// 股票交易计算帮助类
/// </summary>
public class StockTradeCalcHelper
{
/// <summary>
/// 股票印花税
/// </summary>
private static double GetStockTradeStampDuty(ExchangeTrade trade, StockCommissionConfig config)
{
if (trade.TradeType == "股票" && trade.Notional != 0.0)
{
if (config != null && config.StampDutyType != null && config.StampDutyType.Contains(CovertStockTradeSide(trade.TradeSide)))
{
return Math.Max((config.StampDuty ?? 0.0) / 100 * (trade.TradeSinglePrice) * trade.Notional, config.MinStampDuty ?? 0.0);
}
}
return 0;
}
/// <summary>
/// 股票佣金
/// </summary>
private static double GetStockTradeCommission(ExchangeTrade trade, StockCommissionConfig config)
{
if (trade.TradeType == "股票" && trade.Notional != 0.0)
{
if (config != null && config.CommissionType != null && config.CommissionType.Contains(CovertStockTradeSide(trade.TradeSide)))
{
return Math.Max((config.Commission ?? 0.0) / 100 * (trade.TradeSinglePrice) * trade.Notional, config.MinCommission ?? 0.0);
}
}
return 0;
}
private static string CovertStockTradeSide(string tradeSide)
{
if ("买入".Equals(tradeSide) || "卖出".Equals(tradeSide))
{
return tradeSide;
}
if ("多头开仓".Equals(tradeSide) || "空头平仓".Equals(tradeSide))
{
return "买入";
}
return "卖出";
}
/// <summary>
/// 股票交易费
/// </summary>
private static double GetStockTradeTransferFee(ExchangeTrade trade, StockCommissionConfig config, bool actualTrade = true)
{
//交易费只上交所收取
var um = DataCacheProvider.GetUnderlyingDataSource().GetData(trade.UnderlyingId);
if (trade.TradeType == "股票" && (um == null || !"SZ".Equals(um.MarketCode)) && actualTrade && trade.Notional != 0.0)
{
if (config != null && config.TransferFeeType != null && config.TransferFeeType.Contains(CovertStockTradeSide(trade.TradeSide)))
{
var Fee = Math.Max((config.TransferFee ?? 0.0) / 100 * (trade.TradeSinglePrice) * trade.Notional, config.MinTransferFee ?? 0.0);
if (trade.Notional <= 1000)
{
return Math.Max(Fee, config.MinTransferFee ?? 0.0);
}
else
{
return Fee;
}
}
}
return 0;
}
/// <summary>
/// 股票对冲其他费用
/// </summary>
private static double GetStockTradeOtherExpenses(ExchangeTrade trade, StockCommissionConfig config)
{
if (trade.TradeType == "股票" && trade.Notional != 0.0)
{
if (config != null && config.OtherExpensesType != null && config.OtherExpensesType.Contains(CovertStockTradeSide(trade.TradeSide)))
{
return Math.Min(Math.Max((config.OtherExpenses ?? 0.0) / 100 * (trade.TradeSinglePrice) * trade.Notional, config.MinOtherExpenses ?? 0.0), config.MaxOtherExpenses ?? 0.0);
}
}
return 0;
}
/// <summary>
/// 获取交易手续费
/// </summary>
public static double GetStockAllTradeExpenses(ExchangeTrade trade, StockCommissionConfig config, bool actualTrade = true)
{
return GetStockTradeStampDuty(trade, config) + GetStockTradeCommission(trade, config) + GetStockTradeTransferFee(trade, config, actualTrade) + GetStockTradeOtherExpenses(trade, config);
}
}
}