Skip to content

Instantly share code, notes, and snippets.

View scubamut's full-sized avatar

scubamut

  • Individual
  • Johannesburg and London
View GitHub Profile
https://openincolab.com/
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')
'''
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]
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.
import yfinance as yf
symbols = ['SPY','EEM']
start = '2003-01-03'
end = '2024-01-01'
data = yf.download(symbols,start,end)
# frame of frames
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)
import yfinance as yf
data = yf.download('^GSPC', progress=False)
trading_days = data.index
# 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')
# https://github.com/rafa-rod/pytrendseries/tree/main
@scubamut
scubamut / plot.py
Last active December 28, 2024 11:32
df['Close'].plot(figsize=(12,6), grid=True, title='PERFORMANCE', ylabel='Price', linewidth=1, color='blue', legend=True, secondary_y=False);