Beispiel #1
0
        public IEnumerable <SimulationState> Evaluate(
            IStrategy strategy,
            Investor investor,
            DateTime?endDate     = null,
            ProgressBar progress = null)
        {
            var state     = new SimulationState();
            var remaining = _dataCache.Count - _dataCache.BacktestingIndex;

            using var childProgress = ProgressBarProvider.Create(progress, remaining, $"Evaluating: {strategy.StrategyType.GetDescription()}");
            foreach (var data in _dataCache.TakeFrom(Configuration.BacktestingDate, endDate))
            {
                Optimise(strategy);
                var shouldBuy = _simulationCache.GetOrCreate((strategy, data.Date), () => ShouldBuy(strategy, data));

                state = state.UpdateState(data, shouldBuy);
                state.AddFunds(investor.DailyFunds);
                state.ExecuteOrders();

                if (state.ShouldBuy)
                {
                    var funds = strategy.GetStake(data.Date, state.TotalFunds);
                    state.AddBuyOrder(investor.OrderBrokerage, investor.OrderDelayDays, funds);
                }

                childProgress?.Tick();
                yield return(state);
            }
        }
        public IEnumerable <SimulationState> Evaluate(
            IStrategy strategy,
            Investor investor,
            DateTime?endDate = null,
            ProgressBar _    = null)
        {
            var state = new SimulationState();

            foreach (var data in _dataCache.TakeUntil(endDate))
            {
                var shouldBuy = _simulationCache.GetOrCreate((strategy, data.Date), () => ShouldBuy(strategy, data));

                state = state.UpdateState(data, shouldBuy);
                state.AddFunds(investor.DailyFunds);
                state.ExecuteOrders();

                if (state.ShouldBuy)
                {
                    var funds = strategy.GetStake(data.Date, state.TotalFunds);
                    state.AddBuyOrder(investor.OrderBrokerage, investor.OrderDelayDays, funds);
                }

                yield return(state);
            }
        }