/// <summary>
        /// Updates the stock quotes to the most actual date.
        /// </summary>
        /// <param name="strStockFilename">The stock's path and filename to update</param>
        public void Update(string strStockFilename)
        {
            int    nImported = 0;
            string strWKN    = Path.GetFileNameWithoutExtension(strStockFilename);

            Stock stock = dbengine.GetStock(strWKN);

            System.Console.WriteLine("Updating {0}", strWKN);

            nImported = Load(stock);

            System.Console.WriteLine("{0} quotes imported.", nImported);
            System.Console.WriteLine("{0} close gaps filled.", stock.QuotesClose.FillGaps());
            System.Console.WriteLine("{0} low gaps filled.", stock.QuotesLow.FillGaps());

            if (nImported > 0)
            {
                stock.Save();
            }
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            World.GetInstance().SetWorldPaths("Test");

            DBEngine dbengine = DBEngine.GetInstance();

            if (dbengine.Exists("846900") == false)
            {
                return;
            }

            Stock         dax    = dbengine.GetStock("846900");
            DataContainer quotes = dax.QuotesLow;

            Chart chart = new Chart();

            chart.Add(quotes, Chart.LineType.Red, "Test");
            chart.Create(World.GetInstance().ResultPath + "dax.png");

            DataContainer dax_relperf = RelativePerformance.CreateFrom(quotes, new WorkDate(2008, 4, 21));

            dax_relperf.Save(World.GetInstance().ResultPath + "dax_relperf.csv", ";");
        }
        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
        }