Ejemplo n.º 1
0
        private static ITransactionPerformance GetDividendPerformance(ITransactionBook book, Guid stockId, Guid sellTransId)
        {
            var entries  = book.GetLastCommittedChanges(stockId).ToList();
            var dividend = entries.FirstOrDefault(e => e.TransactionId == sellTransId) as IDividendTransactionBookEntry;
            var other    = entries.Where(e => e.TransactionId != sellTransId).Cast <IBuyingTransactionBookEntry>();

            return(new TransactionPerformanceService().GetPerformance(dividend, other));
        }
Ejemplo n.º 2
0
        private static ITransactionPerformance GetPerformance(ITransactionBook book, Guid stockId, Guid sellTransId, decimal?mfe, decimal?mae)
        {
            var entries = book.GetLastCommittedChanges(stockId).ToList();
            var sell    = entries.FirstOrDefault(e => e.TransactionId == sellTransId) as ISellingTransactionBookEntry;
            var other   = entries.Where(e => e.TransactionId != sellTransId).Cast <IBuyingTransactionBookEntry>();

            return(new TransactionPerformanceService().GetPerformance(sell, other, mfe, mae));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Calculates the performance for this transaction if its a selling transaction
        /// </summary>
        //TODO: Move to a domain service
        private void CalculatePerformance(Guid transactionId, Guid stockId, decimal?mae, decimal?mfe)
        {
            var entries = _transactionBook.GetLastCommittedChanges(stockId).ToList();
            var sell    = entries.FirstOrDefault(e => e.TransactionId == transactionId) as ISellingTransactionBookEntry;
            var buys    = entries.Where(e => e.TransactionId != transactionId).Cast <IBuyingTransactionBookEntry>();

            var performance = _transactionPerformanceService.GetPerformance(sell, buys, mfe, mae);

            _eventBus.Publish(new TransactionPerformanceCalculatedEvent(transactionId, typeof(TransactionAggregate),
                                                                        performance.ProfitAbsolute,
                                                                        performance.ProfitPercentage,
                                                                        performance.ProfitMade,
                                                                        performance.HoldingPeriod,
                                                                        performance.R,
                                                                        performance.ExitEfficiency,
                                                                        performance.EntryEfficiency,
                                                                        performance.MAEAbsolute,
                                                                        performance.MFEAbsolute));

            _eventBus.Publish(new StockOverallPerformanceChangedEvent(transactionId, typeof(TransactionAggregate), performance.ProfitAbsolute, stockId));
        }