Esempio n. 1
0
        public void Test()
        {
            var portfolio = new Portfolio
            {
                Name = "Test Portfolio"
            };

            using (var tokenManager = new QuestradeApiTokenManager(new Configuration()))
            {
                var api = new QuestradeService(tokenManager, new InMemorySecurityRepository(), new InMemoryCategoryRepository());
                portfolio.Accounts = api.GetAccounts();

                foreach (var account in portfolio.Accounts)
                {
                    account.Positions    = api.GetPositions(account);
                    account.Transactions = api.GetTransactions(account, new DateTime(2008, 1, 1), DateTime.Now);
                }
            }

            var quoter   = new YahooStockService(new YahooServiceFactory());
            var reporter = new StringValueReporter(quoter);
            var report   = reporter.GetReport(portfolio);

            Console.Out.Write(report);
        }
Esempio n. 2
0
        private static ErrorCode QuestradeMonthReportOperation(string portfolioName)
        {
            var portfolio = new Portfolio
            {
                Name = portfolioName
            };

            using (var tokenManager = new QuestradeApiTokenManager(Configuration))
            {
                var api = new QuestradeService(tokenManager, new InMemorySecurityRepository(), new InMemoryCategoryRepository());
                portfolio.Accounts = api.GetAccounts();

                foreach (var account in portfolio.Accounts)
                {
                    account.Positions = api.GetPositions(account);
                }

                var service   = new YahooStockService(new YahooServiceFactory());
                var reporter  = new StringHistoricalReporter(service);
                var startDate = GetStartOfMarketWeek(DateTime.Now);
                var report    = reporter.GetReport(portfolio, startDate.AddMonths(-1), startDate, Period.Weekly);

                Console.Write(report);
            }

            return(ErrorCode.NoError);
        }
Esempio n. 3
0
        private static ErrorCode QuickQuestradeValueReportOperation(string portfolioName)
        {
            var portfolio = new Portfolio
            {
                Name = portfolioName
            };

            using (var tokenManager = new QuestradeApiTokenManager(Configuration))
            {
                var api = new QuestradeService(tokenManager, new InMemorySecurityRepository(), new InMemoryCategoryRepository());
                portfolio.Accounts = api.GetAccounts();

                foreach (var account in portfolio.Accounts)
                {
                    account.Positions    = api.GetPositions(account);
                    account.Transactions = api.GetTransactions(account, new DateTime(2008, 1, 1), DateTime.Now);
                }

                var reporter = new StringValueReporter(api);
                var report   = reporter.GetReport(portfolio);

                Console.Write(report);
            }

            return(ErrorCode.NoError);
        }
Esempio n. 4
0
        private static ErrorCode QuickQuestradeWeightReportOperation(string portfolioName)
        {
            var portfolio = new Portfolio
            {
                Name = portfolioName
            };
            var categoryRepository      = new InMemoryCategoryRepository();
            var securityRepo            = new InMemorySecurityRepository();
            var securityCategory        = categoryRepository.GetCategory("Security");
            var currencyCategory        = categoryRepository.GetCategory("Currency");
            var assetAllocationCategory = categoryRepository.GetCategory("AssetAllocation");

            using (var tokenManager = new QuestradeApiTokenManager(Configuration))
            {
                var api = new QuestradeService(tokenManager, securityRepo, categoryRepository);
                portfolio.Accounts = api.GetAccounts();
                var morningstar = new MorningstarService(new Scraper(), securityRepo, categoryRepository);
                var weights     = new List <CategoryWeight>();

                foreach (var account in portfolio.Accounts)
                {
                    account.Positions = api.GetPositions(account);
                    foreach (var position in account.Positions)
                    {
                        weights.AddRange(morningstar.GetWeights(assetAllocationCategory, position.Security));
                        //weights.AddRange(api.GetWeights(securityCategory, position.Security));
                        //weights.AddRange(api.GetWeights(currencyCategory, position.Security));
                    }
                }

                var reporter = new StringWeightReporter(api);
                var report   = reporter.GetReport(portfolio, new[] { assetAllocationCategory }, weights.Distinct());

                Console.Write(report);
            }

            return(ErrorCode.NoError);
        }