namespace YLErp.Modules.CalculationModule { /// /// 股票交易计算帮助类 /// public class StockTradeCalcHelper { /// /// 股票印花税 /// 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; } /// /// 股票佣金 /// 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 "卖出"; } /// /// 股票交易费 /// 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; } /// /// 股票对冲其他费用 /// 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; } /// /// 获取交易手续费 /// 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); } } }