Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Screenipy Test] New Features Added - Test Passed #250

Merged
merged 1 commit into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 11 additions & 27 deletions .github/workflows/workflow-download-data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,41 @@ jobs:

Download_Stock_Data:

runs-on: windows-latest
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: actions-data-download
fetch-depth: 0

- name: Set up Python 3.9.4
uses: actions/setup-python@v2
- name: Set up Python 3.11.6
uses: actions/setup-python@v4
with:
python-version: 3.9.4

# - name: Restore Dependencies from Cache
# uses: actions/cache@v2
# with:
# path: ~\AppData\Local\pip\Cache
# key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
# restore-keys: |
# ${{ runner.os }}-pip-

# - name: Install TA-Lib
# run: |
# python -m pip install --upgrade pip
# cd .github/dependencies/
# echo %cd%
# pip install TA_Lib-0.4.19-cp39-cp39-win_amd64.whl
python-version: 3.11.6

- name: Install Python Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Download Stock Data
shell: cmd
run: |
rmdir /s /q actions-data-download
mkdir actions-data-download
rm -rf actions-data-download
mkdir -p actions-data-download
python src/screenipy.py -d
copy "stock_data_*.pkl" "actions-data-download"
mv stock_data_*.pkl actions-data-download/

- name: Push Pickle Data
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git checkout actions-data-download
git add actions-data-download/stock_data_*.pkl --force
git commit -m "GitHub Action Workflow - Market Data Download (Default Config)"
git add --all
git diff --cached --quiet || git commit -m "GitHub Action Workflow - Market Data Download (Default Config)"
git push

- name: Squash Commits (Python)
shell: cmd
run: |
git config user.name github-actions
git config user.email github-actions@github.com
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ retrying
scipy==1.11.2
TA-Lib-Precompiled
tabulate
yfinance==0.2.32
yfinance==0.2.54
alive-progress==1.6.2
Pillow
scikit-learn==1.3.2
Expand Down
6 changes: 5 additions & 1 deletion src/classes/Changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from classes.ColorText import colorText

VERSION = "2.25"
VERSION = "2.26"

changelog = colorText.BOLD + '[ChangeLog]\n' + colorText.END + colorText.BLUE + '''
[1.00 - Beta]
Expand Down Expand Up @@ -302,4 +302,8 @@

[2.25]
1. Reduced docker image size by 50% (Special Thanks to https://github.com/smitpsanghavi)

[2.26]
1. Bugfixes - yfinance package updated to 0.2.54 to fix Yahoo Finance API issue
2. Minor Improvements to maintain backward compatibility of the yfinance df
''' + colorText.END
36 changes: 35 additions & 1 deletion src/classes/Fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,12 @@ def fetchStockData(self, stockCode, period, duration, proxyServer, screenResults
progress=False,
timeout=10,
start=self._getBacktestDate(backtest=backtestDate)[0],
end=self._getBacktestDate(backtest=backtestDate)[1]
end=self._getBacktestDate(backtest=backtestDate)[1],
auto_adjust=False
)
# For df backward compatibility towards yfinance 0.2.32
data = self.makeDataBackwardCompatible(data)
# end
if backtestDate != datetime.date.today():
dateDict = self._getDatesForBacktestReport(backtest=backtestDate)
backtestData = yf.download(
Expand Down Expand Up @@ -260,6 +264,7 @@ def fetchStockData(self, stockCode, period, duration, proxyServer, screenResults
# Get Daily Nifty 50 Index:
def fetchLatestNiftyDaily(self, proxyServer=None):
data = yf.download(
auto_adjust=False,
tickers="^NSEI",
period='5d',
interval='1d',
Expand All @@ -268,6 +273,7 @@ def fetchLatestNiftyDaily(self, proxyServer=None):
timeout=10
)
gold = yf.download(
auto_adjust=False,
tickers="GC=F",
period='5d',
interval='1d',
Expand All @@ -276,19 +282,24 @@ def fetchLatestNiftyDaily(self, proxyServer=None):
timeout=10
).add_prefix(prefix='gold_')
crude = yf.download(
auto_adjust=False,
tickers="CL=F",
period='5d',
interval='1d',
proxy=proxyServer,
progress=False,
timeout=10
).add_prefix(prefix='crude_')
data = self.makeDataBackwardCompatible(data)
gold = self.makeDataBackwardCompatible(gold, column_prefix='gold_')
crude = self.makeDataBackwardCompatible(crude, column_prefix='crude_')
data = pd.concat([data, gold, crude], axis=1)
return data

# Get Data for Five EMA strategy
def fetchFiveEmaData(self, proxyServer=None):
nifty_sell = yf.download(
auto_adjust=False,
tickers="^NSEI",
period='5d',
interval='5m',
Expand All @@ -297,6 +308,7 @@ def fetchFiveEmaData(self, proxyServer=None):
timeout=10
)
banknifty_sell = yf.download(
auto_adjust=False,
tickers="^NSEBANK",
period='5d',
interval='5m',
Expand All @@ -305,6 +317,7 @@ def fetchFiveEmaData(self, proxyServer=None):
timeout=10
)
nifty_buy = yf.download(
auto_adjust=False,
tickers="^NSEI",
period='5d',
interval='15m',
Expand All @@ -313,13 +326,18 @@ def fetchFiveEmaData(self, proxyServer=None):
timeout=10
)
banknifty_buy = yf.download(
auto_adjust=False,
tickers="^NSEBANK",
period='5d',
interval='15m',
proxy=proxyServer,
progress=False,
timeout=10
)
nifty_buy = self.makeDataBackwardCompatible(nifty_buy)
banknifty_buy = self.makeDataBackwardCompatible(banknifty_buy)
nifty_sell = self.makeDataBackwardCompatible(nifty_sell)
banknifty_sell = self.makeDataBackwardCompatible(banknifty_sell)
return nifty_buy, banknifty_buy, nifty_sell, banknifty_sell

# Load stockCodes from the watchlist.xlsx
Expand Down Expand Up @@ -352,3 +370,19 @@ def fetchWatchlist(self):
f'[+] watchlist_template.xlsx created in {os.getcwd()} as a referance template.' + colorText.END)
return None
return data

def makeDataBackwardCompatible(self, data:pd.DataFrame, column_prefix:str=None) -> pd.DataFrame:
data = data.droplevel(level=1, axis=1)
data = data.rename_axis(None, axis=1)
column_prefix = '' if column_prefix is None else column_prefix
data = data[
[
f'{column_prefix}Open',
f'{column_prefix}High',
f'{column_prefix}Low',
f'{column_prefix}Close',
f'{column_prefix}Adj Close',
f'{column_prefix}Volume'
]
]
return data
18 changes: 9 additions & 9 deletions src/classes/Screener.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,23 @@ def getCandleType(self, dailyData):


# Preprocess the acquired data
def preprocessData(self, data, daysToLookback=None):
def preprocessData(self, data:pd.DataFrame, daysToLookback=None):
if daysToLookback is None:
daysToLookback = self.configManager.daysToLookback
if self.configManager.useEMA:
sma = ScreenerTA.EMA(data['Close'],timeperiod=50)
lma = ScreenerTA.EMA(data['Close'],timeperiod=200)
data.insert(6,'SMA',sma)
data.insert(7,'LMA',lma)
data.insert(len(data.columns),'SMA',sma)
data.insert(len(data.columns),'LMA',lma)
else:
sma = data.rolling(window=50).mean()
lma = data.rolling(window=200).mean()
data.insert(6,'SMA',sma['Close'])
data.insert(7,'LMA',lma['Close'])
data.insert(len(data.columns),'SMA',sma['Close'])
data.insert(len(data.columns),'LMA',lma['Close'])
vol = data.rolling(window=20).mean()
rsi = ScreenerTA.RSI(data['Close'], timeperiod=14)
data.insert(8,'VolMA',vol['Volume'])
data.insert(9,'RSI',rsi)
data.insert(len(data.columns),'VolMA',vol['Volume'])
data.insert(len(data.columns),'RSI',rsi)
data = data[::-1] # Reverse the dataframe
# data = data.fillna(0)
# data = data.replace([np.inf, -np.inf], 0)
Expand Down Expand Up @@ -411,7 +411,7 @@ def findReversalMA(self, data, screenDict, saveDict, maLength, percentage=0.015)
maRev = ScreenerTA.EMA(data['Close'],timeperiod=maLength)
else:
maRev = ScreenerTA.MA(data['Close'],timeperiod=maLength)
data.insert(10,'maRev',maRev)
data.insert(len(data.columns),'maRev',maRev)
data = data[::-1].head(3)
if data.equals(data[(data.Close >= (data.maRev - (data.maRev*percentage))) & (data.Close <= (data.maRev + (data.maRev*percentage)))]) and data.head(1)['Close'].iloc[0] >= data.head(1)['maRev'].iloc[0]:
if self.configManager.stageTwo:
Expand All @@ -426,7 +426,7 @@ def findReversalMA(self, data, screenDict, saveDict, maLength, percentage=0.015)
def findRSICrossingMA(self, data, screenDict, saveDict, maLength=9):
data = data[::-1]
maRsi = ScreenerTA.MA(data['RSI'], timeperiod=maLength)
data.insert(10,'maRsi',maRsi)
data.insert(len(data.columns),'maRsi',maRsi)
data = data[::-1].head(3)
if data['maRsi'].iloc[0] <= data['RSI'].iloc[0] and data['maRsi'].iloc[1] > data['RSI'].iloc[1]:
screenDict['MA-Signal'] = colorText.BOLD + colorText.GREEN + f'RSI-MA-Buy' + colorText.END
Expand Down
Loading
Loading