如何计算Day的价值变化?

时间:2013-06-27 22:10:19

标签: c# yahoo-finance

我正在努力计算股票指数 日的价值变化,如下所述: http://www.codeproject.com/Articles/37550/Stock-quote-and-chart-from-Yahoo-in-C

如何用C#计算?

1 个答案:

答案 0 :(得分:0)

从文章中重写GetQuote方法...如果将符号传递给此方法,它将返回Days Value Change。

public string GetDaysValueChange(string symbol)
{
    // Set the return string to null.
    string result = null;            
    try
    {
        // Use Yahoo finance service to download stock data from Yahoo
        //  Note that f=w1 tells the service we just want the Days Value Change
        string yahooURL = @"http://download.finance.yahoo.com/d/quotes.csv?s=" + 
                          symbol + "&f=w1";

        // Initialize a new WebRequest.
        HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(yahooURL);
        // Get the response from the Internet resource.
        HttpWebResponse webresp = (HttpWebResponse)webreq.GetResponse();
        // Read the body of the response from the server.
        StreamReader strm = 
          new StreamReader(webresp.GetResponseStream(), Encoding.ASCII);

        result = strm.ReadLine().Replace("\"", "");
        strm.Close();
    }
    catch
    {
        // Handle exceptions.
    }
    // Return the stock quote data in XML format.
    return result;
}