SeanChenTaipei 2 years ago
parent a153d3d2db
commit ad6245ca2f
  1. 1
      cvxopt
  2. 28
      main.py
  3. 15
      portfolio_builder.py
  4. 1
      templates/base.html

@ -0,0 +1 @@
Subproject commit f236615e5bd326daeb6cda511c31d86bcc354747

@ -20,25 +20,25 @@ pd.options.plotting.backend = "plotly"
# PARAMETERS
CONFIGS = {
"ENV": "development",
"DEBUG": True,
# "ENV": "development",
# "DEBUG": True,
"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",

@ -101,8 +101,17 @@ class MVO(object):
retPort = ret@w # T-dimensional array
stdPort = np.std(retPort)
return cov@w/stdPort
@staticmethod
def quadratic_utility(w, ret, gamma):
retPort = ret@w # T-dimensional array
varPort = np.var(retPort)
return np.mean(retPort) - 0.5*gamma*varPort
@staticmethod
def quadratic_utility_grad(w, ret, cov, gamma):
manual_ret = np.mean(ret, axis=0)
return manual_ret - gamma*cov@w
@classmethod
def opt(cls, ret, role="max_sharpe"):
def opt(cls, ret, gamma=0, role="max_sharpe"):
n = ret.shape[1]
init=np.ones(n)/n
if role=="max_sharpe":
@ -117,6 +126,10 @@ class MVO(object):
cov=np.cov(ret.T)
loss = lambda w: cls.volatility(w, ret)
grad = lambda w: cls.volatility_grad(w, ret, cov)
elif role=="quadratic_utility":
cov=np.cov(ret.T)
loss = lambda w: -cls.quadratic_utility(w, ret, gamma)
grad = lambda w: -cls.quadratic_utility_grad(w, ret, cov, gamma)
else:
return init
bnds = [[0, 0.6] for i in range(n)]

@ -62,6 +62,7 @@
('/', 'index', '首頁', 'bi bi-house-fill'),
('/strategy', 'strategy', '建立策略', 'fa-solid fa-chart-pie'),
('/strategy_tw', 'strategy_tw', '台股建立策略', 'fa-solid fa-chart-pie'),
('/strategy_bl', 'strategy_bl', 'Black-Litterman配置', 'fa-solid fa-chess-knight'),
('/custom', 'custom', '自訂數據建立策略', 'bi bi-database-fill-add'),
('/result', 'result', '分析結果排行', 'fa-solid fa-chart-simple'),
('mailto:r10246002@ntu.edu.tw', 'error', '錯誤回報', 'bi bi-bug-fill')

Loading…
Cancel
Save