public void OnGet() { YahooModel.Ticker = "IBM"; YahooModel.OptionType = "Call"; YahooModel.OptionResult = YahooHelper.GetYahooOption(YahooModel.Ticker); YahooModel.Expiration = YahooModel.OptionResult.Expirations[0]; YahooModel.Expirations = new SelectList(YahooModel.OptionResult.Expirations); }
public void SaveYahooData_ShouldSetYahooTreeMetaData() { _service.SaveYahooData(new List <YahooNormalized>(), "testPath"); _yahooTreeDataRepositoryMock.VerifySet(x => x.CollectionName = "Yahoo", Times.Once); _yahooTreeDataRepositoryMock.VerifySet(x => x.Path = "testPath", Times.Once); _yahooTreeDataRepositoryMock.VerifySet(x => x.NamesFileContents = YahooHelper.BuildYahooNamesFile(), Times.Once); }
public void SaveYahooData(IList <YahooNormalized> yahooRecords, string path) { var yahooTreeData = YahooHelper.BuildYahooTreeDataList(yahooRecords); _yahooTreeDataRepository.CollectionName = "Yahoo"; _yahooTreeDataRepository.Path = path; _yahooTreeDataRepository.NamesFileContents = YahooHelper.BuildYahooNamesFile(); _yahooTreeDataRepository.SaveData(yahooTreeData); }
public void BuildYahooTreeDataList_ShouldSaveCorrectActions() { var yahooTreeDataList = YahooHelper.BuildYahooTreeDataList(_yahooRecords).ToList(); Assert.AreEqual(MarketAction.Buy, yahooTreeDataList[0].Action); Assert.AreEqual(MarketAction.Sell, yahooTreeDataList[1].Action); Assert.AreEqual(MarketAction.Buy, yahooTreeDataList[2].Action); Assert.AreEqual(MarketAction.Sell, yahooTreeDataList[3].Action); Assert.AreEqual(MarketAction.Hold, yahooTreeDataList[4].Action); }
public void BuildYahooTreeDataList_ShouldPreserveVolatilities() { var yahooTreeDataList = YahooHelper.BuildYahooTreeDataList(_yahooRecords).ToList(); Assert.AreEqual(1.25, yahooTreeDataList[0].Volatility); Assert.AreEqual(1.26, yahooTreeDataList[1].Volatility); Assert.AreEqual(1.27, yahooTreeDataList[2].Volatility); Assert.AreEqual(1.28, yahooTreeDataList[3].Volatility); Assert.AreEqual(1.29, yahooTreeDataList[4].Volatility); }
public async Task OnGet() { YahooModel.Ticker = "IBM"; YahooModel.StartDate = DateTime.Parse("2018-01-01"); YahooModel.EndDate = DateTime.Parse("2018-03-01"); YahooModel.Period = "daily"; var start = YahooModel.StartDate.ToString("yyyy-MM-dd"); var end = YahooModel.EndDate.ToString("yyyy-MM-dd"); YahooModel.StockData = await YahooHelper.GetYahooStock(YahooModel.Ticker, start, end, YahooModel.Period); }
public void BuildYahooNamesFile_ShouldBuildCorrectFile() { var builder = new StringBuilder(); builder.AppendLine("Buy,Sell,Hold. |classes"); builder.AppendLine(); builder.AppendLine("Spread: continuous."); builder.AppendLine("Change: continuous."); builder.AppendLine("Volatility: continuous."); var namesFile = YahooHelper.BuildYahooNamesFile(); Assert.AreEqual(builder.ToString(), namesFile); }
protected override string GetUrl() { if (this.Query == string.Empty) { throw new ArgumentNullException("Query", "The passed query text is empty."); } System.Text.StringBuilder url = new System.Text.StringBuilder(); //url.Append("http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=") //url.Append(Uri.EscapeDataString(search.Trim)) //url.Append("&callback=YAHOO.Finance.SymbolSuggest.ssCallback") url.Append("http://d.yimg.com/aq/autoc?query="); url.Append(Uri.EscapeDataString(this.Query.Trim())); url.Append(YahooHelper.CultureToParameters(this.Culture)); url.Append("&callback=YAHOO.util.ScriptNodeDataSource.callbacks"); return(url.ToString()); }
public IEnumerable <YahooNormalized> PrepareData(int updatePeriod = 100) { var yahooRecords = Enumerable.Reverse(_yahooDataRepository.CsvLinesNormalized).ToList(); var data = new List <YahooNormalized>(); var period = 0; double mean = 0.0; double variance = 0.0; var index = 0; foreach (var record in yahooRecords) { var change = index > 0 ? MathHelpers.PreservePrecision(record.Close / yahooRecords[index - 1].Close - 1.0) : 0.0; if (period == 0) { mean = record.Close; variance = 0.0; data.Add(YahooHelper.BuildYahooNormalized(record, change, mean, 0.0)); } else { var prevSize = period; var sizeNow = period + 1; mean = (prevSize * mean + record.Close) / sizeNow; var difference = record.Close - mean; variance = (double)prevSize / sizeNow * variance + 1.0 / prevSize * difference * difference; var volatility = MathHelpers.PreservePrecision(Math.Sqrt(variance)); data.Add(YahooHelper.BuildYahooNormalized(record, change, MathHelpers.PreservePrecision(mean), volatility)); } index++; period++; period %= updatePeriod; } return(data); }
protected override string GetUrl() { if (this.ID == string.Empty) { throw new ArgumentException("ID is empty.", "ID"); } System.Text.StringBuilder url = new System.Text.StringBuilder(); url.Append("http://"); url.Append("chart.finance.yahoo.com/"); if (this.SimplifiedImage) { url.Append("t?"); } else if (this.ImageSize == ChartImageSize.Small) { url.Append("h?"); } else { url.Append("z?"); } url.Append("s="); url.Append(MyHelper.CleanYqlParam(FinanceHelper.CleanIndexID(this.ID))); if (this.SimplifiedImage) { url.Append("&width=" + this.ImageWidth.ToString()); url.Append("&height=" + this.ImageHeight.ToString()); } else if (this.ImageSize != ChartImageSize.Small) { url.Append("&t="); url.Append(FinanceHelper.GetChartTimeSpan(this.TimeSpan)); url.Append("&z="); url.Append(FinanceHelper.GetChartImageSize(this.ImageSize)); url.Append("&q="); url.Append(FinanceHelper.GetChartType(this.Type)); url.Append("&l="); url.Append(FinanceHelper.GetChartScale(this.Scale)); if (this.MovingAverages.Count > 0 | this.ExponentialMovingAverages.Count > 0 | this.TechnicalIndicators.Count > 0) { url.Append("&p="); foreach (MovingAverageInterval ma in this.MovingAverages) { url.Append('m'); url.Append(FinanceHelper.GetMovingAverageInterval(ma)); url.Append(','); } foreach (MovingAverageInterval ma in this.ExponentialMovingAverages) { url.Append('e'); url.Append(FinanceHelper.GetMovingAverageInterval(ma)); url.Append(','); } foreach (TechnicalIndicator ti in this.TechnicalIndicators) { url.Append(FinanceHelper.GetTechnicalIndicatorsI(ti)); } } if (this.TechnicalIndicators.Count > 0) { url.Append("&a="); foreach (TechnicalIndicator ti in this.TechnicalIndicators) { url.Append(FinanceHelper.GetTechnicalIndicatorsII(ti)); } } if (this.ComparingIDs.Count > 0) { url.Append("&c="); foreach (string csid in this.ComparingIDs) { url.Append(MyHelper.CleanYqlParam(FinanceHelper.CleanIndexID(csid))); url.Append(','); } } if (this.Culture == null) { this.Culture = Culture.DefaultCultures.UnitedStates_English; } } url.Append(YahooHelper.CultureToParameters(this.Culture)); return(url.ToString()); }
public OptionResult YahooOption(string ticker, DateTime?expiry) { return(YahooHelper.GetYahooOption(ticker, expiry)); }
public async Task <List <YahooStockData> > YahooStock(string ticker, string start, string end, string period) { return(await YahooHelper.GetYahooStock(ticker, start, end, period)); }
protected override string GetUrl() { if (this.Query.Trim() == string.Empty) { throw new ArgumentNullException("Query", "The query text is empty."); } System.Text.StringBuilder url = new System.Text.StringBuilder(); url.Append("http://"); url.Append(YahooHelper.ServerString(this.Server)); url.Append("finance.yahoo.com/lookup/"); switch (this.Type) { case SecurityType.Any: url.Append("all"); break; case SecurityType.ETF: url.Append("etfs"); break; case SecurityType.Fund: url.Append("funds"); break; case SecurityType.Future: url.Append("futures"); break; case SecurityType.Index: url.Append("indices"); break; case SecurityType.Stock: url.Append("stocks"); break; case SecurityType.Warrant: url.Append("warrants"); break; case SecurityType.Currency: url.Append("currency"); break; } url.Append("?s="); url.Append(Uri.EscapeDataString(this.Query)); url.Append("&t="); if (this.Type == SecurityType.Fund) { url.Append('M'); } else { url.Append(char.ToUpper(this.Type.ToString()[0])); } url.Append("&m="); switch (this.Markets) { case FinancialMarket.France: url.Append("FR"); break; case FinancialMarket.Germany: url.Append("DR"); break; case FinancialMarket.Spain: url.Append("ES"); break; case FinancialMarket.UK: url.Append("GB"); break; case FinancialMarket.UsAndCanada: url.Append("US"); break; default: url.Append("ALL"); break; } url.Append("&r="); if (this.RankedBy != SecurityRankProperty.NoRanking) { int rankNumber = Convert.ToInt32(this.RankedBy); if (this.RankingDirection == ListSortDirection.Descending) { rankNumber += 1; } url.Append(rankNumber.ToString()); } url.Append("&b="); url.Append(this.ResultsIndex); return(url.ToString()); string whereClause = string.Format("url=\"{0}\" AND xpath='//div[@id=\"yfi_sym_lookup\"]'", url.ToString()); return(MyHelper.YqlUrl("*", "html", whereClause, null, false)); }
public void OnPost() { YahooModel.OptionResult = YahooHelper.GetYahooOption(YahooModel.Ticker, DateTime.Parse(YahooModel.Expiration)); YahooModel.Expirations = new SelectList(YahooModel.OptionResult.Expirations); ViewData["data"] = "expiry = " + YahooModel.Expiration; }
public void BuildYahooTreeDataList_ShouldGetCorrectCount() { var yahooTreeDataList = YahooHelper.BuildYahooTreeDataList(_yahooRecords).ToList(); Assert.AreEqual(5, yahooTreeDataList.Count); }
/// <summary> /// Returns the URL of the Yahoo! RSS news feed. /// </summary> /// <param name="culture">The culture of the feed.</param> /// <returns></returns> /// <remarks></remarks> public string RssNewsURL(Culture culture = null) { Culture cult = culture; if (cult == null) { cult = Culture.DefaultCultures.UnitedStates_English; } return("http://feeds.finance.yahoo.com/rss/2.0/headline?s=" + MyHelper.CleanYqlParam(mID) + YahooHelper.CultureToParameters(cult)); }