Skip to content

Instantly share code, notes, and snippets.

@18182324
Created August 31, 2023 16:29
Show Gist options
  • Save 18182324/5506b6a1b808bded373abd77d01e25dd to your computer and use it in GitHub Desktop.
Save 18182324/5506b6a1b808bded373abd77d01e25dd to your computer and use it in GitHub Desktop.
Quandl Fundamental Analysis
# Import necessary libraries
import quandl
import matplotlib.pyplot as plt
# Set your Quandl API key (you need to sign up on Quandl's website to get your API key)
quandl.ApiConfig.api_key = 'YOUR_API_KEY'
# Define the companies and their respective dataset codes
companies = {
'Google': 'WIKI/GOOGL', # Replace with the correct dataset code for Google
'Yahoo': 'WIKI/YHOO', # Replace with the correct dataset code for Yahoo
'Apple': 'WIKI/AAPL' # Replace with the correct dataset code for Apple
}
# Define the date range for the past five years
start_date = '2018-07-31'
end_date = '2023-07-31'
# Initialize empty dictionaries to store the data
revenues = {}
# Fetch the revenue data for each company and store it in the 'revenues' dictionary
for company, dataset_code in companies.items():
data = quandl.get(dataset_code, start_date=start_date, end_date=end_date, column_index=1)
revenues[company] = data
# Plot the revenue data
plt.figure(figsize=(12, 6))
for company, revenue_data in revenues.items():
plt.plot(revenue_data.index, revenue_data['Adj. Close'], label=company)
# Customize the plot
plt.title('Revenue Comparison: Google vs. Yahoo vs. Apple')
plt.xlabel('Year')
plt.ylabel('Revenue')
plt.legend()
plt.grid(True)
# Show the plot
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment