Exemplo n.º 1
0
def ts_stock_data(s_symbol, func_key, s_interval):
    if func_key == 'i':
        ts = timeseries.TimeSeries(key=apikey)
        tsdata, meta_data = ts.get_intraday(symbol=s_symbol,
                                            interval=s_interval)
        pprint(tsdata)
        pprint(meta_data)
    elif func_key == 'd':
        ts = timeseries.TimeSeries(key=apikey)
        tsdata, meta_data = ts.get_daily(symbol=s_symbol)
        pprint(tsdata)
        pprint(meta_data)
    elif func_key == 'da':
        ts = timeseries.TimeSeries(key=apikey)
        tsdata, meta_data = ts.get_daily_adjusted(symbol=s_symbol)
        pprint(tsdata)
        pprint(meta_data)
    elif func_key == 'w':
        ts = timeseries.TimeSeries(key=apikey)
        tsdata, meta_data = ts.get_weekly(symbol=s_symbol)
        pprint(tsdata)
        pprint(meta_data)
    elif func_key == 'wa':
        ts = timeseries.TimeSeries(key=apikey)
        tsdata, meta_data = ts.get_weekly_adjusted(symbol=s_symbol)
        pprint(tsdata)
        pprint(meta_data)
Exemplo n.º 2
0
    def _get_data(self, alpha_vantage_APIkey):
        # determine output size. Might be time critical, maybe not.
        if self.start >= self.retrieve_day - dt.timedelta(
                days=140) and self.end >= self.retrieve_day - dt.timedelta(
                    days=140):
            outputsize = 'compact'
        else:
            outputsize = 'full'

        # get data according to specified times
        timeseries = ts.TimeSeries(key=alpha_vantage_APIkey,
                                   output_format='pandas')
        data, metadata = timeseries.get_daily(symbol=self.ticker,
                                              outputsize=outputsize)
        data.Date = pd.to_datetime(data.index, format='%Y-%m-%d')
        data.set_index(data.Date, inplace=True)
        data = data[self.start:self.end]

        return data, metadata
Exemplo n.º 3
0
def get_ts(ticker, tick='batch_daily_adjusted', dropna=True):
    # tick can be 'intraday', 'daily_adjusted', 'batch_daily_adjusted'
    ts = alpha.TimeSeries(key='VVLO0LVEKD59PF4Y', output_format='pandas')
    if tick == 'intraday':
        data, _ = ts.get_intraday(symbol=ticker,
                                  interval='1min',
                                  outputsize='full')
        data = data[['4. close']]
        data = data.rename(columns={"4. close": ticker})
    elif tick == 'daily_adjusted':
        data, _ = ts.get_daily_adjusted(symbol=ticker, outputsize='full')
        data = data[['5. adjusted close']]
        data = data.rename(columns={"5. adjusted close": ticker})
    elif tick == 'batch_daily_adjusted':
        data = []
        for s in ticker:
            df, _ = ts.get_daily_adjusted(symbol=s, outputsize='full')
            df = df[['5. adjusted close']]
            df = df.rename(columns={"5. adjusted close": s})
            data.append(df)
        data = pd.concat(data, axis=1, sort=True)
    if dropna:
        data.dropna(inplace=True)
    return data
Exemplo n.º 4
0
@author: vmaaaaan
'''
"""data format: open, high, low, close, volume
"""
import alpha_vantage.timeseries as avts


def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        return False


ts = avts.TimeSeries(key='UQV2D45VFXJGX00j')
print("Fetching Data...")

raw_data, meta_data = ts.get_daily('ge', outputsize="full")
#print(raw_data)
data_p1 = str(raw_data).split("': '")
data_p2 = []
for d in data_p1:
    for ds in d.split("', '"):
        data_p2.append(ds)
data_p2b = []
for d in data_p2:
    for ds in d.split("'},"):
        data_p2b.append(ds)
data_rev = []
new_seg = []
Exemplo n.º 5
0
                     label=x,
                     linewidth=1)
        leg = plt.legend()
        for x in leg.get_lines():
            x.set_linewidth(4)

    to_plot = [[[], []]]
    style.use('fivethirtyeight')
    fig = plt.figure()
    ax_data = {}
    ani = matplotlib.animation.FuncAnimation(fig, animate, interval=5000)
    plt.show()


app = QApplication(sys.argv)
window = simple()

holder = timeseries.TimeSeries(key=KEY)

# handling data updating... DaemonThread used so that the GUI will trigger closing
data_update_thread = thread.Timer(refresh_rate, data_thread_handler)
data_update_thread.setDaemon(True)
data_update_thread.start()

thread.Thread(target=handle_graph, daemon=True).start()

print('made it')
# launching application

sys.exit(app.exec_())
Exemplo n.º 6
0
def get_stock_data(strticker):
    """request to get the data for stocks"""
    ts = avt.TimeSeries(key=hidden.alpha_api)
    data, meta = ts.get_daily(strticker)
    return data
Exemplo n.º 7
0
                                        start_date=start_date,
                                        end_date=end_date,
                                        api_key=quandl_api_key)['Adj. Close']

print(data_multiples.head())
data_multiples.plot(figsize=(17, 6))
plt.title('Adjusted closes prices')
plt.ylabel('Price', fontsize=14)
plt.xlabel('Year', fontsize=14)
plt.grid(color='k', linestyle='-.', linewidth=0.5)
plt.show()

#----------------------------
#alpha vantage => get intraday data

ts = avts.TimeSeries(alpha_vantage_api_key, output_format='pandas')
data_intraday, data_intraday_info = ts.get_intraday(tickers[0],
                                                    outputsize='full',
                                                    interval='1min')
print(data_intraday_info)
print(data_intraday.head())

#get custome frecuency data
#During strategy modelling, you are required to work
# with a custom frequency of stock market data such as 7 minutes or 35 minutes.
# This custom frequency candles are not provided by data vendors or web sources, but
# you can always use pandas => 'resample'

#converting 1 min to 10 min frecuency sample data
# define dictionary for convention logic
ohlcv_dict = {