You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

284 lines
15 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{% block title %}NTHU Trading Platform{% endblock title%}</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD"
crossorigin="anonymous"
/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css"
/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
{% block link %}
<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">
{% endblock %}
<style>
body {
padding-top: 70px;
padding-bottom: 70px;
background-color: #eee;
/* font-size: 2vw; */
font-family: Georgia, sans-serif !important;
}
/* .offcanvas-body {
font-size: 2vw
} */
.navbar {
background-image: linear-gradient(to bottom right, #5d9faa , #c4e0e5);
}
.navbar-nav > li > a.active {
font-size: 18px;
border-bottom: 2px ridge #888888;
}
p {
text-indent: 2em;
}
{% block style %}{% endblock %}
</style>
</head>
<header>
{% set navigation_bar = [
('/', 'index', '首頁', 'bi bi-house-fill'),
('/strategy', 'strategy', '建立策略', 'bi bi-piggy-bank-fill'),
('/strategy_tw', 'strategy_tw', '台股建立策略', 'bi bi-piggy-bank-fill'),
('/custom', 'custom', '自訂數據建立策略', 'bi bi-database-fill-add'),
('/result', 'result', '分析結果排行', 'bi bi-graph-up-arrow'),
('/result_tw', 'result_tw', '分析結果排行(台股)', 'bi bi-graph-up-arrow'),
('mailto:r10246002@ntu.edu.tw', 'error', '錯誤回報', 'bi bi-bug-fill')
] -%}
{% set active_page = active_page|default('index') -%}
<nav class="navbar bg-light fixed-top">
<div class="container-fluid px-3 py-2">
<a class="navbar-brand mx-2" href="{{ url_for('index') }}">
<h3><strong></i>投資組合大擂台</strong></h3>
</a>
<!-- TODO: Login/Logout -->
<div class="navbar-expand ms-auto">
<ul class="navbar-nav me-2 mb-lg-0">
{% if not session.username %}
<li class="nav-item">
<a class="nav-link btn btn-lg" href="{{ url_for('login') }}">
<i class="bi bi-box-arrow-in-right"></i>
<i class="bi bi-person-fill"></i>
</a>
</li>
{% else %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle btn btn-lg" href="" role="button" data-bs-toggle="dropdown" aria-expanded="true">
<i class="bi bi-person-check-fill"></i>
</a>
<ul class="dropdown-menu dropdown-menu-end" style="background-color: rgb(244, 250, 255);">
<li class="px-3 active">歡迎您: {{ session.username|safe }}</li>
<li><hr class="dropdown-divider"></li>
<li>
<a class="dropdown-item" href="{{ url_for('logout') }}">
<i class="fas fa-sign-out-alt pe-2 "></i>登出
</a>
</li>
</ul>
</li>
{% endif %}
</ul>
</div>
<button
class="navbar-toggler"
type="button"
data-bs-toggle="offcanvas"
data-bs-target="#offcanvasNavbar"
aria-controls="offcanvasNavbar">
<i class="bi bi-three-dots"></i>
</button>
<div
class="offcanvas offcanvas-start text-bg-light {% if active_page is not none and not active_page == 'index'%}show{% endif %}"
data-bs-scroll="true"
tabindex="-1"
id="offcanvasNavbar"
aria-labelledby="offcanvasNavbarLabel"
>
<div class="offcanvas-header">
<h4 class="offcanvas-title mt-2 p-0" id="offcanvasNavbarLabel">
投資組合大擂台
</h4>
<button
type="button"
class="btn-close btn-close"
data-bs-dismiss="offcanvas"
aria-label="Close"
></button>
</div>
<div class="offcanvas-body">
<ul class="navbar-nav justify-content-end d-flex flex-grow-1 pe-3">
{% for href, id, caption, icon in navigation_bar %}
<li class="nav-item my-2">
<a
class="nav-link {% if id == active_page %}active{% endif %}"
{% if id == active_page %}aria-current="page"{% endif %}
href="{{ href|e }}">
<i class="{{ icon|e }}"></i>
<span class="mx-1">{{ caption|e }}</span>
</a>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</nav>
</header>
<body>
{% block content %}
<div class="container-sm mx-auto my-4 p-4 bg-white shadow-lg" style="border-radius: 5px;">
<!-- <h1 class="text-4xl font-bold mb-4">Document Title - {{ active_page|e }} </h1> -->
<div class="alert alert-secondary" role="alert">
<ul>
<li><i class="bi bi-caret-right-fill"></i> 本網站讓使用者可以自建投資組合,回測其績效,並與其他使用者比較、討論並改進。</li>
<li><i class="bi bi-caret-right-fill"></i> 使用單位:清華大學、台灣大學、政治大學、明新科大、中華大學、臺北大學、證基會、成功大學。</li>
</ul>
</div>
<div class="prose lg:prose-xl p-3">
<h2 class="text-xl font-bold mb-4">平台簡介</h2>
<p>
我們常聽到的「鷄蛋不要放在同個籃子裏」,
爲的就是要分散股市不確定性所帶來的風險。
一般來説,在風險分散的同時,收益也會跟著降低。
於是問題就變成:我們如何在風險與報酬率中取捨。
被稱爲資産配置之父的哈利·馬可維兹(Harry Max Markowitz)就提供了以下的想法。
</p>
<p>
在給定各個標的(underlying)的權重後,
對該投資組合(portfolio)做均值–變異數分析(mean-variance analysis),
其中平均數爲平均報酬率,變異數爲波動率(意即「風險」)。
在這樣定義不同投資組合的報酬與風險的情况下,
我們可以發現:在不同的預期報酬下,
都可以找到一個投資組合(或權重)使波動率達到最小值。
將這些報酬與對應到的最小風險記錄下來後所形成的開口向右的二維拋物線圖形(如下圖),
就是所謂的「效率前緣(efficient frontier)」。
<div class='d-flex justify-content-center'>
<div class="rounded mx-auto d-block" style="height: 80%; width: 80%;">
<img src="{{ url_for('static', filename='img/frontier.jpg') }}" class="img-fluid" alt="frontier-example">
</div>
</div>
<p class="p-0">
本網站使用S&P 500、元大臺灣50以及Nasdaq 100指數的成份股的歷史日資料。
每次計算標的權重,都是取六個月的資料,依照馬可維兹的理論,
畫出效率前緣,然後取夏普值最大的權重,再用接下來三個月的資料,
觀察投資組合的價值如何變化。我們每三個月更新一次權重,
再把許多三個月區間內投資組合的價值變動拼接起來,
得到2015年中到2020年中投資組合的價值變動,
再藉此求出平均年報酬、年波動率,再把報酬除以波動率得到整個投資期間的夏普值。
另外我們還算出最大跌幅(maximum drawdown),就是投資過程中,
會從到目前為止的最高點,最多下跌多少幅度。
</p>
<div class="row">
<div class="col-sm-6">
<div class="card mt-3">
<div class="card-header">
固定預期報酬 $p$,令投資組合權重為 $w$, 則將波動率最小化的數學問題為:
</div>
<div class="card-body">
<p class="card-text" style="font-size: 1.8vmin;">
$$\begin{equation}
\begin{aligned}
\min_{w} \quad &\frac{1}{2}w^{T}\Sigma w\quad\\
\textrm{s.t.} \quad &\sum_{i=1}^{n}w_i = 1\\
&\sum_{i=1}^{n}w_i R_i \geq p\\
&0\leq w_i \leq 1 \quad , 1 \leq i \leq n
\end{aligned}
\end{equation}$$
</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card mt-3">
<div class="card-header">
令投資組合權重為 $w$, 則將夏普率最大化的數學問題為:
</div>
<div class="card-body">
<p class="card-text" style="font-size: 1.8vmin;">
$$\begin{equation}
\begin{aligned}
\min_{w} \quad &\frac{w^T R}{\sqrt{w^{T}\Sigma w}}\quad\\
\textrm{s.t.} \quad &\sum_{i=1}^{n}w_i = 1\\
&0\leq w_i \leq 1 \quad , 1 \leq i \leq n
\end{aligned}
\end{equation}$$
</p>
</div>
</div>
</div>
</div>
<hr class="my-4">
<h2 class="text-xl font-bold mb-4 mt-4">投資組合的$\alpha$、$\beta$值簡介</h2>
<p class="my-1">
在評估投資組合的表現時,經常使用的是絕對性的指標,
例如報酬率、波動率、夏普指數,MDD等,
不過也有相對性的指標alpha、beta值。
比較投組與另一個標的(例如大盤指數,
我們可以透過回歸式,估計出作為超額報酬的alpha值,
以及作為相關性的beta值。Alpha值表示投組的獲利能力,
越高越好。Beta值代表了投組對系統性風險的曝險程度,越低越好。
</p>
<p class="my-1">
根據CAPM模型,給定投組報酬 $r_{p}$, 大盤指數 $r_m$ 以及無風險利率 $r_f$ ,
$\beta$ 值可以藉由以下公式得出:
$$ \mathbb{E}[r_p] - r_f = \beta (\mathbb{E}[r_m] - r_f)$$
$\alpha$ 值則是藉由計算實際的投組報酬與由CAPM得到的理論報酬的差得到,公式為:
$$\alpha = r_p - (r_f + \beta (r_m - r_f))$$
</p>
<p class="my-1">
當給定一組時間序列時,alpha、beta值可以利用線性回歸的方式得出。
我們可以將上述的式子改寫成以下的形式:
$$Y = \alpha + \beta X + \epsilon,$$ 而 $$Y = r_p-r_f , X = r_m-r_f$$
透過此回歸式,我們除了可以得到alpha、beta值外,也可以計算出值,用以衡量此模型的解釋力。
在本擂台上,不限台股的投組使用的大盤指數 ($r_m$) 是SPY,
台股的投組使用的大盤指數是0050.TW,無風險利率暫定為0。
</p>
<hr class="my-4">
<h2 class="text-xl font-bold mb-4 mt-4">VaR 簡介</h2>
</div>
</div>
{% endblock content %}
<!--jQuery -->
<script
src="https://code.jquery.com/jquery-3.6.0.js"
integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk="
crossorigin="anonymous"
></script>
<!-- Boostrap Scripts -->
<script
defer
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
crossorigin="anonymous"
></script>
{% block script %}
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.0/es5/tex-mml-chtml.min.js"></script>
<script>
MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
}
};
</script>
{% endblock %}
</body>
</html>