Finance Data using Python
source code on GitHub - https://github.com/Digital-101/FinanceData
import pandas as pd
import datetime
import numpy as np
import matplotlib.pyplot as plt
from pandas.plotting import scatter_matrix
!pip install yfinance
import yfinance as yf
%matplotlib inline
start = "2022-01-01"
end = '2024-01-01'
apple = yf.download('AAPL',start,end)
amazon = yf.download('AMZN',start,end)
meta = yf.download('META',start,end)
mastercard = yf.download('MA',start,end)
#Volume of Stock Traded
apple['Volume'].plot(label = 'AAPL', figsize = (15,7))
amazon['Volume'].plot(label = "AMZN")
meta['Volume'].plot(label = 'META')
mastercard['Volume'].plot(label = 'MA')
plt.title('Volume of Stock traded')
plt.legend()
#Moving Average
apple['MA50'] = apple['Open'].rolling(50).mean()
apple['MA200'] = apple['Open'].rolling(200).mean()
apple['Open'].plot(figsize = (15,7))
apple['MA50'].plot()
apple['MA200'].plot()
#Volatility - percentage increase
apple['returns'] = (apple['Close']/apple['Close'].shift(1)) -1
amazon['returns'] = (amazon['Close']/amazon['Close'].shift(1))-1
meta['returns'] = (meta['Close']/meta['Close'].shift(1)) - 1
mastercard['returns'] = (mastercard['Close']/mastercard['Close'].shift(1)) - 1
apple['returns'].hist(bins = 100, label = 'Apple', alpha = 0.5, figsize = (15,7))
amazon['returns'].hist(bins = 100, label = 'Amazon', alpha = 0.5)
meta['returns'].hist(bins = 100, label = 'Meta', alpha = 0.5)
mastercard['returns'].hist(bins = 100, label = 'Mastercard', alpha = 0.5)
plt.legend()
Comments
Post a Comment