當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。