private void Construct(StrategyResultStatistics input, List <double> equity, List <double> listMargin) { double value = 0; if (equity.Count > 0) { value = equity[equity.Count - 1]; } else { int pip = input.listEquity[0]; double temp = ForexSuite.SymbolsManager.ValueFromPips(m_TradingCurrency, pip); value = ForexSuite.QuotesManager.ConvertCurrency(m_TradingCurrency, "USD", input.timeBars[0], temp); } int length = Math.Min(input.timeBars.Count, input.listEquity.Count); for (int index = 1; index < length; ++index) { int pip = input.listEquity[index] - input.listEquity[index - 1]; double tempInCurrency = ForexSuite.SymbolsManager.ValueFromPips(m_TradingCurrency, pip); tempInCurrency = ForexSuite.QuotesManager.ConvertCurrency(m_TradingCurrency, "USD", input.timeBars[index], tempInCurrency); value += tempInCurrency; equity.Add(value); tempInCurrency = ForexSuite.SymbolsManager.ValueFromPips(m_MarginCurrency, input.listMargin[index] * 100); listMargin.Add(ForexSuite.QuotesManager.ConvertCurrency(m_MarginCurrency, "USD", input.timeBars[index], tempInCurrency)); } }
public override double OptimizationFunction(StrategyParameter sParam, out StrategyResultStatistics srResult, string directory) { return(StandardOptimizationFunction(sParam, directory, new BuyLimitAndWaitStrategy(), new BuyLimitAndWaitConfigReader(), out srResult)); }
public override double OptimizationFunction(StrategyParameter sParam, out StrategyResultStatistics srResult, string directory) { return(StandardOptimizationFunction(sParam, directory, new PipsovikWeekendStrategy(), new PipsovikWeekendConfigReader(), out srResult)); }
public override double OptimizationFunction(StrategyParameter sParam, out StrategyResultStatistics srResult) { return(StandardOptimizationFunction(sParam, string.Empty, new SuperAdaptStrategy(), new SuperAdaptConfigReader(), out srResult)); }
public abstract double OptimizationFunction(StrategyParameter sParam, out StrategyResultStatistics srResult, string directory);
public double StandardOptimizationFunction(StrategyParameter sParam, string directory, FxAdvisorCore.SimpleAdvisor advisor, ConfigReader configReader, out StrategyResultStatistics srResult) { srResult = new StrategyResultStatistics(); if (!IsValid(sParam)) { return(Double.MinValue); } string cacheKey = CreateKey(SampleData.Symbol, sParam, SampleData.Data.First().DateTime, SampleData.Data.Last().DateTime); if (cacheResult.ContainsKey(cacheKey)) { return(cacheResult[cacheKey]); } using (Log4Smart.Logger logger = new Log4Smart.Logger(false)) { string strategyName = System.Configuration.ConfigurationManager.AppSettings["ExportAdvisorName"]; try { Engine engine = new Engine(logger, logger); advisor.TesterInit(sParam, logger); Account acc = new Account(DefaultAccount.Balance, DefaultAccount.Commission); engine.StartTest(SampleData, advisor, acc); srResult = acc.Statistics; if (!engine.IsTestSuccessfull) { if (string.IsNullOrEmpty(directory)) { directory = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); } string fullDir = directory + string.Format("/errors/{0}/{1}/{2}/", SampleData.Symbol, Guid.NewGuid().ToString(), StartTime.ToString("yyyyMMdd")); configReader.SaveCurrentParameters(strategyName, sParam, fullDir); logger.SaveLogToFile(fullDir, "error"); cacheResult[cacheKey] = Double.MinValue; return(Double.MinValue); } if (sParam.Contains("MinAmountOrdersFLP") && acc.Statistics.NumberOrders < sParam["MinAmountOrdersFLP"] && string.IsNullOrEmpty(directory)) { cacheResult[cacheKey] = Double.MinValue; return(Double.MinValue); } if (!string.IsNullOrEmpty(directory)) { string fullDir = directory + "/" + this.StartTime.ToString("yyyyMMdd") + "_" + (acc.Balance.ToString()) + "$"; configReader.SaveCurrentParameters(strategyName, sParam, fullDir); logger.SaveLogToFile(fullDir, "allData"); } if (DefaultAccount.Commission > 0) { cacheResult[cacheKey] = acc.Statistics.CalculateConfidenceIntervalLow; } else { cacheResult[cacheKey] = 10 - acc.Statistics.CalculateConfidenceIntervalHigh; } return(cacheResult[cacheKey]); } catch (Exception exc) { (logger as Log4Smart.IStrategyLogger).AddMessage("{0}", exc.ToString()); if (string.IsNullOrEmpty(directory)) { directory = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); } string fullDir = directory + string.Format("/errors/{0}/{1}/", SampleData.Symbol, StartTime.ToString("yyyyMMdd")); configReader.SaveCurrentParameters(strategyName, sParam, fullDir); logger.SaveLogToFile(fullDir, "error"); cacheResult[cacheKey] = Double.MinValue; return(Double.MinValue); } } }
public override double OptimizationFunction(StrategyParameter sParam, out StrategyResultStatistics srResult, string directory) { throw new NotImplementedException(); }