示例#1
0
    def __init__(self, ticker, option_type='call', expiry=None, strike=None):
        # objects
        self.yield_curve = EuroArea()
        self.stock = Stock(ticker)
        self.option = web.Options(ticker, "yahoo")

        # save inputs
        self.ticker = ticker
        self.option_type = option_type
        self.expiry = self.__set_expiry(expiry)  # expiry correction
        table = self.option.get_all_data().xs((self.expiry, self.option_type),
                                              level=('Expiry', 'Type'),
                                              drop_level=True)
        self.strike = self.__set_strike(strike, table)  # strike correction

        # attributes
        self.data = table['Last']
        self.price = float(self.data[self.strike])
        self.maturity = (dt.datetime.strptime(self.expiry, "%d-%m-%y") -
                         dt.datetime.today()) / dt.timedelta(days=365)
    def setUpClass(cls):
        super(TestYahooOptions, cls).setUpClass()
        _skip_if_no_lxml()

        # aapl has monthlies
        cls.aapl = web.Options('aapl', 'yahoo')
        today = datetime.today()
        cls.year = today.year
        cls.month = today.month + 1
        if cls.month > 12:  # pragma: no cover
            cls.month = 1
            cls.year = cls.year + 1
        cls.expiry = datetime(cls.year, cls.month, 1)
        cls.dirpath = tm.get_data_path()
        cls.html1 = 'file://' + os.path.join(cls.dirpath,
                                             'yahoo_options1.html')
        cls.html2 = 'file://' + os.path.join(cls.dirpath,
                                             'yahoo_options2.html')
        cls.html3 = 'file://' + os.path.join(
            cls.dirpath, 'yahoo_options3.html')  # Empty table GH#22
        cls.data1 = cls.aapl._option_frames_from_url(cls.html1)['puts']
    def test_get_underlying_price(self):
        # GH7
        try:
            options_object = web.Options('^spxpm', 'yahoo')
            url = options_object._yahoo_url_from_expiry(
                options_object.expiry_dates[0])
            root = options_object._parse_url(url)
            quote_price = options_object._underlying_price_from_root(root)
        except RemoteDataError as e:  # pragma: no cover
            raise nose.SkipTest(e)
        self.assertTrue(isinstance(quote_price, float))

        # Tests the weekend quote time format
        price, quote_time = self.aapl._underlying_price_and_time_from_url(
            self.html1)
        self.assertTrue(isinstance(price, (int, float, complex)))
        self.assertTrue(isinstance(quote_time, (datetime, pd.Timestamp)))

        # Tests the EDT page format
        # regression test for #8741
        price, quote_time = self.aapl._underlying_price_and_time_from_url(
            self.html2)
        self.assertTrue(isinstance(price, (int, float, complex)))
        self.assertTrue(isinstance(quote_time, (datetime, pd.Timestamp)))
示例#4
0
 def test_options_source_warning(self):
     if not assert_produces_warning:
         raise nose.SkipTest("old version of pandas without "
                             "compat.assert_produces_warning")
     with assert_produces_warning():
         aapl = web.Options('aapl')
示例#5
0
 def setup_class(cls):
     # GOOG has monthlies
     cls.goog = web.Options('GOOG', 'google')
示例#6
0
 def test_options_is_not_none(self):
     option = web.Options("aapl", "yahoo")
     assert option is not None
示例#7
0
def aapl():
    aapl = web.Options("aapl", "yahoo")
    yield aapl
    aapl.close()
示例#8
0
oc_st(dow_j, "dow_j", "open", "close", 3)
oc_st(sz, "sz", "open", "close", 23, limit=[0.6, 0.42])

import tushare

etf = tushare.get_h_data("510050")

oc_st(hsi, "^HSI", "close", "close", 30, limit=[0.5, 0.3])
oc_st(etf, "etf", "close", "close", 30, limit=[0.5, 0.3])  ## hightest
oc_st(hsi, "^HSI", "close", "close", 30, limit=[-0.2, 0])
oc_st(spc, "spc", "close", "open", 20, limit=[0.56, 0.42])

oc_st(hsi, "^HSI", "close", "close", 30, limit=[0.5, 0.4])

oc_st(etf, "etf", "close", "open", 23, limit=[0.7, 0.45], cost_rate=0.01)

quato = data.get_quote_yahoo('AMZN')
quato = data.get_quote_yahoo('510050.SS')
quato = data.Options("510050.SS")
data = quato.get_all_data()

import tushare as ts

fd = ts.Options()
fd.OptVar()
df = fd.Opt(contractStatus='L,DE',
            field='optID,secShortName,varShortName,listDate')
df = fd.getOptDpo(contractStatus='L,DE',
                  field='optID,secShortName,varShortName,listDate')
ts.set_token(
    '1b4a1c74f890d52633d9fa3607b4f260ef1c4f8200674d9a6549170ef430ff2f')
示例#9
0
    def setUpClass(cls):
        super(TestGoogleOptions, cls).setUpClass()

        # goog has monthlies
        cls.goog = web.Options('GOOG', 'google')
示例#10
0
 def test_options_is_not_none(self):
     option = web.Options('aapl')
     self.assertTrue(option is not None)
示例#11
0
import os, sys
import pandas
from pandas_datareader import data as pd
from utils import *

# define a stock symbol
underlying_symbol = 'CRM'

if not os.path.isfile('%s.p' % underlying_symbol):
    # define a Options object
    options_obj = pd.Options(underlying_symbol, 'yahoo')
    # request all chains for the underlying symbol
    # ***WARNING THIS TAKES A WHILE***
    options_frame_live = options_obj.get_all_data()
    # let's pickle the dataframe so we don't have to hit the network every time
    options_frame_live.to_pickle('%s.p' % underlying_symbol)

# read the original frame in from cache (pickle)
options_frame = pandas.read_pickle('%s.p' % underlying_symbol)
# and the first ten records
#print options_frame_live.head()
# reset the index so the strike and expiration become columns
options_frame.reset_index(inplace=True)
# remove PctChg and IV - we'll calculate our own
del options_frame['PctChg']
del options_frame['IV']
# rename the columns for consistency
columns = {
    'Expiry': 'Expiration',
    'Type': 'OptionType',
    'Symbol': 'OptionSymbol',
示例#12
0
 def test_options_source_warning(self):
     with tm.assert_produces_warning():
         web.Options('aapl')
 def test_deprecation(self):
     with pytest.raises(ImmediateDeprecationError):
         web.Options('GOOG', 'google')
示例#14
0
def import_equity_options():
    ticker = web.Options('aapl', 'yahoo')
    data = ticker.get_all_data()
示例#15
0
 def test_options_is_not_none(self):
     option = web.Options('aapl', 'yahoo')
     assert option is not None
示例#16
0
def aapl():
    aapl = web.Options('aapl', 'yahoo')
    yield aapl
    aapl.close()
示例#17
0
 def __init__(self, underlying):
     self.underlying = underlying
     self._session = self.underlying._session
     self._pdr = pdr.Options(self.underlying.ticker,
                             'yahoo',
                             session=self._session)