Skip to content

Instantly share code, notes, and snippets.

View yongghongg's full-sized avatar
🏠
Working from home

Yonghong Tan yongghongg

🏠
Working from home
View GitHub Profile
@yongghongg
yongghongg / stock_screener.py
Last active October 19, 2024 06:01
Build your own technical analysis stock screener using Python
#import required modules
from bs4 import BeautifulSoup
import ast
import pandas as pd
import re
import requests
from datetime import datetime
def get_stock_price(ticker):
# pass a ticker name to i3investor website url
@yongghongg
yongghongg / japanese_dict_app.gs
Last active March 9, 2021 07:04
japanese_dict_app.gs
function getJapReading(word) {
var url = "http://jisho.org/api/v1/search/words?keyword=" + word;
var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
var json = JSON.parse(response.getContentText());
japReading = json.data[0].japanese[0].reading;
return japReading;
}
function getEnglishDef(word) {
var url = "http://jisho.org/api/v1/search/words?keyword=" + word;
def get_stock_price(ticker):
data = yf.download(ticker, start="2021-01-01")
return data
def add_EMA(price, day):
return price.ewm(span=day).mean()
def add_STOCH(close, low, high, period, k, d=0):
STOCH_K = ((close - low.rolling(window=period).min()) / (high.rolling(window=period).max() - low.rolling(window=period).min())) * 100
STOCH_K = STOCH_K.rolling(window=k).mean()
# function to check for EMA Bounce
def check_bounce_EMA(df):
candle1 = df.iloc[-1]
candle2 = df.iloc[-2]
cond1 = candle1['EMA18'] > candle1['EMA50'] > candle1['EMA100']
cond2 = candle1['STOCH_%K(5,3,3)'] <= 30 or candle1['STOCH_%D(5,3,3)'] <= 30
cond3 = candle2['Low'] < candle2['EMA50'] and \
candle2['Close'] > candle2['EMA50'] and \
candle1['Low'] > candle1 ['EMA50']
return cond1 and cond2 and cond3
import requests
from bs4 import BeautifulSoup
import yfinance as yf
def get_stock_list():
# this is the website we're going to scrape from
url = "https://www.malaysiastock.biz/Stock-Screener.aspx"
response = requests.get(url, headers={'User-Agent':'test'})
soup = BeautifulSoup(response.content, "html.parser")
table = soup.find(id = "MainContent2_tbAllStock")
import email
# you can add this part of code at the end of part 2
# remember: screened_list contains the result of the screening
# configure email and message
msg = email.message_from_string(", ".join(screened_list))
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
msg['Subject'] = "EMA Bounce Result for Today!"
s = smtplib.SMTP("smtp.gmail.com",587)
import requests
from bs4 import BeautifulSoup
def get_stock_list():
# this is the website we're going to scrape from
url = "https://www.malaysiastock.biz/Stock-Screener.aspx"
response = requests.get(url, headers={'User-Agent':'test'})
soup = BeautifulSoup(response.content, "html.parser")
table = soup.find(id = "MainContent2_tbAllStock")
# return the result (only ticker code) in a list
# import required libraries
import pandas as pd
import yfinance as yf
import numpy as np
import math
# get stock prices
df = yf.download('AAPL', start='2020-01-01', threads= False)
# parameter setup
# we are using mplfinance to help us visualize the indicator
import mplfinance as mpf
# to make the visualization better by only taking the last 100 rows of data
df = df[-100:]
# extract only ['Open', 'High', 'Close', 'Low'] from df
ohcl = df[['Open', 'High', 'Close', 'Low']]
# add colors for the 'value bar'
import pandas as pd
import numpy as np
from datetime import datetime
import yfinance as yf
import math
import matplotlib.pyplot as plt
def Supertrend(df, atr_period, multiplier):
high = df['High']