Skip to content

Commit

Permalink
FreePortfolioValuePercentage Trailing Behavior (QuantConnect#7272)
Browse files Browse the repository at this point in the history
* Implement Trailing FreePortfolioValue

- Implement Trailing FreePortfolioValue by default, users will be able
  to set it to a fixed number if desired. Adding regression algorithm
- Setting the default 'MinimumOrderMarginPortfolioPercentage' from 0 to
  0.1% of the TPV to avoud tiny trades by default

* Update existing regression algorithms

* Address reviews

- Send warning message to the user if a trade does not happen due to the
  default setting of the minimum order margin percentage value

* Address reivews

* Rename TotalPortfolioValueLessFreeBuffer

* Update new regression algorithm
  • Loading branch information
Martin-Molinero authored May 25, 2023
1 parent 2147d86 commit 410956b
Show file tree
Hide file tree
Showing 91 changed files with 957 additions and 877 deletions.
18 changes: 9 additions & 9 deletions Algorithm.CSharp/AddUniverseSelectionModelAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,30 @@ public override void OnEndOfAlgorithm()
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "11"},
{"Total Trades", "10"},
{"Average Win", "0%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-14.217%"},
{"Compounding Annual Return", "-14.233%"},
{"Drawdown", "3.300%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.168%"},
{"Sharpe Ratio", "62.513"},
{"Sharpe Ratio", "62.499"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "1.118"},
{"Alpha", "1.116"},
{"Beta", "1.19"},
{"Annual Standard Deviation", "0.213"},
{"Annual Variance", "0.046"},
{"Information Ratio", "70.862"},
{"Information Ratio", "70.778"},
{"Tracking Error", "0.043"},
{"Treynor Ratio", "11.209"},
{"Total Fees", "$23.21"},
{"Treynor Ratio", "11.206"},
{"Total Fees", "$22.21"},
{"Estimated Strategy Capacity", "$340000000.00"},
{"Lowest Capacity Asset", "FB V6OIPNZEM8V9"},
{"Portfolio Turnover", "26.96%"},
{"OrderListHash", "a7a0983c8413ff241e7d223438f3d508"}
{"Portfolio Turnover", "26.92%"},
{"OrderListHash", "a259afcf4ee1c65ce5d26588ab645dbf"}
};
}
}
36 changes: 18 additions & 18 deletions Algorithm.CSharp/AddUniverseSelectionModelCoarseAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,30 @@ public override void OnEndOfAlgorithm()
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "27"},
{"Average Win", "0.01%"},
{"Total Trades", "21"},
{"Average Win", "0.00%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-75.320%"},
{"Compounding Annual Return", "-75.275%"},
{"Drawdown", "5.800%"},
{"Expectancy", "-0.731"},
{"Net Profit", "-5.588%"},
{"Sharpe Ratio", "-3.252"},
{"Probabilistic Sharpe Ratio", "5.526%"},
{"Loss Rate", "86%"},
{"Win Rate", "14%"},
{"Profit-Loss Ratio", "0.89"},
{"Alpha", "-0.499"},
{"Beta", "1.483"},
{"Expectancy", "-0.609"},
{"Net Profit", "-5.581%"},
{"Sharpe Ratio", "-3.25"},
{"Probabilistic Sharpe Ratio", "5.546%"},
{"Loss Rate", "73%"},
{"Win Rate", "27%"},
{"Profit-Loss Ratio", "0.43"},
{"Alpha", "-0.498"},
{"Beta", "1.484"},
{"Annual Standard Deviation", "0.196"},
{"Annual Variance", "0.039"},
{"Information Ratio", "-3.844"},
{"Tracking Error", "0.142"},
{"Information Ratio", "-3.843"},
{"Tracking Error", "0.141"},
{"Treynor Ratio", "-0.43"},
{"Total Fees", "$37.25"},
{"Estimated Strategy Capacity", "$520000000.00"},
{"Total Fees", "$31.25"},
{"Estimated Strategy Capacity", "$550000000.00"},
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
{"Portfolio Turnover", "7.34%"},
{"OrderListHash", "f837879b96f5e565b60fd040299d2123"}
{"Portfolio Turnover", "7.33%"},
{"OrderListHash", "6aab808e341ae46946b91ba378073531"}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
{
var security = Securities["SPY"];
var priceInAccountCurrency = Portfolio.CashBook.ConvertToAccountCurrency(security.AskPrice, security.QuoteCurrency.Symbol);
_expectedSpyQuantity = (Portfolio.TotalPortfolioValue - Settings.FreePortfolioValue) / priceInAccountCurrency;
_expectedSpyQuantity = Portfolio.TotalPortfolioValueLessFreeBuffer / priceInAccountCurrency;
_expectedSpyQuantity = _expectedSpyQuantity.DiscretelyRoundBy(1, MidpointRounding.ToZero);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,30 @@ public IEnumerable<Symbol> CoarseSelector(IEnumerable<CoarseFundamental> coarse)
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "20"},
{"Total Trades", "14"},
{"Average Win", "0%"},
{"Average Loss", "-0.13%"},
{"Compounding Annual Return", "62.435%"},
{"Average Loss", "-0.23%"},
{"Compounding Annual Return", "63.336%"},
{"Drawdown", "1.100%"},
{"Expectancy", "-1"},
{"Net Profit", "0.667%"},
{"Sharpe Ratio", "3.993"},
{"Probabilistic Sharpe Ratio", "58.777%"},
{"Net Profit", "0.674%"},
{"Sharpe Ratio", "4.042"},
{"Probabilistic Sharpe Ratio", "58.892%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.598"},
{"Beta", "0.569"},
{"Alpha", "-0.592"},
{"Beta", "0.57"},
{"Annual Standard Deviation", "0.133"},
{"Annual Variance", "0.018"},
{"Information Ratio", "-13.973"},
{"Information Ratio", "-13.918"},
{"Tracking Error", "0.104"},
{"Treynor Ratio", "0.932"},
{"Total Fees", "$46.20"},
{"Estimated Strategy Capacity", "$2300000.00"},
{"Treynor Ratio", "0.943"},
{"Total Fees", "$40.20"},
{"Estimated Strategy Capacity", "$4400000.00"},
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
{"Portfolio Turnover", "64.52%"},
{"OrderListHash", "0945ff7a39bb8f8a07b3dcc817c070aa"}
{"Portfolio Turnover", "64.47%"},
{"OrderListHash", "7e43a08e470a1709c7f7066d6ed1d445"}
};
}
}
12 changes: 6 additions & 6 deletions Algorithm.CSharp/ClassicRenkoConsolidatorAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,27 +129,27 @@ public void HandleRenko7Bar(RenkoBar data)
{"Total Trades", "29"},
{"Average Win", "1.85%"},
{"Average Loss", "-1.49%"},
{"Compounding Annual Return", "7.819%"},
{"Compounding Annual Return", "7.817%"},
{"Drawdown", "6.800%"},
{"Expectancy", "0.281"},
{"Net Profit", "7.841%"},
{"Net Profit", "7.839%"},
{"Sharpe Ratio", "0.799"},
{"Probabilistic Sharpe Ratio", "39.344%"},
{"Probabilistic Sharpe Ratio", "39.336%"},
{"Loss Rate", "43%"},
{"Win Rate", "57%"},
{"Profit-Loss Ratio", "1.24"},
{"Alpha", "0.009"},
{"Beta", "0.411"},
{"Annual Standard Deviation", "0.07"},
{"Annual Variance", "0.005"},
{"Information Ratio", "-0.703"},
{"Information Ratio", "-0.704"},
{"Tracking Error", "0.083"},
{"Treynor Ratio", "0.136"},
{"Total Fees", "$129.35"},
{"Total Fees", "$129.34"},
{"Estimated Strategy Capacity", "$1000000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "7.91%"},
{"OrderListHash", "b2286d2421294408c3a390e614f40ef9"}
{"OrderListHash", "cabe86df8bdef1204139d41baff20050"}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,30 +160,30 @@ public override void OnData(Slice slice)
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "4"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "13.695%"},
{"Total Trades", "2"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "14.180%"},
{"Drawdown", "0.200%"},
{"Expectancy", "-0.463"},
{"Net Profit", "0.164%"},
{"Sharpe Ratio", "5.073"},
{"Probabilistic Sharpe Ratio", "67.051%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "0.07"},
{"Alpha", "-0.084"},
{"Beta", "0.098"},
{"Expectancy", "0"},
{"Net Profit", "0.170%"},
{"Sharpe Ratio", "5.221"},
{"Probabilistic Sharpe Ratio", "67.725%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.081"},
{"Beta", "0.099"},
{"Annual Standard Deviation", "0.022"},
{"Annual Variance", "0"},
{"Information Ratio", "-9.329"},
{"Information Ratio", "-9.315"},
{"Tracking Error", "0.201"},
{"Treynor Ratio", "1.129"},
{"Total Fees", "$4.00"},
{"Estimated Strategy Capacity", "$71000000.00"},
{"Treynor Ratio", "1.162"},
{"Total Fees", "$2.00"},
{"Estimated Strategy Capacity", "$260000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "2.06%"},
{"OrderListHash", "dc329f765a22f1fa98d5e87c53c11ef2"}
{"Portfolio Turnover", "2.00%"},
{"OrderListHash", "4d030e24bdb0fdbf6dc2c2b22c763688"}
};
}
}
38 changes: 19 additions & 19 deletions Algorithm.CSharp/Collective2SignalExportDemonstrationAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,30 +170,30 @@ public override void OnData(Slice slice)
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "4"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "13.695%"},
{"Total Trades", "2"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "14.180%"},
{"Drawdown", "0.200%"},
{"Expectancy", "-0.463"},
{"Net Profit", "0.164%"},
{"Sharpe Ratio", "5.073"},
{"Probabilistic Sharpe Ratio", "67.051%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "0.07"},
{"Alpha", "-0.084"},
{"Beta", "0.098"},
{"Expectancy", "0"},
{"Net Profit", "0.170%"},
{"Sharpe Ratio", "5.221"},
{"Probabilistic Sharpe Ratio", "67.725%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.081"},
{"Beta", "0.099"},
{"Annual Standard Deviation", "0.022"},
{"Annual Variance", "0"},
{"Information Ratio", "-9.329"},
{"Information Ratio", "-9.315"},
{"Tracking Error", "0.201"},
{"Treynor Ratio", "1.129"},
{"Total Fees", "$4.00"},
{"Estimated Strategy Capacity", "$71000000.00"},
{"Treynor Ratio", "1.162"},
{"Total Fees", "$2.00"},
{"Estimated Strategy Capacity", "$260000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "2.06%"},
{"OrderListHash", "dc329f765a22f1fa98d5e87c53c11ef2"}
{"Portfolio Turnover", "2.00%"},
{"OrderListHash", "4d030e24bdb0fdbf6dc2c2b22c763688"}
};
}
}
34 changes: 17 additions & 17 deletions Algorithm.CSharp/CompositeAlphaModelFrameworkAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,30 @@ public override void Initialize()
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "18"},
{"Total Trades", "14"},
{"Average Win", "0.00%"},
{"Average Loss", "-0.17%"},
{"Compounding Annual Return", "-37.004%"},
{"Average Loss", "-0.23%"},
{"Compounding Annual Return", "-36.885%"},
{"Drawdown", "1.800%"},
{"Expectancy", "-0.629"},
{"Net Profit", "-0.589%"},
{"Sharpe Ratio", "-2.41"},
{"Probabilistic Sharpe Ratio", "34.293%"},
{"Loss Rate", "64%"},
{"Win Rate", "36%"},
{"Profit-Loss Ratio", "0.02"},
{"Alpha", "-0.886"},
{"Beta", "0.35"},
{"Expectancy", "-0.549"},
{"Net Profit", "-0.587%"},
{"Sharpe Ratio", "-2.4"},
{"Probabilistic Sharpe Ratio", "34.321%"},
{"Loss Rate", "56%"},
{"Win Rate", "44%"},
{"Profit-Loss Ratio", "0.01"},
{"Alpha", "-0.883"},
{"Beta", "0.349"},
{"Annual Standard Deviation", "0.08"},
{"Annual Variance", "0.006"},
{"Information Ratio", "-14.935"},
{"Information Ratio", "-14.897"},
{"Tracking Error", "0.146"},
{"Treynor Ratio", "-0.549"},
{"Total Fees", "$41.79"},
{"Treynor Ratio", "-0.547"},
{"Total Fees", "$37.79"},
{"Estimated Strategy Capacity", "$4700000.00"},
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
{"Portfolio Turnover", "60.76%"},
{"OrderListHash", "c6d413585d8aa6ac8831563aa71653d5"}
{"Portfolio Turnover", "60.65%"},
{"OrderListHash", "eb7a9a4b0da87f71750a24c8913be714"}
};
}
}
36 changes: 18 additions & 18 deletions Algorithm.CSharp/ConfidenceWeightedFrameworkAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,30 @@ public override void OnEndOfAlgorithm()
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "17"},
{"Average Win", "0%"},
{"Total Trades", "4"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "37.229%"},
{"Compounding Annual Return", "39.071%"},
{"Drawdown", "0.600%"},
{"Expectancy", "-1"},
{"Net Profit", "0.405%"},
{"Sharpe Ratio", "5.424"},
{"Probabilistic Sharpe Ratio", "66.818%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.191"},
{"Beta", "0.247"},
{"Expectancy", "-0.028"},
{"Net Profit", "0.423%"},
{"Sharpe Ratio", "5.617"},
{"Probabilistic Sharpe Ratio", "67.478%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "0.94"},
{"Alpha", "-0.182"},
{"Beta", "0.248"},
{"Annual Standard Deviation", "0.055"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-10.052"},
{"Tracking Error", "0.168"},
{"Treynor Ratio", "1.207"},
{"Total Fees", "$17.00"},
{"Information Ratio", "-9.998"},
{"Tracking Error", "0.167"},
{"Treynor Ratio", "1.25"},
{"Total Fees", "$4.00"},
{"Estimated Strategy Capacity", "$45000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "5.44%"},
{"OrderListHash", "8a8c913e5ad4ea956a345c84430649c2"}
{"Portfolio Turnover", "5.15%"},
{"OrderListHash", "3e4a86ba835b56bb863eb355789ab6f4"}
};
}
}
Loading

0 comments on commit 410956b

Please sign in to comment.