public Key(String tickerA, String tickerB, CorrelationPeriodType periodType)
            {
                if (String.IsNullOrWhiteSpace(tickerA))
                {
                    throw new ArgumentException("tickerA");
                }

                if (String.IsNullOrWhiteSpace(tickerB))
                {
                    throw new ArgumentException("tickerB");
                }

                if (tickerA.Equals(tickerB, StringComparison.CurrentCultureIgnoreCase))
                {
                    throw new ArgumentException("tickers are equal");
                }

                toString = "[" + periodType.ToString() + "] [" + tickerA + "] [" + tickerB + "]";

                hashCode = ("[" + periodType.ToString() + "]").GetHashCode() ^ ("[" + tickerA + "]").GetHashCode() ^ ("[" + tickerB + "]").GetHashCode();

                this.tickerB = tickerB;

                this.tickerA = tickerA;

                this.periodType = periodType;
            }
コード例 #2
0
        public ElementCorrelation UpdateElementCorrelation(String tickerA, String tickerB, CorrelationPeriodType correlationPeriodType, Decimal value)
        {
            Byte correlationPeriodTypeValue = (Byte)correlationPeriodType;

            using (FinanceDBEntities context = new FinanceDBEntities())
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    ElementCorrelation item = FirstElementOrNull <ElementCorrelation>((from er in context.ElementCorrelation
                                                                                       where
                                                                                       er.PeriodType == correlationPeriodTypeValue &&
                                                                                       (er.TickerA == tickerA && er.TickerB == tickerB ||
                                                                                        er.TickerA == tickerB && er.TickerB == tickerA)
                                                                                       select er).ToArray <ElementCorrelation>());

                    if (null != item)
                    {
                        item.Upd         = DateTime.Now;
                        item.Correlation = value;

                        LoggerFactory.AppLogger.Debug("[ItemsDataProvider.UpdateElementCorrelation] Updating existing item " + item.TickerA + " " + item.TickerB + " " + correlationPeriodType.ToString());
                    }
                    else
                    {
                        item             = context.ElementCorrelation.CreateObject();
                        item.TickerB     = tickerB;
                        item.TickerA     = tickerA;
                        item.PeriodType  = correlationPeriodTypeValue;
                        item.Upd         = DateTime.Now;
                        item.Correlation = value;

                        LoggerFactory.AppLogger.Debug("[ItemsDataProvider.UpdateElementCorrelation] Adding new item " + item.TickerA + " " + item.TickerB + " " + correlationPeriodType.ToString());

                        context.ElementCorrelation.AddObject(item);
                    }

                    context.SaveChanges();

                    transaction.Complete();

                    return(item);
                }
            }
        }
コード例 #3
0
 public ElementCorrelation[] SelectCorrelationResults(ElementTypeDefs typeA, ElementTypeDefs typeB, CorrelationPeriodType periodType)
 {
     using (FinanceDBEntities context = new FinanceDBEntities())
     {
         return(context.SelectCorrelationResults((Int16)typeA, (Int16)typeB, (Byte)periodType).ToArray <ElementCorrelation>());
     }
 }