Skip to content

Instantly share code, notes, and snippets.

View jweinst1's full-sized avatar
🎯
Focusing

Josh Weinstein jweinst1

🎯
Focusing
View GitHub Profile
@jweinst1
jweinst1 / ib_profit_taker_order.py
Created May 8, 2026 00:13
script to submit profit taker orders
from ib_async import IB, Stock, LimitOrder
import asyncio
# ================== CONFIG ==================
HOST = '127.0.0.1'
PORT = 4001 # ← Change to your Gateway port (4002 paper / 4001 live)
CLIENT_ID = 125 # unique per script
# ================== CONNECT WITH ERROR HANDLING ==================
ib = IB()
@jweinst1
jweinst1 / ordergen.py
Created May 7, 2026 01:34
main script for stock order generation
import yfinance as yf
import requests
import csv
import io
import sys
import statistics
import random
def get_sp500_tickers() -> list[str]:
@jweinst1
jweinst1 / any_tickers_ishares.py
Last active May 7, 2026 01:34
snippets to get ticker lists from ishares catalogue CSVs
import requests
import csv
import io
def get_ishares_tickers(etf_ticker: str = "IVV") -> list[str]:
"""
Fetches current constituents from any major iShares US equity ETF via their holdings CSV.
Pure Python + built-in csv module. No pandas. Handles the messy header + huge disclaimer.
Returns clean tickers ready for yfinance (BRK.B → BRK-B).
@jweinst1
jweinst1 / russell2000.py
Last active May 2, 2026 08:21
get russell 2000 tickers in python
import requests
import csv
import io
def get_russell_2000_tickers() -> list[str]:
"""
Fetches current Russell 2000 constituents from iShares IWM ETF holdings CSV.
Pure Python + built-in csv module. No pandas. Handles the messy header + huge disclaimer.
Returns clean tickers ready for yfinance (BRK.B → BRK-B).
"""
@jweinst1
jweinst1 / stat.py
Last active April 18, 2026 22:35
a study on moving deviation for stocks relative to SMA and analyzing volatility
>>> statistics.mean([0.02, 0.01, -0.06, 0.01])
-0.004999999999999999
>>> statistics.stdev([0.02, 0.01, -0.06, 0.01])
0.03696845502136473
>>> statistics.stdev([0.02, 0.01, -0.02, 0.01])
0.017320508075688773
>>> statistics.mean([0.02, 0.01, -0.01, 0.01])
0.0075
>>> statistics.stdev([0.02, 0.01, -0.00, 0.01])
0.008164965809277261
@jweinst1
jweinst1 / rsi_zones.js
Last active April 16, 2026 19:37
Display zones of RSIs in google sheets for stock
/**
* Calculates the current RSI using your exact percentage-based logic (no smoothing)
*
* @param {A1:A100} priceRange Range containing historical closing prices (oldest to newest)
* @param {number} period RSI period (default 14)
* @return {number} Current RSI value, rounded to 2 decimals
* @customfunction
*/
function CURRENT_RSI(priceRange, period = 14) {
@jweinst1
jweinst1 / nextclosing.js
Last active April 13, 2026 04:32
Next Closing RSI google Sheets script
/**
* FIXED VERSION - Calculates the next closing price needed to reach a target RSI
* Matches your exact percentage-based RSI (no smoothing) perfectly.
*
* @param {A1:A100} priceRange Range containing closing prices (oldest to newest)
* @param {number} period RSI period (default 14)
* @param {number} threshold Target RSI (e.g. 30 or 20)
* @param {string} direction "above" or "below"
* @return {number} Next closing price needed
* @customfunction
@jweinst1
jweinst1 / rsi_window_sliding.py
Last active April 11, 2026 21:50
python script for multi column stock CSV and seeing duration of N day RSI zones
import csv
from typing import Dict, List, Optional
import math # only for sqrt in correlation (pure basics)
def is_float(num):
try:
float(num)
return True
@jweinst1
jweinst1 / full_rsi_window.js
Last active April 10, 2026 23:40
full sliding window of RSI for google sheets
/**this works on already flat array */
function RSIRNG(prices, start, end) {
if (!Array.isArray(prices)) {
throw "Second argument must be a range (e.g. B2:B100)";
}
// Calculate percentage changes
let diffPcnts = [];
for (let i = start + 1; i < end; i++) {
let change = prices[i] - prices[i - 1];
diffPcnts.push(change / prices[i - 1]);
@jweinst1
jweinst1 / rsi_sliding_window.js
Created April 2, 2026 00:44
google app script sliding window function
/**
* Calculates RSI using the last N closing prices up to the current row.
* @param {number} period The RSI period (e.g. 7, 14)
* @param {range} priceRange The full range of closing prices (e.g. C2:C)
* @return The RSI value for the current row.
* @customfunction
*/
function RSI(period, priceRange) {
if (!priceRange || !Array.isArray(priceRange)) {
return "Invalid price range";