public void SetFloatPropertyValue(FloatPropertyRange range, float value) { if (range.IndicatorType == StockIndicatorType.NONE) { if (range.Name == "BuyMargin") { this.BuyMargin = value; } else if (range.Name == "SellMargin") { this.SellMargin = value; } else { throw new System.ArgumentException("Property " + range.Name + " doesn't exist in StockPersonality"); } } else { this.IndicatorDictionary[range.IndicatorType].Impact = value; } }
private void UpdateBestForValue(StockSerie stockSerie, FloatPropertyRange range, bool refreshGUI, ref StockPortofolio bestPortofolio, ref StockPersonality bestPersonality, float currentValue) { stockSerie.StockAnalysis.StockPersonality.SetFloatPropertyValue(range, currentValue); stockSerie.ResetSAREX(); //Console.WriteLine("Fixed Fee:" + this.simulationParameterControl.fixedFee + " Tax Rate:" + this.simulationParameterControl.taxRate); StockPortofolio currentPortofolio = GenerateTradingSimulation(stockSerie, this.simulationParameterControl.StartDate, this.simulationParameterControl.EndDate.AddHours(18), this.simulationParameterControl.amount, this.simulationParameterControl.reinvest, this.simulationParameterControl.amendOrders, this.simulationParameterControl.supportShortSelling, this.simulationParameterControl.fixedFee, this.simulationParameterControl.taxRate); //if (generateReportCheckBox.Checked) //{ // this.simulationParameterControl.Personality = currentPersonality; // this.simulationParameterControl.GenerateReportLine("TuningReport_"+stockSerie.StockName+".csv", stockSerie, currentPortofolio); //} if ((bestPortofolio == null || bestPortofolio.TotalAddedValue < currentPortofolio.TotalAddedValue) && currentPortofolio.OrderList.Count != 0) { bestPersonality = stockSerie.StockAnalysis.StockPersonality.Clone(); //Console.WriteLine("new best" + bestPersonality.ToString()); //Console.WriteLine("new best" + currentPortofolio.ToString()); // Update new best portofolio bestPortofolio = currentPortofolio; // Refresh GUI if (refreshGUI) { this.simulationParameterControl.Personality = bestPersonality; } } if (!this.allStocksCheckBox.Checked) { if (this.progressBar.Value < this.progressBar.Maximum) { this.progressBar.Value++; } else { this.progressBar.Value = 0; } } }
private List<FloatPropertyRange> SarexParamRangeListFromDialog(ref float indicatorSARAccelerationStepStep, ref float indicatorSARFastSwingFactorStep) { #region Validate input Parameters // Validate input parameters FloatPropertyRange accelerationStepRange = new FloatPropertyRange("IndicatorSARAccelerationStep", float.Parse(this.simulationParameterControl.accelerationStepMinTextBox.Text, StockAnalyzerForm.EnglishCulture), float.Parse(this.simulationParameterControl.accelerationStepMaxTextBox.Text, StockAnalyzerForm.EnglishCulture), float.Parse(this.simulationParameterControl.accelerationStepStepTextBox.Text, StockAnalyzerForm.EnglishCulture)); indicatorSARAccelerationStepStep = accelerationStepRange.Step; FloatPropertyRange indicatorSARFastSwingFactorRange = new FloatPropertyRange("IndicatorSARFastSwingFactor", float.Parse(this.simulationParameterControl.fastSwingFactorMinTextBox.Text, StockAnalyzerForm.EnglishCulture), float.Parse(this.simulationParameterControl.fastSwingFactorMaxTextBox.Text, StockAnalyzerForm.EnglishCulture), float.Parse(this.simulationParameterControl.fastSwingFactorStepTextBox.Text, StockAnalyzerForm.EnglishCulture)); indicatorSARFastSwingFactorStep = indicatorSARFastSwingFactorRange.Step; #endregion // Build property range list List<FloatPropertyRange> propertyRangeList = new List<FloatPropertyRange>(); propertyRangeList.Add(accelerationStepRange); propertyRangeList.Add(indicatorSARFastSwingFactorRange); return propertyRangeList; }
private void TuneProperty(StockSerie stockSerie, FloatPropertyRange range, bool refreshGUI, ref StockPortofolio bestPortofolio, ref StockPersonality bestPersonality) { float mediumValue = (range.Max + range.Min) / 2.0f; float maxWidth = (range.Max - range.Min) / 2.0f; UpdateBestForValue(stockSerie, range, refreshGUI, ref bestPortofolio, ref bestPersonality, mediumValue); float precision = range.Step / -100.0f; for (float currentWidth = range.Step; (maxWidth - currentWidth) > precision; currentWidth += range.Step) { UpdateBestForValue(stockSerie, range, refreshGUI, ref bestPortofolio, ref bestPersonality, mediumValue + currentWidth); UpdateBestForValue(stockSerie, range, refreshGUI, ref bestPortofolio, ref bestPersonality, mediumValue - currentWidth); } }
private void UpdateBestForValue(StockSerie stockSerie, FloatPropertyRange range, bool refreshGUI, ref float bestReturn, ref StockPersonality bestPersonality, float currentValue) { stockSerie.StockAnalysis.StockPersonality.SetFloatPropertyValue(range, currentValue); stockSerie.ResetSAREX(); float currentReturn = stockSerie.CalculateSarReturn(StockDataType.SAREX_FOLLOWER_CUSTOM); if ( currentReturn > bestReturn) { bestPersonality = stockSerie.StockAnalysis.StockPersonality.Clone(); bestReturn = currentReturn; // Refresh GUI if (refreshGUI) { this.simulationParameterControl.Personality = bestPersonality; } } if (!this.allStocksCheckBox.Checked) { if (this.progressBar.Value < this.progressBar.Maximum) { this.progressBar.Value++; } else { this.progressBar.Value = 0; } } }