Skip to content

Commit

Permalink
Fix 3/4 of CA2201 warnings (#8102)
Browse files Browse the repository at this point in the history
* Fix 2/4 of CA2201 Warnings

* Fix 3/4 of CA2201 warnings
  • Loading branch information
Marinovsky committed Jun 24, 2024
1 parent f8b169a commit aa5ab68
Show file tree
Hide file tree
Showing 103 changed files with 310 additions and 310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public override void OnData(Slice slice)
{
if (MarketOrder(_contract.Symbol, 1).Status != OrderStatus.Filled)
{
throw new Exception("Expected market order to fill immediately");
throw new RegressionTestException("Expected market order to fill immediately");
}

_marketOrderDone = true;
Expand All @@ -93,7 +93,7 @@ public override void OnData(Slice slice)
{
if (ExerciseOption(_contract.Symbol, 1).Status == OrderStatus.Filled)
{
throw new Exception($"Expected index option to not be exercisable on its expiration date. " +
throw new RegressionTestException($"Expected index option to not be exercisable on its expiration date. " +
$"Time: {UtcTime}. Expiry: {_contract.Expiry.ConvertToUtc(_option.Exchange.TimeZone)}");
}

Expand All @@ -112,7 +112,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
var profit = Portfolio.TotalPortfolioValue - _initialCash;
if (profit < 0)
{
throw new Exception($"Expected profit to be positive. Actual: {profit}");
throw new RegressionTestException($"Expected profit to be positive. Actual: {profit}");
}

_automaticallyExercised = true;
Expand All @@ -123,12 +123,12 @@ public override void OnEndOfAlgorithm()
{
if (!_triedExercise)
{
throw new Exception("Expected to try to exercise index option before and on expiry");
throw new RegressionTestException("Expected to try to exercise index option before and on expiry");
}

if (!_automaticallyExercised || Portfolio.Cash <= _initialCash)
{
throw new Exception("Expected index option to have ben automatically exercised on expiry and to have received cash");
throw new RegressionTestException("Expected index option to have ben automatically exercised on expiry and to have received cash");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override void OnData(Slice data)
var history = History(new[] { spy }, TimeSpan.FromDays(10));
if (!history.Any() || !history.All(slice => slice.Bars.All(pair => pair.Value.Period == TimeSpan.FromHours(1))))
{
throw new Exception("Unexpected history result for internal subscription");
throw new RegressionTestException("Unexpected history result for internal subscription");
}

// we add SPY using Daily > default benchmark using hourly
Expand All @@ -62,7 +62,7 @@ public override void OnData(Slice data)
history = History(new[] { spy }, TimeSpan.FromDays(10));
if (!history.Any() || !history.All(slice => slice.Bars.All(pair => pair.Value.Period == TimeSpan.FromDays(1))))
{
throw new Exception("Unexpected history result for user subscription");
throw new RegressionTestException("Unexpected history result for user subscription");
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Algorithm.CSharp/IronCondorStrategyAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup
{
if (positionGroup.Positions.Count() != 4)
{
throw new Exception($"Expected position group to have 4 positions. Actual: {positionGroup.Positions.Count()}");
throw new RegressionTestException($"Expected position group to have 4 positions. Actual: {positionGroup.Positions.Count()}");
}

var orderedStrikes = _ironCondor.OptionLegs.Select(leg => leg.Strike).OrderBy(x => x).ToArray();
Expand All @@ -72,31 +72,31 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup
.Single(x => x.Symbol.ID.OptionRight == OptionRight.Put && x.Symbol.ID.StrikePrice == longPutStrike);
if (longPutPosition.Quantity != 2)
{
throw new Exception($"Expected long put position quantity to be 2. Actual: {longPutPosition.Quantity}");
throw new RegressionTestException($"Expected long put position quantity to be 2. Actual: {longPutPosition.Quantity}");
}

var shortPutStrike = orderedStrikes[1];
var shortPutPosition = positionGroup.Positions
.Single(x => x.Symbol.ID.OptionRight == OptionRight.Put && x.Symbol.ID.StrikePrice == shortPutStrike);
if (shortPutPosition.Quantity != -2)
{
throw new Exception($"Expected short put position quantity to be -2. Actual: {shortPutPosition.Quantity}");
throw new RegressionTestException($"Expected short put position quantity to be -2. Actual: {shortPutPosition.Quantity}");
}

var shortCallStrike = orderedStrikes[2];
var shortCallPosition = positionGroup.Positions
.Single(x => x.Symbol.ID.OptionRight == OptionRight.Call && x.Symbol.ID.StrikePrice == shortCallStrike);
if (shortCallPosition.Quantity != -2)
{
throw new Exception($"Expected short call position quantity to be -2. Actual: {shortCallPosition.Quantity}");
throw new RegressionTestException($"Expected short call position quantity to be -2. Actual: {shortCallPosition.Quantity}");
}

var longCallStrike = orderedStrikes[3];
var longCallPosition = positionGroup.Positions
.Single(x => x.Symbol.ID.OptionRight == OptionRight.Call && x.Symbol.ID.StrikePrice == longCallStrike);
if (longCallPosition.Quantity != 2)
{
throw new Exception($"Expected long call position quantity to be 2. Actual: {longCallPosition.Quantity}");
throw new RegressionTestException($"Expected long call position quantity to be 2. Actual: {longCallPosition.Quantity}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion Algorithm.CSharp/IsMarketOpenCheckAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected void AssertIsMarketOpen(bool expected)
Log($"IsMarketOpen at {Time}?: {isMarketOpen}");
if (isMarketOpen != expected)
{
throw new Exception($"Expected IsMarketOpen to be {expected} at {Time}.");
throw new RegressionTestException($"Expected IsMarketOpen to be {expected} at {Time}.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion Algorithm.CSharp/LargeQuantityOptionStrategyAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public override void OnEndOfAlgorithm()

if (filledOrders.Count != 2)
{
throw new Exception($"Expected 2 filled orders but found {filledOrders.Count}");
throw new RegressionTestException($"Expected 2 filled orders but found {filledOrders.Count}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion Algorithm.CSharp/LeveragePrecedenceRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override void OnData(Slice data)

if (Securities[_spy].Leverage != 10)
{
throw new Exception($"Expecting leverage to be 10, was {Securities[_spy].Leverage}");
throw new RegressionTestException($"Expecting leverage to be 10, was {Securities[_spy].Leverage}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion Algorithm.CSharp/LimitIfTouchedRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)

if (orderEvent.ToString() != expected)
{
throw new Exception($"orderEvent {orderEvent.Id} differed from {expected}. Actual {orderEvent}");
throw new RegressionTestException($"orderEvent {orderEvent.Id} differed from {expected}. Actual {orderEvent}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public override void OnWarmupFinished()
// Right after warm up we should be outside regular market hours
if (_futureContract.Exchange.ExchangeOpen)
{
throw new Exception("We should be outside regular market hours");
throw new RegressionTestException("We should be outside regular market hours");
}

// Market on open order should not be allowed for futures outside of regular market hours
var futureContractMarketOnOpenOrder = MarketOnOpenOrder(_futureContract.Symbol, 1);
if (futureContractMarketOnOpenOrder.Status != OrderStatus.Invalid)
{
throw new Exception($"Market on open order should not be allowed for futures outside of regular market hours");
throw new RegressionTestException($"Market on open order should not be allowed for futures outside of regular market hours");
}
}

Expand All @@ -77,7 +77,7 @@ public override void OnData(Slice slice)
var continuousContractLimitOrder = LimitOrder(_continuousContract.Mapped, 1, _continuousContract.Price * 2m);
if (futureContractLimitOrder.Status == OrderStatus.Invalid || continuousContractLimitOrder.Status == OrderStatus.Invalid)
{
throw new Exception($"Limit order should be allowed for futures outside of regular market hours");
throw new RegressionTestException($"Limit order should be allowed for futures outside of regular market hours");
}
}
}
Expand All @@ -86,7 +86,7 @@ public override void OnEndOfAlgorithm()
{
if (Transactions.GetOrders().Any(order => order.Status != OrderStatus.Filled ))
{
throw new Exception("Not all orders were filled");
throw new RegressionTestException("Not all orders were filled");
}
}

Expand All @@ -96,7 +96,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
if (orderEvent.Status == OrderStatus.Filled && !Securities[orderEvent.Symbol].Exchange.DateTimeIsOpen(orderEvent.UtcTime) &&
(orderEvent.UtcTime.TimeOfDay >= new TimeSpan(13, 30, 0) && orderEvent.UtcTime.TimeOfDay < new TimeSpan(21, 0, 0)))
{
throw new Exception($"Order should have been filled during extended market hours");
throw new RegressionTestException($"Order should have been filled during extended market hours");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public override void OnData(Slice slice)
var positionGroups = Portfolio.Positions.Groups;
if (positionGroups.Count != 2)
{
throw new Exception($"Expected 2 position groups, one for each spread, but found {positionGroups.Count}");
throw new RegressionTestException($"Expected 2 position groups, one for each spread, but found {positionGroups.Count}");
}

var positionGroupMatchesSpreadStrategy = (IPositionGroup positionGroup, OptionStrategy strategy) =>
Expand All @@ -110,7 +110,7 @@ public override void OnData(Slice slice)
if (!positionGroups.All(group =>
positionGroupMatchesSpreadStrategy(group, _bullCallSpread) || positionGroupMatchesSpreadStrategy(group, _bearPutSpread)))
{
throw new Exception("Expected both spreads to have a matching position group in the portfolio.");
throw new RegressionTestException("Expected both spreads to have a matching position group in the portfolio.");
}

// Step 2: liquidate spreads
Expand All @@ -125,12 +125,12 @@ public override void OnEndOfAlgorithm()
{
if (!_done)
{
throw new Exception("Expected the algorithm to have bought and sold a Bull Call Spread and a Bear Put Spread.");
throw new RegressionTestException("Expected the algorithm to have bought and sold a Bull Call Spread and a Bear Put Spread.");
}

if (Portfolio.Invested)
{
throw new Exception("The spreads should have been liquidated by the end of the algorithm");
throw new RegressionTestException("The spreads should have been liquidated by the end of the algorithm");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup
{
if (positionGroup.Positions.Count() != 3)
{
throw new Exception($"Expected position group to have 3 positions. Actual: {positionGroup.Positions.Count()}");
throw new RegressionTestException($"Expected position group to have 3 positions. Actual: {positionGroup.Positions.Count()}");
}

var higherStrike = _butterflyCall.OptionLegs.Max(leg => leg.Strike);
Expand All @@ -78,7 +78,7 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup

if (higherStrikePosition.Quantity != 2)
{
throw new Exception($"Expected higher strike position quantity to be 2. Actual: {higherStrikePosition.Quantity}");
throw new RegressionTestException($"Expected higher strike position quantity to be 2. Actual: {higherStrikePosition.Quantity}");
}

var lowerStrike = _butterflyCall.OptionLegs.Min(leg => leg.Strike);
Expand All @@ -87,7 +87,7 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup

if (lowerStrikePosition.Quantity != 2)
{
throw new Exception($"Expected lower strike position quantity to be 2. Actual: {lowerStrikePosition.Quantity}");
throw new RegressionTestException($"Expected lower strike position quantity to be 2. Actual: {lowerStrikePosition.Quantity}");
}

var middleStrike = _butterflyCall.OptionLegs.Single(leg => leg.Strike < higherStrike && leg.Strike > lowerStrike).Strike;
Expand All @@ -96,7 +96,7 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup

if (middleStrikePosition.Quantity != -4)
{
throw new Exception($"Expected middle strike position quantity to be -4. Actual: {middleStrikePosition.Quantity}");
throw new RegressionTestException($"Expected middle strike position quantity to be -4. Actual: {middleStrikePosition.Quantity}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup
{
if (positionGroup.Positions.Count() != 3)
{
throw new Exception($"Expected position group to have 3 positions. Actual: {positionGroup.Positions.Count()}");
throw new RegressionTestException($"Expected position group to have 3 positions. Actual: {positionGroup.Positions.Count()}");
}

var higherStrike = _butterflyPut.OptionLegs.Max(leg => leg.Strike);
Expand All @@ -78,7 +78,7 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup

if (higherStrikePosition.Quantity != 2)
{
throw new Exception($"Expected higher strike position quantity to be 2. Actual: {higherStrikePosition.Quantity}");
throw new RegressionTestException($"Expected higher strike position quantity to be 2. Actual: {higherStrikePosition.Quantity}");
}

var lowerStrike = _butterflyPut.OptionLegs.Min(leg => leg.Strike);
Expand All @@ -87,7 +87,7 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup

if (lowerStrikePosition.Quantity != 2)
{
throw new Exception($"Expected lower strike position quantity to be 2. Actual: {lowerStrikePosition.Quantity}");
throw new RegressionTestException($"Expected lower strike position quantity to be 2. Actual: {lowerStrikePosition.Quantity}");
}

var middleStrike = _butterflyPut.OptionLegs.Single(leg => leg.Strike < higherStrike && leg.Strike > lowerStrike).Strike;
Expand All @@ -96,7 +96,7 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup

if (middleStrikePosition.Quantity != -4)
{
throw new Exception($"Expected middle strike position quantity to be -4. Actual: {middleStrikePosition.Quantity}");
throw new RegressionTestException($"Expected middle strike position quantity to be -4. Actual: {middleStrikePosition.Quantity}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup
{
if (positionGroup.Positions.Count() != 2)
{
throw new Exception($"Expected position group to have 2 positions. Actual: {positionGroup.Positions.Count()}");
throw new RegressionTestException($"Expected position group to have 2 positions. Actual: {positionGroup.Positions.Count()}");
}

var nearExpiration = _callCalendarSpread.OptionLegs.Min(leg => leg.Expiration);
Expand All @@ -70,7 +70,7 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup

if (nearExpirationPosition.Quantity != -2)
{
throw new Exception($"Expected near expiration position quantity to be -2. Actual: {nearExpirationPosition.Quantity}");
throw new RegressionTestException($"Expected near expiration position quantity to be -2. Actual: {nearExpirationPosition.Quantity}");
}

var farExpiration = _callCalendarSpread.OptionLegs.Max(leg => leg.Expiration);
Expand All @@ -79,7 +79,7 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup

if (farExpirationPosition.Quantity != 2)
{
throw new Exception($"Expected far expiration position quantity to be 2. Actual: {farExpirationPosition.Quantity}");
throw new RegressionTestException($"Expected far expiration position quantity to be 2. Actual: {farExpirationPosition.Quantity}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup
{
if (positionGroup.Positions.Count() != 2)
{
throw new Exception($"Expected position group to have 2 positions. Actual: {positionGroup.Positions.Count()}");
throw new RegressionTestException($"Expected position group to have 2 positions. Actual: {positionGroup.Positions.Count()}");
}

var nearExpiration = _putCalendarSpread.OptionLegs.Min(leg => leg.Expiration);
Expand All @@ -70,7 +70,7 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup

if (nearExpirationPosition.Quantity != -2)
{
throw new Exception($"Expected near expiration position quantity to be -2. Actual: {nearExpirationPosition.Quantity}");
throw new RegressionTestException($"Expected near expiration position quantity to be -2. Actual: {nearExpirationPosition.Quantity}");
}

var farExpiration = _putCalendarSpread.OptionLegs.Max(leg => leg.Expiration);
Expand All @@ -79,7 +79,7 @@ protected override void AssertStrategyPositionGroup(IPositionGroup positionGroup

if (farExpirationPosition.Quantity != 2)
{
throw new Exception($"Expected far expiration position quantity to be 2. Actual: {farExpirationPosition.Quantity}");
throw new RegressionTestException($"Expected far expiration position quantity to be 2. Actual: {farExpirationPosition.Quantity}");
}
}

Expand Down
Loading

0 comments on commit aa5ab68

Please sign in to comment.