-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathShort Squeeze Finder
More file actions
1 lines (1 loc) · 13.5 KB
/
Short Squeeze Finder
File metadata and controls
1 lines (1 loc) · 13.5 KB
1
{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":10397718,"sourceType":"datasetVersion","datasetId":6442525},{"sourceId":10397950,"sourceType":"datasetVersion","datasetId":6442687}],"dockerImageVersionId":30822,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"raw","source":"To create an open-source-driven Python script that scrapes the latest cryptocurrency and 24-hour stock markets for Short Squeeze opportunities, we need to utilize data from various market sources, apply technical analysis to detect potential Short Squeeze signals, and display the results in a user-friendly format. The script should calculate potential returns and estimate when the short squeeze is expected to begin based on certain market signals.\n\nHere's an outline of what the script will do:\n\nAnalyze data to detect short squeeze opportunities. A short squeeze typically happens when the price of a stock rises sharply, forcing traders who have bet against the stock (short sellers) to buy shares to cover their positions, further driving the price up. This can be detected by analyzing indicators like:\nShort Interest Ratio: Percentage of shares that are shorted relative to the float.\nPrice Action: Price rising rapidly after consolidation or downward trend.\nVolume: Unusually high volume relative to previous periods.\nDisplay the results: List out potential short squeeze candidates, their expected return, and an estimated time when the squeeze could occur based on historical patterns.","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"code","source":"from IPython.display import clear_output\n!pip install yfinance pandas\n!pip install schedule\n!pip install config\nclear_output()","metadata":{"trusted":true,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2025-01-19T01:14:57.189268Z","iopub.execute_input":"2025-01-19T01:14:57.190015Z","iopub.status.idle":"2025-01-19T01:15:13.069048Z","shell.execute_reply.started":"2025-01-19T01:14:57.189941Z","shell.execute_reply":"2025-01-19T01:15:13.067611Z"}},"outputs":[],"execution_count":1},{"cell_type":"code","source":"import yfinance as yf\nimport pandas as pd\nimport numpy as np\nimport datetime\nimport matplotlib.pyplot as plt\n\n# Function to retrieve stock data\ndef get_stock_data(ticker, start_date, end_date):\n stock_data = yf.download(ticker, start=start_date, end=end_date)\n return stock_data\n\n# Function to calculate short squeeze indicators\ndef calculate_short_squeeze_indicators(stock_data):\n try:\n # Calculate daily returns\n stock_data['Daily Return'] = stock_data['Adj Close'].pct_change()\n \n # Calculate the moving average of volume over the past 20 days\n stock_data['Volume MA'] = stock_data['Volume'].rolling(window=23).mean()\n \n # Calculate the average price over the past 20 days\n stock_data['Price MA'] = stock_data['Adj Close'].rolling(window=23).mean()\n \n # Identify if a short squeeze is happening based on these factors\n stock_data['Potential Squeeze'] = (stock_data['Daily Return'] > 0.0618033988749894848204586834365638117720309179805762862135448622705260462818902449707207204189391137484754088075386891752126633862223536931793180060766726354433389086595939582905638322661319928290267880675208766892501711696207032221043216269548626296313614438149758701220340805887954454749246185695364864449241044320771344947049565846788509874339442212544877066478091588460749988712400765217057517978834166256249407589069704000281210427621771117778053153171410117046665991466979873176135600670874807101317952368942752194843530567830022878569978297783478458782289110976250030269615617002504643382437764861028383126833037242926752631165339247316711121158818638513316203840052221657912866752946549068113171599343235973494985090409476213222981017261070596116456299098162905552085247903524060201727997471753427775927786256194320827505131218156285512224809394712341451702237358057727861600868838295230459264787801788992199027077690389532196819861514378031499741106926088674296226757560523172777520353613936210767389376455606060592165894667595519004005559089502295309423124823552122124154440064703405657347976639723949499465845788730396230903750339938562102423690251386804145779956981224457471780341731264532204163972321340) & \\\n (stock_data['Volume'] > stock_data['Volume MA'] * 1.618033988749894848204586834365638117720309179805762862135448622705260462818902449707207204189391137484754088075386891752126633862223536931793180060766726354433389086595939582905638322661319928290267880675208766892501711696207032221043216269548626296313614438149758701220340805887954454749246185695364864449241044320771344947049565846788509874339442212544877066478091588460749988712400765217057517978834166256249407589069704000281210427621771117778053153171410117046665991466979873176135600670874807101317952368942752194843530567830022878569978297783478458782289110976250030269615617002504643382437764861028383126833037242926752631165339247316711121158818638513316203840052221657912866752946549068113171599343235973494985090409476213222981017261070596116456299098162905552085247903524060201727997471753427775927786256194320827505131218156285512224809394712341451702237358057727861600868838295230459264787801788992199027077690389532196819861514378031499741106926088674296226757560523172777520353613936210767389376455606060592165894667595519004005559089502295309423124823552122124154440064703405657347976639723949499465845788730396230903750339938562102423690251386804145779956981224457471780341731264532204163972321340) & \\\n (stock_data['Adj Close'] > stock_data['Price MA'] * 1.1111131111131111133131131313311313111113313113131331131311111331311313133113131111133131131313311313311313131313)\n except:\n pass\n return stock_data\n\n# Function to identify stocks with potential short squeeze\ndef identify_short_squeeze_stocks(tickers):\n today = datetime.date.today()\n start_date = (today - datetime.timedelta(days=365.24218966)).strftime('%Y-%m-%d') # 1-year data\n\n short_squeeze_stocks = []\n \n for ticker in tickers:\n try:\n stock_data = get_stock_data(ticker, start_date, today)\n except:\n pass\n \n try:\n if stock_data.empty:\n continue\n except:pass\n \n try:\n stock_data_with_indicators = calculate_short_squeeze_indicators(stock_data)\n except:\n pass\n \n try:\n \n # Check for the most recent short squeeze signal\n if stock_data_with_indicators['Potential Squeeze'].iloc[-1]:\n short_squeeze_stocks.append({\n 'Ticker': ticker,\n 'Recent Price': stock_data_with_indicators['Adj Close'].iloc[-1],\n 'Recent Volume': stock_data_with_indicators['Volume'].iloc[-1],\n 'Daily Return': stock_data_with_indicators['Daily Return'].iloc[-1],\n 'Volume MA': stock_data_with_indicators['Volume MA'].iloc[-1],\n 'Price MA': stock_data_with_indicators['Price MA'].iloc[-1],\n 'Short Squeeze': True\n })\n except:\n pass \n return short_squeeze_stocks\n\n# List of tickers to analyze\n# takes too long \n# tickers = pd.read_csv(\"/kaggle/input/tickers-stocks/stock_info.csv\",header=None).values.tolist()\n\n\ntickers = pd.read_csv(\"/kaggle/input/tickers-stock-market-amex/tickers.csv\").values.tolist()\n\n# Identify short squeeze opportunities\nshort_squeeze_opportunities = identify_short_squeeze_stocks(tickers)\n\n# Display results\nif short_squeeze_opportunities:\n df = pd.DataFrame(short_squeeze_opportunities).head()\n print(\"Short Squeeze Opportunities Detected:\")\n print(df)\nelse:\n print(\"No short squeeze opportunities detected at this time.\")\nclear_output()","metadata":{"trusted":true,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2025-01-19T02:29:53.032289Z","iopub.execute_input":"2025-01-19T02:29:53.032744Z","iopub.status.idle":"2025-01-19T02:30:33.459621Z","shell.execute_reply.started":"2025-01-19T02:29:53.032710Z","shell.execute_reply":"2025-01-19T02:30:33.458463Z"}},"outputs":[],"execution_count":4},{"cell_type":"code","source":"print(f\"Short Squeezes For {datetime.date.today()}\")\ndf","metadata":{"trusted":true,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2025-01-19T02:30:33.461314Z","iopub.execute_input":"2025-01-19T02:30:33.461648Z","iopub.status.idle":"2025-01-19T02:30:33.480295Z","shell.execute_reply.started":"2025-01-19T02:30:33.461620Z","shell.execute_reply":"2025-01-19T02:30:33.479117Z"}},"outputs":[{"name":"stdout","text":"Short Squeezes For 2025-01-19\n","output_type":"stream"},{"execution_count":5,"output_type":"execute_result","data":{"text/plain":" Ticker Recent Price Recent Volume Daily Return Volume MA Price MA \\\n0 [CHRO] 1.900 14190200 0.979167 748782.608696 0.796826 \n1 [PZG] 0.398 207400 0.105556 101704.347826 0.351000 \n2 [USAS] 0.500 1902600 0.063830 628521.739130 0.409130 \n3 [VINE] 0.690 375200 0.229947 148182.608696 0.608043 \n\n Short Squeeze \n0 True \n1 True \n2 True \n3 True ","text/html":"<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>Ticker</th>\n <th>Recent Price</th>\n <th>Recent Volume</th>\n <th>Daily Return</th>\n <th>Volume MA</th>\n <th>Price MA</th>\n <th>Short Squeeze</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>[CHRO]</td>\n <td>1.900</td>\n <td>14190200</td>\n <td>0.979167</td>\n <td>748782.608696</td>\n <td>0.796826</td>\n <td>True</td>\n </tr>\n <tr>\n <th>1</th>\n <td>[PZG]</td>\n <td>0.398</td>\n <td>207400</td>\n <td>0.105556</td>\n <td>101704.347826</td>\n <td>0.351000</td>\n <td>True</td>\n </tr>\n <tr>\n <th>2</th>\n <td>[USAS]</td>\n <td>0.500</td>\n <td>1902600</td>\n <td>0.063830</td>\n <td>628521.739130</td>\n <td>0.409130</td>\n <td>True</td>\n </tr>\n <tr>\n <th>3</th>\n <td>[VINE]</td>\n <td>0.690</td>\n <td>375200</td>\n <td>0.229947</td>\n <td>148182.608696</td>\n <td>0.608043</td>\n <td>True</td>\n </tr>\n </tbody>\n</table>\n</div>"},"metadata":{}}],"execution_count":5},{"cell_type":"markdown","source":"# Notification","metadata":{"_kg_hide-input":true}},{"cell_type":"code","source":"import schedule,warnings,time,ast,config,sys,random,smtplib,datetime\nclear_output()\nCARRIERS = {\"att\": \"@mms.att.net\",\"tmobile\": \"@tmomail.net\",\"verizon\": \"@vtext.com\",\"sprint\": \"@messaging.sprintpcs.com\"}\n\n# email-password mappings & randomizer\nemail_passwords = {\"aristocles24@gmail.com\": [\"vfvv ingo zjom duzo\",\"mwug tyxy ircx xgbk\",\"fyrs ciyw iwyd amaz\"],\n \"existentialkingdom@gmail.com\": [\"vfvv ingo zjom duzo\",\"bjgm iqhf nkle wskn\",\"hxep heai vbwd jffj\"]}\n\n# email-password randomizer\ndef get_random_email_password():\n \"\"\"Randomly selects an email and a corresponding password.\"\"\"\n # Randomly select an email\n email = random.choice(list(email_passwords.keys()))\n # Randomly select a password for the chosen email\n password = random.choice(email_passwords[email])\n return email, password\n# Generate a random email-password pair\nEMAIL, PASSWORD = get_random_email_password()\n\n# Output the selected pair\nprint(f\"EMAIL = \\\"{EMAIL}\\\"\")\nprint(f\"PASSWORD = \\\"{PASSWORD}\\\"\")\n\ndef send_message(phone_number, carrier, message):\n recipient = phone_number + CARRIERS[carrier]\n auth = (EMAIL, PASSWORD)\n server = smtplib.SMTP(\"smtp.gmail.com\", 587)\n server.starttls()\n server.login(auth[0], auth[1])\n server.sendmail(auth[0], recipient, message)\nsms=print(df.sort_values('Recent Price',ascending=True).reset_index(drop=True).drop(columns=['Short Squeeze']))\n\ndef wake_up_wake_up():\n print(\"\\nShort Squeezes Baby\")\n send_message(\"3016750611\",\"tmobile\",sms)\n send_message(\"4809302330\",\"tmobile\",sms)\n print(\"\\nSMS Sent to Recipients.\")","metadata":{"trusted":true,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2025-01-19T02:12:15.818267Z","iopub.status.idle":"2025-01-19T02:12:15.818630Z","shell.execute_reply":"2025-01-19T02:12:15.818485Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# en fin","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-19T02:12:15.819363Z","iopub.status.idle":"2025-01-19T02:12:15.819756Z","shell.execute_reply":"2025-01-19T02:12:15.819556Z"}},"outputs":[],"execution_count":null}]}