shubhayu-64 commited on
Commit
8580ce6
·
1 Parent(s): 9348211
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -33,6 +33,7 @@ class Stonks:
33
  self.stochastic_oscillator_period = 14
34
  self.stochastic_oscillator_upper_band = 80
35
  self.stochastic_oscillator_lower_band = 20
 
36
  self.bollinger_band_period = 20
37
  self.on_balance_volumne_period = 20
38
 
@@ -385,9 +386,9 @@ class Stonks:
385
  def plot_stochastic_oscillator(self, data, title_txt: str):
386
  fig, ax = plt.subplots(figsize=(20, 10))
387
  data[['Strategy Returns','Market Returns']].cumsum().plot(ax=ax)
388
- ax.set_title('Strategy returns versus AZN.L returns', color = 'black', fontsize = 20)
389
  return fig
390
-
391
  def plot_bollinger_bands(self, data, column_list, title_txt: str):
392
  fig, ax = plt.subplots(figsize=(20, 10))
393
  data[column_list].plot(ax=ax)
@@ -478,6 +479,8 @@ class Stonks:
478
  self.stochastic_oscillator_upper_band = st.sidebar.number_input('Stochastic Oscillator Upper Band', 50, 100, 80)
479
  self.stochastic_oscillator_lower_band = st.sidebar.number_input('Stochastic Oscillator Lower Band', 0, 50, 20)
480
  st.sidebar.markdown("""---""")
 
 
481
  self.bollinger_band_period = st.sidebar.number_input('Bollinger Band Period', 20, 100, 20)
482
  st.sidebar.markdown("""---""")
483
  self.on_balance_volumne_period = st.sidebar.number_input('On Balance Volumne Period', 20, 100, 20)
@@ -787,6 +790,22 @@ class Stonks:
787
  temp_df = get_stochastic_oscillator()
788
  st.pyplot(self.plot_stochastic_oscillator(temp_df, title_txt=f"Stochastic Oscillator for {self.selected_stock} stock"))
789
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
790
  st.markdown("""
791
  ## Volatility trading strategies
792
 
@@ -907,6 +926,5 @@ class Stonks:
907
  It is almost certainly better to choose technical indicators that complement each other, not just those that move in unison and generate the same signals. The intuition here is that the more indicators you have that confirm each other, the better your chances are to profit. This can be done by combining strategies to form a system, and looking for multiple signals.
908
  """)
909
 
910
-
911
  stonks = Stonks(stocks_filepath="Models/stocknames.csv")
912
  stonks.ui_renderer()
 
33
  self.stochastic_oscillator_period = 14
34
  self.stochastic_oscillator_upper_band = 80
35
  self.stochastic_oscillator_lower_band = 20
36
+ self.roc_period = 9
37
  self.bollinger_band_period = 20
38
  self.on_balance_volumne_period = 20
39
 
 
386
  def plot_stochastic_oscillator(self, data, title_txt: str):
387
  fig, ax = plt.subplots(figsize=(20, 10))
388
  data[['Strategy Returns','Market Returns']].cumsum().plot(ax=ax)
389
+ ax.set_title(title_txt, color = 'black', fontsize = 20)
390
  return fig
391
+
392
  def plot_bollinger_bands(self, data, column_list, title_txt: str):
393
  fig, ax = plt.subplots(figsize=(20, 10))
394
  data[column_list].plot(ax=ax)
 
479
  self.stochastic_oscillator_upper_band = st.sidebar.number_input('Stochastic Oscillator Upper Band', 50, 100, 80)
480
  self.stochastic_oscillator_lower_band = st.sidebar.number_input('Stochastic Oscillator Lower Band', 0, 50, 20)
481
  st.sidebar.markdown("""---""")
482
+ self.roc_period = st.sidebar.number_input('ROC Period', 9, 100, 9)
483
+ st.sidebar.markdown("""---""")
484
  self.bollinger_band_period = st.sidebar.number_input('Bollinger Band Period', 20, 100, 20)
485
  st.sidebar.markdown("""---""")
486
  self.on_balance_volumne_period = st.sidebar.number_input('On Balance Volumne Period', 20, 100, 20)
 
790
  temp_df = get_stochastic_oscillator()
791
  st.pyplot(self.plot_stochastic_oscillator(temp_df, title_txt=f"Stochastic Oscillator for {self.selected_stock} stock"))
792
 
793
+ st.markdown("""
794
+ ### Rate of Change (ROC)
795
+
796
+ The ROC indicator is a pure momentum oscillator. The ROC calculation compares the current price with the price "n" periods ago e.g. when we compute the ROC of the daily price with a 9-day lag, we are simply looking at how much, in percentage, the price has gone up (or down) compared to 9 days ago. Like other momentum indicators, ROC has overbought and oversold zones that may be adjusted according to market conditions.
797
+ """)
798
+
799
+ def get_roc():
800
+ temp_df = self.stock_df.copy()
801
+ temp_df['ROC'] = ((temp_df['Adj Close'] - temp_df['Adj Close'].shift(self.roc_period)) / temp_df['Adj Close'].shift(self.roc_period) -1 ) * 100
802
+
803
+ return temp_df
804
+
805
+ temp_df = get_roc()
806
+ st.set_option('deprecation.showPyplotGlobalUse', False)
807
+ st.pyplot(mpf.plot(temp_df, type='candle', style='yahoo', figsize=(15,8), title=f"{self.selected_stock} Daily Price", volume=True))
808
+
809
  st.markdown("""
810
  ## Volatility trading strategies
811
 
 
926
  It is almost certainly better to choose technical indicators that complement each other, not just those that move in unison and generate the same signals. The intuition here is that the more indicators you have that confirm each other, the better your chances are to profit. This can be done by combining strategies to form a system, and looking for multiple signals.
927
  """)
928
 
 
929
  stonks = Stonks(stocks_filepath="Models/stocknames.csv")
930
  stonks.ui_renderer()