Exemplo n.º 1
0
class OptionQuote(object):
    def __init__(self):
        self._expr_url = 'http://finance.yahoo.com/q/os?s=%s'
        self._option_url = "http://finance.yahoo.com/q/os?s=%s&m=%s"
        self._exp_parser = ExpirationParser()
        self._option_parser = OptionParser()

    def _convert_exp2str(self, expr):
        """
        Convert date object to YYYY-MM string format 
        @param expr expiration date as python DateTime object
        """
        return expr.strftime('%Y-%m')

    def _get_option_expirations(self, underlying):
        """
        Parser the main option page for list of expirations dates
        @param symbol symbol of the underlying stock
        @return list of expiration dates as Datetime obj
        """
        url = self._expr_url % underlying
        data = urllib.urlopen(url).read()
        self._exp_parser.reset()
        self._exp_parser.feed(data)
        self._exp_parser.close()
        return self._exp_parser.expirations

    def _get_option_by_expr(self, underlying, expr):
        """
        Parser yahoo option page for data
        @param underlying stock
        @param expr expiration date in YYYY-MM string format
        @return dict of option data for the given stock/expiration date
        """
        url = self._option_url % (underlying, expr)
        data = urllib.urlopen(url).read()
        self._option_parser.reset()
        self._option_parser.feed(data)
        self._option_parser.close()
        return normalize_option_data(self._option_parser.data[1:-1], expr)
Exemplo n.º 2
0
class OptionQuote(object):
    def __init__(self):
        self._expr_url = "http://finance.yahoo.com/q/os?s=%s"
        self._option_url = "http://finance.yahoo.com/q/os?s=%s&m=%s"
        self._exp_parser = ExpirationParser()
        self._option_parser = OptionParser()

    def _convert_exp2str(self, expr):
        """
        Convert date object to YYYY-MM string format 
        @param expr expiration date as python DateTime object
        """
        return expr.strftime("%Y-%m")

    def _get_option_expirations(self, underlying):
        """
        Parser the main option page for list of expirations dates
        @param symbol symbol of the underlying stock
        @return list of expiration dates as Datetime obj
        """
        url = self._expr_url % underlying
        data = urllib.urlopen(url).read()
        self._exp_parser.reset()
        self._exp_parser.feed(data)
        self._exp_parser.close()
        return self._exp_parser.expirations

    def _get_option_by_expr(self, underlying, expr):
        """
        Parser yahoo option page for data
        @param underlying stock
        @param expr expiration date in YYYY-MM string format
        @return dict of option data for the given stock/expiration date
        """
        url = self._option_url % (underlying, expr)
        data = urllib.urlopen(url).read()
        self._option_parser.reset()
        self._option_parser.feed(data)
        self._option_parser.close()
        return normalize_option_data(self._option_parser.data[1:-1], expr)
Exemplo n.º 3
0
 def __init__(self):
     self._expr_url = 'http://finance.yahoo.com/q/os?s=%s'
     self._option_url = "http://finance.yahoo.com/q/os?s=%s&m=%s"
     self._exp_parser = ExpirationParser()
     self._option_parser = OptionParser()
Exemplo n.º 4
0
 def __init__(self):
     self._expr_url = "http://finance.yahoo.com/q/os?s=%s"
     self._option_url = "http://finance.yahoo.com/q/os?s=%s&m=%s"
     self._exp_parser = ExpirationParser()
     self._option_parser = OptionParser()