示例#1
0
 public TransactionsFeeDataGenerator(ITransactionData transactionData, IDataGenerator dataGenerator, IFeeCalculator feeCalculator, IOutputWritter outputWritter)
 {
     _transactionData = transactionData;
     _dataGenerator   = dataGenerator;
     _feeCalculator   = feeCalculator;
     _consoleWritter  = outputWritter;
 }
示例#2
0
 public FeeCalculationService(
     IFeeCalculator feeCalculator,
     IReadOnlyCollection <IExtraFee> extraFees,
     IMapper mapper)
 {
     _feeCalculator = feeCalculator;
     _extraFees     = extraFees;
     _mapper        = mapper;
 }
        private static VehicleFees CreateSut(IFeeCalculator calculator = null)
        {
            if (calculator == null)
            {
                calculator = Substitute.For <IFeeCalculator>();
            }

            var sut = new VehicleFees(calculator);

            return(sut);
        }
示例#4
0
文件: Runner.cs 项目: ztz2018/Trady
 internal Runner(IDictionary <IEnumerable <IOhlcv>, int> weightings,
                 Predicate <IIndexedOhlcv> buyRule,
                 Predicate <IIndexedOhlcv> sellRule,
                 bool buyInCompleteQuantity,
                 IFeeCalculator calculator)
 {
     _weightings            = weightings;
     _buyRule               = buyRule;
     _sellRule              = sellRule;
     _buyInCompleteQuantity = buyInCompleteQuantity;
     _calculator            = calculator;
 }
示例#5
0
        private Builder(
            IDictionary <IEnumerable <IOhlcv>, int> weightings,
            Predicate <IIndexedOhlcv> buyRule,
            Predicate <IIndexedOhlcv> sellRule,
            bool buyInCompleteQuantity,
            IFeeCalculator calculator)
        {
            _weightings            = weightings ?? new Dictionary <IEnumerable <IOhlcv>, int>();
            _buyRule               = buyRule;
            _sellRule              = sellRule;
            _buyInCompleteQuantity = buyInCompleteQuantity;

            //Use default calculator if none defined.
            _calculator = calculator ?? new FeeCalculator();
        }
示例#6
0
文件: Runner.cs 项目: ztz2018/Trady
        private void BuyAsset(IIndexedOhlcv indexedCandle, IFeeCalculator calculator, IDictionary <IEnumerable <IOhlcv>, decimal> assetCashMap, IList <Transaction> transactions)
        {
            if (assetCashMap.TryGetValue(indexedCandle.BackingList, out decimal cash))
            {
                var nextCandle = indexedCandle.Next;

                //Use calculator to determine transaction quantities, costs, etc.
                var transaction = calculator.BuyAsset(nextCandle, cash, nextCandle, _buyInCompleteQuantity);

                assetCashMap[nextCandle.BackingList] -= transaction.AbsoluteCashFlow; //cash to buy asset

                transactions.Add(transaction);
                OnBought?.Invoke(indexedCandle.BackingList, nextCandle.Index, nextCandle.DateTime, nextCandle.Open, transaction.Quantity, transaction.AbsoluteCashFlow, assetCashMap[indexedCandle.BackingList]);
            }
        }
示例#7
0
        public void Message(IRealEstate realEstate, IFeeCalculator feeCalculator)
        {
            var totalCost   = feeCalculator.CalculTotal(realEstate.Price, realEstate.Zone);
            var commissionn = feeCalculator.returnCommissionn(realEstate.Price, realEstate.Zone);

            Console.WriteLine();
            Console.WriteLine("******************************************************************************************************************");
            Console.WriteLine(" The price for a/an {0}, before applying the commission is {1} euro.", realEstate.GetType().Name, realEstate.Price);
            if (realEstate.GetType().Name != "Parcel")
            {
                Console.WriteLine(" The address is: {0}, in the {1} zone.", realEstate.Address, realEstate.Zone);
            }
            else
            {
                Console.WriteLine(" The cadastral number is: {0}, in the {1} zone.", realEstate.Address, realEstate.Zone);
            }
            Console.WriteLine(" The price with commissionn is {0} euro and the commissionn is {1} euro.", totalCost, commissionn);
            Console.WriteLine("******************************************************************************************************************");
        }
示例#8
0
文件: Runner.cs 项目: ztz2018/Trady
        private void SellAsset(IIndexedOhlcv indexedCandle, IFeeCalculator calculator, IDictionary <IEnumerable <IOhlcv>, decimal> assetCashMap, IList <Transaction> transactions)
        {
            if (assetCashMap.TryGetValue(indexedCandle.BackingList, out _))
            {
                var nextCandle      = indexedCandle.Next;
                var lastTransaction = transactions.LastOrDefault(t => t.OhlcvList.Equals(indexedCandle.BackingList));
                if (lastTransaction == default)
                {
                    return;
                }

                var transaction = calculator.SellAsset(indexedCandle, lastTransaction);

                assetCashMap[indexedCandle.BackingList] += transaction.AbsoluteCashFlow;
                decimal profitLossRatio = (transaction.AbsoluteCashFlow - lastTransaction.AbsoluteCashFlow) / lastTransaction.AbsoluteCashFlow;

                transactions.Add(transaction);
                OnSold?.Invoke(indexedCandle.BackingList, nextCandle.Index, nextCandle.DateTime, nextCandle.Open, transaction.Quantity, transaction.AbsoluteCashFlow, assetCashMap[indexedCandle.BackingList], profitLossRatio);
            }
        }
示例#9
0
 public Builder Calculator(IFeeCalculator calculator)
 => new Builder(_weightings, _buyRule, _sellRule, _buyInCompleteQuantity, calculator);
示例#10
0
文件: Runner.cs 项目: ztz2018/Trady
        private BuySellRuleExecutor CreateBuySellRuleExecutor(IAnalyzeContext <IOhlcv> context, IFeeCalculator calculator, IDictionary <IEnumerable <IOhlcv>, decimal> assetCashMap, List <Transaction> transactions)
        {
            bool isPrevTransactionOfType(IEnumerable <Transaction> ts, IAnalyzeContext <IOhlcv> ctx, TransactionType tt)
            => ts.LastOrDefault(_t => _t.OhlcvList.Equals(ctx.BackingList))?.Type == tt;

            bool buyRule(IIndexedOhlcv ic)
            => !isPrevTransactionOfType(transactions, ic.Context, TransactionType.Buy) && _buyRule(ic);

            bool sellRule(IIndexedOhlcv ic)
            => transactions.Any() && !isPrevTransactionOfType(transactions, ic.Context, TransactionType.Sell) && _sellRule(ic);

            (TransactionType, IIndexedOhlcv)? outputFunc(IIndexedOhlcv ic, int i)
            {
                if (ic.Next == null)
                {
                    return(null);
                }

                var type = (TransactionType)i;

                if (type.Equals(TransactionType.Buy))
                {
                    BuyAsset(ic, calculator, assetCashMap, transactions);
                }
                else
                {
                    SellAsset(ic, calculator, assetCashMap, transactions);
                }

                return((TransactionType)i, ic);
            }

            return(new BuySellRuleExecutor(outputFunc, context, buyRule, sellRule));
        }
示例#11
0
 public VehicleFees([NotNull] IFeeCalculator calculator)
 {
     m_Calculator = calculator;
 }
 public void AddCalculator(IFeeCalculator calculator)
 {
     this.Calculators.Add(calculator);
 }