master
SeanChenTaipei 2 years ago
parent cbf7a80c7c
commit 77b16b4846
  1. 21
      main.py
  2. 8
      templates/strategy_tw.html

@ -20,8 +20,8 @@ pd.options.plotting.backend = "plotly"
# PARAMETERS # PARAMETERS
CONFIGS = { CONFIGS = {
"ENV": "development", # "ENV": "development",
"DEBUG": True, # "DEBUG": True,
"SECRET_KEY": os.urandom(30), # Set the secret key for session authentication "SECRET_KEY": os.urandom(30), # Set the secret key for session authentication
"PERMANENT_SESSION_LIFETIME": timedelta(minutes=60) "PERMANENT_SESSION_LIFETIME": timedelta(minutes=60)
} }
@ -238,16 +238,17 @@ def submit_stock_list():
## Query DB ## Query DB
conn = psycopg2.connect(**SQL_CONFIG) conn = psycopg2.connect(**SQL_CONFIG)
port = get_stock(conn, stock_list, session['tw']) port = get_stock(conn, stock_list, session['tw'])
if len(port.index) > 750:
port = port.iloc[-750:, :]
conn.close() conn.close()
fig = port.plot(title = 'Assets in portfolio', fig = port.plot(title='資產價格走勢', labels=dict(index="Date", value="Price", variable="Assets"))
labels=dict(index="Date", value="Price", variable="Assets"))
fig['layout'] = dict( fig['layout'] = dict(
autosize=True, autosize=True,
legend={'title': {'text': 'Assets'}, 'tracegroupgap': 0}, legend={'title': {'text': '資產價格走勢'}, 'tracegroupgap': 0},
title= {'text': 'Assets in portfolio'}, title= {'text': 'Assets in portfolio'},
xaxis= {'anchor': 'y', 'domain': [0.0, 1.0], 'title': {'text': 'Date'}}, xaxis= {'anchor': 'y', 'domain': [0.0, 1.0], 'title': {'text': '日期'}},
yaxis= {'anchor': 'x', 'domain': [0.0, 1.0], 'title': {'text': 'Price'}} yaxis= {'anchor': 'x', 'domain': [0.0, 0.75], 'title': {'text': '價格'}}
) )
fig.update_layout(legend=dict( fig.update_layout(legend=dict(
yanchor="top", yanchor="top",
@ -395,9 +396,9 @@ def result():
# return render_template('result_tw.html') # return render_template('result_tw.html')
# handle login failed # handle login failed
@app.errorhandler(401) # @app.errorhandler(401)
def page_not_found(e): # def page_not_found(e):
return Response('<p>Failed</p>') # return response('<p>Failed</p>')

@ -57,7 +57,7 @@ div.card{
投資組合名稱 投資組合名稱
</div> </div>
<div class="card-body"> <div class="card-body">
<input if="imput1" name="portName" type="text" class="form-control" placeholder="EX. " required> <input if="imput1" name="portName" type="text" class="form-control" placeholder="EX. 問就是歐應" required>
</div> </div>
</div> </div>
<div class="card"> <div class="card">
@ -127,7 +127,10 @@ div.card{
</li> </li>
</ol> </ol>
</div> </div>
<div class="input-group mt-3"> <hr>
<div>
<div class="d-flex p-2 mt-2 font-bold text-lg">策略參數選擇</div>
<div class="input-group">
<span class="input-group-text bg-info">訓練 / 回測數據比</span> <span class="input-group-text bg-info">訓練 / 回測數據比</span>
<select id="ratio-select" class="form-select"> <select id="ratio-select" class="form-select">
<option value="0.5">5:5</option> <option value="0.5">5:5</option>
@ -146,6 +149,7 @@ div.card{
</select> </select>
</div> </div>
</div> </div>
</div>
<div class="modal" id="portModal" tabindex="-1"> <div class="modal" id="portModal" tabindex="-1">

Loading…
Cancel
Save