503 lines
30 KiB
C#
503 lines
30 KiB
C#
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.Linq;
|
|
//using YLErp.BLL.Calculation.V2;
|
|
//using YLErp.Commons;
|
|
//using YLErp.DBModels;
|
|
//using YLErp.DBModels.Consts;
|
|
//using YLErp.Model;
|
|
//using YLErp.QdpModule;
|
|
//using CalculatorHelper = YLErp.BLL.Calculation.CalculatorHelperOld;
|
|
|
|
//namespace YLErp.BLL.MarginCalculationBak
|
|
//{
|
|
// /// <summary>
|
|
// /// 国泰君安保证金计算
|
|
// /// </summary>
|
|
// public class HaiTongMarginCalculation : MarginCalculationBase
|
|
// {
|
|
// // 定义一个静态变量来保存类的实例
|
|
// public static readonly HaiTongMarginCalculation Instance;
|
|
|
|
// static HaiTongMarginCalculation()
|
|
// {
|
|
// Instance = new HaiTongMarginCalculation();
|
|
// }
|
|
|
|
// // 定义私有构造函数,使外界不能创建该类实例
|
|
// protected HaiTongMarginCalculation()
|
|
// {
|
|
// }
|
|
|
|
// public override List<trade_span> RunMarginCalculation(int userId, string userName, List<trade> tradeList, DateTime settleDate, Dictionary<int, double> priceDict, bool hasOptionInfo = false, bool isEodSettle = false, bool forSingleTrade = true, string volType = "交易", bool forOtherSide = false)
|
|
// {
|
|
// //结果集
|
|
// Dictionary<int, trade_span> resultMap = new Dictionary<int, trade_span>();
|
|
// using (YLContext db = new YLContext())
|
|
// {
|
|
// //为了算客户角度的一个保证金数值
|
|
// if (forOtherSide)
|
|
// {
|
|
// tradeList.ForEach(x => x.BuySell = x.BuySell == "买入" ? "卖出" : "买入");
|
|
// }
|
|
// if (!(priceDict?.Count > 0))
|
|
// {
|
|
// var codes = tradeList.Select(O => O.UnderlyingCode).ToArray();
|
|
// priceDict = base.GetSettlePrice(codes, settleDate);
|
|
// }
|
|
// if (priceDict.Count == 0)
|
|
// {
|
|
// //如果价格没有传入也没从数据库获取到,就直接返回,没必要往下运行了。但不应该报错;
|
|
// return resultMap.Values.ToList();
|
|
// }
|
|
|
|
// var underlyingIds = priceDict.Keys.ToList();
|
|
|
|
// //获取标的涨跌幅限制
|
|
// var umDatas = (from um in db.underlying_manager
|
|
// join variety in db.variety on um.CommodityCode equals variety.VarietyCode
|
|
// where underlyingIds.Contains(um.id)
|
|
// select new
|
|
// {
|
|
// um.id,
|
|
// um.VolatilityRate,
|
|
// um.UpDownLimit,
|
|
// defUpLimit = variety.UpLimit,
|
|
// defDownLimit = variety.DownLimit,
|
|
// defVolatilityRate = variety.VolatilityRate
|
|
// }).ToList();
|
|
|
|
// var UpLimitDict = new Dictionary<int, string>();
|
|
// var DownLimitDict = new Dictionary<int, string>();
|
|
// var umVolatilityRateDic = new Dictionary<int, double>();
|
|
// var downVolatilityRateDic = new Dictionary<int, double>();
|
|
|
|
// if (umDatas != null && umDatas.Count > 0)
|
|
// {
|
|
// umDatas.ForEach(t =>
|
|
// {
|
|
// //OTC-8856 Start
|
|
// //1.波动率变化
|
|
// if (DataConvert.TryParsePercentValue(t.VolatilityRate, out double pvalue) && (Math.Abs(pvalue) >= 1e-5))
|
|
// {
|
|
// umVolatilityRateDic[t.id] = pvalue;
|
|
// downVolatilityRateDic[t.id] = -pvalue;
|
|
// }
|
|
// else if (DataConvert.TryParsePercentValue(t.defVolatilityRate, out pvalue) && (Math.Abs(pvalue) >= 1e-5))
|
|
// {
|
|
// umVolatilityRateDic[t.id] = pvalue;
|
|
// downVolatilityRateDic[t.id] = -pvalue;
|
|
// }
|
|
|
|
// //2.涨跌停板幅度
|
|
// if (!string.IsNullOrWhiteSpace(t.UpDownLimit))
|
|
// {
|
|
// UpLimitDict[t.id] = t.UpDownLimit;//百分比或绝对值
|
|
// DownLimitDict[t.id] = t.UpDownLimit;
|
|
// }
|
|
// else
|
|
// {
|
|
// UpLimitDict[t.id] = t.defUpLimit?.ToString() ?? "5%";
|
|
// DownLimitDict[t.id] = t.defDownLimit?.ToString() ?? "5%";
|
|
// }
|
|
// });
|
|
// }
|
|
|
|
// if (!hasOptionInfo)
|
|
// {
|
|
// tradeBLL.SetFieldsByTradeType(tradeList);
|
|
// }
|
|
|
|
// var tradeVolatilityRateDicUp = tradeList.ToDictionary(t => t.id, t => umVolatilityRateDic.ContainsKey(t.UnderlyingId) ? umVolatilityRateDic[t.UnderlyingId] : 0)
|
|
// .Where(d => d.Value > 0).ToDictionary(d => d.Key, d => d.Value);
|
|
// var tradeVolatilityRateDicDown = tradeList.ToDictionary(t => t.id, t => downVolatilityRateDic.ContainsKey(t.UnderlyingId) ? downVolatilityRateDic[t.UnderlyingId] : 0)
|
|
// .Where(d => d.Value > 0).ToDictionary(d => d.Key, d => d.Value);
|
|
// Dictionary<string, Dictionary<int, double>> eodPriceDict = new Dictionary<string, Dictionary<int, double>>();
|
|
// var upLimitPrices = new Dictionary<int, double>();
|
|
// var downLimitPrices = new Dictionary<int, double>();
|
|
// var normalLimitPrices = new Dictionary<int, double>();
|
|
// double tempDouble;
|
|
// //根据涨跌幅限制以及当日结算价计算涨停价以及跌停价
|
|
// foreach (var t in priceDict)
|
|
// {
|
|
// //UpLimit
|
|
// if (UpLimitDict.ContainsKey(t.Key))
|
|
// {
|
|
// var tempVaue = UpLimitDict[t.Key];
|
|
// if (tempVaue.Contains("%"))
|
|
// {
|
|
// //百分比
|
|
// double.TryParse(tempVaue.Replace("%", ""), out tempDouble);
|
|
// upLimitPrices[t.Key] = t.Value * (1 + (tempDouble * 0.01));
|
|
// }
|
|
// else
|
|
// {
|
|
// //绝对值
|
|
// double.TryParse(tempVaue, out double tempAbs);
|
|
// upLimitPrices[t.Key] = t.Value + Math.Abs(tempAbs);
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// upLimitPrices[t.Key] = t.Value * 1.05;
|
|
// }
|
|
|
|
// //DownLimit
|
|
// if (DownLimitDict.ContainsKey(t.Key))
|
|
// {
|
|
// var tempVaue = DownLimitDict[t.Key];
|
|
// if (tempVaue.Contains("%"))
|
|
// {
|
|
// //百分比
|
|
// double.TryParse(tempVaue.Replace("%", ""), out tempDouble);
|
|
// downLimitPrices[t.Key] = t.Value * (1 - (tempDouble * 0.01));
|
|
// }
|
|
// else
|
|
// {
|
|
// //绝对值
|
|
// double.TryParse(tempVaue, out double tempAbs);
|
|
// downLimitPrices[t.Key] = t.Value - Math.Abs(tempAbs);
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// downLimitPrices[t.Key] = t.Value * 0.95;
|
|
// }
|
|
|
|
// //Normal
|
|
// normalLimitPrices[t.Key] = t.Value;
|
|
// }
|
|
// eodPriceDict["up"] = upLimitPrices;
|
|
// eodPriceDict["down"] = downLimitPrices;
|
|
// eodPriceDict["normal"] = normalLimitPrices;
|
|
|
|
// //波动率变化
|
|
// var addVolRateDic = new Dictionary<int, Dictionary<int, double>>();
|
|
// addVolRateDic[0] = null;
|
|
// addVolRateDic[1] = tradeVolatilityRateDicUp;
|
|
// addVolRateDic[2] = tradeVolatilityRateDicDown;
|
|
|
|
// //交易对应客户信息
|
|
// var clientIds = tradeList.Select(t => t.ClientId).ToList();
|
|
// var clientList = (from client in db.client
|
|
// join clientlevel in db.clientlevel
|
|
// on client.LevelId equals clientlevel.id into tempClientlevel
|
|
// from clientlevelTT in tempClientlevel.DefaultIfEmpty()
|
|
// where clientIds.Contains(client.id)
|
|
// select new
|
|
// {
|
|
// client,
|
|
// clientlevel = clientlevelTT
|
|
// }).ToList();
|
|
|
|
// var userIdNew = UniqueTimeId.Get().ToString();
|
|
|
|
// try
|
|
// {
|
|
// foreach (var price in eodPriceDict)
|
|
// {
|
|
// foreach (var itemDic in addVolRateDic)
|
|
// {
|
|
// var key = $"{price.Key}_{itemDic.Key}";
|
|
// var tradeRiskResult = CalculatorHelper.CalculateRisksForTrades(
|
|
// userIdNew, // userId + "_" + price.Key,
|
|
// settleDate,
|
|
// tradeList,
|
|
// price.Value,
|
|
// ValueCalculator.PV_ONLY,
|
|
// itemDic.Value,
|
|
// isEodSettle,
|
|
// volType,
|
|
// isUseTradeVol: PS.Config.IsTradeVol,
|
|
// PreciseTimeMode: !isEodSettle,
|
|
// isAddVolPercent: false);
|
|
// if (tradeRiskResult.Results != null && tradeRiskResult.Results.Count > 0)
|
|
// {
|
|
// foreach (var item in tradeRiskResult.Results)
|
|
// {
|
|
// var client = clientList.FirstOrDefault(c => c.client.id == item.Trade.ClientId);
|
|
// var clientRatio = client == null ? 1.0 : (client.clientlevel == null ? 1.0 : (client.clientlevel.Ratio ?? 1.0));
|
|
|
|
// double value = 0;
|
|
// if (item.Trade.TradeType == "自定义交易")
|
|
// {
|
|
// var eodTradeRiskManual = db.eod_trade_risk_manual.Where(x => x.ValueDate <= settleDate && x.TradeId == item.Trade.id).OrderByDescending(x => x.ValueDate).FirstOrDefault();
|
|
// //收盘时如果自定义交易还活着且没有维护当日风险,并且收的时系统日期当日的盘,抛出exception
|
|
// if (isEodSettle && !ConsTrade.TradeCompleteStatus.Contains(item.Trade.TradeStatus) && settleDate == valuedateBLL.SystemDate.ValueDate)
|
|
// {
|
|
// if (eodTradeRiskManual == null || eodTradeRiskManual.ValueDate != settleDate)
|
|
// {
|
|
// var error = $"TradeNumber:{item.Trade.TradeNumber}在{settleDate.ToString("yyyy-MM-dd")}需先进行交易风险维护";
|
|
// throw new Exception(error);
|
|
// }
|
|
// }
|
|
|
|
// value = eodTradeRiskManual?.Margin ?? 0;
|
|
// }
|
|
// if (resultMap.ContainsKey(item.Trade.id))
|
|
// {
|
|
// switch (key)
|
|
// {
|
|
// case "up_1":
|
|
// resultMap[item.Trade.id].Spv1 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// case "up_0":
|
|
// resultMap[item.Trade.id].Spv2 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// case "up_2":
|
|
// resultMap[item.Trade.id].Spv3 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// case "normal_1":
|
|
// resultMap[item.Trade.id].Spv4 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// case "normal_2":
|
|
// resultMap[item.Trade.id].Spv5 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// case "down_1":
|
|
// resultMap[item.Trade.id].Spv6 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// case "down_0":
|
|
// resultMap[item.Trade.id].Spv7 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// case "down_2":
|
|
// resultMap[item.Trade.id].Spv8 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// default:
|
|
// break;
|
|
// }
|
|
// resultMap[item.Trade.id].setWorstCastClientPayable8();
|
|
// }
|
|
// else
|
|
// {
|
|
// var trade = tradeList.FirstOrDefault(t => t.id == item.Trade.id);
|
|
// var tempTradeSpan = new trade_span
|
|
// {
|
|
// TradeId = item.Trade.id,
|
|
// ClientId = trade.ClientId,
|
|
// ValueDate = settleDate,
|
|
// UnderlyingId = trade.UnderlyingId,
|
|
// UnderlyingCode = trade.UnderlyingCode,
|
|
// OptId = userId,
|
|
// OptName = userName,
|
|
// OptDate = DateTime.Now
|
|
// };
|
|
// switch (key)
|
|
// {
|
|
// case "up_1":
|
|
// tempTradeSpan.Spv1 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// case "up_0":
|
|
// tempTradeSpan.Spv2 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// case "up_2":
|
|
// tempTradeSpan.Spv3 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// case "normal_1":
|
|
// tempTradeSpan.Spv4 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// case "normal_2":
|
|
// tempTradeSpan.Spv5 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// case "down_1":
|
|
// tempTradeSpan.Spv6 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// case "down_0":
|
|
// tempTradeSpan.Spv7 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// case "down_2":
|
|
// tempTradeSpan.Spv8 = item.Trade.TradeType == "自定义交易" ? value : (double.IsNaN(item.ValueResult.Pv) ? 0 : item.ValueResult.Pv) * clientRatio;
|
|
// break;
|
|
// default:
|
|
// break;
|
|
// }
|
|
// resultMap[item.Trade.id] = tempTradeSpan;
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// finally
|
|
// {
|
|
// //上面的计算用到静态生成market,需要清除
|
|
// QdpMarketManager.Instance.RemovePrebuiltMarketProxy(userIdNew);
|
|
// }
|
|
|
|
// //为了保持原有交易买卖方向不变
|
|
// if (forOtherSide)
|
|
// {
|
|
// tradeList.ForEach(x => x.BuySell = x.BuySell == "买入" ? "卖出" : "买入");
|
|
// }
|
|
|
|
// return resultMap.Values.ToList();
|
|
// }
|
|
// }
|
|
|
|
// public override bool CalcClientMargin(int userId, string userName, DateTime settleDate, List<trade_span> tradeSpans, List<trade_span> tradeSpansOtherSide, int SpanType = 0, List<int> RefreshClientIds = null, bool OnlyBuyer = false, Dictionary<int, double> clientAdditionalMarginDic = null)
|
|
// {
|
|
// using (YLContext db = new YLContext())
|
|
// {
|
|
// //删除
|
|
// if (tradeSpans != null && tradeSpans.Count > 0)
|
|
// {
|
|
// var tradeIds = tradeSpans.Select(t => t.TradeId).ToList();
|
|
// var tradeList = db.trade.AsNoTracking().Where(t => tradeIds.Contains(t.id)).ToList();
|
|
// var clientIds = tradeSpans.Select(t => t.ClientId).Distinct().ToList();
|
|
// var clientList = db.client.Where(x => clientIds.Contains(x.id)).ToList();
|
|
// var tradeSpanInfo = (from tradeSpan in tradeSpans
|
|
// join
|
|
// trade in tradeList on tradeSpan.TradeId equals trade.id
|
|
// where tradeSpan.ValueDate == settleDate
|
|
// select new { trade, tradeSpan }).ToList();
|
|
|
|
// var clientSpanNews = new List<client_span>();
|
|
// var clientGroups = tradeSpanInfo.GroupBy(t => t.trade.ClientId);
|
|
// foreach (var clientGroup in clientGroups)
|
|
// {
|
|
// var underlyingGroup = clientGroup.GroupBy(t => t.trade.UnderlyingId).Select(t => new client_span
|
|
// {
|
|
// UnderlyingId = t.Key,
|
|
// ClientId = clientGroup.Key,
|
|
// ValueDate = settleDate,
|
|
// Spv1 = t.Sum(g => g.tradeSpan.Spv1) * (-1),
|
|
// Spv2 = t.Sum(g => g.tradeSpan.Spv2) * (-1),
|
|
// Spv3 = t.Sum(g => g.tradeSpan.Spv3) * (-1),
|
|
// Spv4 = t.Sum(g => g.tradeSpan.Spv4) * (-1),
|
|
// Spv5 = t.Sum(g => g.tradeSpan.Spv5) * (-1),
|
|
// Spv6 = t.Sum(g => g.tradeSpan.Spv6) * (-1),
|
|
// Spv7 = t.Sum(g => g.tradeSpan.Spv7) * (-1),
|
|
// Spv8 = t.Sum(g => g.tradeSpan.Spv8) * (-1),
|
|
// OptId = userId,
|
|
// OptName = userName,
|
|
// OptDate = DateTime.Now,
|
|
// SpanType = SpanType
|
|
// }).ToList();
|
|
// foreach (var item in underlyingGroup)
|
|
// {
|
|
// item.WorstCastClientPayable = new double[] {
|
|
// item.Spv1 ?? 0, item.Spv2 ?? 0, item.Spv3 ?? 0, item.Spv4 ?? 0, item.Spv5 ?? 0, item.Spv6 ?? 0, item.Spv7 ?? 0, item.Spv8 ?? 0
|
|
// }.Min();
|
|
|
|
// #region 更新tradeSpan,使得每笔交易的持仓保证金和客户保证金计算用的Spv组保持一致
|
|
|
|
// var tradeSpansUpdate = db.trade_span.Where(x => x.ClientId == item.ClientId && x.UnderlyingId == item.UnderlyingId && x.ValueDate == settleDate).ToList();
|
|
// if (item.WorstCastClientPayable == item.Spv1)
|
|
// {
|
|
// tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv1);
|
|
// }
|
|
// else if (item.WorstCastClientPayable == item.Spv2)
|
|
// {
|
|
// tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv2);
|
|
// }
|
|
// else if (item.WorstCastClientPayable == item.Spv3)
|
|
// {
|
|
// tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv3);
|
|
// }
|
|
// else if (item.WorstCastClientPayable == item.Spv4)
|
|
// {
|
|
// tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv4);
|
|
// }
|
|
// else if (item.WorstCastClientPayable == item.Spv5)
|
|
// {
|
|
// tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv5);
|
|
// }
|
|
// else if (item.WorstCastClientPayable == item.Spv6)
|
|
// {
|
|
// tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv6);
|
|
// }
|
|
// else if (item.WorstCastClientPayable == item.Spv7)
|
|
// {
|
|
// tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv7);
|
|
// }
|
|
// else
|
|
// {
|
|
// tradeSpansUpdate.ForEach(x => x.WorstCastClientPayable = x.Spv8);
|
|
// }
|
|
|
|
// #endregion
|
|
|
|
// if (!PS.Config.ErpElement.NonInterBankMarginNetting)
|
|
// {
|
|
// item.WorstCastClientPayable = Math.Min(item.WorstCastClientPayable.Value, 0);
|
|
// }
|
|
// }
|
|
// var clientSpan = new client_span
|
|
// {
|
|
// ClientId = clientGroup.Key,
|
|
// ValueDate = settleDate,
|
|
// Spv1 = underlyingGroup.Sum(g => g.Spv1),
|
|
// Spv2 = underlyingGroup.Sum(g => g.Spv2),
|
|
// Spv3 = underlyingGroup.Sum(g => g.Spv3),
|
|
// Spv4 = underlyingGroup.Sum(g => g.Spv4),
|
|
// Spv5 = underlyingGroup.Sum(g => g.Spv5),
|
|
// Spv6 = underlyingGroup.Sum(g => g.Spv6),
|
|
// Spv7 = underlyingGroup.Sum(g => g.Spv7),
|
|
// Spv8 = underlyingGroup.Sum(g => g.Spv8),
|
|
// //负数代表客户应缴保证金,正数代表客户应收保证金
|
|
// WorstCastClientPayable = (PS.Config.ErpElement.TwoSideMargin && clientList.FirstOrDefault(x => x.id == clientGroup.Key) != null && clientList.FirstOrDefault(x => x.id == clientGroup.Key).HasTwoSideMargin == 1) ? underlyingGroup.Sum(g => g.WorstCastClientPayable) : underlyingGroup.Sum(g => g.WorstCastClientPayable) < 0 ? underlyingGroup.Sum(g => g.WorstCastClientPayable) : 0,
|
|
// TwoSideMargin = underlyingGroup.Sum(g => g.TwoSideMargin),
|
|
// OptId = userId,
|
|
// OptName = userName,
|
|
// OptDate = DateTime.Now,
|
|
// SpanType = SpanType,
|
|
// AdditionalWorstCastClientPayable = clientAdditionalMarginDic == null ? 0 : (clientAdditionalMarginDic.ContainsKey(clientGroup.Key ?? 0) ? clientAdditionalMarginDic[clientGroup.Key ?? 0] : 0)
|
|
// };
|
|
// clientSpanNews.Add(clientSpan);
|
|
// }
|
|
|
|
// //span类型为实时删除所有实时计算的交易的保证金信息
|
|
// if (SpanType == client_span.SpanType_RealTime)
|
|
// {
|
|
// //var clientIds = clientSpanNews.Select(t => t.ClientId).Distinct().ToList();
|
|
// //var clientSpanOlds = db.client_span.Where(t => t.SpanType == SpanType);
|
|
// if (RefreshClientIds != null)
|
|
// {
|
|
// //clientSpanOlds = db.client_span.Where(t => RefreshClientIds.Contains(t.ClientId ?? 0));
|
|
// db.BulkDelete<client_span>($"{nameof(client_span.ClientId)} in @ids", new { ids = RefreshClientIds });
|
|
// }
|
|
// else
|
|
// {
|
|
// db.BulkDelete<client_span>($"{nameof(client_span.SpanType)}=@SpanType", new { SpanType });
|
|
// }
|
|
// //MySqlBulkExtensions.BulkDelete(db, clientSpanOlds);
|
|
// MySqlBulkExtensions.BulkInsert(db, clientSpanNews);
|
|
// }
|
|
// else
|
|
// {
|
|
// //var clientSpanOldsWithOutFlag = db.client_span.Where(t => t.ValueDate == settleDate && t.SpanType == SpanType && !t.ModifiedFlag).ToList();
|
|
// //MySqlBulkExtensions.BulkDelete(db, clientSpanOldsWithOutFlag);
|
|
// db.BulkDelete<client_span>($"{nameof(client_span.ValueDate)}=@settleDate and {nameof(client_span.SpanType)}=@SpanType and {nameof(client_span.ModifiedFlag)}=0", new { settleDate, SpanType });
|
|
|
|
// var clientSpanOldsWithFlag = db.client_span.Where(t => t.ValueDate == settleDate && t.SpanType == SpanType && t.ModifiedFlag).ToList();
|
|
// //筛选出可以修改的clientSpan
|
|
// clientSpanNews = clientSpanNews.Where(c => !clientSpanOldsWithFlag.Any(t => t.ValueDate == c.ValueDate && t.ClientId == c.ClientId)).ToList();
|
|
// MySqlBulkExtensions.BulkInsert(db, clientSpanNews);
|
|
// }
|
|
|
|
|
|
// db.SaveChanges();
|
|
// }
|
|
// return true;
|
|
// }
|
|
// }
|
|
|
|
// public override double GetTradeMargin(trade trade, double price, bool isInitialMargin = false, bool hasOptionInfo = false)
|
|
// {
|
|
// using (YLContext db = new YLContext())
|
|
// {
|
|
// if (trade.TradeType == "结构化交易")
|
|
// {
|
|
// trade.SubTrades = db.trade.Where(x => x.ParentTradeId == trade.id).ToList();
|
|
// }
|
|
// }
|
|
|
|
// var tradeMargin = RunMarginCalculation(0, "系统", new List<trade> { trade }, isInitialMargin ? (trade.TradeDate ?? valuedateBLL.ValueDate) : valuedateBLL.ValueDate, new Dictionary<int, double> { { trade.UnderlyingId, price } }, hasOptionInfo: hasOptionInfo);
|
|
// if (null != tradeMargin)
|
|
// {
|
|
// return tradeMargin.FirstOrDefault()?.WorstCastClientPayable ?? 0.0;
|
|
// }
|
|
// return 0.0;
|
|
// }
|
|
// }
|
|
//}
|