/// <summary> /// Gets the historic prices for a stock /// </summary> /// <param name="stock">The stock to collect prices for</param> /// <param name="lastRetrieveDate">The date last retrieved</param> private void GetPricesForStock(Stock stock, DateTime lastRetrieveDate) { List <DailyPrice> historicPrices = this.yahooHistoricWebStockEngine.Fetch(stock, lastRetrieveDate); using (StockBanditDataContext dataContext = new StockBanditDataContext()) { // If different add to queue. foreach (DailyPrice dailyPrice in historicPrices) { // Find price for today DailyPrice existingPrice = dataContext.DailyPrices.FirstOrDefault( p => p.Date == dailyPrice.Date && p.StockCode == stock.StockCode); if (existingPrice != null) { existingPrice.High = dailyPrice.High; existingPrice.Low = dailyPrice.Low; existingPrice.Open = dailyPrice.Open; existingPrice.Close = dailyPrice.Close; existingPrice.Volume = dailyPrice.Volume; existingPrice.AdjustedClose = dailyPrice.AdjustedClose; } else { dataContext.DailyPrices.InsertOnSubmit(dailyPrice); } dataContext.SubmitChanges(); } } }
/// <summary> /// Evaluates a stock to check against this model /// </summary> /// <param name="stock">The stock to check</param> /// <param name="historicPrices">The last prices to use in the model</param> /// <param name="emailBody">An output of the email text to append to the email</param> /// <returns>A flag indicating if the stock evaluated to being above volume</returns> public bool Evaluate(Stock stock, List <DailyPrice> historicPrices, out string emailBody) { if (historicPrices.Count > 0) { this.logQueue.QueueLogEntry(new LogEntry(DateTime.Now, LogType.Info, string.Format("VolumeModel Evaluation of {0} with {1} historic prices.", stock.StockCode, historicPrices.Count))); DailyPrice todayPrice = historicPrices.First(); // Current average price var averageVolume = historicPrices .Take(90) .Select(p => p.Volume) .Average(); if (todayPrice.Volume > (averageVolume * this.alertThreshold)) { // Check the trend and ignore downward trends double slope = 0.0; if (this.CheckUpwardTrend(historicPrices.Take(90).ToList(), out slope)) { // Volume indicates a shift in movement soon emailBody = string.Format( "Stock: {0}\r\nPrice: {1}\r\nVolume: {2}\r\nAverage Volume: {3}\r\nSlope: {4}\r\n\r\n", stock.StockCode, todayPrice.Close, todayPrice.Volume, Math.Round(averageVolume, 0), Math.Round(slope, 2)); this.logQueue.QueueLogEntry(new LogEntry(DateTime.Now, LogType.Info, emailBody)); return(true); } } this.logQueue.QueueLogEntry(new LogEntry(DateTime.Now, LogType.Info, string.Format("Finished VolumeModel Evaluation of {0} with {1} historic prices.", stock.StockCode, historicPrices.Count))); emailBody = null; return(false); } this.logQueue.QueueLogEntry(new LogEntry(DateTime.Now, LogType.Error, string.Format("No historic prices found for: {0}", stock.StockCode))); emailBody = null; return(false); }
private void detach_DailyPrices(DailyPrice entity) { this.SendPropertyChanging(); entity.Stock = null; }
private void attach_DailyPrices(DailyPrice entity) { this.SendPropertyChanging(); entity.Stock = this; }
partial void DeleteDailyPrice(DailyPrice instance);
partial void UpdateDailyPrice(DailyPrice instance);
partial void InsertDailyPrice(DailyPrice instance);