/// <summary> /// Called each time, the variants have changed. /// Attention: May be called by different threads in parallel, dependend /// on the number of Cores of the system CPU. /// </summary> /// <param name="strWKN"></param> public void Prepare() { int nAveraging = this.RuleEngineInfo.Variants["averaging"]; Stock dax = DBEngine.GetInstance().GetStock("846900"); //Stock dax_short = DBEngine.GetInstance().GetStock("A0C4CT"); this.dax_close = dax.QuotesClose.Clone(); this.dax_ma = MovingAverage.CreateFrom(dax_close, nAveraging); this.dax_rel_diff = RelativeDifference.CreateFrom(dax_close, dax_ma); this.dax_price_osc = PriceOscillator.CreateFrom(dax_close, 38, 200).Clone(this.RuleEngineInfo.FromDate); dax_price_osc.Scale(100); dax_trend.Clear(); foreach (WorkDate keyDate in dax_price_osc.Dates) { dax_trend[keyDate] = (dax_price_osc[keyDate] > 0) ? 10 : -10; } dax_rel_diff = dax_rel_diff.Clone(this.RuleEngineInfo.FromDate); dax_ma = dax_ma.Clone(this.RuleEngineInfo.FromDate); dax_close = dax_close.Clone(this.RuleEngineInfo.FromDate); this.buy_events = new DataContainer(); this.sell_events = new DataContainer(); this.buy_events_dax = new DataContainer(); this.sell_events_dax = new DataContainer(); }
/// <summary> /// Called each time, the variants have changed. /// Attention: May be called by different threads in parallel, dependend /// on the number of Cores of the system CPU. /// </summary> /// <param name="strWKN"></param> public void Prepare() { int nAveraging = this.RuleEngineInfo.Variants["averaging"]; dax_ma = MovingAverage.CreateFrom(dax_close, nAveraging); dax_ma = dax_ma.Clone(this.RuleEngineInfo.FromDate); dax_rel_diff = RelativeDifference.CreateFrom(dax_close, dax_ma); dax_rel_diff = dax_rel_diff.Clone(this.RuleEngineInfo.FromDate); this.buy_events = new DataContainer(); this.sell_events = new DataContainer(); this.buy_events_dax = new DataContainer(); this.sell_events_dax = new DataContainer(); }
private void analyzeFor(String wkn, String title) { const int nInvestPeriodStep = 5; const int nMaxInvestPeriod = 30; DBEngine dbengine = DBEngine.GetInstance(); DataContainer dcPerformancesAvg = new DataContainer(); DataContainer[] dcPerformances = new DataContainer[5]; for (int i = 0; i < dcPerformances.Length; i++) { dcPerformances[i] = new DataContainer(); } if (dbengine.Exists(wkn) == false) { return; } Stock dax = dbengine.GetStock(wkn); DataContainer quotes = dax.Quotes; WorkDate fromDate = quotes.YoungestDate.Clone(); fromDate.Set(fromDate.Year - 4, fromDate.Month, 1); WorkDate endDate = quotes.YoungestDate.Clone() - nMaxInvestPeriod; DataContainer dax_ranged = quotes.Clone(fromDate); DataContainer dax_ma200 = MovingAverage.CreateFrom(quotes, 200); dax_ma200 = dax_ma200.Clone(fromDate); DataContainer dax_ma38 = MovingAverage.CreateFrom(quotes, 38); dax_ma38 = dax_ma38.Clone(fromDate); DataContainer dax_rel_diff_38 = RelativeDifference.CreateFrom(quotes, dax_ma38); dax_rel_diff_38 = dax_rel_diff_38.Clone(fromDate); for (; fromDate < endDate; fromDate++) { for (int nInvestPeriod = 10; nInvestPeriod <= nMaxInvestPeriod; nInvestPeriod += nInvestPeriodStep) { double dPerf = ((quotes[fromDate + nInvestPeriod] / quotes[fromDate]) - 1) * 100.0; dcPerformances[(nInvestPeriod / nInvestPeriodStep) - 2][fromDate] = dPerf; } } foreach (WorkDate keydate in dcPerformances[0].Dates) { double dAvg = dcPerformances[0][keydate] + dcPerformances[1][keydate] + dcPerformances[2][keydate] + dcPerformances[3][keydate] + dcPerformances[4][keydate]; dAvg /= 5; dcPerformancesAvg[keydate] = dAvg; } DataContainer upperBarrier = dax_ranged.Clone(); upperBarrier.Set(5); DataContainer middleBarrier = dax_ranged.Clone(); middleBarrier.Set(0); DataContainer lowerBarrier = dax_ranged.Clone(); lowerBarrier.Set(-5); // Create ProfitStatistik Chart chart = new Chart(); chart.Width = 1500; chart.Height = 800; chart.Format = Chart.OutputFormat.SVG; chart.Clear(); chart.LineWidth = 1; chart.SubSectionsX = 6; chart.TicsYInterval = 5; chart.LogScaleY = false; chart.Title = title + " Performance and MA 38/200\\n" + dax_rel_diff_38.OldestDate.ToString() + " - " + dax_rel_diff_38.YoungestDate.ToString(); chart.LabelY = "Performance (%)"; chart.RightDate = quotes.YoungestDate + 10; /*chart.Add(dcPerformances[0], Chart.LineType.SkyBlue, "10"); * chart.Add(dcPerformances[1], Chart.LineType.SkyBlue, "15"); * chart.Add(dcPerformances[2], Chart.LineType.SkyBlue, "20"); * chart.Add(dcPerformances[3], Chart.LineType.SkyBlue, "25"); * chart.Add(dcPerformances[4], Chart.LineType.SkyBlue, "30");*/ chart.Add(dcPerformancesAvg, Chart.LineType.Fuchsia, "Average Profit (5/10/15/20/25/30)"); chart.Add(dax_rel_diff_38, Chart.LineType.MediumBlue, "Rel. diff. to MA38"); chart.Add(upperBarrier, Chart.LineType.MediumRed); chart.Add(middleBarrier, Chart.LineType.Black); chart.Add(lowerBarrier, Chart.LineType.MediumGreen); chart.Create(World.GetInstance().ResultPath + title + "ProfitStatistik"); // Create DAX chart.Clear(); chart.LogScaleY = true; chart.TicsYInterval = 200; chart.Title = title + "\\n" + dax_ranged.OldestDate.ToString() + " - " + dax_ranged.YoungestDate.ToString(); chart.LabelY = "Punkte (log.)"; chart.RightDate = quotes.YoungestDate + 10; chart.Add(dax_ranged, Chart.LineType.MediumBlue, "Index"); //chart.Add(short_ranged, Chart.LineType.SeaGreen, "DAX Short"); chart.Add(dax_ma38, Chart.LineType.HeavyGreen, "Moving Average (38)"); chart.Add(dax_ma200, Chart.LineType.MediumRed, "Moving Average (200)"); chart.Create(World.GetInstance().ResultPath + title + "Overview"); }
public void Analyze() { DBEngine dbengine = DBEngine.GetInstance(); if (dbengine.Exists("846900") == false) { return; } Chart chart = new Chart(); chart.Width = 1500; chart.Height = 800; Stock dax = dbengine.GetStock("846900"); //Stock dax_short = dbengine.GetStock("A0C4CT"); DataContainer quotes = dax.Quotes; DataContainer dax_ma38 = MovingAverage.CreateFrom(quotes, 38); WorkDate startDate = quotes.YoungestDate.Clone(); startDate.Set(startDate.Year - 2, startDate.Month, 1); DataContainer dax_ranged = quotes.Clone(startDate); //DataContainer short_ranged = dax_short.Quotes.Clone(startDate); dax_ma38 = dax_ma38.Clone(startDate); DataContainer fast = MovingAverage.CreateFrom(quotes, 38); DataContainer slow = MovingAverage.CreateFrom(quotes, 200); fast = fast.Clone(startDate); slow = slow.Clone(startDate); #region DAX chart.Clear(); chart.SubSectionsX = 3; chart.LogScaleY = true; chart.TicsYInterval = 200; chart.Title = dax_ranged.OldestDate.ToString() + " - " + dax_ranged.YoungestDate.ToString(); chart.LabelY = "Punkte (log.)"; chart.Add(dax_ranged, Chart.LineType.LightBlue, "DAX"); //chart.Add(short_ranged, Chart.LineType.SeaGreen, "DAX Short"); chart.Add(fast, Chart.LineType.Orange, "Moving Average (fast)"); chart.Add(slow, Chart.LineType.Purple, "Moving Average (slow)"); chart.Create(World.GetInstance().ResultPath + "dax.png"); #endregion #region DAX relative diff DataContainer dax_rel_diff_38 = RelativeDifference.CreateFrom(quotes, dax_ma38); dax_rel_diff_38 = dax_rel_diff_38.Clone(startDate); chart.Clear(); chart.LogScaleY = false; chart.TicsYInterval = 1; chart.Title = dax_ranged.OldestDate.ToString() + " - " + dax_ranged.YoungestDate.ToString(); chart.LabelY = "dB%"; chart.Add(dax_rel_diff_38, Chart.LineType.LightBlue, "DAX rel. diff. to MA38"); chart.Create(World.GetInstance().ResultPath + "dax_rel_diff_38.png"); #endregion #region DAX relative perf. /*DataContainer dax_diff_ma38 = Difference.CreateFrom(quotes, dax_ma38).Clone(startDate); * DataContainer dax_relperf = RelativePerformance.CreateFrom(quotes, startDate); * dax_relperf = dax_relperf.Clone(startDate); * * chart.Clear(); * chart.TicsYInterval = 100; * chart.Title = dax_diff_ma38.OldestDate.ToString() + " - " + dax_diff_ma38.YoungestDate.ToString(); * chart.LabelY = "Abstand zum Durchschnitt"; * chart.Add(dax_diff_ma38, 2, "DAX rel. ma38"); * chart.Create(World.GetInstance().ResultPath + "dax_relperf.png");*/ #endregion }