Skip to content

Commit

Permalink
2.18 - Backtesting bug fixes
Browse files Browse the repository at this point in the history
- Clear cache button added
  • Loading branch information
pranjal-joshi committed Nov 27, 2023
1 parent 645bf4c commit a8356d8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
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.17"
VERSION = "2.18"

changelog = colorText.BOLD + '[ChangeLog]\n' + colorText.END + colorText.BLUE + '''
[1.00 - Beta]
Expand Down Expand Up @@ -277,4 +277,8 @@
[2.17]
1. Backtest Report column added for backtest screening runs
[2.18]
1. Critical backtest bug fixed (dropna axis-1 removed from results)
2. Clear stock cached data button added
''' + colorText.END
7 changes: 5 additions & 2 deletions src/classes/Utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/screenipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 15 additions & 3 deletions src/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ def check_updates():
def show_df_as_result_table():
try:
df:pd.DataFrame = pd.read_pickle('last_screened_unformatted_results.pkl')
ac, bc = st.columns([6,1])
ac, cc, bc = st.columns([6,1,1])
ac.markdown(f'#### 🔍 Found {len(df)} Results')
clear_cache_btn = cc.button(
label='Clear Cached Data',
use_container_width=True,
)
if clear_cache_btn:
os.system('rm stock_data_*.pkl')
st.toast('Stock Cache Deleted!', icon='🗑️')
bc.download_button(
label="Download Results",
data=df.to_csv().encode('utf-8'),
Expand Down Expand Up @@ -101,6 +108,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()

Expand Down Expand Up @@ -177,6 +185,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:
Expand Down Expand Up @@ -272,6 +281,9 @@ def get_extra_inputs(tickerOption, executeOption, c_index=None, c_criteria=None,
.stButton>button {
height: 70px;
}
.stDownloadButton>button {
height: 70px;
}
th {
text-align: left;
}
Expand Down Expand Up @@ -325,7 +337,7 @@ def get_extra_inputs(tickerOption, executeOption, c_index=None, c_criteria=None,

executeOption = str(c_criteria.selectbox('Select Screening Criteria', options=list_criteria).split(' ')[0])

start_button = c_button_start.button('Start Screening', type='primary', key='start_button')
start_button = c_button_start.button('Start Screening', type='primary', key='start_button', use_container_width=True)

get_extra_inputs(tickerOption=tickerOption, executeOption=executeOption, c_index=c_index, c_criteria=c_criteria, start_button=start_button)

Expand Down Expand Up @@ -495,7 +507,7 @@ def get_extra_inputs(tickerOption, executeOption, c_index=None, c_criteria=None,
</style>
</head>
<body>
<marquee class="sampleMarquee" direction="left" scrollamount="7" behavior="scroll">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.</marquee>
<marquee class="sampleMarquee" direction="left" scrollamount="7" behavior="scroll">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.</marquee>
</body>
</html>
'''
Expand Down

0 comments on commit a8356d8

Please sign in to comment.