public static string GenerateBacktestGroupGUID(string responseType, ConfigurationSpace configSpace) { string GUID = responseType + "|"; foreach (var param in configSpace.ParameterSpace) { GUID += param.Name + "=[" + param.Min + "," + param.Max + "]|"; } GUID += configSpace.TemporalSpace.Min.ToString("MM/dd/yyy") + "|" + configSpace.TemporalSpace.Max.ToString("MM/dd/yyy"); return(GUID); }
/* * public static BacktestGroupRecord CreateBacktestGroupRecord(string guid) * { * var record = new BacktestGroupRecord(); * record.GUID = guid; * * var responseConfigArr = guid.Split(new[] { "|" }, 2, StringSplitOptions.None); * * record.ResponseType = responseConfigArr[0]; * record. = CreateConfigurationSpace(responseConfigArr[1]); * * return record; * } */ public static ConfigurationSpace CreateConfigurationSpace(string configString) { int indexLastTrade = configString.LastIndexOf("|"); int indexFirstTrade = configString.Substring(0, indexLastTrade).LastIndexOf("|"); var minDateString = configString.Substring(indexFirstTrade + 1, indexLastTrade - indexFirstTrade - 1); var maxDateString = configString.Substring(indexLastTrade + 1, configString.Length - indexLastTrade - 1); var minDate = Convert.ToDateTime(minDateString); var maxDate = Convert.ToDateTime(maxDateString); var temporalSpace = new ConfigurationVariableSpace <DateTime>("TradeDate", minDate, maxDate, 1); string paramString = configString.Substring(0, indexFirstTrade); var paramSpaceList = ParseParameterSpace(paramString); var configSpace = new ConfigurationSpace { ParameterSpace = paramSpaceList, TemporalSpace = temporalSpace }; return(configSpace); }
private List <OrthogonalLine> GetDoors(IntVector2 position, ConfigurationSpace configurationSpace) { var doors = new List <OrthogonalLine>(); foreach (var doorInfo in configurationSpace.ReverseDoors) { var line = doorInfo.Item1; var doorLine = doorInfo.Item2; var index = line.Contains(position); if (index == -1) { continue; } var offset = line.Length - doorLine.Line.Length; var numberOfPositions = Math.Min(Math.Min(offset, Math.Min(index, line.Length - index)), doorLine.Line.Length) + 1; if (numberOfPositions == 0) { throw new InvalidOperationException(); } for (var i = 0; i < numberOfPositions; i++) { var doorStart = doorLine.Line.GetNthPoint(Math.Max(0, index - offset) + i); var doorEnd = doorStart + doorLine.Length * doorLine.Line.GetDirectionVector(); doors.Add(new OrthogonalLine(doorStart, doorEnd, doorLine.Line.GetDirection())); } } if (doors.Count == 0) { throw new InvalidOperationException(); } return(doors); }
public static List <BacktestGroupRecord> GenerateBacktestGroupRecords(int numGroups) { var groupRecords = new List <BacktestGroupRecord>(); Random random = new Random(); int iRandomResponseIndex = random.Next(1, _responseTypes.Length + 1) - 1; var responseType = _responseTypes[iRandomResponseIndex]; for (int i = 0; i < numGroups; i++) { var paramSpaceList = new List <ConfigurationVariableSpace <double> >(); paramSpaceList.Add(new ConfigurationVariableSpace <double>("XMACoefficient", 0, random.Next(10, 20), 1)); int intervalMin = random.Next(1, 3) * 5 + 5; int intervalMax = random.Next(2, 3) * 5 + intervalMin; paramSpaceList.Add(new ConfigurationVariableSpace <double>("IntervalSize", intervalMin, intervalMax, 1)); int daysBack = -random.Next(25, 35); int daysLong = random.Next(1, 2) * 4 + 3; var startDate = DateTime.Now.AddDays(daysBack); var endDate = startDate.AddDays(daysLong); var temporalSpace = new ConfigurationVariableSpace <DateTime>("TradeDate", startDate, endDate, 1); var configurationSpace = new ConfigurationSpace(); configurationSpace.ParameterSpace = paramSpaceList; configurationSpace.TemporalSpace = temporalSpace; groupRecords.Add(new BacktestGroupRecord { GUID = CommonFunctions.GenerateBacktestGroupGUID(responseType, configurationSpace), CreateDate = DateTime.Now.AddDays(-random.Next(1, 7)).AddSeconds(random.Next(0, 59)), NumBacktests = configurationSpace.GetSpaceSize(), MaxPNL = Math.Round(100 * random.NextDouble(), 2), MinPNL = Math.Round(-100 * random.NextDouble(), 2) }); } return(groupRecords); }
public bool Exists() { return(ConfigurationSpace.Valid()); }