From 82251178bf0ad61190d2e17712bb42ca6e092a12 Mon Sep 17 00:00:00 2001 From: pranjal-joshi Date: Mon, 27 Nov 2023 22:21:01 +0530 Subject: [PATCH] 2.18 - Backtesting bug fixes --- src/classes/Changelog.py | 5 ++++- src/classes/Utility.py | 7 +++++-- src/screenipy.py | 3 +-- src/streamlit_app.py | 4 +++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/classes/Changelog.py b/src/classes/Changelog.py index f2f9e4bf..4e3d1292 100644 --- a/src/classes/Changelog.py +++ b/src/classes/Changelog.py @@ -7,7 +7,7 @@ from classes.ColorText import colorText -VERSION = "2.17" +VERSION = "2.18" changelog = colorText.BOLD + '[ChangeLog]\n' + colorText.END + colorText.BLUE + ''' [1.00 - Beta] @@ -277,4 +277,7 @@ [2.17] 1. Backtest Report column added for backtest screening runs + +[2.18] +1. Critical backtest bug fixed (dropna axis-1 removed from results) ''' + colorText.END diff --git a/src/classes/Utility.py b/src/classes/Utility.py index bc3e87cf..0243f82d 100644 --- a/src/classes/Utility.py +++ b/src/classes/Utility.py @@ -388,13 +388,16 @@ def isBacktesting(backtestDate): def calculateBacktestReport(data, backtestDict:dict): try: recent = data.head(1)['Close'].iloc[0] - for key, val in backtestDict.items(): + for key, val in backtestDict.copy().items(): if val is not None: try: backtestDict[key] = str(round((backtestDict[key]-recent)/recent*100,1)) + "%" except TypeError: - backtestDict[key] = None + del backtestDict[key] + # backtestDict[key] = None continue + else: + del backtestDict[key] except: pass return backtestDict diff --git a/src/screenipy.py b/src/screenipy.py index ecbc28c2..61a161b2 100644 --- a/src/screenipy.py +++ b/src/screenipy.py @@ -292,6 +292,7 @@ def main(testing=False, testBuild=False, downloadOnly=False, execute_inputs:list "[+] Press any key to Exit!" + colorText.END) sys.exit(0) + print(tickerOption) if tickerOption == 'W' or tickerOption == 'N' or tickerOption == 'E' or tickerOption == 'S' or (tickerOption >= 0 and tickerOption < 16): configManager.getConfig(ConfigManager.parser) try: @@ -478,8 +479,6 @@ def main(testing=False, testBuild=False, downloadOnly=False, execute_inputs:list matchedSaveResults = pd.concat([matchedSaveResults, saveResults[saveResults['Stock'].str.contains(stk)]], ignore_index=True) screenResults, saveResults = matchedScreenResults, matchedSaveResults - screenResults.dropna(axis=1, how='all', inplace=True) - saveResults.dropna(axis=1, how='all', inplace=True) screenResults.sort_values(by=['Stock'], ascending=True, inplace=True) saveResults.sort_values(by=['Stock'], ascending=True, inplace=True) screenResults.set_index('Stock', inplace=True) diff --git a/src/streamlit_app.py b/src/streamlit_app.py index fc52e52c..70a04233 100644 --- a/src/streamlit_app.py +++ b/src/streamlit_app.py @@ -101,6 +101,7 @@ def dummy_call(): if Utility.tools.isBacktesting(backtestDate=backtestDate): st.write(f'Running in :red[**Backtesting Mode**] for *T = {str(backtestDate)}* (Y-M-D) : [Backtesting data is subjected to availability as per the API limits]') + st.write('Backtesting is :red[Not Supported] for Intraday timeframes') t = Thread(target=dummy_call) t.start() @@ -177,6 +178,7 @@ def get_extra_inputs(tickerOption, executeOption, c_index=None, c_criteria=None, elif int(tickerOption) == 0 or tickerOption is None: stock_codes:str = c_index.text_input('Enter Stock Code(s)', placeholder='SBIN, INFY, ITC') execute_inputs = [tickerOption, executeOption, stock_codes.upper(), 'N'] + return elif int(executeOption) >= 0 and int(executeOption) < 4: execute_inputs = [tickerOption, executeOption, 'N'] elif int(executeOption) == 4: @@ -495,7 +497,7 @@ def get_extra_inputs(tickerOption, executeOption, c_index=None, c_criteria=None, - Released in Development mode. This tool should be used only for analysis/study purposes. We do NOT provide any Buy/Sell advice for any Securities. Authors of this tool will not be held liable for any losses. Understand the Risks subjected with Markets before Investing. + This tool should be used only for Analysis/Study purposes. We do NOT provide any Buy/Sell advice for any Securities. Authors of this tool will not be held liable for any losses. Understand the Risks subjected with Markets before Investing. '''