Package yahoofinance

Class Stock


  • public class Stock
    extends java.lang.Object
    Author:
    Stijn Strickx
    • Constructor Detail

      • Stock

        public Stock​(java.lang.String symbol)
    • Method Detail

      • isValid

        public boolean isValid()
        Checks if the returned name is null. This probably means that the symbol was not recognized by Yahoo Finance.
        Returns:
        whether this stock's symbol is known by Yahoo Finance (true) or not (false)
      • getQuote

        public StockQuote getQuote()
        Returns the basic quotes data available for this stock.
        Returns:
        basic quotes data available for this stock
        See Also:
        getQuote(boolean)
      • getQuote

        public StockQuote getQuote​(boolean refresh)
                            throws java.io.IOException
        Returns the basic quotes data available for this stock. This method will return null in the following situations:
        • the data hasn't been loaded yet in a previous request and refresh is set to false.
        • refresh is true and the data cannot be retrieved from Yahoo Finance for whatever reason (symbol not recognized, no network connection, ...)

        When the quote data gets refreshed, it will automatically also refresh the statistics and dividend data of the stock from Yahoo Finance in the same request.

        Parameters:
        refresh - indicates whether the data should be requested again to Yahoo Finance
        Returns:
        basic quotes data available for this stock
        Throws:
        java.io.IOException - when there's a connection problem
      • setQuote

        public void setQuote​(StockQuote quote)
      • getStats

        public StockStats getStats()
        Returns the statistics available for this stock.
        Returns:
        statistics available for this stock
        See Also:
        getStats(boolean)
      • getStats

        public StockStats getStats​(boolean refresh)
                            throws java.io.IOException
        Returns the statistics available for this stock. This method will return null in the following situations:
        • the data hasn't been loaded yet in a previous request and refresh is set to false.
        • refresh is true and the data cannot be retrieved from Yahoo Finance for whatever reason (symbol not recognized, no network connection, ...)

        When the statistics get refreshed, it will automatically also refresh the quote and dividend data of the stock from Yahoo Finance in the same request.

        Parameters:
        refresh - indicates whether the data should be requested again to Yahoo Finance
        Returns:
        statistics available for this stock
        Throws:
        java.io.IOException - when there's a connection problem
      • setStats

        public void setStats​(StockStats stats)
      • getDividend

        public StockDividend getDividend()
        Returns the dividend data available for this stock.
        Returns:
        dividend data available for this stock
        See Also:
        getDividend(boolean)
      • getDividend

        public StockDividend getDividend​(boolean refresh)
                                  throws java.io.IOException
        Returns the dividend data available for this stock. This method will return null in the following situations:
        • the data hasn't been loaded yet in a previous request and refresh is set to false.
        • refresh is true and the data cannot be retrieved from Yahoo Finance for whatever reason (symbol not recognized, no network connection, ...)

        When the dividend data get refreshed, it will automatically also refresh the quote and statistics data of the stock from Yahoo Finance in the same request.

        Parameters:
        refresh - indicates whether the data should be requested again to Yahoo Finance
        Returns:
        dividend data available for this stock
        Throws:
        java.io.IOException - when there's a connection problem
      • setDividend

        public void setDividend​(StockDividend dividend)
      • getHistory

        public java.util.List<HistoricalQuote> getHistory​(Interval interval)
                                                   throws java.io.IOException
        Requests the historical quotes for this stock with the following characteristics.
        • from: 1 year ago (default)
        • to: today (default)
        • interval: specified value
        Parameters:
        interval - the interval of the historical data
        Returns:
        a list of historical quotes from this stock
        Throws:
        java.io.IOException - when there's a connection problem
        See Also:
        getHistory()
      • getHistory

        public java.util.List<HistoricalQuote> getHistory​(java.util.Calendar from)
                                                   throws java.io.IOException
        Requests the historical quotes for this stock with the following characteristics.
        • from: specified value
        • to: today (default)
        • interval: MONTHLY (default)
        Parameters:
        from - start date of the historical data
        Returns:
        a list of historical quotes from this stock
        Throws:
        java.io.IOException - when there's a connection problem
        See Also:
        getHistory()
      • getHistory

        public java.util.List<HistoricalQuote> getHistory​(java.util.Calendar from,
                                                          Interval interval)
                                                   throws java.io.IOException
        Requests the historical quotes for this stock with the following characteristics.
        • from: specified value
        • to: today (default)
        • interval: specified value
        Parameters:
        from - start date of the historical data
        interval - the interval of the historical data
        Returns:
        a list of historical quotes from this stock
        Throws:
        java.io.IOException - when there's a connection problem
        See Also:
        getHistory()
      • getHistory

        public java.util.List<HistoricalQuote> getHistory​(java.util.Calendar from,
                                                          java.util.Calendar to)
                                                   throws java.io.IOException
        Requests the historical quotes for this stock with the following characteristics.
        • from: specified value
        • to: specified value
        • interval: MONTHLY (default)
        Parameters:
        from - start date of the historical data
        to - end date of the historical data
        Returns:
        a list of historical quotes from this stock
        Throws:
        java.io.IOException - when there's a connection problem
        See Also:
        getHistory()
      • getHistory

        public java.util.List<HistoricalQuote> getHistory​(java.util.Calendar from,
                                                          java.util.Calendar to,
                                                          Interval interval)
                                                   throws java.io.IOException
        Requests the historical quotes for this stock with the following characteristics.
        • from: specified value
        • to: specified value
        • interval: specified value
        Parameters:
        from - start date of the historical data
        to - end date of the historical data
        interval - the interval of the historical data
        Returns:
        a list of historical quotes from this stock
        Throws:
        java.io.IOException - when there's a connection problem
        See Also:
        getHistory()
      • setHistory

        public void setHistory​(java.util.List<HistoricalQuote> history)
      • getDividendHistory

        public java.util.List<HistoricalDividend> getDividendHistory()
                                                              throws java.io.IOException
        This method will return historical dividends from this stock. If the historical dividends are not available yet, they will be requested first from Yahoo Finance.

        If the historical dividends are not available yet, the following characteristics will be used for the request:

        • from: 1 year ago (default)
        • to: today (default)

        There are several more methods available that allow you to define some characteristics of the historical data. Calling one of those methods will result in a new request being sent to Yahoo Finance.

        Returns:
        a list of historical dividends from this stock
        Throws:
        java.io.IOException - when there's a connection problem
        See Also:
        getDividendHistory(java.util.Calendar), getDividendHistory(java.util.Calendar, java.util.Calendar)
      • getDividendHistory

        public java.util.List<HistoricalDividend> getDividendHistory​(java.util.Calendar from)
                                                              throws java.io.IOException
        Requests the historical dividends for this stock with the following characteristics.
        • from: specified value
        • to: today (default)
        Parameters:
        from - start date of the historical data
        Returns:
        a list of historical dividends from this stock
        Throws:
        java.io.IOException - when there's a connection problem
        See Also:
        getDividendHistory()
      • getDividendHistory

        public java.util.List<HistoricalDividend> getDividendHistory​(java.util.Calendar from,
                                                                     java.util.Calendar to)
                                                              throws java.io.IOException
        Requests the historical dividends for this stock with the following characteristics.
        • from: specified value
        • to: specified value
        Parameters:
        from - start date of the historical data
        to - end date of the historical data
        Returns:
        a list of historical dividends from this stock
        Throws:
        java.io.IOException - when there's a connection problem
        See Also:
        getDividendHistory()
      • setDividendHistory

        public void setDividendHistory​(java.util.List<HistoricalDividend> dividendHistory)
      • getSplitHistory

        public java.util.List<HistoricalSplit> getSplitHistory()
                                                        throws java.io.IOException
        This method will return historical splits from this stock. If the historical splits are not available yet, they will be requested first from Yahoo Finance.

        If the historical splits are not available yet, the following characteristics will be used for the request:

        • from: 1 year ago (default)
        • to: today (default)

        There are several more methods available that allow you to define some characteristics of the historical data. Calling one of those methods will result in a new request being sent to Yahoo Finance.

        Returns:
        a list of historical splits from this stock
        Throws:
        java.io.IOException - when there's a connection problem
        See Also:
        getSplitHistory(java.util.Calendar), getSplitHistory(java.util.Calendar, java.util.Calendar)
      • getSplitHistory

        public java.util.List<HistoricalSplit> getSplitHistory​(java.util.Calendar from)
                                                        throws java.io.IOException
        Requests the historical splits for this stock with the following characteristics.
        • from: specified value
        • to: today (default)
        Parameters:
        from - start date of the historical data
        Returns:
        a list of historical splits from this stock
        Throws:
        java.io.IOException - when there's a connection problem
        See Also:
        getSplitHistory()
      • getSplitHistory

        public java.util.List<HistoricalSplit> getSplitHistory​(java.util.Calendar from,
                                                               java.util.Calendar to)
                                                        throws java.io.IOException
        Requests the historical splits for this stock with the following characteristics.
        • from: specified value
        • to: specified value
        Parameters:
        from - start date of the historical data
        to - end date of the historical data
        Returns:
        a list of historical splits from this stock
        Throws:
        java.io.IOException - when there's a connection problem
        See Also:
        getSplitHistory()
      • setSplitHistory

        public void setSplitHistory​(java.util.List<HistoricalSplit> splitHistory)
      • getSymbol

        public java.lang.String getSymbol()
      • getName

        public java.lang.String getName()
        Get the full name of the stock
        Returns:
        the name or null if the data is not available
      • setName

        public void setName​(java.lang.String name)
      • getCurrency

        public java.lang.String getCurrency()
        Get the currency of the stock
        Returns:
        the currency or null if the data is not available
      • setCurrency

        public void setCurrency​(java.lang.String currency)
      • getStockExchange

        public java.lang.String getStockExchange()
        Get the exchange on which the stock is traded
        Returns:
        the exchange or null if the data is not available
      • setStockExchange

        public void setStockExchange​(java.lang.String stockExchange)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • print

        public void print()