Invicto69 commited on
Commit
61e998e
·
verified ·
1 Parent(s): 3937920

Synced repo using 'sync_with_huggingface' Github Action

Browse files
Files changed (2) hide show
  1. page/single_backtest.py +5 -11
  2. utils.py +3 -4
page/single_backtest.py CHANGED
@@ -96,26 +96,20 @@ def algorithmic_trading_dashboard():
96
  .update_layout(title=dict(text=ticker))
97
  )
98
 
99
- # Generate backtest plot
100
- # if strategy == "Order Block":
101
- # backtest_plot = smc_plot_backtest(data, 'test.html', swing_hl)
102
- # elif strategy == "Order Block with EMA":
103
- # backtest_plot = smc_ema_plot_backtest(data, 'test.html', ema1, ema2, cross_close)
104
- # elif strategy == "Structure trading":
105
- # backtest_plot = smc_structure_plot_backtest(data, 'test.html', swing_hl)
106
-
107
  backtest_results = run_strategy(ticker, strategy, period, interval, swing_hl=swing_hl, ema1=ema1, ema2=ema2, cross_close=cross_close)
108
 
 
 
109
  # Display plots
110
- st.write("### Signal Plot")
111
  st.plotly_chart(signal_plot, width=1200)
112
 
113
- st.write('### Backtest Results')
114
  cols = ['stock', 'Start', 'End', 'Return [%]', 'Equity Final [$]', 'Buy & Hold Return [%]', '# Trades',
115
  'Win Rate [%]', 'Best Trade [%]', 'Worst Trade [%]', 'Avg. Trade [%]']
116
  st.dataframe(backtest_results, hide_index=True, column_order=cols)
117
 
118
- st.write("### Backtest Plot")
119
  plot = backtest_results['plot']
120
  components.html(plot[0], height=1067)
121
 
 
96
  .update_layout(title=dict(text=ticker))
97
  )
98
 
 
 
 
 
 
 
 
 
99
  backtest_results = run_strategy(ticker, strategy, period, interval, swing_hl=swing_hl, ema1=ema1, ema2=ema2, cross_close=cross_close)
100
 
101
+ color = "green" if backtest_results['Return [%]'].values[0] > 0 else "red"
102
+
103
  # Display plots
104
+ st.write(f"### :{color}[Signal Plot]")
105
  st.plotly_chart(signal_plot, width=1200)
106
 
107
+ st.write(f'### :{color}[Backtest Results]')
108
  cols = ['stock', 'Start', 'End', 'Return [%]', 'Equity Final [$]', 'Buy & Hold Return [%]', '# Trades',
109
  'Win Rate [%]', 'Best Trade [%]', 'Worst Trade [%]', 'Avg. Trade [%]']
110
  st.dataframe(backtest_results, hide_index=True, column_order=cols)
111
 
112
+ st.write(f"### :{color}[Backtest Plot]")
113
  plot = backtest_results['plot']
114
  components.html(plot[0], height=1067)
115
 
utils.py CHANGED
@@ -1,12 +1,11 @@
1
  import yfinance as yf
2
  from backtesting import Backtest
3
  import pandas as pd
4
- import random
5
  import os
6
 
7
  from multiprocessing import Pool
8
  from itertools import repeat
9
- import time
10
  from strategies import SMC_test, SMC_ema, SMCStructure
11
 
12
  def fetch(symbol, period, interval):
@@ -87,9 +86,9 @@ def complete_test(strategy: str, period: str, interval: str, multiprocess=True,
87
 
88
  if multiprocess:
89
  with Pool() as p:
90
- result = p.starmap(run_strategy, zip(nifty50['YahooEquiv'].values, repeat(strategy), repeat(period), repeat(interval), repeat(kwargs)))
91
  else:
92
- result = [run_strategy(nifty50['YahooEquiv'].values[i], strategy, period, interval, kwargs) for i in range(len(nifty50))]
93
 
94
  df = pd.concat(result)
95
 
 
1
  import yfinance as yf
2
  from backtesting import Backtest
3
  import pandas as pd
 
4
  import os
5
 
6
  from multiprocessing import Pool
7
  from itertools import repeat
8
+ from functools import partial
9
  from strategies import SMC_test, SMC_ema, SMCStructure
10
 
11
  def fetch(symbol, period, interval):
 
86
 
87
  if multiprocess:
88
  with Pool() as p:
89
+ result = p.starmap(partial(run_strategy, **kwargs), zip(nifty50['YahooEquiv'].values, repeat(strategy), repeat(period), repeat(interval)))
90
  else:
91
+ result = [run_strategy(nifty50['YahooEquiv'].values[i], strategy, period, interval, **kwargs) for i in range(len(nifty50))]
92
 
93
  df = pd.concat(result)
94