public Operations calcaulate(History history, DateTime date, Holds holds) { Operations operations = new Operations(); foreach (Hold hold in holds.holds) { var day = history.getDay(hold.stockName, date); if (day == null) { continue; } if (hold.buyTime.AddDays(20) > date) { continue; } operations.operations.Add(sell(hold)); } foreach (var stockName in history.stocks.Keys) { DayResult currentDay = history.getDay(stockName, date.AddDays(0)); if (currentDay == null || currentDay.volume == 0) { continue; } DateTime currentDate = currentDay.date; operations.operations.Add(buy(stockName, currentDay.adjClose, holds.cash)); } return(operations); }
public Operations calcaulate(History history, DateTime date, Holds holds) { Operations operations = new Operations(); foreach (Hold hold in holds.holds) { var day = history.getDay(hold.stockName, date); if (day == null) { continue; } decimal currentPrice = day.adjClose; if (currentPrice > hold.buyPrice * (decimal)1.1 || currentPrice < hold.buyPrice * (decimal)0.9) { operations.operations.Add(sell(hold)); } } foreach (var stockName in history.stocks.Keys) { List <DayResult> days = new List <DayResult>(); DayResult currentDay = history.getDay(stockName, date.AddDays(0)); if (currentDay == null || currentDay.volume == 0) { continue; } for (int i = 1; i < 50; i++) { DayResult day = history.getDay(stockName, date.AddDays(-i)); if (day != null && day.volume != 0) { days.Add(day); } } if (days.Count < 20) { continue; } bool isNotMatch = false; foreach (DayResult day in days) { if (day.volume > currentDay.volume / 3) { isNotMatch = true; } if (day.adjClose > currentDay.adjClose) { isNotMatch = true; } if (day.adjClose < currentDay.adjClose * (decimal)0.7) { isNotMatch = true; } } if (currentDay.adjClose * currentDay.volume < 10000000) { isNotMatch = true; } if (isNotMatch) { continue; } operations.operations.Add(buy(stockName, currentDay.adjClose)); } return(operations); }