当前位置: 首页>>代码示例>>C#>>正文


C# StockSerie.Add方法代码示例

本文整理汇总了C#中StockSerie.Add方法的典型用法代码示例。如果您正苦于以下问题:C# StockSerie.Add方法的具体用法?C# StockSerie.Add怎么用?C# StockSerie.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StockSerie的用法示例。


在下文中一共展示了StockSerie.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseHarpex

        private bool ParseHarpex(StockSerie stockSerie, string fileName)
        {
            // Read new downloaded values
             if (!File.Exists(fileName))
             {
            return false;
             }
             bool res = false;

             StockDailyValue harpexValue = null;
             DateTime date;
             float harpex = 0;
             string line = string.Empty;
             try
             {
            using (StreamReader sr = new StreamReader(fileName, true))
            {
               // File format
               // "date";"HARPEX";"Class 1";"Class 2";"Class 3";"Class 4";"Class 5";"Class 6";"Class 7";"Class 8"
               // 14/07/07;1296.25;1196.94;1163.11;1207.74;1180.47;1406.11;1404.5;1388.44;1475.32

               sr.ReadLine(); // Skip first line
               while (!sr.EndOfStream)
               {
                  line = sr.ReadLine();
                  string[] row = line.Split(';');
                  date = DateTime.Parse(row[0], StockAnalyzerApp.Global.EnglishCulture);
                  harpex = float.Parse(row[1], StockAnalyzerApp.Global.EnglishCulture);

                  harpexValue = new StockDailyValue(stockSerie.StockName,
                      harpex,
                      harpex,
                      harpex,
                      harpex, 0, date);
                  stockSerie.Add(harpexValue.DATE, harpexValue);
                  harpexValue.Serie = stockSerie;
               }
            }
            res = true;
             }
             catch (System.Exception e)
             {
            StockLog.Write("Failed to parse Harpex file " + e.Message + "\r\r" + line);
             }
             return res;
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:46,代码来源:HarpexDataProvider.cs

示例2: ParseIntradayData

        private static bool ParseIntradayData(StockSerie stockSerie, string fileName)
        {
            bool res = false;
             try
             {
            using (StreamReader sr = new StreamReader(fileName))
            {
               string line = sr.ReadLine();

               while (!(line = sr.ReadLine()).StartsWith("INTERVAL")) ;
               int interval;
               interval = int.Parse(line.Split('=')[1]);

               while (!(line = sr.ReadLine()).StartsWith("TIMEZONE_OFFSET")) ;
               int offset;
               offset = int.Parse(line.Split('=')[1]);

               string[] row;
               DateTime startDate = DateTime.Now;
               while (!sr.EndOfStream)
               {
                  line = sr.ReadLine();
                  DateTime openDate = DateTime.Now;
                  row = line.Split(new char[] { ',' });

                  if (line.StartsWith("a"))
                  {
                     // new day detected
                     string startString = row[0].Replace("a", "");
                     double seconds = double.Parse(startString);

                     startDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(seconds).AddMinutes(offset);
                     openDate = startDate;
                  }
                  else if (line.StartsWith("TIMEZONE_OFFSET"))
                  {
                     offset = int.Parse(line.Split('=')[1]);
                     continue;
                  }
                  else
                  {
                     // just a new bar
                     openDate = startDate.AddSeconds(long.Parse(row[0]) * interval);
                  }

                  if (!stockSerie.ContainsKey(openDate))
                  {
                     StockDailyValue dailyValue = new StockDailyValue(stockSerie.StockName,
                            float.Parse(row[4], usCulture),
                            float.Parse(row[2], usCulture),
                            float.Parse(row[3], usCulture),
                            float.Parse(row[1], usCulture),
                            long.Parse(row[5]),
                            openDate);
                     stockSerie.Add(dailyValue.DATE, dailyValue);
                  }
               }

               stockSerie.ClearBarDurationCache();

               res = true;
            }
             }
             catch (System.Exception e)
             {
            StockLog.Write("Unable to parse intraday data for " + stockSerie.StockName);
            StockLog.Write(e);
             }
             return res;
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:70,代码来源:GoogleIntradayDataProvider.cs

示例3: startButton_Click

        private void startButton_Click(object sender, EventArgs e)
        {
            if (started)
            {
                replaySerie = null;
                started = false;
                startButton.Text = "Start";
                startButton.Focus();
                nextButton.Enabled = false;
                moveButton.Enabled = false;

                this.Position.Number = 0;
                this.Position.OpenValue = 0;
                this.totalValue = 0;

                this.buyButton.Enabled = false;
                this.sellButton.Enabled = false;
                this.shortButton.Enabled = false;
                this.coverButton.Enabled = false;

                string msg = "Replay serie was:\t" + refSerie.StockName + Environment.NewLine +
                             "Start date:\t\t" + startDate.ToShortDateString() + Environment.NewLine +
                             "NbTrades:\t\t\t" + nbTrade + Environment.NewLine +
                             "NbWinTrades:\t\t" + nbWinTrade + Environment.NewLine +
                             "NbLostTrades:\t\t" + nbLostTrade + Environment.NewLine +
                             "AvgGain:\t\t\t" + (tradeGains.Sum() / nbTrade).ToString("P2");

                MessageBox.Show(msg);
            }
            else
            {
                Cursor cursor = this.Cursor;
                this.Cursor = Cursors.WaitCursor;

                try
                {
                    // Initialise stats
                    nbTrade = 0;
                    nbWinTrade = 0;
                    nbLostTrade = 0;
                    tradeGains.Clear();

                    // Create Portfolio
                    StockAnalyzerForm.MainFrame.CurrentPortofolio = portfolio;

                    portfolio.Clear();
                    replaySerie = new StockSerie("Replay", "Replay", StockSerie.Groups.ALL, StockDataProvider.Replay);

                    // Random pick

                    Random rand = new Random(DateTime.Now.Millisecond);
                    var series =
                       StockDictionary.StockDictionarySingleton.Values.Where(s => !s.IsPortofolioSerie && s.BelongsToGroup(StockSerie.Groups.COUNTRY))
                          .Select(s => s.StockName);

                    StockSerie serie = null;
                    do
                    {
                        string stockName = series.ElementAt(rand.Next(0, series.Count()));

                        serie = StockDictionary.StockDictionarySingleton[stockName];
                        serie.Initialise();
                        serie.BarDuration = StockSerie.StockBarDuration.Daily;
                    }
                    while (serie.Count < 400);

                    DateTime currentDate = DateTime.Today;
                    refSerie = new StockSerie(serie.StockName, serie.ShortName, serie.StockGroup, StockDataProvider.Replay);
                    foreach (StockDailyValue dailyVal in serie.Values)
                    {
                        StockDailyValue newValue = new StockDailyValue(serie.StockName, dailyVal.OPEN, dailyVal.HIGH, dailyVal.LOW, dailyVal.CLOSE, dailyVal.VOLUME, currentDate);
                        refSerie.Add(currentDate, newValue);
                        currentDate = currentDate.AddDays(1);
                    }

                    currentDate = DateTime.Today;
                    int nbInitBars = rand.Next(200, refSerie.Count - 200);

                    for (index = 0; index < nbInitBars; index++)
                    {
                        replaySerie.Add(currentDate, refSerie.ValueArray[index]);
                        currentDate = currentDate.AddDays(1);
                    }

                    dailyValue = serie.Values.Last();
                    startDate = dailyValue.DATE;

                    startButton.Text = "Stop";
                    nextButton.Enabled = true;
                    moveButton.Enabled = true;
                    nextButton.Focus();

                    OnPositionClosed();

                    this.Position.Number = 0;
                    this.Position.OpenValue = 0;
                    this.Position.CurrentValue = replaySerie.Values.Last().CLOSE;
                    this.totalValue = 0;

                    started = true;
//.........这里部分代码省略.........
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:101,代码来源:StockMarketReplay.cs

示例4: ParseIntradayData

        private static bool ParseIntradayData(StockSerie stockSerie, string fileName)
        {
            bool res = false;
             try
             {
            using (StreamReader sr = new StreamReader(fileName))
            {
               while (!sr.EndOfStream)
               {
                  string line = sr.ReadLine();
                  string[] row = line.Split(',');
                  if (row.Length <2) continue;

                  DateTime openDate;
                  if (!DateTime.TryParse(row[0], out openDate)) continue;
                  float value = float.Parse(row[1]);

                  if (!stockSerie.ContainsKey(openDate))
                  {
                     StockDailyValue dailyValue = new StockDailyValue(stockSerie.StockName,
                            value,
                            value,
                            value,
                            value,
                            0,
                            openDate);
                     stockSerie.Add(dailyValue.DATE, dailyValue);
                  }
               }

               stockSerie.ClearBarDurationCache();

               res = true;
            }
             }
             catch (System.Exception e)
             {
            StockLog.Write("Unable to parse intraday data for " + stockSerie.StockName);
            StockLog.Write(e);
             }
             return res;
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:42,代码来源:CommerzBankIntradayDataProvider.cs

示例5: ParseVIXPCRatioCSV

        // Private methods
        private bool ParseVIXPCRatioCSV(StockSerie stockSerie, string fileName)
        {
            if (File.Exists(fileName))
             {
            using (StreamReader sr = new StreamReader(fileName))
            {
               try
               {
                  StockDailyValue readValue = null;

                  // Skip 2 first lines
                  string name = "PCR.VIX";
                  sr.ReadLine();
                  sr.ReadLine();
                  while (sr.ReadLine().Contains("\"") && !sr.EndOfStream) ;

                  while (!sr.EndOfStream)
                  {
                     readValue = null;
                     string[] row = sr.ReadLine().Split(',');
                     if (row.GetLength(0) == 5)
                     {
                        readValue = new StockDailyValue(
                            name,
                            float.Parse(row[1], usCulture),
                            float.Parse(row[1], usCulture),
                            float.Parse(row[1], usCulture),
                            float.Parse(row[1], usCulture),
                            long.Parse(row[4], usCulture),
                            DateTime.Parse(row[0], usCulture));
                        stockSerie.Add(readValue.DATE, readValue);
                     }
                  }
               }
               catch (System.Exception e)
               {
                  StockLog.Write(e);
                  return false;
               }
            }
            return true;
             }
             else
             {
            return false;
             }
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:48,代码来源:CBOEDataProvider.cs

示例6: ParseCBOEIndexCSV

        private bool ParseCBOEIndexCSV(StockSerie stockSerie, string fileName)
        {
            if (File.Exists(fileName))
             {
            using (StreamReader sr = new StreamReader(fileName))
            {
               try
               {
                  StockDailyValue readValue = null;

                  sr.ReadLine();  // Skip the first line
                  sr.ReadLine();  // Skip the second line

                  while (!sr.EndOfStream)
                  {
                     // File format
                     // Date,Close
                     // 10-May-07,27.09
                     string[] row = sr.ReadLine().Split(',');
                     if (row.GetLength(0) == 2 && row[1] != "")
                     {
                        readValue = new StockDailyValue(
                            stockSerie.StockName,
                            float.Parse(row[1], usCulture),
                            float.Parse(row[1], usCulture),
                            float.Parse(row[1], usCulture),
                            float.Parse(row[1], usCulture),
                            100,
                            DateTime.Parse(row[0], usCulture));

                        if (readValue != null)
                        {
                           stockSerie.Add(readValue.DATE, readValue);
                        }
                     }
                  }
               }
               catch (System.Exception e)
               {
                  StockLog.Write(e);
                  return false;
               }
            }
            return true;
             }
             else
             {
            return false;
             }
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:50,代码来源:CBOEDataProvider.cs

示例7: ParseIntradayData

        private static bool ParseIntradayData(StockSerie stockSerie, string fileName)
        {
            bool res = false;
             try
             {
            using (StreamReader sr = new StreamReader(fileName))
            {
               string line;

               while ((line = sr.ReadLine()) != null)
               {
                  if (line.StartsWith("timezone")) break;
               }
               if (sr.EndOfStream) return false;
               string[] row = line.Split(new char[] { ':' });
               string timeZone = row[1];
               double gmtoffset = timeZone == "CEST" ? -32400 : 0;

               while ((line = sr.ReadLine()) != null)
               {
                  if (line.StartsWith("gmtoffset")) break;
               }
               if (sr.EndOfStream) return false;

               row = line.Split(new char[] { ':' });
               gmtoffset += double.Parse(row[1]);

               DateTime now = DateTime.Now;
               DateTime utcNow = now.ToUniversalTime();
               gmtoffset -= (now - utcNow).TotalSeconds;

               while (!(line = sr.ReadLine()).StartsWith("range")) ;

               // First Range, read second offest for date calculation.
               row = line.Split(new char[] { ',', ':' });
               DateTime startDate = new DateTime(int.Parse(row[1].Substring(0, 4)), int.Parse(row[1].Substring(4, 2)), int.Parse(row[1].Substring(6, 2)));

               //  startDate = startDate.AddHours(9);
               long startTimeStamp = long.Parse(row[2]);

               while (!(line = sr.ReadLine()).StartsWith("volume")) ;

               while (!sr.EndOfStream)
               {
                  line = sr.ReadLine();

                  row = line.Split(new char[] { ',' });

                  DateTime openDate = startDate;
                  openDate = startDate.AddSeconds(long.Parse(row[0]) - startTimeStamp);
                  openDate = startDate.AddSeconds(long.Parse(row[0]) - startTimeStamp - gmtoffset);
                  if (!stockSerie.ContainsKey(openDate))
                  {
                     StockDailyValue dailyValue = new StockDailyValue(stockSerie.StockName,
                            float.Parse(row[4], usCulture),
                            float.Parse(row[2], usCulture),
                            float.Parse(row[3], usCulture),
                            float.Parse(row[1], usCulture),
                            long.Parse(row[5]),
                            openDate);
                     stockSerie.Add(dailyValue.DATE, dailyValue);
                  }
               }

               stockSerie.ClearBarDurationCache();

               res = true;
            }
             }
             catch (System.Exception e)
             {
            StockLog.Write("Unable to parse intraday data for " + stockSerie.StockName);
            StockLog.Write(e);
             }
             return res;
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:76,代码来源:YahooIntradayDataProvider.cs

示例8: GenerateCAC_Random

        private void GenerateCAC_Random()
        {
            List<StockSerie> cacSeries =
               this.StockDictionary.Values.Where(s => s.BelongsToGroup(StockSerie.Groups.CAC40) && s.Initialise()).ToList();
            StockSerie cacEWSerie = new StockSerie("CAC_RANDOM", "CAC_RANDOM", StockSerie.Groups.INDICES_CALC,
               StockDataProvider.Generated);
            StockSerie cacSerie = this.StockDictionary["CAC40"];
            cacSerie.Initialise();
            StockSerie BX4Serie = this.StockDictionary["BX4"];
            BX4Serie.Initialise();
            cacSeries.Add(BX4Serie);

            Random rnd = new Random();

            float value = 1000f;
            int previousCount = 0;
            foreach (DateTime date in cacSerie.Keys)
            {
                float var = 0.0f;
                int count = 0;
                int nbActive = 0;
                foreach (StockSerie serie in cacSeries)
                {
                    if (serie.ContainsKey(date))
                    {
                        count++;
                        if (rnd.Next(0, 11) > 5)
                        {
                            StockDailyValue dailyValue = serie[date];
                            var += dailyValue.VARIATION;
                            nbActive++;
                        }
                    }
                }
                //if (count < 5 && previousCount >= count && BX4Serie.ContainsKey(date))
                //{
                //   count++;
                //   StockDailyValue dailyValue = BX4Serie[date];
                //   var += dailyValue.VARIATION;
                //}
                if (count != 0) value += value * (var / count);
                cacEWSerie.Add(date, new StockDailyValue("CAC_RANDOM", value, value, value, value, (long)nbActive, date));

                previousCount = count;
            }
            StockDictionary.Add("CAC_RANDOM", cacEWSerie);
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:47,代码来源:MainFrame.cs

示例9: GenerateCAC_SAR

        private void GenerateCAC_SAR(bool stopOnLowBreadth, float speed)
        {
            string serieName = "CAC_SAR_" + speed.ToString("#.######");
            List<StockSerie> cacSeries =
               this.StockDictionary.Values.Where(s => s.BelongsToGroup(StockSerie.Groups.CAC40) && s.Initialise()).ToList();
            StockSerie newIndexSerie = new StockSerie(serieName, serieName, StockSerie.Groups.INDICES_CALC,
               StockDataProvider.Generated);
            StockSerie cacSerie = this.StockDictionary["CAC40"];
            cacSerie.Initialise();
            //StockSerie BX4Serie = this.StockDictionary["BX4"];
            //BX4Serie.Initialise();
            //cacSeries.Add(BX4Serie);

            float value = 1000f;
            int previousCount = 0;
            int previousNbActive = 0;
            foreach (DateTime date in cacSerie.Keys)
            {
                float var = 0.0f;
                int count = 0;
                int nbActive = 0;
                foreach (StockSerie serie in cacSeries)
                {
                    if (serie.ContainsKey(date))
                    {
                        IStockIndicator indicator = serie.GetIndicator("SAR(0," + speed + ",0.2)");

                        count++;

                        int index = serie.IndexOf(date) - 1;
                        if (index >= 0 && indicator.Events[8][index])
                        {
                            StockDailyValue dailyValue = serie[date];
                            var += dailyValue.VARIATION;
                            nbActive++;
                        }
                    }
                }
                //if (count < 5 && previousCount >= count && BX4Serie.ContainsKey(date))
                //{
                //   count++;
                //   StockDailyValue dailyValue = BX4Serie[date];
                //   var += dailyValue.VARIATION;
                //}
                if (stopOnLowBreadth && previousNbActive < count / 2)
                {
                    newIndexSerie.Add(date, new StockDailyValue(serieName, value, value, value, value, (long)0, date));
                }
                else
                {
                    if (count != 0) value += value * (var / count);
                    newIndexSerie.Add(date, new StockDailyValue(serieName, value, value, value, value, (long)nbActive, date));
                }
                previousNbActive = nbActive;
                previousCount = count;
            }
            StockDictionary.Add(serieName, newIndexSerie);
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:58,代码来源:MainFrame.cs

示例10: GenerateCACEqualWeightNoUpDay

        private void GenerateCACEqualWeightNoUpDay(DayOfWeek dayOfWeek)
        {
            //var cacSeries =
            //   this.StockDictionary.Values.Where(s => s.BelongsToGroup(StockSerie.Groups.CAC40) && s.Initialise());
            string serieName = "CAC_EW_NO_UP_" + dayOfWeek;

            StockSplashScreen.ProgressText = "Generating " + serieName + "...";

            StockSerie cacEWSerie = new StockSerie(serieName, serieName, StockSerie.Groups.INDICES_CALC,
               StockDataProvider.Generated);
            StockSerie cacSerie = this.StockDictionary["CAC40"];
            cacSerie.Initialise();

            float value = cacSerie.First().Value.OPEN;
            int cacIndex = 0;
            StockDailyValue previousDailyValue = cacSerie.Values.First();

            foreach (StockDailyValue dailyValue in cacSerie.Values)
            {
                float volume = 0.0f;
                if (previousDailyValue.DATE.DayOfWeek == dayOfWeek && previousDailyValue.VARIATION < 0)
                {
                    value += value * dailyValue.VARIATION;
                }
                cacEWSerie.Add(dailyValue.DATE, new StockDailyValue(serieName, value, value, value, value, (long)volume, dailyValue.DATE));
                cacIndex++;
                previousDailyValue = dailyValue;
            }
            StockDictionary.Add(serieName, cacEWSerie);
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:30,代码来源:MainFrame.cs

示例11: GenerateCAC_Event

        private void GenerateCAC_Event(string indexName, StockSerie.StockBarDuration barDuration, int period1, int period2,
           string eventPattern, string eventName, bool stopOnLowBreadth)
        {
            var cacSeries =
               this.StockDictionary.Values.Where(s => s.BelongsToGroup(StockSerie.Groups.CAC40) && s.Initialise()).ToList();
            string serieName = indexName + period1 + "_" + period2 + "_" + barDuration;
            string ieventName = eventPattern.Replace("%PERIOD1%", period1.ToString());
            ieventName = ieventName.Replace("%PERIOD2%", period2.ToString());
            int eventIndex =
               ((IStockEvent)StockViewableItemsManager.GetViewableItem(ieventName)).EventNames.ToList().IndexOf(eventName);

            StockSerie cacEWSerie = new StockSerie(serieName, serieName, StockSerie.Groups.INDICES_CALC,
               StockDataProvider.Generated);
            StockSerie cacSerie = this.StockDictionary["CAC40"];
            cacSerie.Initialise();
            //StockSerie BX4Serie = this.StockDictionary["BX4"];
            //BX4Serie.Initialise();
            //cacSeries.Add(BX4Serie);

            foreach (StockSerie serie in cacSeries)
            {
                if (serie.BarDuration != barDuration) serie.BarDuration = barDuration;
            }
            float value = 1000f;
            int previousCount = 0;
            int previousNbActive = 0;
            foreach (DateTime date in cacSerie.Keys.Where(d => d.Year > 2005))
            {
                float var = 0.0f;
                int count = 0;
                int nbActive = 0;
                foreach (StockSerie serie in cacSeries)
                {
                    if (serie.ContainsKey(date) && serie.Count > 200)
                    {
                        count++;
                        IStockEvent events = (IStockEvent)serie.GetViewableItem(ieventName);
                        int index = serie.IndexOf(date) - 1;
                        if (index >= 0 && events.Events[eventIndex][index])
                        {
                            StockDailyValue dailyValue = serie.GetValues(StockSerie.StockBarDuration.Daily)
                               .ElementAt(index + 1);
                            var += dailyValue.VARIATION;
                            nbActive++;
                        }
                    }
                }
                if (stopOnLowBreadth && previousNbActive < count / 2)
                {
                    cacEWSerie.Add(date, new StockDailyValue(serieName, value, value, value, value, (long)0, date));
                }
                else
                {
                    if (count != 0) value += value * (var / count);
                    cacEWSerie.Add(date, new StockDailyValue(serieName, value, value, value, value, (long)nbActive, date));
                }
                previousNbActive = nbActive;
                previousCount = count;
            }
            foreach (StockSerie serie in cacSeries)
            {
                if (serie.BarDuration != StockSerie.StockBarDuration.Daily) serie.BarDuration = StockSerie.StockBarDuration.Daily;
            }
            StockDictionary.Add(serieName, cacEWSerie);
            StockLog.Write(serieName + ";" + period1 + ";" + period2 + ";" + cacEWSerie.Values.Last().CLOSE);
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:66,代码来源:MainFrame.cs

示例12: GenerateCACEqualWeight2

        private void GenerateCACEqualWeight2()
        {
            var cacSeries =
               this.StockDictionary.Values.Where(s => s.BelongsToGroup(StockSerie.Groups.CAC40) && s.Initialise());
            string serieName = "CAC_EW2";
            StockSerie cacEWSerie = new StockSerie(serieName, serieName, StockSerie.Groups.INDICES,
               StockDataProvider.Generated);
            StockSerie cacSerie = this.StockDictionary["CAC40"];
            cacSerie.Initialise();

            IStockEvent CACIndicator = cacSerie.GetTrailStop("TRAILHLS(19,3)") as IStockEvent;

            float value = 1000f;
            int cacIndex = -1;
            foreach (DateTime date in cacSerie.Keys)
            {
                float var = 0.0f;
                float volume = 0.0f;
                int count = 0;
                if (cacIndex >= 0 && CACIndicator.Events[0][cacIndex])
                {
                    foreach (StockSerie serie in cacSeries)
                    {
                        if (serie.ContainsKey(date))
                        {
                            count++;
                            StockDailyValue dailyValue = serie[date];
                            var += dailyValue.VARIATION;
                            volume += dailyValue.CLOSE * dailyValue.VOLUME;
                        }
                    }
                    value += value * (var / count);
                }
                cacEWSerie.Add(date, new StockDailyValue(serieName, value, value, value, value, (long)volume, date));
                cacIndex++;
            }
            StockDictionary.Add(serieName, cacEWSerie);
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:38,代码来源:MainFrame.cs

示例13: GenerateCACEqualWeight

        private void GenerateCACEqualWeight()
        {
            var cacSeries =
               this.StockDictionary.Values.Where(s => s.BelongsToGroup(StockSerie.Groups.CAC40) && s.Initialise());
            string serieName = "CAC_EW";
            StockSerie cacEWSerie = new StockSerie(serieName, serieName, StockSerie.Groups.INDICES_CALC,
               StockDataProvider.Generated);
            StockSerie cacSerie = this.StockDictionary["CAC40"];
            cacSerie.Initialise();

            float value = 1000f;
            int cacIndex = 0;
            foreach (DateTime date in cacSerie.Keys)
            {
                float var = 0.0f;
                float volume = 0.0f;
                int count = 0;
                foreach (StockSerie serie in cacSeries)
                {
                    if (serie.ContainsKey(date))
                    {
                        count++;
                        StockDailyValue dailyValue = serie[date];
                        var += dailyValue.VARIATION;
                        volume += dailyValue.CLOSE * dailyValue.VOLUME;
                    }
                }
                value += value * (var / count);
                cacEWSerie.Add(date, new StockDailyValue(serieName, value, value, value, value, (long)volume, date));
                cacIndex++;
            }
            StockDictionary.Add(serieName, cacEWSerie);
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:33,代码来源:MainFrame.cs

示例14: GenerateCAC2_Event

        private void GenerateCAC2_Event(string indexName, StockSerie.StockBarDuration barDuration, int period, string eventPattern, string eventName, bool stopOnLowBreadth)
        {
            var cacSeries = this.StockDictionary.Values.Where(s => s.BelongsToGroup(StockSerie.Groups.CAC40) && s.Initialise()).ToList();
            int seriesCount = cacSeries.Count;
            string serieName = indexName + "2_" + period + "_" + barDuration;
            string ieventName = eventPattern.Replace("%PERIOD%", period.ToString());
            int eventIndex =
               ((IStockEvent)StockViewableItemsManager.GetViewableItem(ieventName)).EventNames.ToList().IndexOf(eventName);

            foreach (StockSerie serie in cacSeries)
            {
                serie.BarDuration = barDuration;
            }
            StockSerie cacEWSerie = new StockSerie(serieName, serieName, StockSerie.Groups.INDICES_CALC,
               StockDataProvider.Generated);
            StockSerie cacSerie = this.StockDictionary["CAC40"];
            cacSerie.Initialise();

            float cash = cacSeries.Count * 1000;
            float value = cash;

            List<Position> openedPositions = new List<Position>();
            List<Position> closedPositions = new List<Position>();
            foreach (DateTime date in cacSerie.Keys.Where(d => d.Year > 1991))
            {
                // Try to sell
                foreach (Position pos in openedPositions)
                {
                    StockSerie serie = cacSeries.First(s => s.StockName == pos.Name);
                    int index = serie.IndexOf(date) - 1;
                    if (index > 0)
                    {
                        IStockEvent events = (IStockEvent)serie.GetViewableItem(ieventName);
                        if (!events.Events[eventIndex][index])
                        {
                            StockDailyValue dailyValue = serie.GetValues(StockSerie.StockBarDuration.Daily).ElementAt(index + 1);
                            cash += pos.EndPosition(dailyValue.OPEN);

                            closedPositions.Add(pos);
                        }
                    }
                }

                // Try to buy
                int openPositionCount = openedPositions.Count(p => p.IsOpened);
                float invested = 0.0f;
                foreach (StockSerie serie in cacSeries.Where(s => !openedPositions.Any(p => p.Name == s.StockName)))
                {
                    int index = serie.IndexOf(date) - 1;
                    if (index > 0)
                    {
                        IStockEvent events = (IStockEvent)serie.GetViewableItem(ieventName);
                        if (events.Events[eventIndex][index])
                        {
                            StockDailyValue dailyValue = serie.GetValues(StockSerie.StockBarDuration.Daily).ElementAt(index + 1);
                            int qty = (int)(cash / ((seriesCount - openPositionCount) * dailyValue.OPEN));

                            openedPositions.Add(new Position(serie.StockName, dailyValue.OPEN, qty));

                            invested += qty * dailyValue.OPEN;
                        }
                    }
                }
                cash -= invested;

                // Clean opened positions
                openedPositions.RemoveAll(p => !p.IsOpened);

                int count = openedPositions.Count;

                value = cash;
                foreach (Position pos in openedPositions)
                {
                    StockSerie serie = cacSeries.First(s => s.StockName == pos.Name);
                    DateTime posDate = date;
                    StockDailyValue dailyValue = null;
                    do
                    {
                        dailyValue = serie.GetValues(StockSerie.StockBarDuration.Daily).FirstOrDefault(v => v.DATE == posDate);
                        posDate = posDate.AddDays(-1);
                    } while (dailyValue == null);

                    value += pos.Number * dailyValue.CLOSE;
                }

                value = value / (float)cacSeries.Count;

                cacEWSerie.Add(date, new StockDailyValue(serieName, value, value, value, value, (long)count, date));
            }
            foreach (StockSerie serie in cacSeries)
            {
                serie.BarDuration = StockSerie.StockBarDuration.Daily;
            }
            StockDictionary.Add(serieName, cacEWSerie);

            StockLog.Write(serieName + ";" + period + ";" + cacEWSerie.Values.Last().CLOSE);
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:97,代码来源:MainFrame.cs

示例15: GenerateSumSerie

        private bool GenerateSumSerie(StockSerie stockSerie, StockSerie trinSerie, bool inverse)
        {
            StockDailyValue logValue = null;
             float sum = 0f;
             foreach (StockDailyValue dailyValue in trinSerie.Values)
             {
            sum += dailyValue.CLOSE;

            logValue = new StockDailyValue(stockSerie.StockName,
               sum,
               sum,
               sum,
               sum, 0, dailyValue.DATE);
            stockSerie.Add(logValue.DATE, logValue);
            logValue.Serie = stockSerie;
             }
             return true;
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:18,代码来源:BarChartDataProvider.cs


注:本文中的StockSerie.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。