public void PrepareBuyAndHoldWithEmptyInputThrowsException() { // Arrange var target = new BuyAndHold(); // Act target.Prepare(new List <Candle>()); }
public void PrepareBuyAndHoldWithNullInputThrowsException() { // Arrange var target = new BuyAndHold(); // Act target.Prepare(null); }
public void PrepareBuyAndHoldWithListReturnsExpectedPattern() { // Arrange var target = new BuyAndHold(); var list = Enumerable.Range(1, 100). Select(_ => new Candle { Close = 2.0m * (decimal)Math.Sin(_) * (decimal)Math.Sin(_) }).ToList(); // Act var result = target.Prepare(list); // Assert Assert.AreEqual(100, result.Count()); Assert.AreEqual(TradeAdvice.Buy, result.First()); for (int index = 1; index < result.Count; index++) { Assert.AreEqual(TradeAdvice.Hold, result[index]); } }
private void RunBenchmark(ReqAnalyzePortfolio request, BacktestingProperty property, DateTime startDate, DateTime endDate, List <DateTime> tradingCalendar, List <Report> reports) { var simulator = new Simulator(); using (var context = new QTContext()) { var assetCode = request.Benchmark.AssetCode; var tradingDataset = new Dictionary <DateTime, ITradingData>(); var benchmarkDataset = new Dictionary <string, Dictionary <DateTime, ITradingData> >(); if (request.Country == "JP") { var index = context.Indices.Where(x => x.AssetCode == assetCode && x.CreatedAt >= startDate && x.CreatedAt <= endDate); if (0 < index.Count()) { index.ToList().ForEach(x => tradingDataset.Add(x.CreatedAt, x)); } } else if (request.Country == "KR") { var index = context.KoreaIndices.Where(x => x.AssetCode == assetCode && x.CreatedAt >= startDate && x.CreatedAt <= endDate); if (0 < index.Count()) { index.ToList().ForEach(x => tradingDataset.Add(x.CreatedAt, x)); } } benchmarkDataset.Add(assetCode, tradingDataset); var strategy = new BuyAndHold(); var benchmark = new Dictionary <string, PortfolioSubject>(); benchmark.Add(assetCode, request.Benchmark); var report = strategy.Run(benchmarkDataset, tradingCalendar, property, benchmark, period: Period.Day, isBenchmark: true); reports.Add(report); } }