Skip to content

Instantly share code, notes, and snippets.

View 18182324's full-sized avatar
🎯
Focusing

Milton_FMR 18182324

🎯
Focusing
View GitHub Profile
@18182324
18182324 / 1_n factor strategy.py
Created September 7, 2023 20:31
Portfolio Allocatgion 1_N Factor Investing
import yfinance as yf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Define a list of stock tickers for the portfolio
tickers = ['AAPL', 'MSFT', 'GOOGL', 'AMZN', 'TSLA']
# Set the date range for historical data
start_date = '2010-01-01'
@18182324
18182324 / Comparing GDP Values of BRICS Nations Using Quandl.py
Created August 31, 2023 16:40
Comparing GDP Values of BRICS Nations Using Quandl
# Import necessary libraries
import quandl
import matplotlib.pyplot as plt
# Set your Quandl API key (you need to sign up on Quandl's website to get your API key)
quandl.ApiConfig.api_key = 'YOUR_API_KEY'
# Define the dataset codes for the BRICS nations' GDP
brics_gdp_datasets = {
'Brazil': 'ODA/BRA_NGDPD',
@18182324
18182324 / Analyzing Trade Entry and Exit Positions with Regression Analysis.py
Created August 31, 2023 16:36
Analyzing Trade Entry and Exit Positions with Regression Analysis with Quandl
# Import necessary libraries
import quandl
import numpy as np
import matplotlib.pyplot as plt
# Set your Quandl API key (you need to sign up on Quandl's website to get your API key)
quandl.ApiConfig.api_key = 'YOUR_API_KEY'
# Define the dataset codes for Google and Yahoo
google_dataset = 'WIKI/GOOGL' # Replace with the correct dataset code for Google
@18182324
18182324 / Quandl Fundamental Analysis.py
Created August 31, 2023 16:29
Quandl Fundamental Analysis
# Import necessary libraries
import quandl
import matplotlib.pyplot as plt
# Set your Quandl API key (you need to sign up on Quandl's website to get your API key)
quandl.ApiConfig.api_key = 'YOUR_API_KEY'
# Define the companies and their respective dataset codes
companies = {
'Google': 'WIKI/GOOGL', # Replace with the correct dataset code for Google
@18182324
18182324 / Perry Kaufmann Market Efficiency Algo.py
Created June 15, 2023 16:24
SPY Trading Algo - Kaufmann Market Efficiency
#Here's a full example of Perry Kaufman's market efficiency strategy implemented in Python, including backtesting capabilities
#using historical data. Remember that this is a simplified example for educational purposes, and it does not include considerations
#such as transaction costs or slippage.
pip install pandas numpy yfinance matplotlib
import pandas as pd
import numpy as np
import yfinance as yf
import matplotlib.pyplot as plt
library(quantmod)
# Download SPY data from Yahoo Finance
getSymbols("SPY", src = "yahoo", from = "2007-01-01", to = "2022-04-07")
# Calculate moving average
ma_length <- 38
ma <- SMA(Cl(SPY), n = ma_length)
# Calculate OBV
@18182324
18182324 / Momentum SPY Trading Strategy.py
Created April 7, 2023 18:51
Momentum Trading in Python
import pandas as pd
import backtrader as bt
# Define the strategy
class MyStrategy(bt.Strategy):
params = dict(
ma_length=50,
obv_ma_length=200,
target=5000,
stop=4000
@18182324
18182324 / Pairs Trading Z Score Top 10 Pairs.py
Last active February 1, 2023 18:57
Pairs Trading S&P 500 Tickers
import pandas as pd
import numpy as np
from pandas_datareader import data as pdr
import statsmodels
from statsmodels.tsa.stattools import coint
import matplotlib.pyplot as plt
# Step 1: Download the stock data from yahoo finance for all stocks in the S&P 500 Index
tickers = pd.read_html("https://en.wikipedia.org/wiki/List_of_S%26P_500_companies")[0]["Symbol"].tolist()
data = pdr.get_data_yahoo(tickers, start="2010-01-01", end="2022-12-31")["Adj Close"]
@18182324
18182324 / Framework fixed income asset allocation model.py
Created January 5, 2023 21:55
Quant Fidelity Fixed Income Asset Allocation Model
import pandas as pd
import matplotlib.pyplot as plt
import yfinance as yf
import requests
# Load the data for the macro, fundamentals, sentiment, and valuation pillars
macro_data = pd.read_csv('macro_data.csv')
fundamentals_data = pd.read_csv('fundamentals_data.csv')
sentiment_data = pd.read_csv('sentiment_data.csv')
valuation_data = pd.read_csv('valuation_data.csv')
@18182324
18182324 / Highest return optimization algorithm.py
Created January 5, 2023 21:04
Tactical Asset Allocation and Automatic Optimization
import numpy as np
import pandas as pd
import yfinance as yf
from scipy.optimize import minimize
# Download the ETF data from Yahoo Finance
etf_data = {}
for etf in ['SPY', 'MDY', 'EFA', 'EEM', 'TLT']:
etf_data[etf] = yf.Ticker(etf).history(period="10y")