This file contains 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 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 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 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 | |
import pandas as pd | |
from datetime import datetime, timedelta | |
import logging | |
def get_data(symbols, start_date, end_date=None, frequency='daily'): | |
""" | |
Fetches historical data for one or more ETFs using yfinance. |
This file contains 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 | |
symbols = ['SPY','EEM'] | |
start = '2003-01-03' | |
end = '2024-01-01' | |
data = yf.download(symbols,start,end) | |
# frame of frames |
This file contains 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 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 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 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 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