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
| ETF_UNIVERSE = { | |
| 'Technology': ['XLK', 'VGT', 'FTEC', 'IYW', 'SOXX'], | |
| 'Healthcare': ['XLV', 'VHT', 'IYH', 'FHLC', 'IBB'], | |
| 'Financials': ['XLF', 'VFH', 'IYF', 'FNCL', 'KRE'], | |
| 'Energy': ['XLE', 'VDE', 'IYE', 'FENY', 'OIH'], | |
| 'Consumer Discretionary': ['XLY', 'VCR', 'IYC', 'FDIS', 'RTH'], | |
| 'Consumer Staples': ['XLP', 'VDC', 'IYK', 'FSTA', 'KXI'], | |
| 'Industrials': ['XLI', 'VIS', 'IYJ', 'FIDU', 'ITA'], | |
| 'Real Estate': ['XLRE', 'VNQ', 'IYR', 'FREL', 'RWR'], | |
| 'Utilities': ['XLU', 'VPU', 'IDU', 'FUTY', 'PUI'], |
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
| https://openincolab.com/ |
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
| import logging | |
| # Set up logging | |
| logger = logging.getLogger(__name__) # create a logger | |
| logger.propagate = False # Add this line | |
| logger.setLevel(logging.DEBUG) # set logging level | |
| logger.handlers.clear() # Add this before adding your new handler | |
| handler = logging.StreamHandler() # Create a console handler | |
| # set the logging format | |
| formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') |
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
| ''' | |
| The asterisk * is the unpacking operator in Python. | |
| - When used before an iterable (like a list, tuple, or generator), it "unpacks" the elements of that iterable. | |
| - Unpacking can be used in multiple contexts: | |
| + Function arguments: function(*iterable) passes elements of the iterable as separate positional arguments to the function. | |
| + Creating new iterables: [ *iterable1 , *iterable2 ] creates a new list by combining elements from both. | |
| ''' | |
| def my_function(a, b, c): | |
| print(f"a = {a}, b = {b}, c = {c}") | |
| my_list = [10, 20, 30] |
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
| def get_etf_data(symbols, period='2y'): | |
| """Download ETF data with comprehensive error handling""" | |
| data = {} | |
| successful_downloads = 0 | |
| # print(f"📊 Downloading data for {len(symbols)} ETFs...") | |
| for i, symbol in enumerate(symbols): | |
| try: | |
| # print(f" • Fetching {symbol}... ({i+1}/{len(symbols)})", end="") | |
| ticker = yf.Ticker(symbol) | |
| # Get historical 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
| import requests | |
| import io | |
| FILE_ID = '1e8hAGdDC2hAbEnosh1Odo9tAj_Wlzl8H' | |
| LOCAL_FILE_NAME = 'TA_Lib-0.4.26-cp310-cp310-linux_x86_64.whl' | |
| def download_public_file(file_id, local_file_name): | |
| url = f'https://drive.google.com/uc?id={file_id}' | |
| try: | |
| response = requests.get(url, stream=True) |
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
| import yfinance as yf | |
| data = yf.download('^GSPC', progress=False) | |
| trading_days = data.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
| # MONDAY '201005031' WAS NOT TRADING DAY!!!!! | |
| !pip -q install pandas_market_calendars | |
| import pandas_market_calendars as mcal | |
| # Create a calendar | |
| nyse = mcal.get_calendar('NYSE') | |
| early = nyse.schedule(start_date='2010-05-15', end_date='2010-06-15') |
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
| # https://github.com/rafa-rod/pytrendseries/tree/main |
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
| df['Close'].plot(figsize=(12,6), grid=True, title='PERFORMANCE', ylabel='Price', linewidth=1, color='blue', legend=True, secondary_y=False); |
NewerOlder