public async Task PopulateDividends(Stock stock, HistoricalData historicalData) { var dividendsHistory = await Task.Run(() => _yahooFinanceDataSource.GetDividendsData(stock, historicalData.BeginDate, historicalData.EndDate)); dividendsHistory.ForEach(dividend => { historicalData.Quotes.FirstOrDefault(x => x.Key >= dividend.Date).Value.Dividend = dividend.Div; }); }
private ICustomData <double, bool> CreateAndFillCross(HistoricalData currentData, ICustomData <double, double> a, ReferenceSeries b, CrossDirection direction) { CrossDataSeries.Insert(0, new CROSS(a, b.Name, direction)); (CrossDataSeries[0] as DataSeries <double, bool>).GetHistoricalData(currentData); FillCross(currentData, a); CrossDataSeries[0].GetValue(b.Value); return(CrossDataSeries[0]); }
public override void Send(HistoricalDataRequest request) { if (base.IsDisconnected) { base.EmitHistoricalDataEnd(request.RequestId, RequestResult.Error, "Provider is not connected."); Log.Error("Provider is not connected."); return; } var _list = new List <DataObject>(); switch (request.DataType) { case DataObjectType.Trade: _list = RequestTrade(request); break; case DataObjectType.Quote: _list = RequestQuote(request); break; case DataObjectType.Bar: _list = RequestBar(request); break; } List <DataObject> list = new List <DataObject>(); for (int i = 0; i < _list.Count; i++) { DataObject item = _list[i]; if ((item.DateTime >= request.DateTime1) && (item.DateTime < request.DateTime2)) { list.Add(item); } } // 对数据过滤一下,然后判断是否有数据 if (list.Count == 0) { base.EmitHistoricalDataEnd(request.RequestId, RequestResult.Completed, "No data"); return; } if (list.Count > 0) { HistoricalData data = new HistoricalData { RequestId = request.RequestId, Objects = list.ToArray(), TotalNum = list.Count }; base.EmitHistoricalData(data); } base.EmitHistoricalDataEnd(request.RequestId, RequestResult.Completed, "Completed"); }
void AddHistoricalData(HistoricalData hData) { if (dbContext.Database.CurrentTransaction == null) { dbContextTransaction = dbContext.Database.BeginTransaction(); } // insert into HistoricalData table dbContext.SaveChanges(); }
/// <summary> /// Populate 6 month standard deviation /// </summary> public static double GetPriceRangeStdDevFor6Months(this HistoricalData data) { DateTime last6Months = DateTime.UtcNow.AddMonths(-6).Date; int index = ((IReadOnlyList <DateTime>)data.Date).FirstAndIndex(item => item >= last6Months).Item1; List <double> highPrices = data.High.Skip(index).ToList(); List <double> lowPrices = data.Low.Skip(index).ToList(); double rangeStdDev = ArrayStatistics.StandardDeviation(highPrices.Select((item, i) => item - lowPrices[i]).ToArray()); return(rangeStdDev); }
private ICustomData <double, double> CreateAndFillMA(HistoricalData currentData, MAMode MAMode, int period, PriceType type, string name) { this.AppendMa(currentData, MAMode, period, name); FillMA(currentData, type); BuiltInIndicatorDataSeries[0].GetValue(currentData.GetValue(type, 0)); return(BuiltInIndicatorDataSeries[0]); }
private ICustomData <double, double> CreateMomentum(HistoricalData currentData, int period, string name, double value) { BuiltInIndicatorDataSeries.Insert(0, new MOM(period, name)); (BuiltInIndicatorDataSeries[0] as DataSeries <double, double>).GetHistoricalData(currentData); BuiltInIndicatorDataSeries[0].GetValue(value); return(BuiltInIndicatorDataSeries[0]); }
private static TickerData ProcessHistDataByTicker(HistoricalData data, string quoteSymbol) { float avgDev = 0; bool basing = true; if (data?.chart?.result == null) { return(null); } if (data.chart.result.Count < 1) { return(null); } List <double> close = data.chart.result[0].indicators.quote[0].close; if (close == null) { return(null); } float avg = (float)close.Average(); float support = avg - (avg * _Range); float resistance = avg + (avg * _Range); foreach (double p in close) { float newDev = (float)Math.Abs((p - avg) / avg); if (p > resistance || p < support) { basing = false; } avgDev += newDev; } avgDev /= close.Count; if (avgDev > 0.05f) { basing = false; } if (basing && avgDev != 0.0f) { TickerData ticker = new TickerData(); ticker.Deviation = avgDev * 1000; ticker.Resistance = resistance; ticker.Support = support; ticker.Ticker = quoteSymbol; return(ticker); } return(null); }
/// <summary> /// Override this method only if you want to provide more efficient way to take <paramref name="last"/> signals /// </summary> protected virtual List <Signal> GetSignals(HistoricalData historicalData, List <Signal> dependencySignals = null, int?last = null) { List <Signal> signals = GetSignalsBase(historicalData, dependencySignals); if (last.HasValue) { signals = signals.Take(last.Value).ToList(); } return(signals); }
private static Selection ToCodeSelection(HistoricalData data) { return(new Selection { BarCount = data.Bars.Count, DataFeed = data.DataFeed, Symbol = data.Symbol, TimeFactor = data.Interval, Timeframe = ToExternalPeriodicity(data.Periodicity), MarketDataSlot = data.Slot }); }
/// <summary> /// Append new tick to Data Provider and run User Code /// </summary> /// <param name="tick"></param> /// <param name="data"></param> public void AppendTick(Quote tick, HistoricalData data) { if (_dataProvider != null) { ((DataProvider)_dataProvider).AppendTick(tick, data); } if (_selectedData != null && _selectedData.Any(i => i.SecurityID == data.SecurityID && i.DataFeed == data.DataFeed)) { RunOnNewQuote(data); } }
public string Insert(HistoricalData entity) { try { ExecuteInsert("HistoricalData.InsertHistoricalData", entity); return("true"); } catch (Exception e) { return(e.Message); } }
private void btnCreateSimulatedData_Click(object sender, RoutedEventArgs e) { var wnd = new wndCreateSimulatedData(); var res = wnd.ShowDialog(); if (!res.HasValue || !res.Value) { return; } if (HistoricalData.Any(p => p.Symbol.Equals(wnd.Symbol) && p.DataFeed.Equals(wnd.DataFeed) && p.Periodicity == wnd.Periodicity && p.Interval == wnd.Interval)) { MessageBox.Show("Historical data with same parameters already loaded", "Info", MessageBoxButton.OK, MessageBoxImage.Information); return; } var data = GlobalHelper.CreateSimulated(new SimulatedDataParameters { Symbol = wnd.Symbol, SecurityId = wnd.SecurityID, DataFeed = wnd.DataFeed, Periodicity = wnd.Periodicity, Interval = wnd.Interval, BarsCount = wnd.BarsCount, TicksCount = wnd.TicksCount, MarketLevels = wnd.MarketLevels, PriceMax = wnd.PriceMax, PriceMin = wnd.PriceMin, Slot = wnd.Slot }); ////optional //var questionResult = MessageBox.Show("Save simulated data to CSV file?", "Question", // MessageBoxButton.YesNoCancel, MessageBoxImage.Question); //if (questionResult == MessageBoxResult.Yes) //{ // var saveFileDialog = new SaveFileDialog(); // saveFileDialog.Filter = "CSV Files|*.csv"; // saveFileDialog.FilterIndex = 1; // saveFileDialog.RestoreDirectory = true; // saveFileDialog.FileName = data.ToString().Replace('/', '-'); // if (saveFileDialog.ShowDialog().Value) // { // using (var writer = File.CreateText(saveFileDialog.FileName)) // writer.Write(GlobalHelper.CreateCSV(data)); // } //} HistoricalData.Add(data); }
protected override List <Signal> GetSignalsBase(HistoricalData historicalData, List <Signal> dependencySignals = null) { int outBegIdx; int outNbElement; double[] outVolOfVol; GetVolOfVol(historicalData.Close, out outBegIdx, out outNbElement, out outVolOfVol); List <Signal> signals = GetSignals(historicalData.SecurityCode, outVolOfVol, historicalData.Date, outBegIdx, outNbElement); return(signals); }
public override Task <bool?> ShouldBuyStock(StockInput newData) { HistoricalData.Add(newData); var modelBuilder = new ModelBuilder(_config); var model = modelBuilder.BuildModel(HistoricalData.Select(x => new ModelInput { PriceDiffrence = (float)((x.ClosingPrice - HistoricalData.Last().ClosingPrice) / HistoricalData.Last().ClosingPrice), Time = x.Time }).ToList()); var result = model.Predict(); return(Task.FromResult((bool?)(result.ForecastedPriceDiffrence[0] > 0))); }
private Workspace GetWorkspace() { return(new Workspace { Bid = Bid, Ask = Ask, BidSize = BidSize, AskSize = AskSize, Date = Date, Accounts = Accounts.ToList(), HistoricalDataCollections = HistoricalData.ToList(), }); }
public (Stack <decimal> originalNumbers, HistoricalData historyData) Operate(Stack <decimal> numbers, Stack <HistoricalData> historicalDataStack) { var history = new Stack <decimal>(); while (numbers.TryPop(out var number)) { history.Push(number); } // todo: check 'clear' is enable to be 'undo' operation. var historyData = new HistoricalData(history, _operationName, 0); return(numbers, historyData); }
public override void Update(TickStatus args) { if (HistoryDataSeries.Count == 1) { var timeRequest = HistoryDataSeries.HistoricalRequest as TimeHistoricalRequest; if (timeRequest == null) { return; } var interval = new Interval(HistoryDataSeries.GetTimeUtc(HistoryDataSeries.Count - 1), DateTime.UtcNow); hd1 = HistoryDataSeries; hd2 = HistoricalDataManager.Get(timeRequest.GetRequest(instrument2), interval); } }
private void RunOnNewQuote(HistoricalData data) { try { var msc = DateTime.UtcNow; if (Code is IndicatorBase) { var indicator = Code as IndicatorBase; var res = indicator.Calculate(); var seconds = (DateTime.UtcNow - msc); var seriesLength = indicator.Series.Select(series => series.Length).ToList(); var maxRecords = seriesLength.Count > 0 ? seriesLength.Max() : 0; RaiseOutput(String .Format(" > On new quote run: series count - {0}, records count - {1}, {2} items recalculated, time: {3}", indicator.Series.Count, maxRecords, res, seconds.ToString("g"))); } else if (Code is SignalBase) { var signal = Code as SignalBase; if (signal.StartMethod != StartMethod.NewQuote || !signal.IsReadyToRun) { return; } if (signal.StartMethod == StartMethod.Once && _prevExecution != DateTime.MinValue) { return; } _prevExecution = DateTime.UtcNow; signal.Start(ToCodeSelection(data)); var seconds = (DateTime.UtcNow - msc); RaiseOutput(" > On new quote start, time: " + seconds.ToString("g")); var alerts = Code.GetActualAlerts(); alerts.AddRange(((SimulationBroker)_broker).ActivityLog); foreach (var alert in alerts) { RaiseOutput(" - Alert: " + alert); } } } catch (Exception ex) { RaiseOutput(ex.ToString()); throw; } }
public void InsertTally() { try { LFGuestSystemEntities db = new LFGuestSystemEntities(); HistoricalData tDat = new HistoricalData(); tDat.Id = 1; if (db.HistoricalDatas.Count() > 0) { tDat.Id = db.HistoricalDatas.Max(h => h.Id) + 1; } this.Id = tDat.Id; tDat.Date = this.Date; tDat.Meals = this.Meals; tDat.Guests = this.Guests; tDat.Male = this.Male; tDat.Female = this.Female; tDat.Children = this.Children; tDat.Seniors = this.Seniors; tDat.NativeAm = this.NativeAm; tDat.Hispanic = this.Hispanic; tDat.AfricanAm = this.AfricanAm; tDat.White = this.White; tDat.AsianAm = this.AsianAm; tDat.Unspecified = this.Unspecified; tDat.Appleton = this.Appleton; tDat.Menasha = this.Menasha; tDat.Kimberly = this.Kimberly; tDat.Kaukauna = this.Kaukauna; tDat.LtChute = this.LtChute; tDat.Neenah = this.Neenah; tDat.Other = this.Other; tDat.Weather = this.Weather ?? "Clear"; tDat.Adult = this.Adult; tDat.Temp_F = this.Temp_F; tDat.EventID = this.EventID; tDat.SiteID = this.SiteID; tDat.Comments = this.Comments; tDat.RepeatVisitors = this.RepeatVisitors; db.SaveChanges(); } catch (Exception ex) { throw ex; } }
protected IEnumerable <HistoricalData> RequestHistoricalDaily(string url) { var json = Request(url).Result; if (!(json is JArray)) { yield break; } var jarray = (JArray)json; foreach (var histoDataJson in jarray.Children <JObject>()) { yield return(HistoricalData.FromJson(histoDataJson)); } }
public IEnumerable <HistoricalData> RequestIexRecentStat() { var json = Request(RECENT_URL).Result; if (!(json is JArray)) { yield break; } var jarray = (JArray)json; foreach (var histoDataJson in jarray.Children <JObject>()) { yield return(HistoricalData.FromJson(histoDataJson)); } }
public override bool Equals(object obj) { if (!(obj is LearningProcess)) { return(false); } var tmp = (LearningProcess)obj; return(obj.GetType() == GetType() && Population.SequenceEqual(tmp.Population) && Generation == tmp.Generation && PopulationCount == tmp.PopulationCount && BestIndex == tmp.BestIndex && HistoricalData.SequenceEqual(tmp.HistoricalData) && LearningAlgorithm.Equals(tmp.LearningAlgorithm)); }
/// <summary> /// Creating string for writing in .CSV file /// </summary> /// <param name="data">Simulated historical data</param> public static string CreateCSV(HistoricalData data) { var builder = new StringBuilder(); builder.AppendFormat("{0},{1},{2},{3},{4},{5}{6}", data.Symbol, data.SecurityID, data.DataFeed, data.Periodicity, data.Interval, data.Slot, Environment.NewLine); foreach (var bar in data.Bars) { builder.AppendFormat("{0},{1},{2},{3},{4},{5}{6}", bar.Open, bar.High, bar.Low, bar.MeanClose, bar.MeanVolume, bar.Timestamp.ToString("MM/dd/yyyy hh:mm"), Environment.NewLine); } if (data.Quotes.Count == 0) { return(builder.ToString()); } builder.Append("Ticks" + Environment.NewLine); foreach (var quote in data.Quotes) { builder.AppendFormat("{0},{1},{2},{3},{4}{5}", quote.BidPrice, quote.BidSize, quote.AskPrice, quote.AskSize, quote.Time.ToString("MM/dd/yyyy hh:mm:ss"), Environment.NewLine); } var maxCount = data.Quotes.Max(p => p.Level2.Count); if (maxCount == 0) { return(builder.ToString()); } for (var i = 0; i < maxCount - 1; i++) { builder.Append("Ticks" + Environment.NewLine); foreach (var quote in data.Quotes) { if (quote.Level2.Count <= i) { continue; } builder.AppendFormat("{0},{1},{2},{3}{4}", quote.Level2[i].BidPrice, quote.Level2[i].BidSize, quote.Level2[i].AskPrice, quote.Level2[i].AskSize, Environment.NewLine); } } return(builder.ToString()); }
private void OnLoadedHandler(HistoricalData data) { if ((data.HistoricalRequest as TimeHistoricalRequest).Period == Period.Day) { dailyHistory = true; } else if ((data.HistoricalRequest as TimeHistoricalRequest).Period == Period.Week) { weeklyHistory = true; } else if ((data.HistoricalRequest as TimeHistoricalRequest).Period == Period.Month) { monthlyHistory = true; } Process(HistoryDataSeries.Count - 1); }
/// <summary> /// Gets syrah term signals (short and long) /// </summary> /// <returns>Item1 - syrah short term signals, Item2 - syrah long term signals</returns> public Tuple <List <Signal>, List <Signal> > GetSentiments(List <HistoricalQuote> historicalQuotes2Years) { IIndicator syrahSentimentShortTerm = new SyrahSentiment(SyrahSentiment.TermValue.ShortTerm); IIndicator syrahSentimenLongTerm = new SyrahSentiment(SyrahSentiment.TermValue.LongTerm); HistoricalData historicalData2Years = new HistoricalData(historicalQuotes2Years); List <Signal> signals = _signalsProxyService.GetSignals(historicalData2Years, new List <IIndicator> { syrahSentimentShortTerm, syrahSentimenLongTerm }, null); List <Signal> syrahShortTermSignals = signals.ForIndicator(syrahSentimentShortTerm).OrderBy(signal => signal.Date).ToList(); List <Signal> syrahLongTermSignals = signals.ForIndicator(syrahSentimenLongTerm).OrderBy(signal => signal.Date).ToList(); Tuple <List <Signal>, List <Signal> > result = new Tuple <List <Signal>, List <Signal> >(syrahShortTermSignals, syrahLongTermSignals); return(result); }
public override Task <bool?> ShouldBuyStock(StockInput newData) { HistoricalData.Add(newData); if (HistoricalData.Count > 20) { HistoricalData = HistoricalData.OrderByDescending(x => x.Time).Take(20).ToList(); var avg = HistoricalData.Select(x => x.ClosingPrice).Average(); var diff = avg - newData.ClosingPrice; return(Task.FromResult <bool?>(diff >= 0)); } else { Console.WriteLine($"Waiting on more data for {GetType().Name}."); return(Task.FromResult <bool?>(null)); } }
public ICustomData <double, bool> CreateOrUpdateCross(HistoricalData currentData, ICustomData <double, double> a, ReferenceSeries b, CrossDirection direction) { ICustomData <double, bool> result; string name = direction == CrossDirection.Down ? a.Name + CrossPartialName + b.Name : b.Name + CrossPartialName + a.Name; int findResult = CrossDataSeries.FindIndex(x => x.Name == name); if (findResult != -1) { CrossDataSeries[findResult].GetValue(b.Value); result = CrossDataSeries[findResult]; } else { result = CreateAndFillCross(currentData, a, b, direction); } return(result); }
private void GenerateTradeIdeasForSymbol(string symbol) { List <HistoricalQuote> historicalQuotes1YearsResponse = _marketDataService.GetHistoricalQuotes(symbol, "1y"); if (historicalQuotes1YearsResponse.Count == 0) { return; } HistoricalData historicalData1Year = null; if (!historicalQuotes1YearsResponse.IsNullOrEmpty()) { historicalData1Year = new HistoricalData(historicalQuotes1YearsResponse); } List <Signal> signals = _signalsProxyService.GetSignals(historicalData1Year, _indicatorsToCalculate, _lastSignalsCountForTradeIdeas); _tradeIdeasGenerator.GenerateTradeIdeas(signals, historicalQuotes1YearsResponse); }
protected override void OnRun() { if (symbol == null || account == null || symbol.ConnectionId != account.ConnectionId) { Log("Incorrect input parameters... Symbol or Account are not specified or they have diffent connectionID.", StrategyLoggingLevel.Error); return; } this.symbol.NewQuote += this.QuoteHandler; this.indicatorFastMA = Core.Instance.Indicators.BuiltIn.SMA(this.fastMA, PriceType.Close); this.indicatorSlowMA = Core.Instance.Indicators.BuiltIn.SMA(this.slowMA, PriceType.Close); this.hdm = this.symbol.GetHistory(period, this.symbol.HistoryType, DateTime.UtcNow.AddDays(-100)); this.hdm.AddIndicator(this.indicatorFastMA); this.hdm.AddIndicator(this.indicatorSlowMA); }
internal OnHistoricalData(HistoricalData data) { this.data = data; }