Compare commits

...

5 Commits

Author SHA1 Message Date
SeanChenTaipei f30ce83649 f 2 years ago
SeanChenTaipei 9c214de61a f 2 years ago
SeanChenTaipei 72aa37391b f 2 years ago
SeanChenTaipei e6d4ea10c6 d 2 years ago
SeanChenTaipei 41cedf648e f 2 years ago
  1. 6
      main.py
  2. 1
      sql_script/create_strategy.sql
  3. 7
      static/js/addStock.js
  4. 5
      templates/base.html
  5. 5
      templates/strategy_tw.html

@ -339,13 +339,13 @@ def buildPort():
info = MVO.portfolio_info(np.array([1]), rets['Portfolio'].to_numpy().reshape(-1, 1), market.pct_change().dropna().to_numpy()) info = MVO.portfolio_info(np.array([1]), rets['Portfolio'].to_numpy().reshape(-1, 1), market.pct_change().dropna().to_numpy())
data = (ts, name, session.get('username').split('@')[0], comp, role, info['annual_ret'], data = (ts, name, session.get('username').split('@')[0], comp, role, info['annual_ret'],
info['vol'], info['mdd'], info['annual_sr'], info['vol'], info['mdd'], info['annual_sr'],
info['beta'], info['alpha'], info['var10'], info['R2'], True, comment, stock_list, json.dumps(weight.to_dict()), json.dumps(rets.to_dict())) info['beta'], info['alpha'], info['var10'], info['R2'], gamma, True, comment, stock_list, json.dumps(weight.to_dict()), json.dumps(rets.to_dict()))
sql='insert into strategy \ sql='insert into strategy \
(date, name, username,\ (date, name, username,\
competition, role, annual_ret,\ competition, role, annual_ret,\
vol, mdd, annual_sr, beta, alpha,\ vol, mdd, annual_sr, beta, alpha,\
var10, R2, tw, notes, assets, weight, ret)\ var10, R2, gamma, tw, notes, assets, weight, ret)\
values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) RETURNING id;' values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) RETURNING id;'
with conn: with conn:
with conn.cursor() as curs: with conn.cursor() as curs:
curs.execute(sql, data) curs.execute(sql, data)

@ -14,6 +14,7 @@ CREATE TABLE strategy (
alpha REAL NOT NULL, alpha REAL NOT NULL,
var10 REAL NOT NULL, var10 REAL NOT NULL,
R2 REAL NOT NULL, R2 REAL NOT NULL,
gamma REAL NOT NULL,
tw BOOLEAN DEFAULT TRUE, tw BOOLEAN DEFAULT TRUE,
notes VARCHAR(255), notes VARCHAR(255),
assets TEXT[] NOT NULL, assets TEXT[] NOT NULL,

@ -67,7 +67,7 @@ $addStockBtn.click(function(event) {
var text = $('input[name=assetSelect]').val(); var text = $('input[name=assetSelect]').val();
// const selectedStock = text; // const selectedStock = text;
// var text = $('#stock-select option:selected').text(); // var text = $('#stock-select option:selected').text();
console.log(text) // console.log(text)
if (text != null && text!= '' && stockList.indexOf(text)===-1) { if (text != null && text!= '' && stockList.indexOf(text)===-1) {
// Add new item to list // Add new item to list
addStockItem(text, text); addStockItem(text, text);
@ -75,7 +75,7 @@ $addStockBtn.click(function(event) {
// Clear input field // Clear input field
$('#stockAll').val(''); $('#stockAll').val('');
} }
console.log(stockList); // console.log(stockList);
}); });
// Event listener for submit button click // Event listener for submit button click
@ -83,7 +83,7 @@ $submitPort.click(function(event) {
event.preventDefault(); event.preventDefault();
if (stockList.length > 1){ if (stockList.length > 1){
$('#portModal').modal('show'); $('#portModal').modal('show');
console.log('asset confirm'); // console.log('asset confirm');
// $(this).prop('disabled', true); // $(this).prop('disabled', true);
} }
}); });
@ -120,6 +120,7 @@ $sendPort.click(function(event) {
}, },
error: function(xhr) { error: function(xhr) {
console.log('Error submitting stock list: ' + xhr.responseText); console.log('Error submitting stock list: ' + xhr.responseText);
alert('建立失敗,請確認資產名稱是否正確! 美股代號均為大寫、台股代號為數字後接".TW"或是"TWO"');
} }
}); });
$commentPort.val(''); $commentPort.val('');

@ -21,6 +21,7 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tailwindcss/dist/tailwind.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tailwindcss/dist/tailwind.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css">
{% endblock %} {% endblock %}
<style> <style>
body { body {
/* // padding-bottom: 10px; */ /* // padding-bottom: 10px; */
@ -385,14 +386,14 @@
</div> </div>
<!-- Copyright --> <!-- Copyright -->
</footer> </footer>
<!--jQuery --> <!--jQuery -->
<script <script
src="https://code.jquery.com/jquery-3.6.0.js" src="https://code.jquery.com/jquery-3.6.0.js"
integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk="
crossorigin="anonymous" crossorigin="anonymous"
></script> ></script>
<!-- Boostrap Scripts --> <!-- Boostrap Scripts -->
<script <script
defer defer

@ -51,8 +51,8 @@ div.card{
<li><span class="fa-li"><i class="fa-solid fa-scroll"></i></span>未輸入投資組合名稱則會由系統隨機生成。</li> <li><span class="fa-li"><i class="fa-solid fa-scroll"></i></span>未輸入投資組合名稱則會由系統隨機生成。</li>
</ul> </ul>
</div> </div>
<div class="modal" id="intro" tabindex="-1" data-bs-backdrop="static"> <div class="modal fade" id="intro" tabindex="-1" data-bs-backdrop="static">
<div class="modal-dialog"> <div class="modal-dialog modal-dialog-centered">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="card-title text-xl font-bold pt-2"> <h5 class="card-title text-xl font-bold pt-2">
@ -79,7 +79,6 @@ div.card{
</div> </div>
</div> </div>
</div> </div>
<div class="card my-2" style="border-radius: 7px;"> <div class="card my-2" style="border-radius: 7px;">
<div class="card-header d-flex"> <div class="card-header d-flex">
<div class="py-2 font-bold text-xl"> <div class="py-2 font-bold text-xl">

Loading…
Cancel
Save