//using System; //using System.Collections.Generic; //using System.Linq; //using YLErp.DBModels; //using YLErp.Model; //namespace YLErp.BLL.MarginCalculationBak //{ // /// // /// 格林大华 // /// // public class GLDHMarginCalculation : MarginCalculationBase // { // // 定义一个静态变量来保存类的实例 // public static readonly GLDHMarginCalculation Instance; // static GLDHMarginCalculation() // { // Instance = new GLDHMarginCalculation(); // } // // 定义私有构造函数,使外界不能创建该类实例 // private GLDHMarginCalculation() // { // } // public override List RunMarginCalculation(int userId, string userName, List tradeList, DateTime settleDate, Dictionary priceDict, bool hasOptionInfo = false, bool isEodSettle = false, bool forSingleTrade = true, string volType = "交易", bool forOtherSide = false) // { // List tradeSpans = new List(); // //实际计算的时候没有使用到收盘价格,所以先把取价格的逻辑注释掉; // //if (!(priceDict?.Count > 0)) // //{ // // var codes = tradeList.Select(O => O.UnderlyingCode).ToArray(); // // priceDict = base.GetSettlePrice(codes, settleDate); // //} // //if (priceDict.Count == 0) // //{ // // //如果价格没有传入也没从数据库获取到,就直接返回,没必要往下运行了。但不应该报错; // // return tradeSpans; // //} // if (tradeList != null && tradeList.Count > 0) // { // var tempStockTradeList = tradeList.Where(t => t.UnderlyingInstrumentType == ConsGlobal.InstrumentType.Stock).ToList(); // if (tempStockTradeList.Any()) // { // var stockTradeSpanlist = StockMarginCalculation(userId, userName, tempStockTradeList, settleDate, priceDict, hasOptionInfo, isEodSettle); // if (stockTradeSpanlist.Count > 0) // { // tradeSpans.AddRange(stockTradeSpanlist); // } // } // var tempFutureTradeList = tradeList.Where(t => t.UnderlyingInstrumentType == ConsGlobal.InstrumentType.CommodityFutures).ToList(); // if (tempFutureTradeList.Any()) // { // var futureTradeSpanlist = FutureMarginCalculation(userId, userName, tempFutureTradeList, settleDate, priceDict, hasOptionInfo, isEodSettle); // if (futureTradeSpanlist.Count > 0) // { // tradeSpans.AddRange(futureTradeSpanlist); // } // } // } // return tradeSpans; // } // /// // /// 股票类期权计算保证金 // /// // /// // /// // /// // /// // /// // /// // public List StockMarginCalculation(int userId, string userName, List tradeList, DateTime settleDate, Dictionary priceDict, bool hasOptionInfo = false, bool isEodSettle = false) // { // List tradeSpans = new List(); // if (tradeList != null && tradeList.Count > 0) // { // using (YLContext db = new YLContext()) // { // var marginRation = valuedateBLL.SystemDate.MarginRatio ?? 0.15; // 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(); // if (clientList != null) // { // tradeList.ForEach(t => // { // var client = clientList.FirstOrDefault(c => c.client.id == t.ClientId); // if (client != null) // { // //未设置相关保证金系数默认为1.0 // var clientRatio = client.clientlevel == null ? 1.0 : (client.clientlevel.Ratio ?? 1.0); // //如果是股票去名义本金,如果是期货取:份额 * 即期价格 // var value = (t.StockEqvNotional ?? (t.Notional * t.SpotPrice ?? 0.0)) * marginRation * (t.BuySell == "买入" ? 1 : (PS.Config.ErpElement.TwoSideMargin && client.client.HasTwoSideMargin == 1 ? -1 : 0)) * clientRatio; // var twoSideMargin = (t.StockEqvNotional ?? (t.Notional * t.SpotPrice ?? 0.0)) * marginRation * (t.BuySell == "买入" ? 1 : -1) * clientRatio; // tradeSpans.Add(new trade_span // { // TradeId = t.id, // OptDate = DateTime.Now, // OptId = userId, // OptName = userName, // ClientId = client.client.id, // UnderlyingId = t.UnderlyingId, // UnderlyingCode = t.UnderlyingCode, // ValueDate = settleDate, // Spv1 = value, // Spv2 = value, // Spv3 = value, // Spv4 = value, // WorstCastClientPayable = value, // TwoSideMargin = twoSideMargin // }); // } // }); // } // } // } // return tradeSpans; // } // /// // /// 商品期权计算保证金 // /// // /// // /// // /// // /// // /// // /// // public List FutureMarginCalculation(int userId, string userName, List futureTradeList, DateTime settleDate, Dictionary priceDict, bool hasOptionInfo = false, bool isEodSettle = false) // { // List tradeSpans = new List(); // if (futureTradeList != null && futureTradeList.Count > 0) // { // using (YLContext db = new YLContext()) // { // var marginRation = valuedateBLL.SystemDate.FutureMarginRatio ?? 0.15; // var clientIds = futureTradeList.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(); // if (clientList != null) // { // futureTradeList.ForEach(t => // { // var client = clientList.FirstOrDefault(c => c.client.id == t.ClientId); // if (client != null) // { // //未设置相关保证金系数默认为1.0 // var clientRatio = client.clientlevel == null ? 1.0 : (client.clientlevel.Ratio ?? 1.0); // //如果是股票去名义本金,如果是期货取:份额 * 即期价格 // var value = (t.StockEqvNotional ?? (t.Notional * t.SpotPrice ?? 0.0)) * marginRation * (t.BuySell == "买入" ? 1 : (PS.Config.ErpElement.TwoSideMargin && client.client.HasTwoSideMargin == 1 ? -1 : 0)) * clientRatio; // var twoSideMargin = (t.StockEqvNotional ?? (t.Notional * t.SpotPrice ?? 0.0)) * marginRation * (t.BuySell == "买入" ? 1 : -1) * clientRatio; // tradeSpans.Add(new trade_span // { // TradeId = t.id, // OptDate = DateTime.Now, // OptId = userId, // OptName = userName, // ClientId = client.client.id, // UnderlyingId = t.UnderlyingId, // UnderlyingCode = t.UnderlyingCode, // ValueDate = settleDate, // Spv1 = value, // Spv2 = value, // Spv3 = value, // Spv4 = value, // WorstCastClientPayable = value, // TwoSideMargin = twoSideMargin // }); // } // }); // } // } // } // return tradeSpans; // } // 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 }, isInitialMargin ? (trade.TradeDate ?? valuedateBLL.ValueDate) : valuedateBLL.ValueDate, new Dictionary { { trade.UnderlyingId, price } }, hasOptionInfo: hasOptionInfo); // if (null != tradeMargin) // { // return tradeMargin.FirstOrDefault()?.WorstCastClientPayable ?? 0.0; // } // return 0.0; // } // } //}