public override void WriteXml(ref XmlElement parent) { //Create a new Tag node. XmlElement tagElement = parent.OwnerDocument.CreateElement("Tag"); tagElement.SetAttribute("Name", Name); tagElement.SetAttribute("Description", Description); tagElement.SetAttribute("DataType", DataType.ToString()); tagElement.SetAttribute("Address", Address); tagElement.SetAttribute("Driver", Driver.Id); tagElement.SetAttribute("Historical", Historical.ToString()); tagElement.SetAttribute("SignalCondition", SignalCondition != null ? SignalCondition.Id : String.Empty); tagElement.SetAttribute("Min", Min); tagElement.SetAttribute("Max", Max); tagElement.SetAttribute("LowChk", LowChk.ToString()); tagElement.SetAttribute("LowVl", LowVl); tagElement.SetAttribute("LowMsg", LowMsg); tagElement.SetAttribute("LowLowChk", LowLowChk.ToString()); tagElement.SetAttribute("LowLowVl", LowLowVl); tagElement.SetAttribute("LowLowMsg", LowLowMsg); tagElement.SetAttribute("HiChk", HiChk.ToString()); tagElement.SetAttribute("HiVl", HiVl); tagElement.SetAttribute("HiMsg", HiMsg); tagElement.SetAttribute("HiHiChk", HiHiChk.ToString()); tagElement.SetAttribute("HiHiVl", HiHiVl); tagElement.SetAttribute("HiHiMsg", HiHiMsg); parent.AppendChild(tagElement); }
/// <summary> /// Gets the historical price. /// </summary> /// <param name="symbol">The symbol seen like 2330.TW, but don't need .TW to add.</param> /// <param name="start">The start Datetime.</param> /// <param name="end">The end Datetime.</param> /// <returns></returns> public async Task <List <StockHistoricalPrice> > YahooGetHistoricalPrice( string symbolType, string symbol, DateTime start, DateTime end) { //first get a valid token from Yahoo Finance while (string.IsNullOrEmpty(Token.Cookie) || string.IsNullOrEmpty(Token.Crumb)) { await Token.RefreshAsync().ConfigureAwait(false); } List <HistoryPrice> hps = await Historical.GetPriceAsync(symbol + symbolType, start, end).ConfigureAwait(false); //Historyprice轉換為HistoryPriceExtStkCode類型, 新增StkCode後傳回 List <StockHistoricalPrice> shpList = new List <StockHistoricalPrice>(); foreach (HistoryPrice hp in hps) { shpList.Add( new StockHistoricalPrice( symbol, hp.Date, (decimal)hp.Open, (decimal)hp.High, (decimal)hp.Low, (decimal)hp.Close, (decimal)hp.Volume)); } return(shpList); }
public HistoricalData GetHistoricalData(Stock stock, DateTime startDate, DateTime endDate) { var rawHistoricalData = new List <HistoryPrice>(); var numberOfTries = 0; while (rawHistoricalData.Count == 0 && numberOfTries < 4) { rawHistoricalData = Historical.GetPriceAsync(this.GetSymbol(stock), startDate, endDate).Result; numberOfTries++; } var historicalData = rawHistoricalData.GroupBy(x => x.Date).Select(grp => grp.First()); var quotes = new SortedList <DateTime, Quote>( historicalData.ToDictionary( x => x.Date, x => new Quote { Date = x.Date, Open = x.Open, Close = x.Close, AdjClose = x.AdjClose, Low = x.Low, High = x.High, Volume = x.Volume })); return(new HistoricalData(quotes) { Id = stock.GetUniqueId() }); }
public HttpStatusCode saveHistoricalData(string id) // convert to json { var response = new HttpResponseMessage(); HttpStatusCode res; try { Historical historical = Historical.Deserialize(id); bool idExists = _stockScreenerService.HistoricalIdExists(historical.Id); if (idExists) { return(HttpStatusCode.Ambiguous); } _stockScreenerService.Create(historical); res = response.StatusCode; } catch (Exception ex) { if (ex is System.ArgumentNullException) { Console.WriteLine("Exception " + ex); } Console.WriteLine("Exception " + ex); res = response.StatusCode; } return(res); }
public async Task GetPriceAsyncTest() { var prices = await Historical.GetPriceAsync(Symbol, DateTime.Now.AddYears(-1), DateTime.Now).ConfigureAwait(false); Assert.NotNull(prices); Assert.IsTrue(prices.Any()); Assert.IsTrue(prices[0].Close > 0); }
public async Task GetDividendAsyncTest() { var dividends = await Historical.GetDividendAsync(Symbol, DateTime.Now.AddYears(-2), DateTime.Now).ConfigureAwait(false); Assert.NotNull(dividends); Assert.IsTrue(dividends.Any()); Assert.IsTrue(dividends[0].Div > 0); }
public void DatasetAlreadyExistGoodParameters2(int dataset) { Historical historyObj = historyMock.Object; historyObj.UpisanDataset[dataset] = true; Assert.True(historyMock.Object.DatasetAlreadyExists(dataset)); }
public void FillHistoryComponentNullParameters() { historyMock = new Mock <Historical>(); Historical historyObj = historyMock.Object; Assert.Throws <ArgumentNullException>(() => { historyObj.FillHistoryComponent(null); }); }
public void ReadDirectlyFromClientNullParameters(string code, int dataset) { historyMock = new Mock <Historical>(); Historical historyObj = historyMock.Object; Assert.Throws <ArgumentNullException>(() => { historyObj.ReadDirectlyFromClient(code, null, dataset); }); }
public void ReadFromHistoricalConverterNullParameters() { historyMock = new Mock <Historical>(); Historical historyObj = historyMock.Object; Assert.Throws <ArgumentNullException>(() => { historyObj.ReadFromHistoricalConverter(null); }); }
public void DatasetAlreadyExistBadParameters(int dataset) { historyMock = new Mock <Historical>(); Historical historyObject = historyMock.Object; Assert.Throws <ArgumentException>(() => { historyObject.DatasetAlreadyExists(dataset); }); }
private List <HistoryPrice> getHistoricalPrice(string symbol, DateTime from, DateTime until) { //first get a valid token from Yahoo Finance while (string.IsNullOrEmpty(Token.Cookie) || string.IsNullOrEmpty(Token.Crumb)) { Token.Refresh(); } return(Historical.Get(symbol, from, until)); }
public void RemoveDatasetNullParameters( ) { historyMock = new Mock <Historical>(); Historical historyObj = historyMock.Object; Assert.Throws <ArgumentNullException>(() => { historyObj.RemoveDataset(null); }); }
public override dynamic Create(GroupBox g) { Historical h = new Historical(base.Create(g)); GroupBox histGroupBox = ((Grid)g.Content).Children.OfType <GroupBox>().First(x => x.Name == "HistoricalGroup"); IEnumerable <TextBox> tbList = ((Grid)histGroupBox.Content).Children.OfType <TextBox>(); h.Period = tbList.First(x => x.Name == "InpHistPeriod").Text; h.Genre = "Historical"; return(h); }
public void CheckDeadbandDifferenceNullParameters() { historyMock = new Mock <Historical>(); Historical historyObj = historyMock.Object; Assert.Throws <ArgumentNullException>(() => { historyObj.CheckDeadBand(null); }); }
public void DatasetAlreadyExistBadParameters(int dataset) { hcMock = new Mock <HistoricalConverter>(); HistoricalConverter hObj = hcMock.Object; Historical history = new Historical(); history.UpisanDataset[dataset] = false; hObj.History = history; Assert.False(hObj.DatasetAlreadyExist(dataset)); }
private async Task GetRawHistoricalPrice(string symbol) { //first get a valid token from Yahoo Finance while (string.IsNullOrEmpty(Token.Cookie) || string.IsNullOrEmpty(Token.Crumb)) { await Token.RefreshAsync().ConfigureAwait(false); } csvdata = await Historical.GetRawAsync(symbol, DateTime.Now.AddMonths(-1), DateTime.Now).ConfigureAwait(false); //process further }
public async Task <List <StockData> > GetHistoricalDataAsync( string stockSymbol, DateTime startDate) { var historicalData = await Historical.GetPriceAsync(stockSymbol, startDate, DateTime.Now).ConfigureAwait(false); return(historicalData?.Select( x => new StockData { Date = x.Date, Open = x.Open, Close = x.Close, High = x.High, Low = x.Low }) .ToList()); }
private static void Sim_OnNeedData(object sender, Simulator.Simulator.NeedDataEventArgs e) { decimal?val = null; while (string.IsNullOrEmpty(Token.Cookie) || string.IsNullOrEmpty(Token.Crumb)) { Token.RefreshAsync().ConfigureAwait(false).GetAwaiter().GetResult(); } var sym = e.Symbol.Replace(" ", "-") + ".ST"; var data = Historical.GetPriceAsync(sym, e.Date.Date.AddDays(-5), e.Date.Date.AddDays(5)).ConfigureAwait(false).GetAwaiter().GetResult(); if (!data.Any()) { Token.RefreshAsync().ConfigureAwait(false).GetAwaiter().GetResult(); data = Historical.GetPriceAsync(sym, e.Date.Date.AddDays(-5), e.Date.Date.AddDays(5)).ConfigureAwait(false).GetAwaiter().GetResult(); } var p = data.FirstOrDefault(d => d.Date.Equals(e.Date.Date)); if (p != null) { switch (e.Point.ToLower()) { case "c": val = (decimal)p.Close; break; case "o": val = (decimal)p.Open; break; } } var adt = data.Average(d => d.Volume); if (val.HasValue) { var tickSize = GetTickSize(val.Value, (int)Math.Round(adt)); val = Math.Round(val.Value / tickSize) * tickSize; } while (!val.HasValue) { Console.Write($"{e.Message}: "); var str = Console.ReadLine(); if (decimal.TryParse(str, out var x)) { val = x; } } e.Data = val.Value; }
public async void FetchEurostralHisto(DateTime debut, int freq, DateTime fin) { done = false; string symbolEurostral = "FR0012034023.PA"; while (string.IsNullOrEmpty(Token.Cookie) || string.IsNullOrEmpty(Token.Crumb)) { await Token.RefreshAsync().ConfigureAwait(false); } cour = await Historical.GetRawAsync(symbolEurostral, dateDebut, dateFin).ConfigureAwait(false); cour = cour.Replace(",", ";"); done = true; }
public int Direction(double[] state) { var sta = new State { Values = state, Occurrence = 1, Output = -1 }; lastKey = Tembo.GetId(); Historical.Add(lastKey, sta); lastAction = dqnAgent.Act(state); return(lastAction); }
public void CheckDeadbandDifferenceGoodParameters2(string code) { Mock <HistoricalProperty> hp = new Mock <HistoricalProperty>(); historyMock = new Mock <Historical>(); Historical historyObj = historyMock.Object; HistoricalProperty hpObj = hp.Object; hpObj.Code = code; hpObj.HistoricalValue = new Value("1212", 1); hpObj.HistoricalValue.Timestamp = DateTime.Now; Assert.False(historyObj.CheckDeadBand(hpObj)); }
public List <HistoryPrice> HistPrices() { // first get valid token from yahoo finance while (string.IsNullOrEmpty(Token.Cookie) | string.IsNullOrEmpty(Token.Crumb)) { Token.Refresh(); } List <HistoryPrice> histprices = Historical.Get(Ticker, Start, End); //histprices.Reverse(); return(histprices); }
public void ReadDirectlyFromClientBadParameters(string code, int dataset) { historyMock = new Mock <Historical>(); Historical historyObj = historyMock.Object; Mock <Value> mockVal = new Mock <Value>("4141", 100); Value objVal = mockVal.Object; objVal.Timestamp = DateTime.Now; Assert.Throws <ArgumentException>(() => { historyObj.ReadDirectlyFromClient(code, objVal, dataset); }); }
public void ReadDirectlyFromClientGoodParameters(string code, int dataset) { historyMock = new Mock <Historical>(); Historical historyObj = historyMock.Object; Mock <Value> mockVal = new Mock <Value>("4141", 100); Value objVal = mockVal.Object; objVal.Timestamp = DateTime.Now; historyObj.ReadDirectlyFromClient(code, objVal, dataset); Assert.AreEqual(historyObj.DescriptionDic[dataset].HistoricalList[0].HistoricalValue.IDGeoPolozaja, objVal.IDGeoPolozaja); Assert.AreEqual(historyObj.DescriptionDic[dataset].HistoricalList[0].HistoricalValue.Potrosnja, objVal.Potrosnja); Assert.AreEqual(historyObj.DescriptionDic[dataset].HistoricalList[0].HistoricalValue.Timestamp, objVal.Timestamp); }
public void Reward(double value, int outPut) { total += 1; if (value > 0) { wins += 1; } var last = Historical.LastOrDefault(); Historical[last.Key].Output = outPut; WinRate = wins / total; RewardCollected += value; dqnAgent.Learn(value); }
private async Task <List <HistoryPrice> > GetHistoricalPrice(string symbol) { //first get a valid token from Yahoo Finance while (string.IsNullOrEmpty(Token.Cookie) || string.IsNullOrEmpty(Token.Crumb)) { await Token.RefreshAsync().ConfigureAwait(false); } List <HistoryPrice> hps = await Historical.GetPriceAsync(symbol, DateTime.Now.AddMonths(-1), DateTime.Now).ConfigureAwait(false); return(hps); //do something }
private void BLearning() { while (true) { if (Historical.Count < 20000) { // Thread.Sleep(TimeSpan.FromMinutes(30)); } var correct = 0.0; var total = 0.0; var options = new AgentOptions { Gamma = Tembo.Random(0.01, 0.99), Epsilon = Tembo.Random(0.01, 0.75), Alpha = Tembo.Random(0.01, 0.99), ExperinceAddEvery = Tembo.RandomInt(1, 10000), ExperienceSize = 0, LearningSteps = Tembo.RandomInt(1, 10), HiddenUnits = Tembo.RandomInt(100000, 100000000), ErrorClamp = Tembo.Random(0.01, 1.0), AdaptiveLearningSteps = true }; var agent = new DQN(dqnAgent.NumberOfStates, dqnAgent.NumberOfActions, options); for (var i = 0; i < Historical.Count; i++) { var spi = Historical.ElementAt(i); var action = agent.Act(spi.Value.Values); if (action == spi.Value.Output) { correct += 1; agent.Learn(1); } else { agent.Learn(-1); } total += 1; } var winrate = (correct / total) * 100; if (winrate > WinRate) { CN.Log($"NEW AGENT DISCOVERED --> WINRATE {winrate.ToString("p")}, CLASS: {AgentName}", 2); Save(); dqnAgent = agent; WinRate = winrate; } } }
private async Task GetYahooCSV() { for (int i = 0; i < Symbols.Count; i++) { while (string.IsNullOrEmpty(Token.Cookie) || string.IsNullOrEmpty(Token.Crumb)) { await Token.RefreshAsync().ConfigureAwait(false); } string csvdata = await Historical.GetRawAsync(Symbols[i], dateDebut, dateFin).ConfigureAwait(false); csvdata = csvdata.Replace(",", ";"); RawData.Add(csvdata); //System.IO.File.WriteAllText(Files[i], csvdata); } }
public void HistoricalCandleData() { var timeStamp = new DateTimeOffset(2021, 06, 11, 9, 15, 0, new TimeSpan(5, 30, 0)); List <object> param = new List <object>() { timeStamp, "1575", "1610.5", "1572", "1608.75", "2179" }; var expectedCandleData = new Historical(param); Assert.AreEqual(new DateTime(2021, 06, 11, 3, 45, 0), expectedCandleData.TimeStamp); Assert.AreEqual(1575, expectedCandleData.Open); Assert.AreEqual(1610.5, expectedCandleData.High); Assert.AreEqual(1572, expectedCandleData.Low); Assert.AreEqual(1608.75, expectedCandleData.Close); Assert.AreEqual(2179, expectedCandleData.Volume); }