コード例 #1
0
        virtual protected Future FindFuture(Feed feed, TradeInfo info, IList<Contract> contracts, string ticker, out Contract contract)
        {
            contract = null;
            try
            {
                //First Find Contract;  
                var words = ticker.Split(' ');
                string symbol = ticker;
                if (words.Length == 2)
                    symbol = words[0];
                else if (words.Length == 3)
                    symbol = words[0] + " " + words[1];
                foreach (var c in contracts)
                {
                    if (ticker.StartsWith(c.TickerSymbol) && ticker.EndsWith(c.TickerSuffix))
                    {
                        contract = c;
                        break;
                    }
                }

                if (contract == null) return null;
                var fromDate = info.ReportDate.AddYears(1) > info.Maturity ? info.ReportDate : info.Maturity.AddMonths(-1);
                var exps = GetExpirations(feed, contract, fromDate);
                if (exps == null || exps.Count == 0) return null;
                foreach (var exp in exps)
                {
                    if (contract.GetFutureCode(exp).EndsWith(symbol)) 
                        return contract.CreateFuture(exp);
                }
                
                return null;
            }
            catch (Exception x)
            {
                Logger.Error("FindFuture " + ticker, x);
                return null;
            }
            
        }