public override object Clone() { var p = new BacktestingProject() { Name = Name, Memo = Memo, IsUnlimited = IsUnlimited, AnalyseGrade = AnalyseGrade, AnalyseStartTime = AnalyseStartTime, CurrentDataSource = CurrentDataSource.Clone() as IDataSource, CurrentTradeGate = CurrentTradeGate, Fine = Fine, Grade = Grade, ProjectStartTime = ProjectStartTime, RiskPolicy = RiskPolicy.Clone() as IRiskControl, Status = Status, TargetPortfolio = TargetPortfolio.Clone() as IPortfolio, TestStrategy = TestStrategy.Clone() as IStrategy, TestCurrentTime = TestCurrentTime, TestEndTime = TestEndTime, TestStartTime = TestStartTime, TestStepDelayMS = TestStepDelayMS, }; ConditionList.ForEach(v => p.ConditionList.Add(v.Clone() as ICondition)); InstrumentList.ForEach(v => p.InstrumentList.Add(v.Clone() as IInstrument)); return(p); }
static void RunFoxHunt() { Stopwatch sw = new Stopwatch(); sw.Start(); using (var sim = new QuantumSimulator()) { var foxSurvives = 0; var hunterWins = 0; for (int i = 0; i < 1000; i++) { var result = (Result)(TestStrategy.Run(sim).Result); if (result == Result.Zero) { foxSurvives++; } else { hunterWins++; } } Console.WriteLine($"Fox survives: \t{foxSurvives}"); Console.WriteLine($"Hunter wins: \t{hunterWins}"); } sw.Stop(); Console.WriteLine($"Experiment finished. " + $"Time spent: {sw.ElapsedMilliseconds / 1000} seconds"); }
public override void SaveOriginalStatus() { CurrentDataSource.SaveOriginalStatus(); ConditionList.ForEach(v => v.SaveOriginalStatus()); TargetPortfolio.SaveOriginalStatus(); TestStrategy.SaveOriginalStatus(); CurrentTradeGate.SaveOriginalStatus(); RiskPolicy.SaveOriginalStatus(); }
public void TestChangeValidationStrategy() { var vm = new TestViewModel(); var strat = new TestStrategy(); vm.ValidationStrategy = strat; Assert.AreSame(strat, vm.ValidationStrategy); }
public override void FinishWork() { TestCurrentTime = TestEndTime; TargetPortfolio.FinishWork(); ConditionList.ForEach(v => v.FinishWork()); //SensorList.ForEach(v => v.FinishWork()); CurrentTradeGate.FinishWork(); CurrentDataSource.FinishWork(); TestStrategy.FinishWork(); RiskPolicy.FinishWork(); }
private static void AssertGetsActuals(string columnName, string headerName) { var table = new DataTable(); table.Columns.Add(columnName, typeof (string)); DataRow row = table.NewRow(); row[columnName] = "hi"; var strategy = new TestStrategy(new Parse("tr", string.Empty, new Parse("td", headerName, null, null), null)); TypedValue[] values = strategy.ActualValues(row); Assert.AreEqual(1, values.Length); Assert.AreEqual(typeof(string), values[0].Type); Assert.AreEqual("hi", values[0].Value); }
public override void LoadOriginalStatus() { if (Status != ProjectStatus.Stopped) { Stop(); } CurrentDataSource.LoadOriginalStatus(); ConditionList.ForEach(v => v.LoadOriginalStatus()); TargetPortfolio.LoadOriginalStatus(); TestStrategy.LoadOriginalStatus(); CurrentTradeGate.LoadOriginalStatus(); RiskPolicy.LoadOriginalStatus(); }
public void StrategyBase_Ctor() { // Arrange ... var options = new OptionsWrapper <StrategyOptions>(new StrategyOptions()); // Act ... var result = new TestStrategy(options); // Assert ... Assert.IsTrue( result.GetPropertyValue("Options", true) != null, "The Options property wasn't initialized by the ctor." ); }
private static void AssertGetsActuals(string columnName, string headerName) { var table = new DataTable(); table.Columns.Add(columnName, typeof(string)); DataRow row = table.NewRow(); row[columnName] = "hi"; var strategy = new TestStrategy(new Parse("tr", string.Empty, new Parse("td", headerName, null, null), null)); TypedValue[] values = strategy.ActualValues(row); Assert.AreEqual(1, values.Length); Assert.AreEqual(typeof(string), values[0].Type); Assert.AreEqual("hi", values[0].Value); }
public List <IPlayStrategy> BuildAll() { var result = new List <IPlayStrategy>(); result.Add(new TeachOnlyShowStrategy(_speaker, _listener)); result.Add(new TeachWriteStrategy(_speaker, _listener)); var testEnglishToRussian = new TestStrategy(3, new EnglishToRussian(), _speaker, _listener); result.Add(testEnglishToRussian); var testRussianToEnglish = new TestStrategy(3, new RussianToEnglish(), _speaker, _listener); result.Add(testRussianToEnglish); return(result); }
public void GetsDataRowActuals() { var table = new DataTable(); table.Columns.Add("test", typeof (bool)); table.Columns.Add("other_test", typeof (string)); DataRow row = table.NewRow(); row["test"] = true; row["other_test"] = "hi"; var strategy = new TestStrategy(new Parse("tr", string.Empty, new Parse("td", "test", null, new Parse("td", "\"other_test\"", null, null)), null)); TypedValue[] values = strategy.ActualValues(row); Assert.AreEqual(2, values.Length); Assert.AreEqual(typeof(bool), values[0].Type); Assert.AreEqual(true, values[0].Value); Assert.AreEqual(typeof(string), values[1].Type); Assert.AreEqual("hi", values[1].Value); }
public async Task It_Decorates_Using_Local() { var testString = ""; var s1 = new TestStrategy(() => testString += "1"); var s2 = new TestStrategy(() => testString += "2"); var s3 = new TestStrategy(() => testString += "3"); var factory = new DynamicCommandBuilderFactory(); var command = factory.CreateFromAction(DefaultCommandName, () => { }) .WithStrategy(s1) .WithStrategy(s2) .WithStrategy(s3) .Build(); await command.Execute(); testString.Should().Be("123"); }
public async Task It_applies_strategies_in_order2() { var testString = ""; var s1 = new TestStrategy(() => testString += "1"); var s2 = new TestStrategy(() => testString += "2"); var s3 = new TestStrategy(() => testString += "3"); var factory = new DynamicCommandBuilderFactory(b => b .WithStrategy(s2) ); var command = factory.CreateFromAction(DefaultCommandName, () => { }) .WithStrategy(s3) .WithStrategy(s1, wrapExisting: true) .Build(); await command.Execute(); testString.Should().Be("123"); }
public void SimpleWriteRoundtrip() { var strategy = new TestStrategy(); var setup = Compose(strategy); setup.AddOrUpdateEntity(1, "test"); setup.AddOrUpdateSingleton(() => 1, i => 1); AssertContents(setup); var memStore = new MemoryStorageConfig(); var mem = memStore.CreateNuclear(strategy); mem.CopyFrom(setup, strategy.GetEntityBucket<string>(), strategy.GetEntityBucket<int>()); AssertContents(mem); setup.Container.Reset(strategy.GetEntityBucket<string>()); setup.Container.Reset(strategy.GetEntityBucket<int>()); setup.CopyFrom(mem, strategy.GetEntityBucket<string>(), strategy.GetEntityBucket<int>()); AssertContents(setup); }
/// <summary> /// Test an archive for integrity/validity /// </summary> /// <param name="testData">Perform low level data Crc check</param> /// <param name="strategy">The <see cref="TestStrategy"></see> to apply.</param> /// <param name="resultHandler">The <see cref="ZipTestResultHandler"></see> handler to call during testing.</param> /// <returns>true if all tests pass, false otherwise</returns> /// <exception cref="ObjectDisposedException">The object has already been closed.</exception> public bool TestArchive(bool testData, TestStrategy strategy, ZipTestResultHandler resultHandler) { if (isDisposed_) { throw new ObjectDisposedException("ZipFile"); } TestStatus status = new TestStatus(this); if ( resultHandler != null ) { resultHandler(status, null); } HeaderTest test = testData ? (HeaderTest.Header | HeaderTest.Extract) : HeaderTest.Header; bool testing = true; try { int entryIndex = 0; while ( testing && (entryIndex < Count) ) { if ( resultHandler != null ) { status.SetEntry(this[entryIndex]); status.SetOperation(TestOperation.EntryHeader); resultHandler(status, null); } try { TestLocalHeader(this[entryIndex], test); } catch(ZipException ex) { status.AddError(); if ( resultHandler != null ) { resultHandler(status, string.Format("Exception during test - '{0}'", ex.Message)); } if ( strategy == TestStrategy.FindFirstError ) { testing = false; } } if ( testing && testData && this[entryIndex].IsFile ) { if ( resultHandler != null ) { status.SetOperation(TestOperation.EntryData); resultHandler(status, null); } Crc32 crc = new Crc32(); using (Stream entryStream = this.GetInputStream(this[entryIndex])) { byte[] buffer = new byte[4096]; long totalBytes = 0; int bytesRead; while ((bytesRead = entryStream.Read(buffer, 0, buffer.Length)) > 0) { crc.Update(buffer, 0, bytesRead); if (resultHandler != null) { totalBytes += bytesRead; status.SetBytesTested(totalBytes); resultHandler(status, null); } } } if (this[entryIndex].Crc != crc.Value) { status.AddError(); if ( resultHandler != null ) { resultHandler(status, "CRC mismatch"); } if ( strategy == TestStrategy.FindFirstError ) { testing = false; } } if (( this[entryIndex].Flags & (int)GeneralBitFlags.Descriptor) != 0 ) { ZipHelperStream helper = new ZipHelperStream(baseStream_); DescriptorData data = new DescriptorData(); helper.ReadDataDescriptor(this[entryIndex].LocalHeaderRequiresZip64, data); if (this[entryIndex].Crc != data.Crc) { status.AddError(); } if (this[entryIndex].CompressedSize != data.CompressedSize) { status.AddError(); } if (this[entryIndex].Size != data.Size) { status.AddError(); } } } if ( resultHandler != null ) { status.SetOperation(TestOperation.EntryComplete); resultHandler(status, null); } entryIndex += 1; } if ( resultHandler != null ) { status.SetOperation(TestOperation.MiscellaneousTests); resultHandler(status, null); } // TODO: the 'Corrina Johns' test where local headers are missing from // the central directory. They are therefore invisible to many archivers. } catch (Exception ex) { status.AddError(); if ( resultHandler != null ) { resultHandler(status, string.Format("Exception during test - '{0}'", ex.Message)); } } if ( resultHandler != null ) { status.SetOperation(TestOperation.Complete); status.SetEntry(null); resultHandler(status, null); } return (status.ErrorCount == 0); }
public static analysis.analysisResult Strategy(analysis.workData data, string strategyCode) { GenericStrategy strategy; curStrategyCode = strategyCode; switch (strategyCode) { //Screening case "SCRPRICE": { Parameters p = null; strategy = new PriceScreening(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "SCRMACD01": { Parameters p = new Parameters(12, 26, 9); strategy = new BasicMACD(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Screening()); } case "SCRMACD02": { Parameters p = new Parameters(12, 26, 9); strategy = new MACD_HistogramChanged(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Screening()); } case "SCRDMI": { Parameters p = new Parameters(14, 14); strategy = new BasicDMI(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Screening()); } case "SCRSupport": { Parameters p = new Parameters(30, 0.01); strategy = new SupportScreening(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Screening()); } case "SCRResist": { Parameters p = new Parameters(30, 0.01); strategy = new ResistanceScreening(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Screening()); } case "BUYANDHOLD": { strategy = new BuyAndHoldStrategy(data, strategyCode, fExportData, curStrategyCode); return(strategy.Execute()); } #region SMA Strategy case "SMAONLY": { Parameters p = new Parameters(5, 10); strategy = new TwoSMA(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "EMAONLY": { Parameters p = new Parameters(5, 10); strategy = new TwoEMA(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "WMAONLY": { strategy = new BasicWMA_5_10(data, strategyCode, fExportData, curStrategyCode); return(strategy.Execute()); } case "SMAPRICE": { //strategy = new Price_SMA_5_10(data, strategyCode, fExportData, curStrategyCode); //return strategy.Execute(); Parameters p = new Parameters(50, 100); strategy = new PriceTwoSMA(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "SMAVFIL": { Parameters p = new Parameters(5, 10, 50000); strategy = new TwoSMA_VolumeFilter(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "3SMAPRICE": { Parameters p = new Parameters(5, 10, 20); strategy = new BasicPrice_3SMA(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "3SMANEW": { Parameters p = new Parameters(10, 20, 30); strategy = new BasicPrice_3SMA(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "SMARIRW": { Parameters p = new Parameters(5, 10, 20); strategy = new Price_3SMA_Risk_Reward(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "SMAMID": { Parameters p = new Parameters(20, 50); strategy = new PriceTwoSMA(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); //strategy = new Price_SMA_20_50(data, strategyCode, fExportData, curStrategyCode); //return strategy.Execute(); } case "SMAM50_100": { Parameters p = new Parameters(50, 100); strategy = new PriceTwoSMA(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } #endregion //Statistic case "AVERAGE": { Parameters p = new Parameters(30, -15, 10); strategy = new AverageStrategy(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } //Statistic case "AVERAGE1": { Parameters p = new Parameters(30, -15, 15); strategy = new AverageStrategy(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "RAND": { Parameters p = null; strategy = new RandomStrategy(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } //Statistic case "MARKOV": { Parameters p = null; strategy = new SimpleMarkov(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } #region MACD strategy //MACD strategy case "MACDBAS": { Parameters p = new Parameters(12, 26, 9); strategy = new BasicMACD(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "MACD1": { strategy = new MACD_Line_Cut(data, strategyCode, fExportData, curStrategyCode); return(strategy.Execute()); } case "MACD2": { Parameters p = new Parameters(12, 26, 9); strategy = new MACD_HistogramChanged(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "MACD_CL": { strategy = new MACD_HistogramChanged_CutLoss(data, strategyCode, fExportData, curStrategyCode); return(strategy.Execute()); } #endregion //Strategy with DMI indicator case "DMI": { Parameters p = new Parameters(14, 14); strategy = new BasicDMI(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "DMI_CL": { Parameters p = new Parameters(14, 14, -5); strategy = new BasicDMI(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute_CutLoss()); } //Strategy with Stochastic case "STOCHFAST": { Parameters p = new Parameters(14, 3); strategy = new StochasticFast(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } //Strategy with Stochastic case "STOCHSLOW": { Parameters p = new Parameters(15, 5, 3); strategy = new StochasticSlow(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } //Strategy with pattern case "PATERN32": { const int CONSECUTIVE_UP = 4; const int CONSECUTIVE_DOWN = 3; Parameters p = new Parameters(CONSECUTIVE_DOWN, CONSECUTIVE_UP); strategy = new Pattern_Consecutive_UpAndDown(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } #region Hybrid strategy ////Hybrid strategy case "RSI": { int RSI_LOWER_LEVEL = 30; int RSI_UPPER_LEVEL = 70; double[] d = { 14, 26, 12, 9, RSI_LOWER_LEVEL, RSI_UPPER_LEVEL }; Parameters p = new Parameters(d); strategy = new RSI_MACD_Histogram(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "SMASTOCH": { double[] d = { 5, 10, 15, 5, 3 }; Parameters p = new Parameters(d);; strategy = new SMA_Stochastic(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "MACDSTOC": { double[] d = { 20, 12, 26, 9, 15, 5, 3 }; Parameters p = new Parameters(d); strategy = new MACD_Stochastic(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "MS_BOTTOM": { Parameters p = null; strategy = new MACD_Stochastic_Bottom(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "MS_BOTv1": { Parameters p = null; strategy = new MACD_Stochastic_Bottom_v1(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } case "TEST": { Parameters p = new Parameters(5, 10, 1.5); strategy = new TestStrategy(data, strategyCode, fExportData, curStrategyCode, p); return(strategy.Execute()); } #endregion default: return(null); } }
public static analysis.analysisResult Strategy(analysis.workData data, string strategyCode) { GenericStrategy strategy; curStrategyCode = strategyCode; switch (strategyCode) { //Screening case "SCRPRICE": { Parameters p = null; strategy = new PriceScreening(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } case "SCRMACD01": { Parameters p = new Parameters(12, 26, 9); strategy = new BasicMACD(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Screening(); } case "SCRMACD02": { Parameters p = new Parameters(12, 26, 9); strategy = new MACD_HistogramChanged(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Screening(); } case "SCRDMI": { Parameters p = new Parameters(14, 14); strategy = new BasicDMI(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Screening(); } case "SCRSupport": { Parameters p = new Parameters(30, 0.01); strategy = new SupportScreening(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Screening(); } case "SCRResist": { Parameters p = new Parameters(30, 0.01); strategy = new ResistanceScreening(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Screening(); } case "BUYANDHOLD": { strategy = new BuyAndHoldStrategy(data, strategyCode, fExportData, curStrategyCode); return strategy.Execute(); } #region SMA Strategy case "SMAONLY": { Parameters p = new Parameters(5, 10); strategy = new TwoSMA(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } case "EMAONLY": { Parameters p = new Parameters(5, 10); strategy = new TwoEMA(data, strategyCode, fExportData, curStrategyCode,p); return strategy.Execute(); } case "WMAONLY": { strategy = new BasicWMA_5_10(data, strategyCode, fExportData, curStrategyCode); return strategy.Execute(); } case "SMAPRICE": { //strategy = new Price_SMA_5_10(data, strategyCode, fExportData, curStrategyCode); //return strategy.Execute(); Parameters p = new Parameters(50, 100); strategy = new PriceTwoSMA(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } case "SMAVFIL": { Parameters p = new Parameters(5, 10, 50000); strategy = new TwoSMA_VolumeFilter(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } case "3SMAPRICE": { Parameters p = new Parameters(5, 10, 20); strategy = new BasicPrice_3SMA(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } case "3SMANEW": { Parameters p = new Parameters(10, 20, 30); strategy = new BasicPrice_3SMA(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } case "SMARIRW": { Parameters p = new Parameters(5, 10, 20); strategy = new Price_3SMA_Risk_Reward(data, strategyCode, fExportData, curStrategyCode,p); return strategy.Execute(); } case "SMAMID": { Parameters p = new Parameters(20, 50); strategy = new PriceTwoSMA(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); //strategy = new Price_SMA_20_50(data, strategyCode, fExportData, curStrategyCode); //return strategy.Execute(); } case "SMAM50_100": { Parameters p = new Parameters(50, 100); strategy = new PriceTwoSMA(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } #endregion //Statistic case "AVERAGE": { Parameters p = new Parameters(30, -15, 10); strategy = new AverageStrategy(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } //Statistic case "AVERAGE1": { Parameters p = new Parameters(30, -15, 15); strategy = new AverageStrategy(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } case "RAND": { Parameters p = null; strategy = new RandomStrategy(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } //Statistic case "MARKOV": { Parameters p = null; strategy = new SimpleMarkov(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } #region MACD strategy //MACD strategy case "MACDBAS": { Parameters p = new Parameters(12, 26, 9); strategy = new BasicMACD(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } case "MACD1": { strategy = new MACD_Line_Cut(data, strategyCode, fExportData, curStrategyCode); return strategy.Execute(); } case "MACD2": { Parameters p = new Parameters(12, 26, 9); strategy = new MACD_HistogramChanged(data, strategyCode, fExportData, curStrategyCode,p); return strategy.Execute(); } case "MACD_CL": { strategy = new MACD_HistogramChanged_CutLoss(data, strategyCode, fExportData, curStrategyCode); return strategy.Execute(); } #endregion //Strategy with DMI indicator case "DMI": { Parameters p = new Parameters(14, 14); strategy = new BasicDMI(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } case "DMI_CL": { Parameters p = new Parameters(14, 14, -5); strategy = new BasicDMI(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute_CutLoss(); } //Strategy with Stochastic case "STOCHFAST": { Parameters p = new Parameters(14, 3); strategy = new StochasticFast(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } //Strategy with Stochastic case "STOCHSLOW": { Parameters p = new Parameters(15, 5, 3); strategy = new StochasticSlow(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } //Strategy with pattern case "PATERN32": { const int CONSECUTIVE_UP = 4; const int CONSECUTIVE_DOWN = 3; Parameters p = new Parameters(CONSECUTIVE_DOWN, CONSECUTIVE_UP); strategy = new Pattern_Consecutive_UpAndDown(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } #region Hybrid strategy ////Hybrid strategy case "RSI": { int RSI_LOWER_LEVEL = 30; int RSI_UPPER_LEVEL = 70; double[] d = { 14, 26, 12, 9, RSI_LOWER_LEVEL, RSI_UPPER_LEVEL }; Parameters p = new Parameters(d); strategy = new RSI_MACD_Histogram(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } case "SMASTOCH": { double[] d = { 5, 10, 15, 5, 3 }; Parameters p = new Parameters(d); ; strategy = new SMA_Stochastic(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } case "MACDSTOC": { double[] d = { 20, 12, 26, 9, 15, 5, 3 }; Parameters p = new Parameters(d); strategy = new MACD_Stochastic(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } case "MS_BOTTOM": { Parameters p = null; strategy = new MACD_Stochastic_Bottom(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } case "MS_BOTv1": { Parameters p = null; strategy = new MACD_Stochastic_Bottom_v1(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } case "TEST": { Parameters p = new Parameters(5, 10, 1.5); strategy = new TestStrategy(data, strategyCode, fExportData, curStrategyCode, p); return strategy.Execute(); } #endregion default: return null; } }
public bool TestArchive(bool testData, TestStrategy strategy = TestStrategy.FindFirstError, ZipTestResultHandler resultHandler = null) { if (isDisposed_) { throw new ObjectDisposedException("ZipFile"); } TestStatus status = new TestStatus(this); if (resultHandler != null) { resultHandler(status, null); } HeaderTest tests = testData ? (HeaderTest.Header | HeaderTest.Extract) : HeaderTest.Header; bool flag = true; try { for (int i = 0; flag && (i < Count); i++) { if (resultHandler != null) { status.SetEntry(this[i]); status.SetOperation(TestOperation.EntryHeader); resultHandler(status, null); } try { TestLocalHeader(this[i], tests); } catch (ZipException exception) { status.AddError(); if (resultHandler != null) { resultHandler(status, string.Format("Exception during test - '{0}'", exception.Message)); } if (strategy == TestStrategy.FindFirstError) { flag = false; } } if ((flag && testData) && this[i].IsFile) { if (resultHandler != null) { status.SetOperation(TestOperation.EntryData); resultHandler(status, null); } Crc32 crc = new Crc32(); using (Stream stream = GetInputStream(this[i])) { int num3; byte[] buffer = new byte[DefaultBufferSize]; long num2 = 0L; while ((num3 = stream.Read(buffer, 0, buffer.Length)) > 0) { crc.Update(buffer, 0, num3); if (resultHandler != null) { num2 += num3; status.SetBytesTested(num2); resultHandler(status, null); } } } if (this[i].Crc != crc.Value) { status.AddError(); if (resultHandler != null) { resultHandler(status, "CRC mismatch"); } if (strategy == TestStrategy.FindFirstError) { flag = false; } } if ((this[i].Flags & 8) != 0) { ZipHelperStream stream2 = new ZipHelperStream(baseStream_); DescriptorData data = new DescriptorData(); stream2.ReadDataDescriptor(this[i].LocalHeaderRequiresZip64, data); if (this[i].Crc != data.Crc) { status.AddError(); } if (this[i].CompressedSize != data.CompressedSize) { status.AddError(); } if (this[i].Size != data.Size) { status.AddError(); } } } if (resultHandler != null) { status.SetOperation(TestOperation.EntryComplete); resultHandler(status, null); } } if (resultHandler != null) { status.SetOperation(TestOperation.MiscellaneousTests); resultHandler(status, null); } } catch (Exception exception2) { status.AddError(); if (resultHandler != null) { resultHandler(status, string.Format("Exception during test - '{0}'", exception2.Message)); } } if (resultHandler != null) { status.SetOperation(TestOperation.Complete); status.SetEntry(null); resultHandler(status, null); } return (status.ErrorCount == 0); }
public override void PrepareWork() { TargetPortfolio.PrepareWork(); MarketDataList.Clear(); CurrentDataSource.DataList.Clear(); CurrentValueList.Clear(); StandardValueList.Clear(); OrderList.Clear(); DateTime st = TestStartTime; if (TestStartTime > AnalyseStartTime) { st = AnalyseStartTime; } CurrentDataSource.CacheStartTime = st; CurrentDataSource.CacheEndTime = TestEndTime; TestCurrentTime = TestStartTime; analyseTime = MarketData.GetNextTime(TestCurrentTime, AnalyseGrade); _MaxLost = new Money() { FxCode = Pnl.FxCode, Number = 0 }; if (UseFirstMarketDataInit) { var fdl = new List <IMarketData>(); InstrumentList.ForEach(v => { var d = CurrentDataSource.GetFirstData(v, TestStartTime, TestEndTime, Grade); if (d != null) { fdl.Add(d); } }); TargetPortfolio.ProcessMarketData(fdl); TargetPortfolio.PositionList.ForEach(v => { var d = fdl.FirstOrDefault(m => m.InstrumentTicker == v.InstrumentTicker); if (d != null) { v.Cost = d.Close; } }); } if (IsUnlimited) { TargetPortfolio.IsUnlimited = true; } standardPortfolio = TargetPortfolio.Clone() as IPortfolio; testStartValue = TargetPortfolio.CurrentValue; CurrentDataSource.PrepareWork(); CurrentTradeGate.PrepareWork(); foreach (var condition in ConditionList) { condition.PrepareWork(); condition.GetInstrumentList = () => { return(InstrumentList); }; condition.AnalyseDataSource = CurrentDataSource; } TestStrategy.CurrentPortfolio = TargetPortfolio; TestStrategy.PrepareWork(); RiskPolicy.PrepareWork(); }
void TestStep(DateTime start, DateTime end) { TestStrategy.CurrentTime = end; AddInfo("test step, start:" + start.ToString() + ",end:" + end.ToString()); var dl = CurrentDataSource.GetDataList(InstrumentList, start, end, Grade); AddInfo("got market data ,count is:" + dl.Count.ToString()); if (dl == null || dl.Count == 0) { return; } TestStrategy.CurrentTime = dl.Max(d => d.Time); dl.ForEach(v => { var inst = InstrumentList.FirstOrDefault(i => i.Ticker == v.InstrumentTicker); if (inst != null) { AddInfo("update " + inst.Name + " price, value is:" + v.Close.ToString() + "(" + v.Time.ToString() + ")"); inst.CurrentPrice = v.Close; } }); MarketDataList.AddRange(dl); AddInfo("portfolio process market data!"); TargetPortfolio.ProcessMarketData(dl); AddInfo("standard portfolio process market data!"); standardPortfolio.ProcessMarketData(dl); AddInfo("strategy process market data!"); TestStrategy.ProcessMarketData(dl); if (analyseTime <= end) { AddInfo("prepare analyse, analyse time is:" + analyseTime.ToString()); AnalyseStep(); analyseTime = MarketData.GetNextTime(end, AnalyseGrade); var cl = new List <ISignal>(); foreach (var condition in ConditionList) { var rl = condition.GetResult(); if (rl != null && rl.Count > 0) { cl.AddRange(rl); } } if (cl.Count > 0) { AddInfo("got signal, count is " + cl.Count.ToString()); TestStrategy.ProcessSignal(cl); } } AddInfo("strategy process portfolio"); TestStrategy.ProcessPortfolio(); var ol = TestStrategy.GetOrderList(); if (ol.Count > 0) { AddInfo("strategy generate order, count is :" + ol.Count.ToString()); List <IOrder> col = new List <IOrder>(); foreach (var o in ol) { if (o != null && RiskPolicy.PredictOrder(o, TargetPortfolio)) { col.Add(o); } } OrderList.AddRange(col); AddInfo("trade gate process order"); CurrentTradeGate.ProcessorOrder(col); AddInfo("portfolio info before process order is" + GetPortfolioMemo(TargetPortfolio)); TargetPortfolio.ProcessOrderList(col); AddInfo("portfolio info after process order is" + GetPortfolioMemo(TargetPortfolio)); } if (!IsUnlimited)//adjust risk { AddInfo("adjust risk"); ol = RiskPolicy.AdjustRisk(TargetPortfolio); if (ol.Count > 0) { AddInfo("risk order generate, count is:" + ol.Count.ToString()); OrderList.AddRange(ol); List <IOrder> col = ol.Where(v => v != null).ToList(); CurrentTradeGate.ProcessorOrder(col); TargetPortfolio.ProcessOrderList(col); } } CurrentValueList.Add(new TimeValueObject() { Time = dl.Max(v => v.Time), Value = CurrentValue, Memo = GetPortfolioMemo(TargetPortfolio) }); StandardValueList.Add(new TimeValueObject() { Time = dl.Max(v => v.Time), Value = StandardValue, Memo = GetPortfolioMemo(standardPortfolio) }); if (_MaxLost.Number > Pnl.Number) { _MaxLost.Number = Pnl.Number; } if (TestStepDelayMS > 0) { Thread.Sleep(TestStepDelayMS); } }
private void button11_Click(object sender, EventArgs e) { TestStrategy.Testar(); }
public TestAssembly(ILaunchSettings launchSettings) { this.assemblyPath = launchSettings.Arguments.AssemblyPath; this.testStrategy = launchSettings.Arguments.TestStratgey; }
private void button1_Click(object sender, EventArgs e) { TestStrategy t = new TestStrategy(settings); t.Show(); }