Beispiel #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="account">User account</param>
 /// <param name="value">Initial value for this order</param>
 /// <param name="requestedCurrency">Currency that is requested</param>
 /// <param name="feeFactory">Fee factory to use for calculating transaction costs</param>
 public MonetaryOrder(IAccountTypeInternal account, Money value, ICurrency requestedCurrency, IFeeFactory feeFactory)
     : base(account, value)
 {
     this.requestedCurrency = requestedCurrency;
     checkInitialValues();
     setCommission(feeFactory);
 }
Beispiel #2
0
 public CardService(ICardRepository cardRepository, IWithdrawalFeeCalculator withdrawalFeeCalculator,
                    IFeeRepository feeRepository, IFeeFactory feeFactory)
 {
     _cardRepository          = cardRepository;
     _withdrawalFeeCalculator = withdrawalFeeCalculator;
     _feeRepository           = feeRepository;
     _feeFactory = feeFactory;
 }
Beispiel #3
0
 public OrderAllocation(IOrder order, IAccountTypeInternal acctA, IAccount acctB,
         InstrumentSize valueSize, Price price, decimal exRate, DateTime transactionDate,
         DateTime transactionDateTime, Decimal ServiceChargePercentage, Side txSide, IFeeFactory feeFactory, ITradingJournalEntry tradingJournalEntry,
         IGLLookupRecords lookups, ListOfTransactionComponents[] components)
     : base(order, acctA, acctB, valueSize, price, exRate, transactionDate, transactionDateTime,
            ServiceChargePercentage, txSide,
            tradingJournalEntry, lookups, components)
 {
 }
Beispiel #4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="account">User account</param>
 /// <param name="value">Initial value</param>
 /// <param name="tradedInstrument">Traded instrument</param>
 /// <param name="isValueInclComm">Is in the value the commission included?</param>
 /// <param name="feeFactory">Fee factory to use for calculating transaction costs</param>
 /// <param name="doNotChargeCommission">parameter that decides whether commission should be charged</param>
 /// <param name="actionType">The action type that created this order.</param>
 public OrderAmountBased(IAccountTypeInternal account, Money value, IInstrument tradedInstrument, bool isValueInclComm, IFeeFactory feeFactory, bool doNotChargeCommission, OrderActionTypes actionType)
     : base(account, value, (ITradeableInstrument)tradedInstrument, doNotChargeCommission)
 {
     this.ActionType = actionType;
     this.IsValueInclComm = isValueInclComm;
     checkInitialValues();
     setCommission(feeFactory);
     // If same currency -> ExRate = 1
     exRate = ((ICurrency)Value.Underlying).GetExRate(TradedInstrument.CurrencyNominal, this.Side);
 }
        private FeesForVehicleFactory CreateSut(IFeeFactory factory = null)
        {
            if (factory == null)
            {
                factory = Substitute.For <IFeeFactory>();
            }

            var sut = new FeesForVehicleFactory(factory);

            return(sut);
        }
Beispiel #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:B4F.TotalGiro.PortfolioComparer.PortfolioComparer">PortfolioComparer</see> class.
        /// </summary>
        /// <param name="setting">The settings used in the portfolio comparer</param>
        /// <param name="feeFactory">An instance of the <see cref="T:B4F.TotalGiro.Fees.FeeFactory">FeeFactory</see> class</param>
        public PortfolioComparer(PortfolioCompareSetting setting, IFeeFactory feeFactory)
        {
            if (setting == null)
                throw new ApplicationException("Can not do a Portfolio check without an initialized PortfolioCompareSetting object");
            if (setting.Instruction == null || setting.Instruction.Account == null)
                throw new ApplicationException(string.Format("Not possible to instantiate a comparer class when account is null."));

            this.setting = setting;
            this.feeFactory = feeFactory;

            if (Account.ModelPortfolio == null)
                throw new ApplicationException(string.Format("Not possible to compare to model for account {0}: Model is null", Account.DisplayNumberWithName));
        }
Beispiel #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="parent">Parent order</param>
 /// <param name="feeFactory">Fee factory to use for calculating transaction costs</param>
 internal MonetaryOrder(IOrderAmountBased parent, IFeeFactory feeFactory)
     : base(parent.Account, (parent.Amount - parent.Commission))
 {
     if (parent.TradedInstrument != null && parent.TradedInstrument.IsTradeable)
     {
         ITradeableInstrument instrument = (ITradeableInstrument)parent.TradedInstrument;
         this.requestedCurrency = instrument.CurrencyNominal;
         checkInitialValues();
         setCommission(feeFactory);
         this.moneyParent = parent;
     }
     else
         throw new ApplicationException("Can not insert a monetary order without a requested currency");
 }
Beispiel #8
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="account">User account</param>
        /// <param name="value">Instrument size</param>
        /// <param name="isClosure">Is this order closing a position.</param>
        /// <param name="feeFactory">The set of rules to use for calculating transaction costs.</param>
        /// <param name="doNotChargeCommission">parameter that decides whether commission should be charged</param>
        /// <param name="actionType">The action type that created this order.</param>
        public OrderSizeBased(IAccountTypeInternal account, InstrumentSize value, bool isClosure, IFeeFactory feeFactory, bool doNotChargeCommission, OrderActionTypes actionType)
            : base(account, value, (ITradeableInstrument)value.Underlying, doNotChargeCommission)
        {
            this.ActionType = actionType;
            this.isClosure = isClosure;
            setCommission(feeFactory);

            // Accrued Interest for Client Orders
            if (account.IsAccountTypeCustomer && TradedInstrument.SecCategory.Key == SecCategories.Bond)
            {
                IBond bond = (IBond)TradedInstrument;
                if (bond.DoesPayInterest)
                {
                    IExchange exchange = bond.DefaultExchange ?? bond.HomeExchange;
                    AccruedInterestDetails calc = bond.AccruedInterest(value, bond.GetSettlementDate(DateTime.Today, exchange), exchange);
                    if (calc.IsRelevant)
                        this.AccruedInterest = calc.AccruedInterest.Abs() * (decimal)this.Side * -1M;
                }
            }
        }
Beispiel #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="account">User account</param>
 /// <param name="value">Initial value</param>
 /// <param name="tradedInstrument">Traded instrument</param>
 /// <param name="isValueInclComm">Is in the value the commission included?</param>
 /// <param name="feeFactory">Fee factory to use for calculating transaction costs</param>
 /// <param name="doNotChargeCommission">parameter that decides whether commission should be charged</param>
 public OrderAmountBased(IAccountTypeInternal account, Money value, IInstrument tradedInstrument, bool isValueInclComm, IFeeFactory feeFactory, bool doNotChargeCommission)
     : this(account, value, tradedInstrument, isValueInclComm, feeFactory, doNotChargeCommission, OrderActionTypes.NoAction)
 {
 }
Beispiel #10
0
 public override bool CalculateCosts(IOrder order, IFeeFactory feeFactory)
 {
     checkCostCalculater(order, feeFactory);
     Commission commDetails = feeFactory.CalculateCommission(order);
     if (commDetails != null)
     {
         order.CommissionDetails = commDetails;
         order.CommissionDetails.Parent = (ICommissionParent)order;
     }
     return true;
 }
Beispiel #11
0
        public TransactionFillDetails GetTransactionFillDetails(
            IOrderAmountBased order, Price price, DateTime settlementDate, IFeeFactory feeFactory,
            decimal fillRatio, IExchange exchange)
        {
            decimal serviceChargePercentageforOrder = getServiceChargePercentage(order, exchange);
            TransactionFillDetails details = null;

            if (IsCommissionLinear)
            {
                Money amount = order.Amount * fillRatio;
                Money serviceCharge = null;

                if (serviceChargePercentageforOrder != 0M)
                {
                    Money newAmount = amount * (decimal)(1M / (1M + serviceChargePercentageforOrder));
                    serviceCharge = (amount.Abs() - newAmount.Abs());
                    amount = newAmount;
                }

                // Calculate Commission
                Money commission = null;
                // if the trade fills the Order completely -> take the Commission from the Order
                if (fillRatio == 1M)
                    commission = order.Commission;

                // Convert amount when necessary
                if (!amount.Underlying.Equals(price.Underlying) && !price.Underlying.IsObsoleteCurrency)
                    amount = amount.Convert(order.ExRate, price.Underlying);

                InstrumentSize size = amount.CalculateSize(price);

                details = new TransactionFillDetails(size, amount, null, serviceCharge, serviceChargePercentageforOrder, commission, order.GrossAmount, order.Side);
            }
            else
            {
                // Do the goalseek
                ICommClient client;
                ICommRule rule = feeFactory.GetRelevantCommRule(order.Account, this, order.Side,
                    order.ActionType, settlementDate, true, out client);

                for (int i = 4; i > 0; i--)
                {
                    details = getTransactionFillDetailsAmountBasedOrderByGoalSeek(
                        order, settlementDate, price, exchange,
                        rule, client, serviceChargePercentageforOrder, i);

                    if (details.IsOK && !details.IsDiff)
                        break;
                }
                if (!details.IsOK || details.IsDiff)
                    throw new ApplicationException("Not possible to calculate the trade amounts, probably a commission rule applied with a minimum amount.");
            }
            if (details != null)
                details.SetSign(order.Side);
            return details;
        }
Beispiel #12
0
 protected override void setCommission(IFeeFactory feeFactory)
 {
     if (!DoNotChargeCommission)
     {
         base.setCommission(feeFactory);
         if (IsValueInclComm)
         {
             // Only subtract commission from value for buy orders
             // For sell orders you need to sell the whole lot
             if (Value.Sign)
                 Value += Commission;
         }
         else
         {
             // Add the commission from value for sell orders
             // You need to sell more to get the commission + req. value back
             // Buy orders -> just buy the req. value and pay the commission from the cash position
             if (!Value.Sign)
                 Value += Commission;
         }
     }
 }
Beispiel #13
0
 public virtual TransactionFillDetails GetTransactionFillDetails(
     IOrder order, Price price, DateTime settlementDate, IFeeFactory feeFactory,
     decimal fillRatio, IExchange exchange)
 {
     if (order.IsSizeBased)
         return GetTransactionFillDetails((IOrderSizeBased)order, price, settlementDate, feeFactory, fillRatio, exchange);
     else
         return GetTransactionFillDetails((IOrderAmountBased)order, price, settlementDate, feeFactory, fillRatio, exchange);
 }
Beispiel #14
0
        public virtual TransactionFillDetails GetTransactionFillDetails(
            IOrderSizeBased order, Price price, DateTime settlementDate, IFeeFactory feeFactory,
            decimal fillRatio, IExchange exchange)
        {
            Money serviceCharge = null;
            Money commission = null;
            decimal serviceChargePercentageforOrder = getServiceChargePercentage(order, exchange);

            // Use the Value of the child order -> difference will go to Crumble account
            InstrumentSize size = order.Value * fillRatio;
            Money amount = size.CalculateAmount(price);

            if (serviceChargePercentageforOrder != 0M)
                serviceCharge = (amount * serviceChargePercentageforOrder).Abs().Negate();

            TransactionFillDetails details = new TransactionFillDetails(size, amount, null, serviceCharge, serviceChargePercentageforOrder, commission, order.GrossAmount, order.Side);
            details.SetSign(order.Side);
            return details;
        }
Beispiel #15
0
 public FeesForVehicleFactory([NotNull] IFeeFactory feeFactory)
 {
     m_FeeFactory = feeFactory;
 }
Beispiel #16
0
 public override bool CalculateCosts(IOrderAllocation transaction, IFeeFactory feeFactory, IGLLookupRecords lookups)
 {
     checkCostCalculater(transaction, feeFactory);
     Commission commDetails = feeFactory.CalculateCommission(transaction);
     if (commDetails != null)
         transaction.setCommission(lookups, commDetails.Amount);
     return true;
 }
Beispiel #17
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="account">User account</param>
 /// <param name="value">Instrument size</param>
 /// <param name="isClosure">Is this order closing a position.</param>
 /// <param name="feeFactory">The set of rules to use for calculating transaction costs.</param>
 /// <param name="doNotChargeCommission">parameter that decides whether commission should be charged</param>
 public OrderSizeBased(IAccountTypeInternal account, InstrumentSize value, bool isClosure, IFeeFactory feeFactory, bool doNotChargeCommission)
     : this(account, value, isClosure, feeFactory, doNotChargeCommission, OrderActionTypes.NoAction)
 {
 }
Beispiel #18
0
        public IOrderAllocation FillasAllocation(IOrderExecution ParentExecution, ITradingJournalEntry tradingJournalEntry, IGLLookupRecords lookups, IFeeFactory feeFactory)
        {
            if (!RequestedInstrument.IsTradeable)
                throw new Exception("FillasAllocation not possible when the instrument is not tradeable.");

            ITradeableInstrument instrument = (ITradeableInstrument)RequestedInstrument;
            IExchange exchange = ParentExecution.Exchange ?? instrument.DefaultExchange ?? instrument.HomeExchange;
            TransactionFillDetails details = instrument.GetTransactionFillDetails(
                this, ParentExecution.Price, ParentExecution.ContractualSettlementDate,
                feeFactory, ParentExecution.FillRatio, exchange);

            // convert servicecharge?
            if (details.ServiceCharge != null && details.ServiceCharge.IsNotZero)
            {
                if (!details.ServiceCharge.Underlying.Equals(ParentExecution.Price.Underlying) && !ParentExecution.Price.Underlying.IsObsoleteCurrency)
                    details.ServiceCharge = details.ServiceCharge.Convert(ExRate, ParentExecution.Price.Underlying);
            }

            decimal exRate = (ExRate != 0 ? ExRate : ParentExecution.ExchangeRate);
            if (IsMonetary)
                exRate = ParentExecution.ExchangeRate;

            ListOfTransactionComponents[] components = packageComponents(details.Amount, details.ServiceCharge, details.AccruedInterest);

            OrderAllocation newTrade = new OrderAllocation(
                this, this.account, ParentExecution.AccountA, details.Size,
                ParentExecution.Price, exRate, ParentExecution.TransactionDate,
                ParentExecution.TransactionDateTime, details.ServiceChargePercentage,
                this.Side, feeFactory, tradingJournalEntry, lookups, components);
            newTrade.Exchange = ParentExecution.Exchange;
            newTrade.ContractualSettlementDate = ParentExecution.ContractualSettlementDate;

            if (details.Commission == null)
                instrument.CalculateCosts(newTrade, feeFactory, lookups);
            else
                newTrade.setCommission(lookups, details.Commission);

            fillOrder(newTrade, details.Size, ParentExecution.Price, details.Amount, details.ServiceCharge, details.AccruedInterest);
            ParentExecution.Allocations.AddAllocation(newTrade);
            return newTrade;
        }
Beispiel #19
0
 public override bool CalculateCosts(IOrder order, IFeeFactory feeFactory)
 {
     return true;
 }
Beispiel #20
0
 private static void executeBooking(ICashDividend booking, IFeeFactory feeFactory)
 {
     ITradeableInstrument instrument;
     if (booking.NeedToCreateCashInitiatedOrder(out instrument))
     {
         Money divAmount = booking.Components.TotalAmount;
         if (instrument != null)
         {
             OrderAmountBased order = new OrderAmountBased(booking.Account, divAmount, instrument, true, feeFactory, true);
             order.OrderInfo = booking.Description;
             booking.CashInitiatedOrder = order;
         }
         else
         {
             // Sell from the biggest position
             IFundPosition pos = booking.Account.Portfolio.PortfolioInstrument.Where(x => x.Size.IsGreaterThanZero).OrderByDescending(x => x.CurrentValue).FirstOrDefault();
             if (pos != null && (pos.CurrentBaseValue + divAmount).IsGreaterThanOrEqualToZero)
             {
                 OrderAmountBased order = new OrderAmountBased(booking.Account, divAmount, pos.Instrument, true, feeFactory, true);
                 order.OrderInfo = booking.Description;
                 booking.CashInitiatedOrder = order;
             }
         }
     }
     booking.Execute();
 }
 public override bool CalculateCosts(IOrderAllocation transaction, IFeeFactory feeFactory, IGLLookupRecords lookups)
 {
     throw new ApplicationException("The method is mot supported for a corpa.");
 }
 public override bool CalculateCosts(IOrder order, IFeeFactory feeFactory)
 {
     throw new ApplicationException("The method is mot supported for a corpa.");
 }
Beispiel #23
0
        public override TransactionFillDetails GetTransactionFillDetails(
            IOrderSizeBased order, Price price, DateTime settlementDate, IFeeFactory feeFactory,
            decimal fillRatio, IExchange exchange)
        {
            TransactionFillDetails details = base.GetTransactionFillDetails(order, price, settlementDate, feeFactory, fillRatio, exchange);

            // accrued interest
            if (DoesPayInterest)
            {
                AccruedInterestDetails calc = AccruedInterest(details.Size, settlementDate, exchange);
                if (calc.IsRelevant)
                    details.AccruedInterest = calc.AccruedInterest.Abs() * (decimal)order.Side * -1M;
            }
            return details;
        }
Beispiel #24
0
 public override bool CalculateCosts(IOrderAllocation transaction, IFeeFactory feeFactory, IGLLookupRecords lookups)
 {
     return true;
 }
Beispiel #25
0
 /// <summary>
 /// An instance of the <see cref="T:B4F.TotalGiro.Fees.FeeFactory">FeeFactory</see> class
 /// </summary>
 /// <param name="instanceType"></param>
 /// <returns></returns>
 protected IFeeFactory getFeeFactory(FeeFactoryInstanceTypes instanceType)
 {
     if (this.feeFactory == null || (this.feeFactory != null && !this.feeFactory.IsInstanceTypeActivated(instanceType)))
     {
         IDalSession session = NHSessionFactory.CreateSession();
         if (this.feeFactory == null)
             this.feeFactory = FeeFactory.GetInstance(session, instanceType, true);
         else
             this.feeFactory.InitiateInstance(session, instanceType, true);
     }
     return this.feeFactory;
 }