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


C# Bar.IsSessionOpenBar方法代码示例

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


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

示例1: ReloadDailyData

        /*
        protected void ReloadDailyData()
        {
            DateTime start = DateTime.Now;
            DailyBarSeries = GetHistoricalBars("IB", Instrument, DateTime.Now.AddDays(-60), DateTime.Now, PeriodConstants.PERIOD_DAILY);
            DateTime end = DateTime.Now;

            LoggingUtility.WriteDebug(LoggingConfig, string.Format("Took {0}ms to retrieve data from IB for daily data", end.Subtract(start).TotalMilliseconds));

            start = DateTime.Now;
            foreach (Bar currentBar in DailyBarSeries)
            {
                Bars.Add(currentBar);
                if (PersistHistoricalData)
                    DataManager.Add(Instrument, currentBar);
            }
            end = DateTime.Now;

            LoggingUtility.WriteVerbose(LoggingConfig, string.Format("Took {0}ms to load data into memory for daily data", end.Subtract(start).TotalMilliseconds));
        }*/
        protected Bar GetPreviousBar(Bar bar, int period)
        {
            Bar retVal = null;
            BarSeries barsToUse = null;

            bool isSessionOpenBar = bar.IsSessionOpenBar(Instrument.Type);
            bool isDailyPeriod = period == PeriodConstants.PERIOD_DAILY;

            if (isDailyPeriod)
                return GetPreviousDayBar();

            barsToUse = MinutelyBarSeries;

            if (barsToUse.Count > 0)
            {
                int idx = 0;
                bool found = false;

                while (!found && idx <= barsToUse.Count - 1)
                {
                    Bar prevBar = barsToUse.Ago(idx);
                    if ((prevBar.EndTime <= bar.BeginTime) && prevBar.IsWithinRegularTradingHours(Instrument.Type))
                    {
                        if (isSessionOpenBar || isDailyPeriod)
                        {
                            found = DateTime.Today.Subtract(prevBar.BeginTime.Date).TotalDays >= 1;
                            if (!found && DateTime.Now.IsPastRegularTradingHours(Instrument.Type))
                                found = DateTime.Today.Subtract(prevBar.BeginTime.Date).TotalDays >= 0;
                        }
                        else
                        {
                            found = true;
                        }
                    }

                    if (found)
                        retVal = prevBar;
                    else
                        idx++;
                }
            }

            if (retVal == null)
                throw new ApplicationException(string.Format("Count not retreive a period {0} bar to {1}. If it is due to exchange holidays - then set the 'DaysToGoBackForMinutelyData' parameter to fetch more data.", period, bar));

            LoggingUtility.WriteInfo(LoggingConfig, string.Format("Previous closing bar was {0}", retVal));

            return retVal;
        }
开发者ID:aggarwalmanuj,项目名称:open-quant,代码行数:69,代码来源:BaseStrategy.DataHandling.cs

示例2: GetPreviousBar

        /// <summary>
        /// 
        /// </summary>
        /// <param name="bar"></param>
        /// <returns></returns>
        protected Bar GetPreviousBar(Instrument instrument, Bar bar, int period)
        {
            Bar retVal = null;
            BarSeries barsToUse = null;
            string instId = instrument.ToIdentifier();
            Dictionary<string, BarSeries> dictionaryToUse = null;

            bool isSessionOpenBar = bar.IsSessionOpenBar(Instrument.Type);
            bool isDailyPeriod = period == PeriodConstants.PERIOD_DAILY;

            if (isDailyPeriod) // || isSessionOpenBar
                dictionaryToUse = dailyBarSeriesDictionary;
            else
                dictionaryToUse = minutelyBarSeriesDictionary;

            barsToUse = dictionaryToUse[instId];

            if (barsToUse.Count > 0)
            {
                int idx = 0;
                bool found = false;

                while (!found && idx <= barsToUse.Count - 1)
                {
                    Bar prevBar = barsToUse.Ago(idx);
                    if ((prevBar.EndTime <= bar.BeginTime) && prevBar.IsWithinRegularTradingHours(Instrument.Type))
                    {
                        if (isSessionOpenBar || isDailyPeriod)
                        {
                            found = DateTime.Today.Subtract(prevBar.BeginTime.Date).TotalDays >= 1;
                            if (!found && DateTime.Now.IsPastRegularTradingHours(Instrument.Type))
                                found = DateTime.Today.Subtract(prevBar.BeginTime.Date).TotalDays >= 0;
                        }
                        else
                        {
                            found = true;
                        }
                    }

                    if (found)
                        retVal = prevBar;
                    else
                        idx++;
                }
            }

            if (retVal == null)
                throw new ApplicationException(string.Format("Count not retreive a period {0} bar to {1}", period, bar));

            LoggingUtility.WriteDebug(LoggingConfig, string.Format("Previous closing bar was {0}", retVal));

            return retVal;
        }
开发者ID:aggarwalmanuj,项目名称:open-quant,代码行数:58,代码来源:BaseStrategy.cs


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