Exemplo n.º 1
0
        protected virtual TransactionFillDetails getTransactionFillDetailsAmountBasedOrderByGoalSeek(
            Money grossAmount, Side side, bool isCommissionRelevant, bool isValueInclComm,
            DateTime settlementDate, Price price, IExchange exchange,
            ICommRule rule, ICommClient client, decimal servChargePerc, int precision)
        {
            decimal realAmount;
            decimal guess = grossAmount.Abs().CalculateSize(price).Quantity;
            FinancialMath.MaxCycles = 200;

            // Check -> use Commission
            bool useComm = true;
            bool useAddComm = false;
            if (!isCommissionRelevant || rule == null)
                useComm = false;

            if (useComm)
                useAddComm = (rule.AdditionalCalculation != null);

            realAmount = FinancialMath.GoalSeek(x =>
                new InstrumentSize(x, this).CalculateAmount(price).Quantity +
                (useComm ? rule.CommCalculation.Calculate(client.GetNewInstance(new InstrumentSize(x, this), price, (useAddComm ? rule.AdditionalCalculation.Calculate(client.GetNewInstance(new InstrumentSize(x, this), price)) : null))).Quantity : 0M) +
                (useAddComm ? rule.AdditionalCalculation.Calculate(client.GetNewInstance(new InstrumentSize(x, this), price)).Quantity : 0M) +
                (new InstrumentSize(x, this).CalculateAmount(price).Abs().Quantity * servChargePerc),
                grossAmount.Abs().Quantity, guess, precision);

            InstrumentSize size = new InstrumentSize(realAmount, this);
            Money amount = size.CalculateAmount(price);
            InstrumentSize cleanSize = amount.CalculateSize(price);

            Money servCh = (amount.Abs() * servChargePerc);
            Money comm = amount.ZeroedAmount();
            Money addComm = amount.ZeroedAmount();
            if (useComm)
            {
                if (rule.AdditionalCalculation != null)
                    addComm = rule.AdditionalCalculation.Calculate(client.GetNewInstance(cleanSize, price));
                comm = rule.CommCalculation.Calculate(client.GetNewInstance(cleanSize, price, addComm));

                // if sell -> comm is already in the amount
                if (side == Side.Sell && (comm + addComm) != null && (comm + addComm).IsNotZero)
                {
                    amount += (comm + addComm);
                    cleanSize = amount.CalculateSize(price);
                    if (!isValueInclComm)
                    {
                        if (rule.AdditionalCalculation != null)
                            addComm = rule.AdditionalCalculation.Calculate(client.GetNewInstance(cleanSize, price));
                        comm = rule.CommCalculation.Calculate(client.GetNewInstance(cleanSize, price, addComm));
                    }
                }
            }
            return new TransactionFillDetails(cleanSize, amount, null, servCh, servChargePerc, comm + addComm, grossAmount.Abs(), side);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Deletes a <b>CommRule</b> object from the database.
 /// </summary>
 /// <param name="session">An instance of the Data Access Library (see class <see cref="B4F.TotalGiro.DAL.NHSession">NHSession</see>).</param>
 /// <param name="obj">The <b>CommRule</b> object to delete from the database.</param>
 public static void Delete(IDalSession session, ICommRule obj)
 {
     session.Delete(obj);
 }
Exemplo n.º 3
0
 protected virtual TransactionFillDetails getTransactionFillDetailsAmountBasedOrderByGoalSeek(
     IOrderAmountBased order, DateTime settlementDate, Price price, IExchange exchange,
     ICommRule rule, ICommClient client, decimal servChargePerc, int precision)
 {
     try
     {
         TransactionFillDetails details = getTransactionFillDetailsAmountBasedOrderByGoalSeek(
             order.GrossAmount, order.Side, order.IsCommissionRelevant, order.IsValueInclComm,
             settlementDate, price, exchange, rule, client, servChargePerc, precision);
         if (details.IsOK)
         {
             Money diff = details.Diff;
             if (diff != null && diff.IsNotZero && diff.IsWithinTolerance(0.09M))
             {
                 details.FixUp(order);
                 details.Size = details.Amount.CalculateSize(price);
                 details.Info = string.Format("F{0}", precision);
             }
         }
         return details;
     }
     catch
     {
     }
     return new TransactionFillDetails();
 }
Exemplo n.º 4
0
 /// <summary>
 /// Updates a <b>CommRule</b> object to the database.
 /// </summary>
 /// <param name="session">An instance of the Data Access Library (see class <see cref="B4F.TotalGiro.DAL.NHSession">NHSession</see>).</param>
 /// <param name="obj">The <b>CommRule</b> object to update into the database.</param>
 public static void Update(IDalSession session, ICommRule obj)
 {
     session.InsertOrUpdate(obj);
 }