public bool VaildateBearCollar() { IsVaildated = false; //BearCollar 必须是三腿的 if (Legs.Count != 3) { throw new VaildateException("BearCollar 必须是三腿的"); } var OptionLegsCount = Legs.Count((leg) => leg.Asset.GetType() == typeof(Option)); var SpotLegsCount = Legs.Count((leg) => leg.Asset.GetType() == typeof(STK)); if (!(OptionLegsCount == 2 && SpotLegsCount == 1)) { throw new VaildateException("BearCollar 必须有两腿期权和一腿现货,那才叫BearCollar啊!"); } //期权腿的集合 var OptionLegs = new List <Position>(); //归置出现货和期权头寸 Legs.ForEach((leg) => { if (leg.Asset.GetType() == typeof(Option)) { OptionLegs.Add(leg); } else { if (leg.Quantity >= 0) { throw new VaildateException("BearCollar 必须有现货头寸必须是做空的"); } else { PosSpot = leg; } } }); Option opt1 = (Option)OptionLegs[0].Asset; Option opt2 = (Option)OptionLegs[1].Asset; if (opt1.StrikePrice == opt2.StrikePrice) { throw new VaildateException("期权腿的执行价不能相同"); } //必须是异常权与同到期日的 if ((opt1.Right == opt2.Right) || (opt1.ExpiryDate != opt2.ExpiryDate)) { throw new VaildateException("BearCollar 两腿必须异权且同到期日"); } //必须是高执行价的Call做多,低执行价的Put做空 if (opt1.StrikePrice > opt2.StrikePrice) { if ((opt1.Right == OptionRight.CALL && OptionLegs[0].Quantity > 0) && (opt2.Right == OptionRight.PUT) && OptionLegs[1].Quantity < 0) { OptHigherK = opt1; OptLowerK = opt2; PosHigherK = OptionLegs[0]; PosLowerK = OptionLegs[1]; } else { throw new VaildateException("BearCollar 组成异常"); } } else { if ((opt2.Right == OptionRight.CALL && OptionLegs[1].Quantity > 0) && (opt1.Right == OptionRight.PUT) && OptionLegs[0].Quantity < 0) { OptHigherK = opt2; OptLowerK = opt1; PosHigherK = OptionLegs[1]; PosLowerK = OptionLegs[0]; } else { throw new VaildateException("BearCollar 组成异常"); } } return(true); }
public bool VaildateCBSS() { IsVaildated = false; //BearCollar 必须是三腿的 if (Legs.Count != 3) { throw new VaildateException("CBSS 必须是三腿的"); } var OptionLegsCount = Legs.Count((leg) => leg.Asset.GetType() == typeof(Option)); var SpotLegsCount = Legs.Count((leg) => leg.Asset.GetType() == typeof(STK)); if (!(OptionLegsCount == 2 && SpotLegsCount == 1)) { throw new VaildateException("CBSS 必须有两腿期权和一腿现货,那才叫BearCollar啊!"); } //期权腿的集合 var OptionLegs = new List <Position>(); //归置出现货和期权头寸 Legs.ForEach((leg) => { if (leg.Asset.GetType() == typeof(Option)) { OptionLegs.Add(leg); } else { if (leg.Quantity >= 0) { throw new VaildateException("CBSS 必须有现货头寸且必须是做空的"); } else { PosSpot = leg; } } }); Option opt1 = (Option)OptionLegs[0].Asset; Option opt2 = (Option)OptionLegs[1].Asset; if (opt1.StrikePrice == opt2.StrikePrice) { throw new VaildateException("期权腿的执行价不能相同"); } //必须是异常权与同到期日的 if ((opt1.Right == OptionRight.PUT || opt2.Right == OptionRight.PUT) || (opt1.ExpiryDate != opt2.ExpiryDate)) { throw new VaildateException("CBSS 两腿期权必须都是看涨期权且同到期日"); } if (opt1.StrikePrice > opt2.StrikePrice) { OptHigherK = opt1; OptLowerK = opt2; PosHigherK = OptionLegs[0]; PosLowerK = OptionLegs[1]; } else { OptHigherK = opt2; OptLowerK = opt1; PosHigherK = OptionLegs[1]; PosLowerK = OptionLegs[0]; } //高执行价价买低执行价卖 Higher(k) Buy Lower(k) Sell bool HBLS = PosHigherK.Quantity > 0 && PosLowerK.Quantity < 0; if (!HBLS) { throw new VaildateException("Call BackSpread 必须保证更高执行价是做多,低执行价是做空的"); } //高执行价看涨期权的张数必须比较低执行价的要高。 if (!(PosHigherK.Quantity > Math.Abs(PosLowerK.Quantity))) { throw new VaildateException("Call BackSpread 必须保证更高执行价的期权张数更多"); } //现货的持仓量必然是个负数,先取绝对值 bool Safe = Math.Abs(PosSpot.Quantity) <= PosHigherK.Quantity - PosLowerK.Quantity; if (!Safe) { throw new VaildateException("CBSS 必须保障两边的安全"); } return(false); }