public string GetCharMapping(IStockHistory hist) { string totalMapping = ""; DateTime startDate = hist.MinDate; DateTime endDate = hist.MaxDate; while (startDate < endDate) { IStockData todayData = hist.GetStock(startDate); IStockData pervData = hist.GetPrevDayStock(startDate); if (todayData == null) { startDate = DateFunc.GetNextWorkday(startDate); continue; } string s = ParseChars(pervData, todayData); if (!string.IsNullOrEmpty(s)) { totalMapping += s + "|"; } startDate = DateFunc.GetNextWorkday(startDate); } return(totalMapping); }
public string GetCharMapping(IStockHistory hist) { string totalMapping = ""; DateTime startDate = hist.MinDate; DateTime endDate = hist.MaxDate; while (startDate < endDate) { IStockData todayData = hist.GetStock(startDate); IStockData pervData = hist.GetPrevDayStock(startDate); if (todayData == null) { startDate = DateFunc.GetNextWorkday(startDate); continue; } string s = ParseChars(pervData, todayData); if (!string.IsNullOrEmpty(s)) { totalMapping += s + "|"; } startDate = DateFunc.GetNextWorkday(startDate); } return totalMapping; }
public void Go(IStockHistory history, IStrategyFactory strategies) { History_ = history; foreach (IFinanceStrategy strategy in strategies.AllStrategies) { ExecTask(strategy); } }
private const double INITCASH = 100000; // 初始化的账户金额 public void Go(IStockHistory history, IStrategyFactory strategies) { History_ = history; foreach (IFinanceStrategy strategy in strategies.AllStrategies) { ExecTask(strategy); } }
public void Update(IStockHistory entity) { StockHistory dbStock = dbContext.StockHistories.Where(s => s.Id == entity.Id).FirstOrDefault(); dbStock.Price = entity.Price; dbStock.StockId = entity.StockId; dbStock.ObservationTime = entity.ObservationTime; dbStock.IsEod = entity.IsEod; dbContext.SaveChanges(); }
public void Calc(IStockHistory hist) { DateTime startDate = hist.MinDate; DateTime endDate = hist.MaxDate; while (startDate < endDate) { IStockData stock = hist.GetStock(startDate); CalculateSignal(startDate, stock); startDate = DateFunc.GetNextWorkday(startDate); } }
/// <summary> /// Add stock data from a stock history /// </summary> /// <param name="hist">a stock history</param> public void Calc(IStockHistory hist) { DateTime startDate = hist.MinDate; DateTime endDate = hist.MaxDate; while (startDate < endDate) { IStockData stock = hist.GetStock(startDate); results_.AddStockData(stock); startDate = startDate.AddDays(1); } }
/// <summary> /// Calculate score of each strategy /// </summary> /// <param name="history">One stock history</param> /// <param name="factory">Strategy Factory</param> /// <param name="reader">Bonus imformation</param> public void Calc(IStockHistory history, IStrategyFactory factory, IBonusProcessor reader) { FinanceRunner runner = new FinanceRunner(); runner.CurrentBonusProcessor = reader; runner.Go(history, factory); IStrategyJudger judger = new StrategyJudger(); judger.Judge(runner.Results); IStrategyJudger judger2 = new ValidationJudger(); judger2.Judge(runner.Results); AllScores_.AddRange(judger.ScoresArr); AllScores_.AddRange(judger2.ScoresArr); }
/// <summary> /// 查看指定的历史的匹配 /// </summary> /// <param name="hist">一段时间的股票走势</param> public void FindMatches(IStockHistory hist) { string s = StringMapping_.GetCharMapping(hist); if (string.IsNullOrEmpty(s)) { return; } var findResult = (from item in StockMappings_ where item.Contains(s) select item); foreach (var item in findResult) { AnalyzeNextDay(item, s); } PrintResult(); }
void AnalyseHistory() { // Load from DB IEnumerable <int> allStockId = new List <int> { 600238, 600239, 600240, 600007, 600008, 600009, 600010, 600019, 600020, 600021, 600022 }; StocksHistory histories = new StocksHistory(); histories.Load(allStockId); StockCharMappingAnalyzer analyzer = new StockCharMappingAnalyzer(); analyzer.Init(histories); int firstId = 0; foreach (int stockId in allStockId) { firstId = stockId; break; } IStockHistory history = histories.GetHistory(firstId); if (history == null) { return; } IStockHistory oneWeekHistory = history.GetPartStockHistory(history.MaxDate.AddDays(-7), history.MaxDate); if (oneWeekHistory == null) { return; } analyzer.FindMatches(oneWeekHistory); }
public ICollection <StockVertex> FindVertex(IStockHistory hist) { Dictionary <int, StockVertex> datePosToVertex = new Dictionary <int, StockVertex>(); //List<StockVertex> vertexes = new List<StockVertex>(); Vertexes vertexes = new Vertexes(); //FixedSizeLinkedList<IStockData> fixedvertexes = new FixedSizeLinkedList<IStockData>(TIME_WINDOW_MARGIN); FixedSizeLinkedList <SortStock> fixedvertexes = new FixedSizeLinkedList <SortStock>(TIME_WINDOW_MARGIN); FixedSizeLinkedList <SortStock> fixedvertexesmin = new FixedSizeLinkedList <SortStock>(TIME_WINDOW_MARGIN); DateTime startDate = hist.MinDate; DateTime endDate = hist.MaxDate; int currentIdx = 0; while (startDate < endDate) { IStockData stock = hist.GetStock(startDate); if (stock != null) { fixedvertexes.AddLast(new SortStock(currentIdx, startDate, stock.MaxPrice)); fixedvertexesmin.AddLast(new SortStock(currentIdx, startDate, stock.MinPrice)); } if (fixedvertexes.IsEnough()) { SortStock stockMax = fixedvertexes.FindMax(); SortStock stockMin = fixedvertexesmin.FindMin(); vertexes.Add(CreateVertex(stockMax, VertexType.Max)); vertexes.Add(CreateVertex(stockMin, VertexType.Min)); } startDate = DateFunc.GetNextWorkday(startDate); currentIdx++; } return(vertexes.GetAll()); }
public ICollection<StockVertex> FindVertex(IStockHistory hist) { Dictionary<int, StockVertex> datePosToVertex = new Dictionary<int, StockVertex>(); //List<StockVertex> vertexes = new List<StockVertex>(); Vertexes vertexes = new Vertexes(); //FixedSizeLinkedList<IStockData> fixedvertexes = new FixedSizeLinkedList<IStockData>(TIME_WINDOW_MARGIN); FixedSizeLinkedList<SortStock> fixedvertexes = new FixedSizeLinkedList<SortStock>(TIME_WINDOW_MARGIN); FixedSizeLinkedList<SortStock> fixedvertexesmin = new FixedSizeLinkedList<SortStock>(TIME_WINDOW_MARGIN); DateTime startDate = hist.MinDate; DateTime endDate = hist.MaxDate; int currentIdx = 0; while (startDate < endDate) { IStockData stock = hist.GetStock(startDate); if (stock != null) { fixedvertexes.AddLast(new SortStock(currentIdx, startDate, stock.MaxPrice)); fixedvertexesmin.AddLast(new SortStock(currentIdx, startDate, stock.MinPrice)); } if (fixedvertexes.IsEnough()) { SortStock stockMax = fixedvertexes.FindMax(); SortStock stockMin = fixedvertexesmin.FindMin(); vertexes.Add(CreateVertex(stockMax, VertexType.Max)); vertexes.Add(CreateVertex(stockMin, VertexType.Min)); } startDate = DateFunc.GetNextWorkday(startDate); currentIdx++; } return vertexes.GetAll(); }
public void Add(IStockHistory entity) { dbContext.StockHistories.Add(Mapper.Map <IStockHistory, Data.StockHistory>(entity)); dbContext.SaveChanges(); }
public void Add(IStockHistory entity) { dbContext.StockHistories.Add(Mapper.Map<IStockHistory, Data.StockHistory>(entity)); dbContext.SaveChanges(); }