Ejemplo n.º 1
0
        public static int CreateOrSaveInstrumentConversion(InstrumentConversionDetails convData)
        {
            using (IDalSession session = NHSessionFactory.CreateSession())
            {
                ITradeableInstrument instrument = (ITradeableInstrument)InstrumentMapper.GetTradeableInstrument(session, convData.InstrumentID);
                ITradeableInstrument newInstrument = (ITradeableInstrument)InstrumentMapper.GetTradeableInstrument(session, convData.NewInstrumentID);
                IInstrumentsHistoryConversion conversion = null;
                if (convData.Key == 0)
                    conversion = new InstrumentsHistoryConversion(instrument, newInstrument,
                        convData.ChangeDate, convData.OldChildRatio,
                        convData.NewParentRatio, convData.IsSpinOff);
                else
                    conversion = InstrumentHistoryMapper.GetInstrumentConversion(session, convData.Key);

                conversion.ChangeDate = convData.ChangeDate;
                conversion.ExecutionDate = convData.ExecutionDate;
                conversion.IsSpinOff = convData.IsSpinOff;
                conversion.NewParentRatio = convData.NewParentRatio;
                conversion.OldChildRatio = convData.OldChildRatio;

                instrument.ParentInstrument = newInstrument;

                session.BeginTransaction();
                session.Update(instrument);
                session.InsertOrUpdate(conversion);
                session.CommitTransaction();

                return conversion.Key;
            }
        }
Ejemplo n.º 2
0
        protected bool transform(SecurityInstrument newInstrument, DateTime changeDate, decimal oldChildRatio, byte newParentRatio, bool isSpinOff,
                string instrumentName, string isin, DateTime issueDate)
        {
            if (ParentInstrument != null)
                throw new ApplicationException(string.Format("This instrument already has been transformed to {0} (key {1})", ParentInstrument.Name, ParentInstrument.Key.ToString()));

            newInstrument.AllowNetting = this.AllowNetting;
            newInstrument.CompanyName = this.CompanyName;
            newInstrument.IsGreenFund = this.IsGreenFund;
            newInstrument.IsCultureFund = this.IsCultureFund;
            newInstrument.CreationDate = DateTime.Now;
            newInstrument.CurrencyNominal = this.CurrencyNominal;
            newInstrument.DecimalPlaces = this.DecimalPlaces;
            newInstrument.DefaultExchange = this.DefaultExchange;
            newInstrument.DefaultRoute = this.DefaultRoute;
            newInstrument.HomeExchange = this.HomeExchange;
            newInstrument.IsActive = true;
            newInstrument.Isin = isin;
            newInstrument.IssueDate = issueDate;
            newInstrument.LastUpdated = DateTime.Now;
            newInstrument.Name = instrumentName;
            newInstrument.PriceType = this.PriceType;
            newInstrument.SecCategory = this.SecCategory;
            newInstrument.IsGreenFund = this.IsGreenFund;
            newInstrument.IsCultureFund = this.IsCultureFund;
            this.ParentInstrument = newInstrument;
            this.InActiveDate = changeDate;
            InstrumentHistory history = new InstrumentsHistoryConversion(this, newInstrument, changeDate, oldChildRatio, newParentRatio, isSpinOff);
            this.HistoricalTransformations.Add(history);
            return newInstrument.Validate();
        }