示例#1
0
        public static IActionResult CalculateToBuyStocks(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "calculateToBuyStocks")] AdvisorRequest request)
        {
            var stockPrices   = request.BvbStocks.AsStockPrices();
            var targetWeights = request.BvbStocks.AsStockWeights();

            var existingStocks = request.ExistingStocks.UpdatePrices(stockPrices);

            decimal currentPortfolioValue = existingStocks.Sum(s => s.TotalValue);

            var strategy =
                new MinOrderValueCutOffStrategy(
                    new FollowTargetAdjustmentStrategy(), MIN_ORDER_VALUE / request.ToBuyAmount);

            var portfolio = new PortfolioBuilder()
                            .UseStocks(existingStocks)
                            .UsePrices(stockPrices)
                            .UseTargetWeights(targetWeights)
                            .UseToBuyAmount(request.ToBuyAmount)
                            .UseMinOrderValue(MIN_ORDER_VALUE)
                            .UseWeightAdjustmentStrategy(strategy)
                            .Build();

            return(new OkObjectResult(portfolio.DeriveToBuyStocks(existingStocks)));
        }
示例#2
0
        public void MinOrderValueCutOffStrategy_AsExpected()
        {
            var toBuyAmount = 2070.2175m;

            var(currentWeights, targetWeights, portfolioValue) = TestResources.ReadWeights();

            var strategy = new MinOrderValueCutOffStrategy(new FollowTargetAdjustmentStrategy(), MIN_ORDER_VALUE / toBuyAmount);

            var adjustedWeights =
                strategy.AdjustWeights(currentWeights, targetWeights, portfolioValue / toBuyAmount);

            Assert.IsTrue(adjustedWeights.Sum(w => w.Value).IsApproxOne());
        }
示例#3
0
        public void AdjustWeights_WeightsBellowMinimalWeightAreCutOff_CutOffWeightIsRedistributed()
        {
            var currentWeights = new StockWeights
            {
                { "TLV", 0.08m }, { "SNG", 0.09m }, { "FP", 0.22m }, { "EL", 0.61m }
            };

            var targetWeights = new StockWeights
            {
                { "TLV", 0.08m }, { "SNG", 0.09m }, { "FP", 0.22m }, { "EL", 0.61m }
            };

            var strategy     = new MinOrderValueCutOffStrategy(new FollowTargetAdjustmentStrategy(), 0.1m);
            var toBuyWeights = strategy.AdjustWeights(currentWeights, targetWeights, toBuyInverseRatio: 2);

            Assert.IsFalse(toBuyWeights.ContainsKey("TLV"));
            Assert.IsTrue(toBuyWeights.Sum(w => w.Value).IsApproxOne());
        }
示例#4
0
        public void PortfolioBuilder_ExpectedDerivedPortfolio()
        {
            var toBuyAmount = 2000m;

            var(currentStocks, bvbStocks, _) = TestResources.ReadStocks();

            var strategy =
                new MinOrderValueCutOffStrategy(
                    new FollowTargetAdjustmentStrategy(), MIN_ORDER_VALUE / toBuyAmount);

            var portfolio = new PortfolioBuilder()
                            .UseStocks(currentStocks)
                            .UsePrices(bvbStocks.AsStockPrices())
                            .UseTargetWeights(bvbStocks.AsStockWeights())
                            .UseToBuyAmount(toBuyAmount)
                            .UseMinOrderValue(MIN_ORDER_VALUE)
                            .UseWeightAdjustmentStrategy(strategy)
                            .Build();

            var toBuyStocks    = portfolio.DeriveToBuyStocks(currentStocks);
            var investedAmount = toBuyStocks.Sum(s => s.Count * s.Price);

            Assert.IsTrue((toBuyAmount / investedAmount).IsApproxOne());
        }