예제 #1
0
        private void FillTrades(ReportOptions reportOptions, ITaxReport taxReport, List <StatementData> statements)
        {
            var tradeTransformer = dataTransformerFactory.GetInstance <IDataTransformer <Trade, ClosedOperation <Trade> > >(typeof(IDataTransformer <Trade, ClosedOperation <Trade> >));
            var extrator         = new TradesExtrator(taxReport, brokerParserProvider, tradeTransformer, tradeConvertor);

            extrator.Prepare(statements, reportOptions);
        }
예제 #2
0
 public TradesExtrator(
     ITaxReport taxReport,
     IBrokerParserProvider brokerParserProvider,
     IDataTransformer <Trade, ClosedOperation <Trade> > tradeTransformer,
     IEntityConvertor <Trade> tradeConvertor
     )
 {
     this.taxReport            = taxReport;
     this.brokerParserProvider = brokerParserProvider;
     this.tradeConvertor       = tradeConvertor;
     this.tradeTransformer     = tradeTransformer;
 }
예제 #3
0
        public void Export(Stream stream, Profile profile, ITaxReport taxReport)
        {
            var currentCulture = CultureInfo.CurrentUICulture;

            try
            {
                CultureInfo.CurrentUICulture = new CultureInfo(profile.CultureCode, false);

                using (var p = new ExcelPackage())
                {
                    if (taxReport.TradeData.TradeAggregations.Any())
                    {
                        (ExcelWorksheet ws, int row) = ExportEntities(p, profile, taxReport.TradeData.TradeAggregations);
                        ExportTaxes(ws, row, taxReport.CalcTradesTaxes());
                    }

                    if (taxReport.TradeData.Trades.Any())
                    {
                        ExportEntities(p, profile, taxReport.TradeData.FlatConvertedTrades);
                    }

                    if (taxReport.ForexTrades.Any())
                    {
                        ExportEntities(p, profile, taxReport.ForexTrades);
                    }

                    if (taxReport.Dividends.Any())
                    {
                        (ExcelWorksheet ws, int row) = ExportEntities(p, profile, taxReport.Dividends);
                        ExportTaxes(ws, row, taxReport.CalcDividendsTaxes());
                    }

                    if (taxReport.SecuritiesLentInterests.Any())
                    {
                        ExportEntities(p, profile, taxReport.SecuritiesLentInterests);
                    }

                    if (taxReport.Interests.Any())
                    {
                        (ExcelWorksheet ws, int row) = ExportEntities(p, profile, taxReport.Interests);
                        ExportTaxes(ws, row, taxReport.CalcInterestsTaxes());
                    }

                    if (taxReport.Fees.Any())
                    {
                        ExportEntities(p, profile, taxReport.Fees);
                    }

                    if (taxReport.Deposits.Any())
                    {
                        ExportEntities(p, profile, taxReport.Deposits);
                    }

                    p.SaveAs(stream);
                }
            }
            finally
            {
                CultureInfo.CurrentUICulture = currentCulture;
            }
        }
예제 #4
0
 public OrderController(NorthwindContext context, ITaxReport report)
 {
     this.context = context;
     this.report  = report;
 }
 public HomeController(ILogger <HomeController> logger, IRateService rateService, ITaxReport report, IOptions <SampleSettings> settingsOptions, IEmailSender emailSender)
 {
     sampleSettings   = settingsOptions.Value;
     _logger          = logger;
     this.rateService = rateService;
     //emailSender.SendEmailAsync("*****@*****.**","dasdasdas", "tjenare<br />hopp").Wait();
 }
예제 #6
0
        private IList <TradeAggregation> AggregateTrades(
            ReportOptions reportOptions,
            ITaxReport taxReport,
            IList <ClosedOperation <ConvertedTrade> > convertedTrades)
        {
            List <TradeAggregation> tradeAggregations = new List <TradeAggregation>();
            var symbol = string.Empty;
            TradeAggregation tradeAggregation = null;

            Action <ClosedOperation <ConvertedTrade>, TradeAggregation, ConvertedEntity <Trade> > appendToAggregation = (closedOp, tradeAggregation, trade) =>
            {
                if (trade.Entity.TradeOperation == TradeOperation.Buy)
                {
                    tradeAggregation.BuyBasis          += Math.Abs(trade.Entity.BasisAmount);
                    tradeAggregation.BuyConvertedBasis += Math.Abs(trade.ConvertedBasis);
                }
                else if (trade.Entity.TradeOperation == TradeOperation.Sell)
                {
                    if (trade.Entity.AssetCategoryType == AssetCategoryType.Options &&
                        closedOp.IsClosed && closedOp.CloseTrade.ConvertedBasis == 0)
                    {
                        // for options sells comm will go to buy side (so buy side will not be  0 for sold options)
                        tradeAggregation.SellBasis          += Math.Abs(trade.Entity.Proceeds);
                        tradeAggregation.SellConvertedBasis += Math.Abs(trade.ConvertedGrossAmount);

                        tradeAggregation.BuyBasis          += Math.Abs(trade.Entity.Comm);
                        tradeAggregation.BuyConvertedBasis += Math.Abs(trade.ConvertedComm);
                    }
                    else
                    {
                        tradeAggregation.SellBasis          += Math.Abs(trade.Entity.BasisAmount);
                        tradeAggregation.SellConvertedBasis += Math.Abs(trade.ConvertedBasis);
                    }
                }
            };

            foreach (var ct in convertedTrades)
            {
                if (!ct.IsClosed)
                {
                    continue;
                }

                if (ct.Symbol != symbol)
                {
                    symbol                      = ct.Symbol;
                    tradeAggregation            = new TradeAggregation();
                    tradeAggregation.Symbol     = symbol;
                    tradeAggregation.SymbolName = taxReport.FindFinInstrument(symbol)?.Description ?? symbol;


                    if (ct.IsClosed)
                    {
                        tradeAggregation.AssetCategoryType = ct.CloseTrade.Entity.AssetCategoryType;
                        tradeAggregation.BaseCurrency      = ct.CloseTrade.Currency;
                    }
                    tradeAggregation.Currency = reportOptions.Profile.TaxCurrency;

                    tradeAggregations.Add(tradeAggregation);
                }

                if (ct.OpenTrades.Any())
                {
                    foreach (var trade in ct.OpenTrades)
                    {
                        appendToAggregation(ct, tradeAggregation, trade);
                    }
                }

                if (ct.IsClosed)
                {
                    appendToAggregation(ct, tradeAggregation, ct.CloseTrade);
                }
            }

            return(tradeAggregations);
        }