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


C# StockSerie.GetValues方法代码示例

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


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

示例1: ToSerie

        internal void ToSerie(StockSerie stockSerie, StockSerie referenceSerie = null)
        {
            float open = 0.0f;
             float high = 0.0f;
             float low = 0.0f;
             float close = 0.0f;
             int volume = 1;
             float cash = TotalDeposit;

             Dictionary<string, PositionValues> stockPositionDico = new Dictionary<string, PositionValues>();

             // Statistics
             int nbTrades = 0;
             int nbWinTrades = 0;
             float maxDrawdown = float.MaxValue;
             float maxGain = float.MinValue;
             float maxLoss = float.MinValue;

             if (referenceSerie == null)
             {
            referenceSerie = StockDictionary.StockDictionarySingleton["CAC40"];
             }
             referenceSerie.Initialise();

             foreach (DateTime date in referenceSerie.GetValues(StockSerie.StockBarDuration.Daily).Where(d => d.DATE.Year > 2014).Select(v => v.DATE.Date))
             {
            // Calculate open value

            // Retrieve orders for this date/time
            var orderList = this.OrderList.FindAll(order => order.ExecutionDate.Date == date).OrderBy(o => o.ID);

            // Manage new orders
            foreach (StockOrder stockOrder in orderList)
            {
               int numberOfShare = stockOrder.IsShortOrder ? -stockOrder.Number : stockOrder.Number;
               if (stockOrder.IsBuyOrder()) // Buy position
               {
                  cash -= stockOrder.TotalCost;
                  if (stockPositionDico.ContainsKey(stockOrder.StockName))
                  {
                     stockPositionDico[stockOrder.StockName].Position += numberOfShare;
                     stockPositionDico[stockOrder.StockName].OpenValue =
                        (stockPositionDico[stockOrder.StockName].Position *
                         stockPositionDico[stockOrder.StockName].OpenValue + numberOfShare * stockOrder.Value) /
                        (stockPositionDico[stockOrder.StockName].Position + numberOfShare);
                  }
                  else
                  {
                     if (stockDictionary.ContainsKey(stockOrder.StockName) &&
                         stockDictionary[stockOrder.StockName].Initialise())
                     {
                        stockPositionDico.Add(stockOrder.StockName,
                           new PositionValues(numberOfShare, stockOrder.Value,
                              stockDictionary[stockOrder.StockName].GetValues(StockSerie.StockBarDuration.Daily)));
                     }
                     else
                     {
                        StockLog.Write("Initialisation failed: " + stockOrder.StockName);
                        stockPositionDico.Add(stockOrder.StockName,
                           new PositionValues(numberOfShare, stockOrder.Value, null));
                     }
                  }
               }
               else // Closing Position
               {
                  if (stockPositionDico.ContainsKey(stockOrder.StockName))
                  {
                     cash += stockOrder.TotalCost;
                     PositionValues position = stockPositionDico[stockOrder.StockName];
                     if (position.Position == numberOfShare)
                     {
                        maxDrawdown = Math.Min(maxDrawdown, position.MaxDrawdown);
                        stockPositionDico.Remove(stockOrder.StockName);
                        nbTrades++;
                     }
                     else
                     {
                        position.Position -= numberOfShare;
                     }
                     if (stockOrder.IsShortOrder)
                     {
                        if (position.OpenValue > stockOrder.Value)
                        {
                           nbWinTrades++;
                           maxGain = Math.Max(maxGain, (position.OpenValue - stockOrder.Value) / position.OpenValue);
                        }
                        else
                        {
                           maxLoss = Math.Max(maxLoss, -(position.OpenValue - stockOrder.Value) / position.OpenValue);
                        }
                     }
                     else
                     {
                        if (position.OpenValue < stockOrder.Value)
                        {
                           nbWinTrades++;
                           maxGain = Math.Max(maxGain, -(position.OpenValue - stockOrder.Value) / position.OpenValue);
                        }
                        else
                        {
//.........这里部分代码省略.........
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:101,代码来源:StockPortofolio.cs

示例2: LoadIntradayDurationArchiveData

        public override bool LoadIntradayDurationArchiveData(string rootFolder, StockSerie serie, StockSerie.StockBarDuration duration)
        {
            StockLog.Write("LoadIntradayDurationArchiveData Name:" + serie.StockName + " duration:" + duration);
             string durationFileName = rootFolder + ARCHIVE_FOLDER + "\\" + duration + "\\" + serie.ShortName.Replace(':', '_') + "_" + serie.StockName + "_" + serie.StockGroup.ToString() + ".txt";
             if (File.Exists(durationFileName))
             {
            var values = serie.GetValues(duration);
            if (values == null)
               StockLog.Write("LoadIntradayDurationArchiveData Cache File Found, current size is: 0");
            else  StockLog.Write("LoadIntradayDurationArchiveData Cache File Found, current size is: " + values.Count);
            serie.ReadFromCSVFile(durationFileName, duration);

            StockLog.Write("LoadIntradayDurationArchiveData New serie size is: " + serie.GetValues(duration).Count);
            if (serie.GetValues(duration).Count > 0)
            {
               StockLog.Write("LoadIntradayDurationArchiveData First bar: " +
                              serie.GetValues(duration).First().ToString());
               StockLog.Write("LoadIntradayDurationArchiveData Last bar: " + serie.GetValues(duration).Last().ToString());
            }
            else
            {
               return false;
            }
             }
             else
             {
            return false;
             }
             return true;
        }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:30,代码来源:CommerzBankIntradayDataProvider.cs


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