Carsten Stahl commited on
Commit
d4add36
1 Parent(s): d31af6a

Introduced UserInput class to take care of userinput

Browse files
Files changed (1) hide show
  1. utilities/py/ui_elements.py +75 -0
utilities/py/ui_elements.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+
3
+ import streamlit as st
4
+ from utilities.py.data_management import CompData
5
+
6
+ class UserInputData:
7
+ def __init__(self, company_list, opt_method, start_date, init_invest, ef_parameter = None):
8
+ self.company_list = company_list
9
+ self.opt_method = opt_method
10
+ self.ef_parameter = ef_parameter
11
+ self.start_date = start_date
12
+ self.init_invest = init_invest
13
+
14
+
15
+ class UserInput:
16
+
17
+ def __init__(self, company_data: CompData):
18
+ """
19
+ Class that renders the user selection (company, optimization technique, etc.)
20
+ """
21
+ self.comp_data = company_data
22
+ self.ef_parameter_input = None
23
+ self.company_list_input = None
24
+ self.opt_method_input = None
25
+ self.start_date_input = None
26
+ self.initial_investment_input = None
27
+
28
+ def company_selection(self):
29
+ self.company_list_input = st.multiselect(
30
+ "Select Multiple Companies", self.comp_data.company_names, default=None
31
+ )
32
+
33
+ def opt_method_selection(self):
34
+ self.opt_method_input = st.selectbox(
35
+ "Choose an optimization method accordingly",
36
+ (
37
+ "Efficient Frontier",
38
+ "Hierarchical Risk Parity",
39
+ ),
40
+ )
41
+
42
+ if self.opt_method_input == "Efficient Frontier":
43
+ self.ef_parameter_input = st.selectbox(
44
+ "Choose an optimization parameter accordingly",
45
+ (
46
+ "Maximum Sharpe Ratio",
47
+ "Efficient Risk",
48
+ "Minimum Volatility",
49
+ "Efficient Return",
50
+ ),
51
+ )
52
+
53
+ def start_date(self):
54
+ self.start_date_input = st.date_input(
55
+ "Start Date",
56
+ format="YYYY-MM-DD",
57
+ value=pd.Timestamp("1947-08-15"),
58
+ max_value=pd.Timestamp.now(),
59
+ )
60
+
61
+ def initial_investment(self):
62
+ self.innit_invest_input = st.number_input("How much would you want to invest?", value=45000)
63
+
64
+ def get_selected_comp_ids(self):
65
+ if self.company_list_input is not None:
66
+ return self.comp_data.comp_name_to_id(self.company_list_input)
67
+ print("WARINING: Selected company ids accessed, eventhough company not yet rendered in UI")
68
+ return None
69
+
70
+ def get_user_input_data(self) -> UserInputData:
71
+ return UserInputData(self.company_list_input,
72
+ self.opt_method_input,
73
+ self.start_date_input,
74
+ self.innit_invest_input,
75
+ self.ef_parameter_input)