/// <summary> /// Writes this layer as XML /// </summary> /// <param name="writer">The XML writer</param> public void WriteTo(XmlWriter writer) { writer.WriteStartElement("layer"); writer.WriteAttributeString("input-size", InputSize.ToString()); writer.WriteAttributeString("output-size", OutputSize.ToString()); writer.WriteAttributeString("activation", Activation.ToString()); writer.WriteAttributeString("weight-init", WeightInitialisation.ToString()); writer.WriteAttributeString("regularisation", Regularisation.ToString()); writer.WriteAttributeString("weight-update", WeightUpdate.ToString()); writer.WriteAttributeString("trainer", LayerTrainer.ToString()); writer.WriteAttributeString("lambda", Lambda.ToString()); writer.WriteAttributeString("momentum", Momentum.ToString()); writer.WriteAttributeString("decay-rate", DecayRate.ToString()); writer.WriteAttributeString("decay-rate2", DecayRate2.ToString()); writer.WriteAttributeString("dropout", Dropout.ToString()); if (Bias != null) { Bias.WriteTo("bias", writer); } if (Weight != null) { writer.WriteStartElement("weight"); foreach (var item in Weight) { item.WriteTo("row", writer); } writer.WriteEndElement(); } writer.WriteEndElement(); }
public async Task <IActionResult> GetDailyTimeSeriesAsync(string symbol, OutputSize outputSize = OutputSize.Compact) { var result = await _alphaVantageService.GetDailyTimeSeriesAsync(symbol, outputSize); return(Ok(new { symbol, outputSize = outputSize.ToString(), Data = result, })); }
/// <summary> /// Retrieves quotes from Alpha Vantage API based on ticker and outputSize. /// </summary> /// <param name="ticker">Security ticker. A string.</param> /// <param name="outputSize">Alpha Vantage API response output size. An OutputSize enum.</param> /// <returns>List of serialized Quote objects.</returns> internal async Task <List <Quote> > GetQuotesAsync(string ticker, OutputSize outputSize, CancellationToken cancellationToken) { var outputSizeLowercase = outputSize.ToString().ToLower(); var apiKey = Configuration.GetValue <string>("AlphaVantage:ApiKey"); HttpClient httpClient = HttpClientFactory.CreateClient(); HttpResponseMessage response = await httpClient.GetAsync($"{TimeSeriesDailyAdjustedURL}&symbol={ticker}&outputsize={outputSizeLowercase}&apikey={apiKey}", cancellationToken); response.EnsureSuccessStatusCode(); var responseBody = await response.Content.ReadAsStringAsync(); return(ParseResponseBody(responseBody)); }
public async Task <IActionResult> GetIntradaySeriesAsync(string symbol, Intervals interval, OutputSize outputSize = OutputSize.Full) { var result = await _alphaVantageService.GetIntradaySeriesAsync(symbol, interval, outputSize); return(Ok(new { symbol, interval = interval.ToString(), outputSize = outputSize.ToString(), Data = result, })); }
private void initControls() { TbxIpAddr.Text = IpAddr; TbxUsername.Text = Username; TbxPassword.Text = Password; BtnConnect.Content = "连接"; TbxTest.Text = ""; tbxPlatName.Text = ""; tbxPlatVen.Text = ""; tbxPlatVer.Text = ""; tbxDevName.Text = ""; tbxDevVen.Text = ""; tbxDevVer.Text = ""; tbxDevCU.Text = ""; tbxDevFreq.Text = ""; tbxDevPerf.Text = ""; lbxDevList.Items.Clear(); tbxN.Text = N.ToString(); tbxC.Text = C.ToString(); tbxH.Text = H.ToString(); tbxW.Text = W.ToString(); tbxK.Text = K.ToString(); tbxOutW.Text = OutW.ToString(); tbxOutH.Text = OutH.ToString(); tbxGroupSz.Text = String.Format("{0:D}, {1:D}, 1", group_size_x, group_size_y); tbxGlobalSz.Text = String.Format("{0:D}, {1:D}, 1", global_size_x, global_size_y); tbxPck.Text = pck_order.ToString(); tbxLdsAtomic.Text = c_lds_atomic.ToString(); tbxLdsSplit.Text = c_lds_split.ToString(); tbxL2Atomic.Text = c_l2_atomic.ToString(); tbxL2Split.Text = c_l2_split.ToString(); tbxKoutMaps.Text = k_out_maps.ToString(); tbxInSize.Text = InputSize.ToString(); tbxWeiSize.Text = WeightSize.ToString(); tbxOutSize.Text = OutputSize.ToString(); tbxSigSize.Text = sig_slot_size.ToString(); tbxL2Size.Text = l2_tmp_size.ToString(); tbxElapsed.Text = BestElapsedTime.ToString(); tbxPerf.Text = BestPerformence.ToString(); tbxEffic.Text = BestEfficiency.ToString(); tbxCalcu.Text = Calculation.ToString(); tbxtheore.Text = TheoryElapsedTime.ToString(); tbxProcess.Text = String.Format("Tunning Problem: {0:D}/{1:D}... Searching Kernel: {2:D}/{3:D}...", TunnedProblem, TotalProblem, SearchedKernel, TotalProblem); tbxPercent.Text = String.Format("{0:F2}%", SearchingPercent * 100); btnTensile.IsEnabled = false; }
public async Task DownloadAsync( string symbol, Interval interval, OutputSize outputSize, DirectoryInfo directoryInfo, DateOrder dateOrder, bool timestampFiles = false, string apiKey = "demo") { Console.WriteLine($"Downloading: {symbol}"); var func = ToFunctionIntervalQueryValues(interval); var output = outputSize.ToString().ToLower(); var uri = $"https://www.alphavantage.co/query?{func}&symbol={symbol}&outputsize={output}&datatype=csv&apikey={apiKey}"; var response = await _client.GetAsync(uri); if (!response.IsSuccessStatusCode) { Console.WriteLine($"Failed download for: {symbol}. StatusCode: {response.StatusCode}, Content: {response.Content}"); return; } Console.WriteLine($"Saving: {symbol}"); if (!directoryInfo.Exists) { directoryInfo.Create(); } var data = await response.Content.ReadAsStringAsync(); if (dateOrder == DateOrder.Ascending) { var dataRows = data.Split(Environment.NewLine); data = $"{dataRows[0]}{string.Join(Environment.NewLine, dataRows.Skip(1).Reverse())}"; } var timestampString = timestampFiles ? "_" + DateTime.UtcNow.ToFileTimeUtc() : string.Empty; var fileName = $"{symbol}{timestampString}"; var path = Path.Combine(directoryInfo.FullName, $"{fileName}.csv"); await File.WriteAllTextAsync(path, data); Console.WriteLine($"Stored: {symbol}"); }
/// <summary> /// Imports the async. endTime stock history inclusive /// </summary> /// <returns>The async.</returns> /// <param name="symbol">Symbol.</param> /// <param name="startTime">Start time.</param> /// <param name="endTime">End time.</param> /// <param name="period">Period.</param> /// <param name="token">Token.</param> public async Task <IReadOnlyList <IOhlcv> > ImportAsync(string symbol, DateTime?startTime = default(DateTime?), DateTime?endTime = default(DateTime?), PeriodOption period = PeriodOption.Daily, CancellationToken token = default(CancellationToken)) { if (period == PeriodOption.PerSecond || period == PeriodOption.Per10Minute || period == PeriodOption.BiHourly) { throw new ArgumentException($"This importer does not support {period.ToString()}"); } Client.BaseAddress = new Uri("https://www.alphavantage.co"); string query = string.Empty; string function = "TIME_SERIES_DAILY"; string format = "yyyy-MM-dd"; switch (period) { case PeriodOption.PerMinute: format = "yyyy-MM-dd HH:mm:ss"; function = "function=TIME_SERIES_INTRADAY&interval=1min"; break; case PeriodOption.Per5Minute: format = "yyyy-MM-dd HH:mm:ss"; function = "function=TIME_SERIES_INTRADAY&interval=5min"; break; case PeriodOption.Per15Minute: format = "yyyy-MM-dd HH:mm:ss"; function = "function=TIME_SERIES_INTRADAY&interval=15min"; break; case PeriodOption.Per30Minute: format = "yyyy-MM-dd HH:mm:ss"; function = "function=TIME_SERIES_INTRADAY&interval=30min"; break; case PeriodOption.Hourly: format = "yyyy-MM-dd HH:mm:ss"; function = "function=TIME_SERIES_INTRADAY&interval=60min"; break; case PeriodOption.Daily: function = "function=TIME_SERIES_DAILY"; break; case PeriodOption.Weekly: function = "function=TIME_SERIES_WEEKLY"; break; case PeriodOption.Monthly: function = "function=TIME_SERIES_MONTHLY"; break; default: break; } query = $"/query?{function}&symbol={symbol}&apikey={ApiKey}&outputsize={OutputSize.ToString()}&datatype=csv"; var csvStream = await client.GetStreamAsync(query); TextReader textReader = new StreamReader(csvStream); var culture = "en-US"; var cultureInfo = new CultureInfo(culture); var candles = new List <IOhlcv>(); using (var csvReader = new CsvReader(textReader, new Configuration() { CultureInfo = cultureInfo, Delimiter = ",", HasHeaderRecord = true })) { bool isHeaderBypassed = false; while (csvReader.Read()) { // HasHeaderRecord is not working for CsvReader 6.0.2 if (!isHeaderBypassed) { isHeaderBypassed = true; continue; } var date = string.IsNullOrWhiteSpace(format) ? csvReader.GetField <DateTime>(0) : DateTime.ParseExact(csvReader.GetField <string>(0), format, cultureInfo); if ((!startTime.HasValue || date >= startTime) && (!endTime.HasValue || date <= endTime)) { candles.Add(GetRecord(csvReader, format, cultureInfo)); } } } return(candles.OrderBy(c => c.DateTime).ToList()); }
private void procTensileLog(String logStr) { Action act; String tmpLog; tmpLog = delLogHead(logStr); if (initInfoFlag == true) { if (tmpLog.StartsWith("output WHKN")) { tmpLog = tmpLog.Split('=')[1]; tmpLog = tmpLog.Trim(); OutW = int.Parse(tmpLog.Split(',')[0].Trim()); OutH = int.Parse(tmpLog.Split(',')[1].Trim()); OutK = int.Parse(tmpLog.Split(',')[2].Trim()); OutN = int.Parse(tmpLog.Split(',')[3].Trim()); } if (tmpLog.StartsWith("init tensor input")) { InputSize = tmpLog.Split('=')[2].Trim(); } if (tmpLog.StartsWith("init tensor weight")) { WeightSize = tmpLog.Split('=')[2].Trim(); } if (tmpLog.StartsWith("init tensor output")) { OutputSize = tmpLog.Split('=')[2].Trim(); } if (tmpLog.StartsWith("Calculation")) { Calculation = tmpLog.Split(',')[0].Trim().Split('=')[1].Trim(); TheoryElapsedTime = tmpLog.Split(',')[1].Trim().Split('=')[1].Trim(); } if (tmpLog.StartsWith("run host calculate")) { initInfoFlag = false; kernelParamFlag = false; act = new Action(() => { tbxOutW.Text = OutW.ToString(); tbxOutH.Text = OutH.ToString(); tbxInSize.Text = InputSize.ToString(); tbxWeiSize.Text = WeightSize.ToString(); tbxOutSize.Text = OutputSize.ToString(); tbxCalcu.Text = Calculation.ToString(); tbxtheore.Text = TheoryElapsedTime.ToString(); }); this.Dispatcher.Invoke(act); } } if (kernelParamFlag == true) { if (tmpLog.Contains("PCK_order")) { pck_order = int.Parse(getNumStr(tmpLog.Split('=')[1].Trim())); } if (tmpLog.Contains("c_lds_atomic") && tmpLog.Contains("c_lds_split")) { c_lds_atomic = int.Parse(tmpLog.Split(',')[0].Split('=')[1].Trim()); c_lds_split = int.Parse(tmpLog.Split(',')[1].Split('=')[1].Trim()); } if (tmpLog.Contains("c_l2_atomic") && tmpLog.Contains("c_l2_split")) { c_l2_atomic = int.Parse(tmpLog.Split(',')[0].Split('=')[1].Trim()); c_l2_split = int.Parse(tmpLog.Split(',')[1].Split('=')[1].Trim()); } if (tmpLog.Contains("k_out_maps") && tmpLog.Contains("k_out_group")) { k_out_maps = int.Parse(tmpLog.Split(',')[0].Split('=')[1].Trim()); } if (tmpLog.Contains("group_size")) { group_size_x = int.Parse(tmpLog.Split('=')[1].Split(',')[0].Trim()); group_size_y = int.Parse(tmpLog.Split('=')[1].Split(',')[1].Trim()); } if (tmpLog.Contains("sigal_size") && tmpLog.Contains("l2_size")) { sig_slot_size = tmpLog.Split(',')[0].Split('=')[1].Trim(); l2_tmp_size = tmpLog.Split(',')[1].Split('=')[1].Trim(); } if (tmpLog.Contains("-------------------------------------------------------------------------")) { kernelParamFlag = false; act = new Action(() => { tbxPck.Text = pck_order.ToString(); tbxLdsAtomic.Text = c_lds_atomic.ToString(); tbxLdsSplit.Text = c_lds_split.ToString(); tbxL2Atomic.Text = c_l2_atomic.ToString(); tbxL2Split.Text = c_l2_split.ToString(); tbxKoutMaps.Text = k_out_maps.ToString(); tbxSigSize.Text = sig_slot_size.ToString(); tbxL2Size.Text = l2_tmp_size.ToString(); tbxGroupSz.Text = String.Format("{0:D}, {1:D}, 1", group_size_x, group_size_y); }); this.Dispatcher.Invoke(act); } } else { if (tmpLog.StartsWith("launch kernel")) { KernelIterations = int.Parse(getNumStr(tmpLog)); } if (tmpLog.Contains("elapsed") && tmpLog.Contains("performence") && (!tmpLog.StartsWith("Best for now"))) { ElapsedTime = tmpLog.Split(',')[0].Split('=')[1].Trim(); Performence = tmpLog.Split(',')[1].Split('=')[1].Trim(); Efficiency = tmpLog.Split(',')[1].Split('=')[2].Trim(); } if (tmpLog.StartsWith("Best for now:")) { BestElapsedTime = tmpLog.Split(',')[0].Split('=')[1].Trim(); BestEfficiency = tmpLog.Split(',')[1].Split('=')[1].Trim(); } if (tmpLog.StartsWith("Searching")) { SearchedKernel = int.Parse(getNumStr(tmpLog.Split(':')[1]).Split('/')[0].Trim()); TotalKernel = int.Parse(getNumStr(tmpLog.Split(':')[1]).Split('/')[1].Trim()); SearchingPercent = 1.0 * SearchedKernel / TotalKernel; } if (tmpLog.Contains("Kernel Param:")) { kernelParamFlag = true; act = new Action(() => { tbxElapsed.Text = BestElapsedTime.ToString(); tbxPerf.Text = BestPerformence.ToString(); tbxEffic.Text = BestEfficiency.ToString(); tbxProcess.Text = String.Format("Tunning Problem: {0:D}/{1:D}... Searching Kernel: {2:D}/{3:D}...", TunnedProblem, TotalProblem, SearchedKernel, TotalKernel); tbxPercent.Text = String.Format("{0:F2}%", SearchingPercent * 100); pbProcPercent.Value = SearchingPercent * 100; }); this.Dispatcher.Invoke(act); } if (tmpLog.Contains("search kernel parameters finished")) { finishFlag = true; } } if (finishFlag == true) { if (tmpLog.Contains("Best score")) { BestElapsedTime = tmpLog.Split(':')[1].Split(',')[0].Trim(); BestPerformence = tmpLog.Split(':')[1].Split(',')[1].Trim(); BestEfficiency = tmpLog.Split(':')[1].Split(',')[2].Trim(); } if (tmpLog.Contains("+ group_size =")) { group_size_x = int.Parse(tmpLog.Split('=')[1].Split(',')[0].Trim()); group_size_y = int.Parse(tmpLog.Split('=')[1].Split(',')[1].Trim()); } if (tmpLog.Contains("global_size")) { global_size_x = int.Parse(tmpLog.Split('=')[1].Split(',')[0].Trim()); global_size_y = int.Parse(tmpLog.Split('=')[1].Split(',')[1].Trim()); } if (tmpLog.Contains("PCK_order")) { pck_order = int.Parse(tmpLog.Split('=')[1].Trim()); } if (tmpLog.Contains("c_in_lds_atomic_group")) { c_lds_atomic = int.Parse(tmpLog.Split('=')[1].Trim()); } if (tmpLog.Contains("c_in_lds_split_group")) { c_lds_split = int.Parse(tmpLog.Split('=')[1].Trim()); } if (tmpLog.Contains("c_in_l2_atomic_group")) { c_l2_atomic = int.Parse(tmpLog.Split('=')[1].Trim()); } if (tmpLog.Contains("c_in_l2_split_group")) { c_l2_split = int.Parse(tmpLog.Split('=')[1].Trim()); } if (tmpLog.Contains("k_out_maps") && (!tmpLog.Contains("k_out_group"))) { k_out_maps = int.Parse(tmpLog.Split('=')[1].Trim()); } if (tmpLog.Contains("mean err")) { if (tmpLog.Contains('@')) { mean_err = double.Parse(getNumStr(tmpLog.Split('=')[1].Split('@')[1])); } else { mean_err = double.Parse(tmpLog.Split('=')[1].Trim()); } } if (tmpLog.Contains("release host")) { act = new Action(() => { tbxElapsed.Text = BestElapsedTime.ToString(); tbxPerf.Text = BestPerformence.ToString(); tbxEffic.Text = BestEfficiency.ToString(); tbxPck.Text = pck_order.ToString(); tbxLdsAtomic.Text = c_lds_atomic.ToString(); tbxLdsSplit.Text = c_lds_split.ToString(); tbxL2Atomic.Text = c_l2_atomic.ToString(); tbxL2Split.Text = c_l2_split.ToString(); tbxKoutMaps.Text = k_out_maps.ToString(); tbxSigSize.Text = sig_slot_size.ToString(); tbxL2Size.Text = l2_tmp_size.ToString(); SearchedKernel = TotalKernel; tbxGroupSz.Text = String.Format("{0:D}, {1:D}, 1", group_size_x, group_size_y); tbxGlobalSz.Text = String.Format("{0:D}, {1:D}, 1", global_size_x, global_size_y); tbxProcess.Text = String.Format("Tunning Problem: {0:D}/{1:D}... Searching Kernel: {2:D}/{3:D}...", TunnedProblem, TotalProblem, SearchedKernel, TotalKernel); tbxPercent.Text = String.Format("{0:F2}%", SearchingPercent * 100); pbProcPercent.Value = 100; }); this.Dispatcher.Invoke(act); } } }