예제 #1
0
        public InstrumentConversion(IAccountTypeInternal acctA, IAccount acctB,
                InstrumentSize valueSize, InstrumentSize convertedInstrumentSize, Money additionalCash,
                decimal exRate, IInstrumentHistory instrumentTransformation,
                ITradingJournalEntry tradingJournalEntry, IGLLookupRecords lookups)
            : base(acctA, acctB, valueSize, valueSize.GetPrice(0M), exRate,
                instrumentTransformation.ChangeDate, instrumentTransformation.ChangeDate, 0M,
                (valueSize.Sign ? Side.XI : Side.XO), tradingJournalEntry, lookups, null)
        {
            if (instrumentTransformation == null)
                throw new ApplicationException("Corporate action information is missing");

            if (!(valueSize != null && valueSize.IsNotZero && convertedInstrumentSize != null && convertedInstrumentSize.IsNotZero))
                throw new ApplicationException("Not all instrument information for this corporate action is available, both instruments have to be supplied");

            if (valueSize.Underlying.Equals(convertedInstrumentSize.Underlying))
                throw new ApplicationException("Both instruments can not be the same in a corporate action");

            if (valueSize.Sign.Equals(convertedInstrumentSize.Sign))
                throw new ApplicationException("Both instruments can not have the same side in a corporate action");

            IInstrumentsHistoryConversion conversion = (IInstrumentsHistoryConversion)instrumentTransformation;
            if (!(conversion.Instrument.Equals(valueSize.Underlying) && conversion.NewInstrument.Equals(convertedInstrumentSize.Underlying)))
                throw new ApplicationException("Corporate action does not equal the instrument history data");

            decimal diff = (convertedInstrumentSize.Abs().Quantity / valueSize.Abs().Quantity) - conversion.ConversionRate;
            if (diff != 0)
                throw new ApplicationException("Sizes do not correspond with conversion rate of the Corporate action");

            if (additionalCash != null && additionalCash.IsNotZero)
            {
                ListOfTransactionComponents[] components = new ListOfTransactionComponents[1];
                components[0] = new ListOfTransactionComponents() { ComponentType = BookingComponentTypes.Conversion, ComponentValue = additionalCash };
                createComponents(lookups, components);

            }

            this.CorporateActionType = CorporateActionTypes.Conversion;

            ConvertedInstrumentSize = convertedInstrumentSize;
            CorporateActionType = instrumentTransformation.CorporateActionType;
            InstrumentTransformation = instrumentTransformation;
        }
예제 #2
0
파일: OrderP4.cs 프로젝트: kiquenet/B4F
 private InstrumentSize getTradeDifferenceOpenValue(InstrumentSize size, Money amount, Money serviceCharge, Money accruedInterest)
 {
     InstrumentSize diff;
     if (IsSizeBased)
         diff = (this.OpenValue.Abs() - size.Abs());
     else
         diff = (this.OpenValue.Abs() - amount.Abs() + serviceCharge + accruedInterest);
     return diff;
 }
예제 #3
0
파일: OrderP4.cs 프로젝트: kiquenet/B4F
 protected bool orderCheckSide(Side side, ref Money amount, ref InstrumentSize size)
 {
     if (side == Side.Buy)
     {
         size = size.Abs();
         amount = amount.Abs() * -1;
     }
     else
     {
         size = size.Abs() * -1;
         amount = amount.Abs();
     }
     return true;
 }
예제 #4
0
        /// <summary>
        /// Used by method <b>Calculate</b> on derived classes to perform the common part of the commission calculation.
        /// </summary>
        /// <param name="size">The size for which to calculate commission.</param>
        /// <param name="client">The order for which to calculate commission.</param>
        /// <returns>The value of the commission.</returns>
        protected Money calculateNormal(InstrumentSize size, ICommClient client)
        {
            Money result = new Money(0m, CommCurrency);
            InstrumentSize comSize = size.Abs();

            foreach (CommCalcLineSizeBased line in CommLines)
            {
                if (line.Envelops(comSize))
                {
                    result = line.Calculate(comSize);
                    SetCommissionInfoOnOrder(client, string.Format("Flat -> Size ({0}) {1} -> use {2}.", comSize.DisplayString, line.DisplayRange, line.LineDistinctives));
                    break;
                }
            }
            return addFixMinMax(result, client);
        }
예제 #5
0
        protected void getPosTxInfo(IFundPositionTx posTx, out InstrumentSize newSize, out IsOpenClose isOpen)
        {
            isOpen = IsOpenClose.Close;
            newSize = InstrumentSize.Add(posTx.Size, Size, true);

            // Determine if it is opening or closing
            if (Size == null || Size.IsZero)
                isOpen = IsOpenClose.Open;
            else if (newSize.Sign != Size.Sign && newSize.IsNotZero)
                isOpen = IsOpenClose.Both;
            // short position -> gets larger
            else if (!Size.Sign && newSize.Sign == Size.Sign && newSize.Abs() > Size.Abs())
                isOpen = IsOpenClose.Open;
            else
            {
                if (IsSecurityValuationMutation)
                {
                    if (posTx.Side == Side.Sell || posTx.Side == Side.XO)
                        isOpen = IsOpenClose.Close;
                    else
                        isOpen = IsOpenClose.Open;
                }
                else
                {
                    // Cash -> just check the effect of the transaction
                    if (Size.Sign == posTx.Size.Sign)
                        isOpen = IsOpenClose.Open;
                    else
                        isOpen = IsOpenClose.Close;
                }
            }
        }