Skip to content

Commit

Permalink
MaximumOrderQuantity Bug Fix (QuantConnect#5727)
Browse files Browse the repository at this point in the history
* Implement solution with lightest changes possible

* Update regressions v1

* Adjust AlgorithmTradingTests

* Adjust PatternDayTradingMarginBuyingPowerModel tests

* Drop need to loop twice

* Adjust last unit test, with calculations included

* nit - comment fix

* Break out adjustment calculation to static function; add unit test

* Update Py regression

* Upgrade adjustment calculation to be smart enough to get us to target always

* nit - cleanup GetAmountToOrder

* Add license to test

* nit - comment fix

* cleanup GetAmountToOrder further

* Add additional test cases
  • Loading branch information
C-SELLERS authored Jul 2, 2021
1 parent e5a5010 commit 171f0f1
Show file tree
Hide file tree
Showing 34 changed files with 583 additions and 453 deletions.
34 changes: 17 additions & 17 deletions Algorithm.CSharp/AccumulativeInsightPortfolioRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,31 @@ public override void OnEndOfAlgorithm()
{"Total Trades", "199"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "-12.392%"},
{"Compounding Annual Return", "-12.611%"},
{"Drawdown", "0.200%"},
{"Expectancy", "-0.586"},
{"Net Profit", "-0.169%"},
{"Sharpe Ratio", "-9.597"},
{"Probabilistic Sharpe Ratio", "13.309%"},
{"Loss Rate", "79%"},
{"Win Rate", "21%"},
{"Profit-Loss Ratio", "0.95"},
{"Expectancy", "-0.585"},
{"Net Profit", "-0.172%"},
{"Sharpe Ratio", "-10.169"},
{"Probabilistic Sharpe Ratio", "12.075%"},
{"Loss Rate", "78%"},
{"Win Rate", "22%"},
{"Profit-Loss Ratio", "0.87"},
{"Alpha", "-0.149"},
{"Beta", "0.036"},
{"Beta", "0.035"},
{"Annual Standard Deviation", "0.008"},
{"Annual Variance", "0"},
{"Information Ratio", "-9.605"},
{"Tracking Error", "0.214"},
{"Treynor Ratio", "-2.136"},
{"Information Ratio", "-9.603"},
{"Tracking Error", "0.215"},
{"Treynor Ratio", "-2.264"},
{"Total Fees", "$199.00"},
{"Estimated Strategy Capacity", "$25000000.00"},
{"Estimated Strategy Capacity", "$26000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Fitness Score", "0.002"},
{"Kelly Criterion Estimate", "38.796"},
{"Kelly Criterion Probability Value", "0.228"},
{"Sortino Ratio", "-21.623"},
{"Return Over Maximum Drawdown", "-77.986"},
{"Portfolio Turnover", "1.154"},
{"Sortino Ratio", "-22.493"},
{"Return Over Maximum Drawdown", "-77.93"},
{"Portfolio Turnover", "1.211"},
{"Total Insights Generated", "100"},
{"Total Insights Closed", "99"},
{"Total Insights Analysis Completed", "99"},
Expand All @@ -115,7 +115,7 @@ public override void OnEndOfAlgorithm()
{"Mean Population Magnitude", "53.5354%"},
{"Rolling Averaged Population Direction", "58.2788%"},
{"Rolling Averaged Population Magnitude", "58.2788%"},
{"OrderListHash", "7baad0d75f652da1b801ec2fc368e710"}
{"OrderListHash", "3c4c4085810cc5ecdb927d3647b9bbf3"}
};
}
}
26 changes: 13 additions & 13 deletions Algorithm.CSharp/AddUniverseSelectionModelAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,34 @@ public override void OnEndOfAlgorithm()
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "10"},
{"Total Trades", "11"},
{"Average Win", "0%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-13.928%"},
{"Compounding Annual Return", "-14.217%"},
{"Drawdown", "3.300%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.164%"},
{"Sharpe Ratio", "-0.12"},
{"Probabilistic Sharpe Ratio", "45.109%"},
{"Net Profit", "-0.168%"},
{"Sharpe Ratio", "-0.126"},
{"Probabilistic Sharpe Ratio", "45.081%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-2.892"},
{"Alpha", "-2.896"},
{"Beta", "0.551"},
{"Annual Standard Deviation", "0.385"},
{"Annual Variance", "0.149"},
{"Information Ratio", "-13.646"},
{"Annual Variance", "0.148"},
{"Information Ratio", "-13.66"},
{"Tracking Error", "0.382"},
{"Treynor Ratio", "-0.084"},
{"Total Fees", "$22.21"},
{"Treynor Ratio", "-0.088"},
{"Total Fees", "$23.21"},
{"Estimated Strategy Capacity", "$340000000.00"},
{"Lowest Capacity Asset", "FB V6OIPNZEM8V9"},
{"Fitness Score", "0.147"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "1"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-4.264"},
{"Portfolio Turnover", "0.268"},
{"Return Over Maximum Drawdown", "-4.352"},
{"Portfolio Turnover", "0.269"},
{"Total Insights Generated", "15"},
{"Total Insights Closed", "12"},
{"Total Insights Analysis Completed", "12"},
Expand All @@ -124,7 +124,7 @@ public override void OnEndOfAlgorithm()
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "28605a89cd5f0d59ebe14af370764291"}
{"OrderListHash", "a7a0983c8413ff241e7d223438f3d508"}
};
}
}
26 changes: 13 additions & 13 deletions Algorithm.CSharp/AddUniverseSelectionModelCoarseAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,18 @@ public override void OnEndOfAlgorithm()
{"Total Trades", "25"},
{"Average Win", "0.00%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-75.369%"},
{"Compounding Annual Return", "-75.314%"},
{"Drawdown", "5.800%"},
{"Expectancy", "-0.748"},
{"Net Profit", "-5.596%"},
{"Expectancy", "-0.633"},
{"Net Profit", "-5.587%"},
{"Sharpe Ratio", "-3.271"},
{"Probabilistic Sharpe Ratio", "5.816%"},
{"Loss Rate", "85%"},
{"Win Rate", "15%"},
{"Profit-Loss Ratio", "0.64"},
{"Alpha", "-0.595"},
{"Probabilistic Sharpe Ratio", "5.832%"},
{"Loss Rate", "75%"},
{"Win Rate", "25%"},
{"Profit-Loss Ratio", "0.47"},
{"Alpha", "-0.594"},
{"Beta", "0.707"},
{"Annual Standard Deviation", "0.204"},
{"Annual Standard Deviation", "0.203"},
{"Annual Variance", "0.041"},
{"Information Ratio", "-2.928"},
{"Tracking Error", "0.193"},
Expand All @@ -115,9 +115,9 @@ public override void OnEndOfAlgorithm()
{"Fitness Score", "0.004"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "1"},
{"Sortino Ratio", "-4.466"},
{"Return Over Maximum Drawdown", "-13.048"},
{"Portfolio Turnover", "0.083"},
{"Sortino Ratio", "-4.468"},
{"Return Over Maximum Drawdown", "-13.058"},
{"Portfolio Turnover", "0.084"},
{"Total Insights Generated", "33"},
{"Total Insights Closed", "30"},
{"Total Insights Analysis Completed", "30"},
Expand All @@ -131,7 +131,7 @@ public override void OnEndOfAlgorithm()
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "93b8c04ef334327062d5a79e6dd73130"}
{"OrderListHash", "c5553cbcef8480c184203c444794ccf1"}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,31 @@ public IEnumerable<Symbol> CoarseSelector(IEnumerable<CoarseFundamental> coarse)
{"Total Trades", "17"},
{"Average Win", "0%"},
{"Average Loss", "-0.17%"},
{"Compounding Annual Return", "62.899%"},
{"Compounding Annual Return", "62.842%"},
{"Drawdown", "1.100%"},
{"Expectancy", "-1"},
{"Net Profit", "0.671%"},
{"Sharpe Ratio", "3.528"},
{"Probabilistic Sharpe Ratio", "59.247%"},
{"Net Profit", "0.670%"},
{"Sharpe Ratio", "3.525"},
{"Probabilistic Sharpe Ratio", "59.239%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.381"},
{"Alpha", "-0.382"},
{"Beta", "0.565"},
{"Annual Standard Deviation", "0.116"},
{"Annual Variance", "0.013"},
{"Information Ratio", "-10.77"},
{"Information Ratio", "-10.772"},
{"Tracking Error", "0.092"},
{"Treynor Ratio", "0.723"},
{"Treynor Ratio", "0.722"},
{"Total Fees", "$43.20"},
{"Estimated Strategy Capacity", "$3200000.00"},
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
{"Fitness Score", "0.644"},
{"Kelly Criterion Estimate", "13.787"},
{"Kelly Criterion Probability Value", "0.231"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "66.129"},
{"Portfolio Turnover", "0.644"},
{"Return Over Maximum Drawdown", "66.069"},
{"Portfolio Turnover", "0.645"},
{"Total Insights Generated", "13"},
{"Total Insights Closed", "10"},
{"Total Insights Analysis Completed", "10"},
Expand All @@ -115,7 +115,7 @@ public IEnumerable<Symbol> CoarseSelector(IEnumerable<CoarseFundamental> coarse)
{"Mean Population Magnitude", "70%"},
{"Rolling Averaged Population Direction", "94.5154%"},
{"Rolling Averaged Population Magnitude", "94.5154%"},
{"OrderListHash", "b6b918fcc982a0126901ccbf14792d54"}
{"OrderListHash", "3d0949901dfba45209ed339866d4f4f1"}
};
}
}
22 changes: 11 additions & 11 deletions Algorithm.CSharp/CompositeAlphaModelFrameworkAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,30 @@ public override void Initialize()
{"Total Trades", "7"},
{"Average Win", "0.01%"},
{"Average Loss", "-0.40%"},
{"Compounding Annual Return", "1143.721%"},
{"Compounding Annual Return", "1143.086%"},
{"Drawdown", "1.800%"},
{"Expectancy", "-0.321"},
{"Expectancy", "-0.319"},
{"Net Profit", "3.275%"},
{"Sharpe Ratio", "23.505"},
{"Probabilistic Sharpe Ratio", "80.498%"},
{"Sharpe Ratio", "23.495"},
{"Probabilistic Sharpe Ratio", "80.494%"},
{"Loss Rate", "33%"},
{"Win Rate", "67%"},
{"Profit-Loss Ratio", "0.02"},
{"Alpha", "4.369"},
{"Alpha", "4.366"},
{"Beta", "1.255"},
{"Annual Standard Deviation", "0.292"},
{"Annual Variance", "0.085"},
{"Information Ratio", "47.982"},
{"Information Ratio", "47.955"},
{"Tracking Error", "0.102"},
{"Treynor Ratio", "5.463"},
{"Total Fees", "$71.36"},
{"Treynor Ratio", "5.461"},
{"Total Fees", "$71.37"},
{"Estimated Strategy Capacity", "$3500000.00"},
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
{"Fitness Score", "0.501"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "148.133"},
{"Return Over Maximum Drawdown", "1487.868"},
{"Sortino Ratio", "148.07"},
{"Return Over Maximum Drawdown", "1487.238"},
{"Portfolio Turnover", "0.501"},
{"Total Insights Generated", "2"},
{"Total Insights Closed", "0"},
Expand All @@ -112,7 +112,7 @@ public override void Initialize()
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "61b6afca11a1f15a63237d0346f383f7"}
{"OrderListHash", "5a171f804d47cd27f84aaef791da8594"}
};
}
}
34 changes: 17 additions & 17 deletions Algorithm.CSharp/ConfidenceWeightedFrameworkAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,33 +74,33 @@ public override void OnEndOfAlgorithm()
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "6"},
{"Average Win", "0%"},
{"Total Trades", "5"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "38.832%"},
{"Compounding Annual Return", "38.796%"},
{"Drawdown", "0.600%"},
{"Expectancy", "-1"},
{"Expectancy", "-0.247"},
{"Net Profit", "0.420%"},
{"Sharpe Ratio", "5.579"},
{"Probabilistic Sharpe Ratio", "67.318%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.184"},
{"Beta", "0.248"},
{"Sharpe Ratio", "5.57"},
{"Probabilistic Sharpe Ratio", "67.303%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "0.51"},
{"Alpha", "-0.185"},
{"Beta", "0.249"},
{"Annual Standard Deviation", "0.055"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-10.012"},
{"Information Ratio", "-10.015"},
{"Tracking Error", "0.167"},
{"Treynor Ratio", "1.241"},
{"Total Fees", "$6.00"},
{"Estimated Strategy Capacity", "$38000000.00"},
{"Treynor Ratio", "1.24"},
{"Total Fees", "$5.00"},
{"Estimated Strategy Capacity", "$42000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Fitness Score", "0.063"},
{"Kelly Criterion Estimate", "38.796"},
{"Kelly Criterion Probability Value", "0.228"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "70.89"},
{"Return Over Maximum Drawdown", "71.109"},
{"Portfolio Turnover", "0.063"},
{"Total Insights Generated", "100"},
{"Total Insights Closed", "99"},
Expand All @@ -115,7 +115,7 @@ public override void OnEndOfAlgorithm()
{"Mean Population Magnitude", "53.5354%"},
{"Rolling Averaged Population Direction", "58.2788%"},
{"Rolling Averaged Population Magnitude", "58.2788%"},
{"OrderListHash", "21e4704a124ba562d042e1e9962f4316"}
{"OrderListHash", "6ab0483f63f36295e21400be1271ad40"}
};
}
}
34 changes: 17 additions & 17 deletions Algorithm.CSharp/DropboxBaseDataUniverseSelectionAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,31 +187,31 @@ public override BaseData Reader(SubscriptionDataConfig config, string line, Date
{"Total Trades", "6441"},
{"Average Win", "0.07%"},
{"Average Loss", "-0.07%"},
{"Compounding Annual Return", "14.722%"},
{"Drawdown", "10.700%"},
{"Expectancy", "0.067"},
{"Net Profit", "14.722%"},
{"Sharpe Ratio", "1.056"},
{"Probabilistic Sharpe Ratio", "49.750%"},
{"Compounding Annual Return", "14.513%"},
{"Drawdown", "10.600%"},
{"Expectancy", "0.066"},
{"Net Profit", "14.513%"},
{"Sharpe Ratio", "1.047"},
{"Probabilistic Sharpe Ratio", "49.415%"},
{"Loss Rate", "46%"},
{"Win Rate", "54%"},
{"Profit-Loss Ratio", "0.97"},
{"Alpha", "0.136"},
{"Beta", "-0.07"},
{"Alpha", "0.135"},
{"Beta", "-0.069"},
{"Annual Standard Deviation", "0.121"},
{"Annual Variance", "0.015"},
{"Information Ratio", "0.043"},
{"Tracking Error", "0.171"},
{"Treynor Ratio", "-1.836"},
{"Total Fees", "$7500.86"},
{"Information Ratio", "0.033"},
{"Tracking Error", "0.17"},
{"Treynor Ratio", "-1.832"},
{"Total Fees", "$7494.82"},
{"Estimated Strategy Capacity", "$320000.00"},
{"Lowest Capacity Asset", "BNO UN3IMQ2JU1YD"},
{"Fitness Score", "0.691"},
{"Fitness Score", "0.689"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "1.238"},
{"Return Over Maximum Drawdown", "1.378"},
{"Portfolio Turnover", "1.638"},
{"Sortino Ratio", "1.226"},
{"Return Over Maximum Drawdown", "1.367"},
{"Portfolio Turnover", "1.627"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
Expand All @@ -225,7 +225,7 @@ public override BaseData Reader(SubscriptionDataConfig config, string line, Date
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "6047b278450c563805d0ea68c04c013a"}
{"OrderListHash", "6cf9ae04274be760ff10b47c718e9797"}
};
}
}
Loading

0 comments on commit 171f0f1

Please sign in to comment.