Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Author: James Campbell
# Date Created: May 21st 2016
# Date Updated: 2 July 2019
# What: Example to get stock prices
from sys import exit
try:
import quandl
except Exception:
exit('quandl module required, run pip or pip3 install quandl --update')
try:
from configs import myqkey
except Exception:
print('no configs file set, create a file called configs.py and add var myqkey = "whatever"')
myqkey = 'yoursecretkeyfromquandl.com'
# set API key
quandl.ApiConfig.api_key = myqkey # get free key at quandl.com
dataset_data = quandl.Dataset('WIKI/AAPL').data(params={'start_date': '2001-01-01',
'end_date': '2010-01-01',
'collapse': 'annual',
'transformation': 'rdiff', 'rows': 4})
print('first date: {}'.format(dataset_data[0].date))
print('Total days of stock data available: {}'.format(len(dataset_data)))
print('The data includes the following columns: {}'.format(dataset_data.column_names))
def quandl_process(loop):
quandl.ApiConfig.api_key = settings.QUANDL_API_KEY
quandl_symbols = ["YAHOO/INDEX_VIX", "CBOE/VXV"]
quandl_periods = [("monthly", 43200), (None, 1440), ("weekly", 10080)]
loop.run_until_complete(gather(*[save_quandl_file(\
sym=sym, quandl_periods=quandl_periods) for sym in quandl_symbols], \
return_exceptions=True
))
# We are gonna use Scikit's LinearRegression model
from sklearn.linear_model import LinearRegression
import quandl
import math
import sys, os
predict_accuracy = 0.91
price_compare = "bid"
# FORMAT EXAMPLE
# epic_id = "KA.D.LLOY.DAILY.IP"
# epic_id = "KA.D.BARC.DAILY.IP"
# QUAND_REF = "LSE/LLOY"
# QUAND_REF = "LSE/BARC"
quandl.ApiConfig.api_key = "**************"
#MORE INFORMATION HERE:
#http://help.quandl.com/article/320-where-can-i-find-my-api-key
########################################################################################################################
REAL_OR_NO_REAL = 'https://demo-api.ig.com/gateway/deal'
API_ENDPOINT = "https://demo-api.ig.com/gateway/deal/session"
API_KEY = '**************'
#API_KEY = '**************'
data = {"identifier":"**************","password": "**************"}
########################################################################################################################
########################################################################################################################
########################################################################################################################
# FOR REAL....
########################################################################################################################
########################################################################################################################
########################################################################################################################
symbol = 'PTT'
print(json.dumps(getQuotes('SET:' + symbol), indent=2)) # for Stock of Thailand, There is a prefix with 'SET:'
print()
except:
print("Error:", sys.exc_info()[0])
print("Description:", sys.exc_info()[1])
#http://www.google.com/finance/company_news?output=json&q=GOOG&start=0&num=1000
# Second example
# How to install quandl package
# https://github.com/quandl/quandl-python
# pip install quandl
print("+++++quandl example+++++")
import quandl
try:
quandl.ApiConfig.api_key = 'YOUR_API_KEY' #(must register at https://www.quandl.com/)
print("THAISE index:")
data = quandl.get("THAISE/INDEX")
#data = quandl.get("THAISE/INDEX", authtoken="YOUR_API_KEY")
print(data.head())
except:
print("Error:", sys.exc_info()[0])
print("Description:", sys.exc_info()[1])
try:
print("\nAAPL:")
data = quandl.get("WIKI/AAPL", start_date="2006-10-01", end_date="2012-01-01")
print(data.head())
print()
except:
print("Error:", sys.exc_info()[0])
print("Description:", sys.exc_info()[1])
# company_details_values['country'] = 'NA'
# company_details_values['phone_number'] = 'NA'
# company_details_values['website'] = 'NA'
# return render(request, 'visualisation/company.html', { 'date' : date_json , 'price' : close_json , 'company' : company,'company_details' : company_details,'company_details_values' : company_details_values})
# else:
pred = {}
arg = request.GET.get('company_name')
quandl.ApiConfig.api_key = "23KLyzjn5UvKQog-DZyM"
company = arg
data = quandl.get_table('WIKI/PRICES', ticker = company,
qopts = { 'columns': ['ticker', 'date', 'adj_close' , 'volume'] },
date = { 'gte': '2015-12-31', 'lte': '2016-12-31' },
paginate=True)
data = data.set_index('ticker')
print(type(data))
date_col = data.ix[:,0]
date_json = date_col.to_json(orient='records')
close_col = data.ix[:,1]
volume = data.ix[:,2]
print(date_col)
close_json = close_col.to_json(orient='records')
print(date_json)
print(close_json)
# We are gonna use Scikit's LinearRegression model
from sklearn.linear_model import LinearRegression
import quandl
import math
import sys, os
predict_accuracy = 0.98
price_compare = "bid"
# FORMAT EXAMPLE
# epic_id = "KA.D.LLOY.DAILY.IP"
# epic_id = "KA.D.BARC.DAILY.IP"
# QUAND_REF = "LSE/LLOY"
# QUAND_REF = "LSE/BARC"
quandl.ApiConfig.api_key = "*********"
#MORE INFORMATION HERE:
#http://help.quandl.com/article/320-where-can-i-find-my-api-key
########################################################################################################################
REAL_OR_NO_REAL = 'https://demo-api.ig.com/gateway/deal'
API_ENDPOINT = "https://demo-api.ig.com/gateway/deal/session"
#API_KEY = '*********'
API_KEY = '*********'
data = {"identifier":"*********","password": "*********"}
########################################################################################################################
########################################################################################################################
########################################################################################################################
# FOR REAL....
########################################################################################################################
########################################################################################################################
########################################################################################################################
def get_adj_close(self, selected):
"""
Get a 3D dataframe of Adjusted close price from Quandl.
"""
# get adjusted closing prices of 5 selected companies with Quandl
quandl.ApiConfig.api_key = 'CxU5-dDyxppBFzVgGG6z'
data = quandl.get_table('WIKI/PRICES', ticker=selected,
qopts={'columns': ['date', 'ticker', 'adj_close']},
date={'gte': START_TRAIN, 'lte': END_TRAIN}, paginate=True)
return data
import pickle
import pandas as pd
import quandl
import matplotlib.pyplot as plt
from matplotlib import style
style.use('seaborn')
quandl.ApiConfig.api_key = 'rFsSehe51RLzREtYhLfo'
def mortgage_30yr():
df = quandl.get('FMAC/MORTG', trim_start="1975-01-01")
df['Value'] = (df['Value'] - df['Value'][0]) / df['Value'][0] * 100
df = df.resample('M').mean()
df.rename(columns={'Value': 'M30'}, inplace=True)
df = df['M30']
return df
def sp500_data():
df = quandl.get("YAHOO/INDEX_GSPC", trim_start="1975-01-01")
df["Adjusted Close"] = (df["Adjusted Close"]-df["Adjusted Close"][0]) / df["Adjusted Close"][0] * 100.0
df=df.resample('M').mean()
df.rename(columns={'Adjusted Close':'sp500'}, inplace=True)
df = df['sp500']
return df
import matplotlib.pyplot as plt
import os
import pandas as pd
from matplotlib import style
from my_utils import my_gather, my_df_cols, FEATURES
from my_keys import quandl_api_key
import numpy as np
from sklearn import svm, preprocessing
import quandl
style.use("ggplot")
style.use('dark_background')
path = "/Users/tomiwa/Downloads/intraQuarter"
quandl.ApiConfig.api_key = quandl_api_key
data = quandl.Dataset("WIKI/KO" ).data(params={ 'start_date':'2001-12-01', 'end_date':'2010-12-30'})
def Key_Stats(gather=my_gather):
statspath = path + '/_KeyStats'
stock_list = [x[0] for x in os.walk(statspath)]
df = pd.DataFrame(columns=my_df_cols)
sp500_df = pd.DataFrame.from_csv("YAHOO-INDEX_GSPC.csv")
stock_list = stock_list[1:550:7]
print('stock_list: ', stock_list)
time.sleep(5)
ticker_list = []
counter = 0
for each_dir in stock_list: # first 25 elements (1-50 skip 2)
"""
DEPRECATED: DOESN'T WORK ANY MORE
"""
import quandl
import pandas as pd
from sysdata.quandl.quandl_utils import load_private_key
from sysdata.fx.spotfx import fxPricesData, fxPrices
from syscore.fileutils import get_filename_for_package
quandl.ApiConfig.api_key = load_private_key()
NOT_IN_QUANDL_MSG = "You can't add, delete, or get a list of codes for Quandl FX data"
QUANDL_CCY_CONFIG_FILE = get_filename_for_package("sysdata.quandl.QuandlFXConfig.csv")
class quandlFxPricesData(fxPricesData):
def __repr__(self):
return "Quandl FX price data"
def _get_fx_prices_without_checking(self, currency_code):
qcode = self._get_qcode(currency_code)
try:
fx_prices = quandl.get(qcode)
except Exception as exception:
self.log.warn("Can't get QUANDL data for %s error %s" % (qcode, exception))
return fxPrices.create_empty()