This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define a list of the tickers we are interested to observe | |
ticker_list = ['RELIANCE.NS','ADANIPOWER.NS','TCS.NS', 'HDFCBANK.NS', 'WIPRO.NS', 'HCLTECH.NS', 'KOTAKBANK.NS','INFY.NS','M&M.NS', 'BAJFINANCE.NS','ICICIBANK.NS'] | |
# Define function to pull data from yahoo | |
def get_prices(tickers,start): | |
prices = yf.download(tickers, start=start, auto_adjust=False)['Adj Close'] | |
return prices | |
prices_df = get_prices(ticker_list,start) | |
prices_df.shape |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To work with the date | |
import datetime | |
# We will be working with pandas | |
import pandas as pd | |
# To pull the data from yahoo | |
import yfinance as yf | |
# To visualize the results | |
import matplotlib.pyplot as plt | |
import seaborn as sns |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Download the GBPUSD data from 2003 to 2013 | |
data = yf.download('GBPUSD=X', start='2003-12-01', end='2023-10-06', auto_adjust=True, group_by='ticker')['GBPUSD=X'] | |
# Compute the log returns | |
data['returns'] = np.log(data['Close']/data['Close'].shift(1)) | |
# Print the data | |
data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !pip install pyfolio-reloaded | |
# For data manipulation | |
import numpy as np | |
import pandas as pd | |
import yfinance as yf | |
import pyfolio as pf | |
from hmmlearn import hmm | |
from sklearn.utils import check_random_state |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set the for loop | |
for i in range(1,len(monthly_index)): | |
print('='*100) | |
# Set the current month-end variable | |
current_month_end = monthly_index[(i-1)] | |
# Set the next month-end variable | |
next_month_end = monthly_index[i] | |
# Set the span from the previous to the next month end | |
span = len(data.loc[current_month_end:next_month_end,:].index) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from statsmodels.tsa.arima.model import ARIMA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install pandas numpy matplotlib statsmodels yfinance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install pandas statsmodels matplotlib |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz \ | |
&& sudo tar -xzf ta-lib-0.4.0-src.tar.gz \ | |
&& sudo rm ta-lib-0.4.0-src.tar.gz \ | |
&& cd ta-lib/ \ | |
&& sudo ./configure --prefix=/usr \ | |
&& sudo make \ | |
&& sudo make install \ | |
&& cd ~ \ | |
&& sudo rm -rf ta-lib/ \ | |
&& pip install ta-lib |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Predicting the Gold ETF prices | |
predicted_price = linear.predict(X_test) | |
predicted_price = pd.DataFrame( | |
predicted_price, index=y_test.index, columns=['price']) | |
predicted_price.plot(figsize=(10, 7)) | |
y_test.plot() | |
plt.legend(['predicted_price', 'actual_price']) | |
plt.ylabel("Gold ETF Price") | |
plt.show() |
NewerOlder