-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
119 lines (94 loc) · 3.35 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from modules import *
st.set_page_config(layout="wide")
col1, col2= st.columns(2)
with col1:
st.markdown("# Stock Data")
#get file names from data/
def get_filenames(directory):
# List all files in the directory
files = os.listdir(directory)
# Filter and remove the .csv extension
filenames = [os.path.splitext(file)[0] for file in files if file.endswith('.csv')]
return filenames
directory = './data'
filenames = get_filenames(directory)
#select box with stock names from filenames
stock = st.selectbox(
"Please select the stock for quant analysis:",
(filenames),
)
def get_date(stock):
csv_loc = f'./data/{stock}.csv'
df = pd.read_csv(csv_loc, sep=',', header=0)
df['Date'] = pd.to_datetime(df['Date'])
min_date = df['Date'].min().date()
max_date = df['Date'].max().date()
return min_date, max_date
min_date, max_date = get_date(stock)
#select data range to display on chart/ perform operations with selected range.. default always 0% 100%
date_range = st.slider(
"Select date range: ",
value=(
date(min_date.year, min_date.month, min_date.day),
date(max_date.year, max_date.month, max_date.day)
),
format="YYYY/MM/DD",
)
#table with usefull information, avg annual rate, std deviation.. check porfolio analyser
def stock_data():
csv_loc = f'./data/{stock}.csv'
df = pd.read_csv(csv_loc, sep=',', header=0)
return df.set_index("Date")
csv_loc = './data/QQQ.csv'
# Specify the date range
start_date = f'{date_range[0]}'
end_date = f'{date_range[1]}'
# Function to filter rows based on date range
def filter_date_range(df, start_date, end_date):
return df[(df.index >= start_date) & (df.index <= end_date)]
#####################################
# Optimised Stop Loss
#####################################
def OSL(df, start_date, end_date):
csv_loc = f'./data/{stock}.csv'
# Read the CSV file and parse dates
df = pd.read_csv(
csv_loc,
sep=',',
parse_dates=['Date'], # Replace 'Date' with the name of your date column
header=0,
skiprows=0
)
df_filtered = df[(df['Date'] >= start_date) & (df['Date'] <= end_date)]
st.line_chart(df_filtered, x="Date", y="Close")
table_column = ["ATR","return","annualize average return"]
df = pd.DataFrame(
np.random.randn(1, len(table_column)), columns=table_column
)
st.table(df)
#####################################
# RANDOM TRADE
#####################################
with col2:
st.markdown("# Probability calculator")
col1, col2, col3 = st.columns(3)
with col1:
amount = st.number_input("Starting \$$$")
with col2:
stop_loss = st.number_input("S/L pips")
with col3:
stop_loss = st.number_input("T/P pips")
if st.button("Enter trading sequence", type="primary"):
col1, col2, col3, col4, col5 = st.columns(5)
with col1:
"Total Trades"
with col2:
"Winning Trades"
with col3:
"Loosing Trades"
with col4:
"Max trade time (Days)"
with col5:
"Min trade time (Days)"
else:
st.write("Goodbye")