SeanChenTaipei 2 years ago
parent f6ab0812eb
commit cffee03873
  1. 1
      main.py
  2. 5
      portfolio_builder.py
  3. 4
      static/js/addStock.js
  4. 56
      static/js/view.js

@ -527,7 +527,6 @@ def copy_portfolio():
stock_list = request.form.get('stockList')
stock_list = json.loads(stock_list)
session['tw'] = 0
print(stock_list)
return render_template('strategy_tw.html', data_us = data_us, data_tw=data_tw, stock=stock_list)
@app.errorhandler(404)

@ -80,12 +80,11 @@ class MVO(object):
g1=manual_ret/stdPort
g2=np.mean(retPort)*stdPort**(-3)*cov_sor@w
return g1-g2
# equivalent opt problem with min vol
@staticmethod
def volatility(w, ret):
retPort = ret@w # T-dimensional array
stdPort = np.std(retPort)
return stdPort
return np.std(retPort)
@staticmethod
def volatility_grad(w, ret, cov):
retPort = ret@w # T-dimensional array

@ -1,8 +1,8 @@
// Initialize empty stock list
// let stockList = ['2330.TW'];
var stockList = [];
$('#stock-list span').each(function(){
stockList.push($(this).text());
$('#stock-list span').each(function(){
stockList.push($(this).text());
});
console.log(stockList);
let currentList = [];

@ -1,56 +0,0 @@
const wlayout = {
'autosize': true,
'barmode': 'relative',
'title': {'text': ''},
'xaxis': {'anchor': 'y', 'domain': [0.0, 1.0], 'title':''},
'yaxis': {'anchor': 'x', 'domain': [0.0, 1.0], 'title':''},
'margin': {'l': 50, 'r': 50, 't': 10, 'b': 50},
'legend': {'yanchor': 'bottom', 'y': 1.3, 'xanchor': 'left', 'x': 0, 'orientation':'h',
'font': {'size':8}
}
};
const rlayout = {
'autosize': true,
'title': {'text': ''},
'xaxis': {'anchor': 'y', 'domain': [0.0, 1.0], 'title':'', 'rangeslider': {'visible': true}
},
'yaxis': {'anchor': 'x', 'domain': [0.0, 1.0], 'title':''},
'margin': {'l': 40, 'r': 20, 't': 30, 'b': 50},
'legend': {'yanchor': 'top', 'y': 1.3, 'xanchor': 'left', 'x': 0.01, 'orientation':'h'}
};
const blayout = {
'autosize': true,
'title': {'text': ''},
'xaxis': {'anchor': 'y', 'domain': [0.0, 1.0], 'title':''},
'yaxis': {'anchor': 'x', 'domain': [0.0, 1.0], 'title':''},
'margin': {'l': 40, 'r': 20, 't': 50, 'b': 70},
'legend': {'yanchor': 'top', 'y': 1.3, 'xanchor': 'left', 'x': 0.01, 'orientation':'h'}
};
var w = {{ data.weight|safe }};
var r = {{ data.ret|safe }};
var b = {{ data.bar|safe }};
Plotly.newPlot("weight", w.data, wlayout, {responsive: true});
Plotly.newPlot("price", r.data, rlayout, {responsive: true});
Plotly.newPlot("bar", b.data, blayout, {responsive: true});
$('#copy-port').click(function(event) {
var stockList = [];
$('.asset').each(function(){
stockList.push($(this).text());
});
// alert(currentList.includes(texts));
if (stockList.length > 0) {
$.ajax({
url: '/copyPort', //todo create_strategy
method: 'POST',
data: { stockList: JSON.stringify(stockList) },
success: function(response) {
console.log('success');
document.write(response);
},
error: function(xhr) {
console.log('Error submitting stock list: ' + xhr.responseText);
}
});
}
});
Loading…
Cancel
Save