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

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  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.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

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