def download_weekly_bars(instrument, year, csvFile): """Download weekly bars from Yahoo! Finance for a given year. :param instrument: Instrument identifier. :type instrument: string. :param year: The year. :type year: int. :param csvFile: The path to the CSV file to write. :type csvFile: string. """ begin = dt.get_first_monday(year) end = dt.get_last_monday(year) + datetime.timedelta(days=6) bars = download_csv(instrument, begin, end, "w") f = open(csvFile, "w") f.write(bars) f.close()
def download_weekly_bars(sourceCode, tableCode, year, csvFile, authToken=None): """Download weekly bars from Quandl for a given year. :param sourceCode: The dataset's source code. :type sourceCode: string. :param tableCode: The dataset's table code. :type tableCode: string. :param year: The year. :type year: int. :param csvFile: The path to the CSV file to write. :type csvFile: string. :param authToken: Optional. An authentication token needed if you're doing more than 50 calls per day. :type authToken: string. """ begin = dt.get_first_monday(year) - datetime.timedelta(days=1) # Start on a sunday end = dt.get_last_monday(year) - datetime.timedelta(days=1) # Start on a sunday bars = download_csv(sourceCode, tableCode, begin, end, "weekly", authToken) f = open(csvFile, "w") f.write(bars) f.close()
def testGetFirstMonday(self): self.assertEquals(dt.get_first_monday(2010), datetime.date(2010, 1, 4)) self.assertEquals(dt.get_first_monday(2011), datetime.date(2011, 1, 3))
nasdaq_df = pd.read_csv("data/nasdaq.csv") nasdaq_df = nasdaq_df[nasdaq_df.Industry != 'n/a'] #amex amex_df = pd.read_csv("data/amex.csv") amex_df = amex_df[amex_df.Industry != 'n/a'] #ntse nyse_df = pd.read_csv("data/nyse.csv") nyse_df = nyse_df[nyse_df.Industry != 'n/a'] now = datetime.datetime.now() year = now.year begin = dt.get_first_monday(year-3) end = dt.get_last_monday(year) + datetime.timedelta(days=6) data = nasdaq_df['Symbol'].tolist() + amex_df['Symbol'].tolist() + nyse_df['Symbol'].tolist() def callback(request, result): symbol = request.args[0] csvFile = "result/%s.csv"%(symbol) if result is not None: f = open(csvFile, "w") f.write(result) f.close() def run(symbol):
nasdaq_df = pd.read_csv("data/nasdaq.csv") nasdaq_df = nasdaq_df[nasdaq_df.Industry != 'n/a'] #amex amex_df = pd.read_csv("data/amex.csv") amex_df = amex_df[amex_df.Industry != 'n/a'] #ntse nyse_df = pd.read_csv("data/nyse.csv") nyse_df = nyse_df[nyse_df.Industry != 'n/a'] now = datetime.datetime.now() year = now.year BEGIN = dt.get_first_monday(year - 3) END = dt.get_last_monday(year) + datetime.timedelta(days=6) DATA = nasdaq_df['Symbol'].tolist() + amex_df['Symbol'].tolist( ) + nyse_df['Symbol'].tolist() def callback(request, result): symbol = request.args[0] csvFile = "result/%s.csv" % (symbol) if result is not None: f = open(csvFile, "w") f.write(result) f.close()
nasdaq_df = pd.read_csv("data/nasdaq.csv") nasdaq_df = nasdaq_df[nasdaq_df.Industry != 'n/a'] #amex amex_df = pd.read_csv("data/amex.csv") amex_df = amex_df[amex_df.Industry != 'n/a'] #ntse nyse_df = pd.read_csv("data/nyse.csv") nyse_df = nyse_df[nyse_df.Industry != 'n/a'] now = datetime.datetime.now() year = now.year BEGIN = dt.get_first_monday(year - 3) END = dt.get_last_monday(year) + datetime.timedelta(days=6) DATA = nasdaq_df['Symbol'].tolist() + amex_df['Symbol'].tolist() + nyse_df['Symbol'].tolist() def callback(request, result): symbol = request.args[0] csvFile = "result/%s.csv"%(symbol) if result is not None: f = open(csvFile, "w") f.write(result) f.close() def run(symbol):