public void RemovesOldValues() { var kellyCriterionManager = new KellyCriterionManager(); var start = new DateTime(2019, 1, 1); kellyCriterionManager.AddNewValue(10, start); kellyCriterionManager.AddNewValue(10, start); kellyCriterionManager.UpdateScores(); Console.WriteLine($"Estimate {kellyCriterionManager.KellyCriterionEstimate}" + $" - ProbabilityValue {kellyCriterionManager.KellyCriterionProbabilityValue}"); Assert.AreEqual(0.1, kellyCriterionManager.KellyCriterionEstimate); Assert.AreEqual(0.5, kellyCriterionManager.KellyCriterionProbabilityValue); kellyCriterionManager.AddNewValue(-10, start.AddDays(365)); kellyCriterionManager.AddNewValue(-10, start.AddDays(365)); kellyCriterionManager.UpdateScores(); Console.WriteLine($"Estimate {kellyCriterionManager.KellyCriterionEstimate}" + $" - ProbabilityValue {kellyCriterionManager.KellyCriterionProbabilityValue}"); Assert.AreEqual(-0.1, kellyCriterionManager.KellyCriterionEstimate); Assert.AreEqual(0.5, kellyCriterionManager.KellyCriterionProbabilityValue); }
/// <summary> /// Initializes a new instance of the <see cref="StatisticsInsightManagerExtension"/> class /// </summary> /// <param name="accountCurrencyProvider">The account currency provider</param> /// <param name="tradablePercentOfVolume">Percent of volume of first bar used to estimate the maximum number of tradable shares. Defaults to 1%</param> /// <param name="period">The period used for exponential smoothing of scores - this is a number of insights. Defaults to 100 insight predictions.</param> /// <param name="requireRollingAverageWarmup">Specify true to force the population average scoring to warmup before plotting.</param> public StatisticsInsightManagerExtension( IAccountCurrencyProvider accountCurrencyProvider, decimal tradablePercentOfVolume = 0.01m, int period = 100, bool requireRollingAverageWarmup = false) { Statistics = new AlphaRuntimeStatistics(accountCurrencyProvider); _tradablePercentOfVolume = tradablePercentOfVolume; _smoothingFactor = 2.0 / (period + 1.0); // use normal ema warmup period _rollingAverageIsReadyCount = period; _requireRollingAverageWarmup = requireRollingAverageWarmup; _kellyCriterionManager = new KellyCriterionManager(); }
public void ExtremeCasesBigNumbers(int extremeCase) { var extremePositive = new decimal[] { 1000, 2000, 3000, 1000, 5000, 1000, 1000 }; var extremeNegative = new decimal[] { -1000, -2000, -3000, -1000, -5000, -1000, -1000 }; decimal[] collection = extremeCase == 1 ? extremePositive : extremeNegative; var kellyCriterionManager = new KellyCriterionManager(); foreach (var newValue in collection) { kellyCriterionManager.AddNewValue(newValue, DateTime.UtcNow); kellyCriterionManager.UpdateScores(); } var estimate = kellyCriterionManager.KellyCriterionEstimate; var probabilityValue = kellyCriterionManager.KellyCriterionProbabilityValue; Console.WriteLine($"Estimate {estimate} - ProbabilityValue {probabilityValue}"); Assert.AreEqual(extremeCase == 1 ? 0.00031578947368421 : -0.00031578947368421, kellyCriterionManager.KellyCriterionEstimate); Assert.AreEqual(1, kellyCriterionManager.KellyCriterionProbabilityValue); }
public void ExtremeCasesSmallNumbers(int extremeCase) { var extremePositive = new decimal[] { 1, 2, 3, 1, 5, 1, 1 }; var extremeNegative = new decimal[] { -1, -2, -3, -1, -5, -1, -1 }; decimal[] collection = extremeCase == 1 ? extremePositive : extremeNegative; var kellyCriterionManager = new KellyCriterionManager(); foreach (var newValue in collection) { kellyCriterionManager.AddNewValue(newValue, DateTime.UtcNow); kellyCriterionManager.UpdateScores(); } var estimate = kellyCriterionManager.KellyCriterionEstimate; var probabilityValue = kellyCriterionManager.KellyCriterionProbabilityValue; Log.Trace($"Estimate {estimate} - ProbabilityValue {probabilityValue}"); Assert.AreEqual(extremeCase == 1 ? 0.315789473684211m : -0.315789473684211m, kellyCriterionManager.KellyCriterionEstimate); Assert.AreEqual(1, kellyCriterionManager.KellyCriterionProbabilityValue); }
public void MiddleCase() { // values sum up to 0 -> average will be 0 var middleCase = new decimal[] { 1000, -2000, -3000, 1000, 5000, -1000, -1000 }; var kellyCriterionManager = new KellyCriterionManager(); foreach (var newValue in middleCase) { kellyCriterionManager.AddNewValue(newValue, DateTime.UtcNow); kellyCriterionManager.UpdateScores(); } var estimate = kellyCriterionManager.KellyCriterionEstimate; var probabilityValue = kellyCriterionManager.KellyCriterionProbabilityValue; Console.WriteLine($"Estimate {estimate} - ProbabilityValue {probabilityValue}"); Console.WriteLine($"Estimate {estimate} - ProbabilityValue {probabilityValue}"); // compare with a delta Assert.Less(Math.Abs(0 - kellyCriterionManager.KellyCriterionEstimate), 0.000000000000001m); Assert.AreEqual(1, kellyCriterionManager.KellyCriterionProbabilityValue); }