diff --git a/main.py b/main.py index 81a742e..d760b68 100644 --- a/main.py +++ b/main.py @@ -25,20 +25,20 @@ CONFIGS = { "SECRET_KEY": os.urandom(30), # Set the secret key for session authentication "PERMANENT_SESSION_LIFETIME": timedelta(minutes=60) } -SQL_CONFIG = dict( - database= os.getenv("PGDATABASE"), - user=os.getenv("PGUSER"), - host=os.getenv("PGHOST"), - port=os.getenv("PGPORT"), - password=os.getenv("PGPASSWORD") -) # SQL_CONFIG = dict( -# database="railway", -# user="postgres", -# host="containers-us-west-103.railway.app", -# port="5913", -# password="gv5Mh7cPjCm9YTjAmsYD" +# database= os.getenv("PGDATABASE"), +# user=os.getenv("PGUSER"), +# host=os.getenv("PGHOST"), +# port=os.getenv("PGPORT"), +# password=os.getenv("PGPASSWORD") # ) +SQL_CONFIG = dict( + database="railway", + user="postgres", + host="containers-us-west-103.railway.app", + port="5913", + password="gv5Mh7cPjCm9YTjAmsYD" +) # SQL_CONFIG = { # 'database': "tpm", # 'user': "hsienchen", @@ -337,12 +337,12 @@ def buildPort(): train_info = MVO.portfolio_info(sol, train, train_market) test_info = MVO.portfolio_info(sol, test, test_market) # print(sol, train_info, test_info) - print("-"*10) - print(ts, name, session.get('username'), comp, - role, test_info['annual_ret'], test_info['vol'], test_info['mdd'], test_info['annual_sr'], - test_info['beta'], test_info['alpha'], test_info['var10'], test_info['R2'], True, comment, stock_list, list(sol), sep=", ") - print("-"*10) - data = (ts, name, session.get('username'), comp, + # print("-"*10) + # print(ts, name, session.get('username'), comp, + # role, test_info['annual_ret'], test_info['vol'], test_info['mdd'], test_info['annual_sr'], + # test_info['beta'], test_info['alpha'], test_info['var10'], test_info['R2'], True, comment, stock_list, list(sol), sep=", ") + # print("-"*10) + data = (ts, name, session.get('username').split('@')[0], comp, role, ratio, test_info['annual_ret'], test_info['vol'], test_info['mdd'], test_info['annual_sr'], test_info['beta'], test_info['alpha'], test_info['var10'], test_info['R2'], True, comment, stock_list, list(sol)) sql='insert into strategy \ @@ -355,6 +355,8 @@ def buildPort(): print("\n------Write in Success--------\n") return jsonify({'mes': '投資組合已完成建立,請至gooooooo查詢分析結果。'}) + + @app.route('/custom') def custom(): if login_required(): @@ -363,6 +365,8 @@ def custom(): flash('使用投組功能請先登入。', 'warning') return redirect(url_for('login')) return render_template('custom.html', message='No') + + @app.route('/result') def result(): if login_required(): @@ -370,15 +374,25 @@ def result(): else: flash('使用投組功能請先登入。', 'warning') return redirect(url_for('login')) - return render_template('result.html') -@app.route('/result_tw') -def result_tw(): - if login_required(): - pass - else: - flash('使用投組功能請先登入。', 'warning') - return redirect(url_for('login')) - return render_template('result_tw.html') + + sql="""select id, date, name, username, annual_ret, vol, annual_sr\ + from strategy order by id desc limit 100;""" + conn = psycopg2.connect(**SQL_CONFIG) + with conn: + with conn.cursor() as curs: + curs.execute(sql) + data= curs.fetchall() + conn.close() + return render_template('result.html', strategy_data=data) + +# @app.route('/result_tw') +# def result_tw(): +# if login_required(): +# pass +# else: +# flash('使用投組功能請先登入。', 'warning') +# return redirect(url_for('login')) +# return render_template('result_tw.html') # handle login failed @app.errorhandler(401) diff --git a/static/img/growth.png b/static/img/growth.png new file mode 100644 index 0000000..d59e906 Binary files /dev/null and b/static/img/growth.png differ diff --git a/static/js/addStock.js b/static/js/addStock.js index 449c996..61ab08f 100644 --- a/static/js/addStock.js +++ b/static/js/addStock.js @@ -54,6 +54,7 @@ $stockList.on('click', '.delete-btn', function(){ $addStockBtn.click(function(event) { event.preventDefault(); $('#search').val(''); + $('#search').trigger("keyup"); // Get selected stock from form const selectedStock = $stockSelect.val(); var text = $('#stock-select option:selected').text(); diff --git a/t.html b/t.html new file mode 100644 index 0000000..b47f9c4 --- /dev/null +++ b/t.html @@ -0,0 +1,86 @@ + + +
+Serial Number | +Description | +
---|---|
001 | +Serial 001 Information | +
002 | +Serial 002 Information | +
003 | +Serial 003 Information | +
{{ item.description }}
+我們常聽到的「鷄蛋不要放在同個籃子裏」, 爲的就是要分散股市不確定性所帶來的風險。 @@ -222,8 +224,8 @@
在評估投資組合的表現時,經常使用的是絕對性的指標, 例如報酬率、波動率、夏普指數,MDD等, @@ -248,8 +250,27 @@ 在本擂台上,不限台股的投組使用的大盤指數 ($r_m$) 是SPY, 台股的投組使用的大盤指數是0050.TW,無風險利率暫定為0。
-+ Value at Risk(VaR)是一種風險度量方法,用於衡量某個金融投資組合在一定置信水平下的最大可能損失, + 即在給定的時間段內,可能出現的最大虧損額度。VaR的置信水平通常為95%或99%,表示對於未來某個時間段, + 投資組合的損失不會超過該置信水平對應的虧損額度。VaR的計算需要考慮投資組合的市場風險、信用風險和操作風險等多個因素, + 並且常常使用統計方法和模型來估計。常見的VaR模型包括歷史模擬法、蒙特卡羅模擬法和參數化模型等。 + 以下針對資產報酬率,在常態分配的假設下,10-day 95% VaR 風險值的計算方式如下: +
++ 給定資產的每日投組價值後,我們可以計算出該投組的(每日)報酬率與(每日)波動率。利用常態分配的假設,我們假設 + $\mu$為$n$日報酬率(亦即(每日)報酬率 x n), $\sigma$為$n$日波動率亦即(每日)波動率 + 則 n-day 5% VaR 的公式為: $$-(\mu - 1.645\times\sigma)$$ +
++ 其中,置信水平的標準正態分位數是指標準正態分布累積分布函數在置信水平下的分位數, + 可以通過查找標準正態分布表來獲得。在這個式子中,第一項是投資組合價值乘以置信水平, + 表示投資組合的預期損失;第二項是投資組合價值乘以投資組合日收益的標準差乘以置信水平的標準正態分位數, + 表示在一定置信水平下,投資組合可能遭受的最大損失。因此,VaR可以用來幫助投資者評估其投資組合的風險水平, + 制定合適的風險管理策略。 +
{% endblock content %} diff --git a/templates/result.html b/templates/result.html index d14c449..393f6bb 100644 --- a/templates/result.html +++ b/templates/result.html @@ -1,6 +1,95 @@ {% extends 'base.html' %} {% set active_page = 'result' %} +{% block style %} +body { + background-image: url({{ url_for('static', filename='img/money.jpeg') }}); + background-repeat: no-repeat; /* Do not repeat the image */ + background-size: cover; +} +{% endblock style %} {% block title %}Strategy Page{% endblock%} -{% block content %}Hello world - {{ active_page|e }} {% endblock %} +{% block content %} +Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.
+Whenever you need to, be sure to use margin utilities to keep things nice and tidy.
+#ID | +投組名稱 | +創建者 | +報酬率 | +夏普率 | +波動率 | +創建時間 | +
---|---|---|---|---|---|---|
+ + {{ info[0] }} + + | +{{ info[2] }} | +{{ info[3] }} | +{{ info[4] }} | +{{ info[6] }} | +{{ info[5] }} | +{{ info[1] }} | +