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
// === INPUTS === | |
Inputs: | |
ORStart(0930), | |
OREnd(0950), | |
ARangeTicks(8), | |
CRangeTicks(8), | |
ConfirmBars(3), | |
MaxBarsLookback(30); | |
// === VARIABLES === |
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
Inputs: | |
Length(14); // Optimizable lookback period | |
Vars: | |
UpCount(0), | |
DownCount(0), | |
UpSum(0), | |
DownSum(0), | |
i(0), | |
PriceChange(0), |
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 json | |
import time | |
from bs4 import BeautifulSoup | |
# ================================================ | |
# CONFIGURATION | |
# ================================================ | |
# Your SEC EDGAR user agent string |
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 | |
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' |
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 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', |
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 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 |
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 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 |
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
#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 |
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
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 |
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 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 |
NewerOlder