Python code for grabbing data from yahoo finance

Assignment Help Python Programming
Reference no: EM13842066

I am new to Phython. Using Spyder IDE Simple code. It is not recognizing by Data file see line 33.

I/O error TSX_Listing.cvs not found

# -*- coding: utf-8 -*-
"""

Assignment 1 Sample code: Python code for grabbing data from Yahoo!Finance

Note: This code guides you to grab Canadian stock returns data from Yahoo!Finance.

The purpose of this assignment is to get you familiar with the Python. Enjoy!

Reference: https://pandas.pydata.org/pandas-docs/stable/remote_data.html
Source file https://github.com/pydata/pandas/blob/master/pandas/io/data.py
"""

# Load packages
import pandas.io.data as web
import datetime
import pandas as pd
import os
import numpy as np
import statsmodels.formula.api as sm

#create your current working directory of the located .py file
directory = 'C:\\Users\\maryannp\\Documents\\Phython Scripts\\Assignment#1'

#Choose your starting and ending time
start = datetime.datetime(2014, 1, 1) #(YYYY, m, d)
end = datetime.datetime(2014, 12, 31)

#Load the csv file with the TSX Tickers, this code assume that the ticker files
#located in the same folder as the directory
tickers = pd.read_csv(directory + '\\' + 'TSX_Listing.csv')
tickers = list(tickers['YAHOO_TICKER'])

#Intiate the dictionnary that will store all the downloaded tick data
d = pd.DataFrame()

# Options for web.DataReader function:
"""
input 1: ticker in string form - Ex: OSPTX is for the S&P/TSX
input 2: the source (ex: 'yahoo' or 'google') to download the data from
input 3: start time in datatime.datetime format
input 4: end time in datatime.datetime format
"""
#Loop over each tickers to load the data to be stored in the dictionnary d
for tick in tickers:
f = web.DataReader(tick, 'yahoo', start, end)
d[tick] = f['Adj Close'] # select the adjusted close price

# how to calculate simple returns
ret=d.pct_change()
#Example on how to compute the log returns for all the stocks in d
d_lret = np.log(d) - np.log(d.shift())

#export the return data to csv file
d_lret.to_csv ('C:\\Users\\maryannp\\Documents\\Phyton Scripts\\Assignment#1\\TSX_data2014.csv')

Attachment:- TSX_Listing.csv

Reference no: EM13842066

Questions Cloud

Perform preliminary SWOT analysis : Based on the information provided on the website, describe Sony's SBUs. Does Sony have SBUs that are divisions, product lines, or some other profit center structure within the parent company? Assess the quality and effectiveness of Sony's website. Sp..
What is corporate entrepreneurship : In your own words, what is corporate entrepreneurship? What are some of the corporate obstacles that must be overcome to establish a corporate entrepreneurial environment? What are some of the innovative principles identified by James Brian Quinn tha..
External resource approach and internal systems approach : As a leader in business, what one would be your preferred approach (External Resource Approach / Internal Systems Approach / Technical Approach) and why? Have you had the opportunity to experience any of them first hand?
Most projects overrun their budget : Did you overrun the project budget again? Discuss from your experience some of the most important components of good project management practices. What is your view on the statement "Most projects overrun their budget?" Give specific examples from yo..
Python code for grabbing data from yahoo finance : I am new to Phython. Using Spyder IDE Simple code. It is not recognizing by Data file see line 33 - The purpose of assignment is to get you familiar with the Python.
Ethically responsible for what occurred : Identify a company you believe is/was ethically responsible for what occurred. How would you have approached this differently as the CEO/Marketer to ensure this hadn't happened? Be sure to share the URL with your fellow students of the organization y..
The glass ceiling is an invisible barrier : The textbook states the "glass ceiling" is an invisible barrier that exists for women and minorities that limits their upward mobility. Do you feel this ceiling still exists? Why?
Helpful in measuring nonfinancial performance : Research Six Sigma, Balanced Scorecard, and Triple Bottom Line. (A Google search with ethics AND the chosen model works well.) Which do you think would be most helpful in measuring nonfinancial performance? Why?
Planning and goals are important part of any undertaking : Planning and goals are an important part of any undertaking. Who do you feel they should be including in business planning and why

Reviews

Write a Review

Python Programming Questions & Answers

  Arithmetic progression is a sequence of numbers

An arithmetic progression is a sequence of numbers in which the distance (or difference) between any two successive numbers if the same.

  Question 1 research 5-8 species within one family of birds

question 1 research 5-8 species within one family of birds. be sure to use primary or very good secondary literature

  Question 1 research 5-8 species within one family of birds

question 1 research 5-8 species within one family of birds. be sure to use primary or very good secondary literature

  Permutation ciphers

Permutation Ciphers (a.k.a. Transposition Ciphers) are another class of simple cryptosystems. For this we use the functions apply(.,.) and inv(.) from Homework 4; copy these two functions into your le as auxiliary functions.

  Python journeyman

What are the steps YOU would recommend to a Python journeyman, from apprenticeship to guru status?

  The number of lowercase letters in the file

The number of uppercase letters in the file The number of lowercase letters in the file

  We would like to implement the lexical order

We would like to implement the lexical order for lists. For simplicity, we only consider lists of numbers, where , >= have their usual meaning.

  Data file is a comma separated

The data file is a comma separated text values stored in a file with '.CSV' extension. The file has five columns corresponding to employee data fields listed above.

  Write a python program that performs simple encryption

You are required to write a Python program that performs simple encryption and decryption on strings entered by the user. To do so, you are to use one of the simplest and most widely known encryption techniques known as the Caesar Cipher

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  Write a function rmduplic(l), where l is any list

Write a function rmDuplic(L), where L is any list. The function should return a list M that contains the same items as L, except that repetitions (duplicates) have been removed: only the first occurrence of each entry is kept (i.e., order is prese..

  Turn the turtle image into a .gif picture

How can you turn the turtle image into a .gif picture when using the built-in turtle for Python? If that's impossible how do you remove the line when you move the turtle around?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd