sankhyikii commited on
Commit
b1bda1b
·
1 Parent(s): f015b53
Files changed (1) hide show
  1. main.py +2 -14
main.py CHANGED
@@ -5,6 +5,8 @@ import streamlit as st
5
  import plotly.graph_objects as go
6
  import time
7
  import datetime
 
 
8
 
9
  with open(r"style/style.css") as css:
10
  st.markdown(f"<style>{css.read()}</style>", unsafe_allow_html=True)
@@ -94,24 +96,10 @@ if num_tick > 1:
94
  st.dataframe(com_data, use_container_width=True)
95
 
96
  # make a function to calculate moving averages from the dataframe com_data, store those moving averages in dictionary for respective company
97
- def moving_average(data, window):
98
- ma = {}
99
- for i in data.columns:
100
- ma[i] = data[i].rolling(window=window).mean().values[2]
101
- return ma
102
-
103
  moving_avg = moving_average(com_data, 3)
104
  MA_df = pd.DataFrame(moving_avg.items(), columns=["Company", "Purchase Rate (MA)"])
105
 
106
  # calculate percentage return till present date from the moving average price of the stock
107
- def percentage_return(data, moving_avg):
108
- pr = {}
109
- for i in data.columns:
110
- pr[i] = (
111
- f"{round(((data[i].values[-1] - moving_avg[i]) / moving_avg[i]) * 100,2) }%"
112
- )
113
- return pr
114
-
115
  # make percentage return a dataframe from dictionary
116
  percentage_return = pd.DataFrame(
117
  percentage_return(com_data, moving_avg).items(),
 
5
  import plotly.graph_objects as go
6
  import time
7
  import datetime
8
+ from utilities import moving_average, percentage_return
9
+
10
 
11
  with open(r"style/style.css") as css:
12
  st.markdown(f"<style>{css.read()}</style>", unsafe_allow_html=True)
 
96
  st.dataframe(com_data, use_container_width=True)
97
 
98
  # make a function to calculate moving averages from the dataframe com_data, store those moving averages in dictionary for respective company
 
 
 
 
 
 
99
  moving_avg = moving_average(com_data, 3)
100
  MA_df = pd.DataFrame(moving_avg.items(), columns=["Company", "Purchase Rate (MA)"])
101
 
102
  # calculate percentage return till present date from the moving average price of the stock
 
 
 
 
 
 
 
 
103
  # make percentage return a dataframe from dictionary
104
  percentage_return = pd.DataFrame(
105
  percentage_return(com_data, moving_avg).items(),