newman
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: 新人資訊 description: 投資組合 資產配置 GA: G-YWCCFEGXSJ --- [Home](https://hackmd.io/@newman/portal) - [新人資訊](https://hackmd.io/@newman/portal-info) # 應用-資產配置管理系統 part.12:V1.0 之後,探討各種最佳化理論 自從歷經千辛萬苦的錄製了生平第一支影片之後,已經好整以暇多日,好好再度審視自己所講的觀念,目前結論算是滿意。在錄製的影片的事上,雖然經過大量的練習,還是無法達到順暢的地步,但該表達意思都有到位;如果用 1.5 倍速播放可以大幅抵銷許多缺點,推薦一看。 https://youtu.be/-0FPVE0oNJ8 {%youtube -0FPVE0oNJ8 %} 悠閒漫步的氛圍,正是學習新知與迸發創意的溫床,來研究一下理論吧!很快的我就發現了一座寶庫:一位出身天文物理名叫 [Robert](https://reasonabledeviations.com/about/) 的年輕人,竟然把數十年來主要的投資組合最佳化的演算法都實作成 python package [PyPortfolioOpt](https://pyportfolioopt.readthedocs.io) 並公開分享給大眾使用,真是太令人敬佩了,在此恭敬地引用: > Martin, R. A., (2021). PyPortfolioOpt: portfolio optimization in Python. Journal of Open Source Software, 6(61), 3066, https://doi.org/10.21105/joss.03066 首先定義問題,如同大部分現實世界的問題: > 在投入有限額度的<font color=red>成本</font>下,追求最大<font color=red>效益</font>。 在此投資領域,問題就變成: > 在承受特定程度的<font color=red>風險</font>下,追求最大<font color=red>報酬</font>。 而面對不可知的未來,需要設計適當的估計量(estimator)去估計。其中「報酬」的部分在此探討不多,就是用歷史資料的年化報酬率,最佳化著墨的項目主要在於「風險」的估計和消除。風險的基本量化表示法,對於個股而言就是標準差,對於投資組合而言就是:「共變異矩陣 Σ」與權重 𝑤 的乘積: $$ \omega^T\Sigma\omega $$ 在研讀理論以前,這個值是用投資組合的日報酬卷算出來的,只能算是這理論裡的一個特例,就是 sample_cov,此外風險估計量還有許多算法如下: > sample_cov > semicovariance > exp_cov > ledoit_wolf > ledoit_wolf_constant_variance > ledoit_wolf_single_factor > ledoit_wolf_constant_correlation 在套件中都是一行可得!不禁再次向作者致敬 Orz 試著視覺化一組 portfolio,採用 sample_cov 算法: ![](https://newprediction.blob.core.windows.net/notebook-img/sample_cov.png) 可大致看出標的間的關聯性,顏色越深者表示關聯性低,搭配起來可以對沖風險。 而作者比較推薦 ledoit_wolf 算法,還撰文解說:[Honey, I Shrunk the Sample Covariance Matrix](https://reasonabledeviations.com/notes/papers/ledoit_wolf_covariance/),有了高手背書,我這凡夫俗子就直接引用吧,算出來的數字比 sample_cov 略小,據說因此可讓最佳化結果較為穩定。此共變異矩陣若畫出圖來非常相像,肉眼無法分辨出差異。 # 以各種不同的風險估計量,執行最佳化運算 有了報酬和風險的估計量,就可以開始執行最佳化演算法了。先跑一個最一般性的,就是最大化 sharpe,得出權重和績效: > 最佳化 sharpe ratio: > Expected annual return: 44.3% > Annual volatility: 26.6% > Sharpe Ratio: 1.59 ![](https://newprediction.blob.core.windows.net/notebook-img/wMaxSharpe.png) sharpe ratio 觀念在系統中已經多次使用,從這裡的理論架構觀點,可解釋成「效率前緣的 45<sup>。</sup>切線交點」,效率前緣是給定橫軸為特定風險尺度下,最佳報酬的投資組合,縱軸定義為報酬的情況下,座落在最高點位置。套件也可畫出整條效率前緣,看起來更有 fu 了: ![](https://newprediction.blob.core.windows.net/notebook-img/frontier.png) 但前面有指出關於報酬的預測是有待商榷的,因為我們直接把歷史年化報酬當成估計量比較不合適,像這裡的 44% 的歷史報酬能否在未來重現?我們寧願嚴格控制自 high 情緒,應該去針對最小風險去執行最佳化,得出權重和績效: > 最小化風險: > Expected annual return: 14.3% > Annual volatility: 15.8% > Sharpe Ratio: 0.78 ![](https://newprediction.blob.core.windows.net/notebook-img/wMinRisk.png) 結果這結果有點脫離現實,大部分權重配給大盤指數和 1101 台泥!這是怎樣?波動去掉是不錯,但報酬也去掉了!所以實務上還是要適度調高風險值,讓其他標的有參與的機會啦。所以給定期望報酬 30% 跑出來會怎樣呢: > 期望 30% 報酬的條件下,最小化風險: > Expected annual return: 30.0% > Annual volatility: 19.5% > Sharpe Ratio: 1.43 ![](https://newprediction.blob.core.windows.net/notebook-img/wReturn30.png) 這樣相對合理一點。 接下來再玩一些變化式,一樣聚焦在風險衡量部分,把正報酬忽略掉,只考慮負報酬的波動性,若期望報酬 30%,最小化波動的結果: > 期望 30% 報酬的條件下,最小化負報酬的波動 > Expected annual return: 30.0% > Annual semi-deviation: 13.5% > Sortino Ratio: 2.07 ![](https://newprediction.blob.core.windows.net/notebook-img/semiReturn30.png) 另外系統中已經強調的 drawdown 也有相關的理論依據,最小化 CDaR (Conditional Drawdown at Risk),期望 30% 報酬的結果: > 期望 30% 報酬的條件下,最小化 draw down > Expected annual return: 30.0% > Conditional Drawdown at Risk: 16.00% ![](https://newprediction.blob.core.windows.net/notebook-img/wCDaR.png) # 較新穎的最佳化演算法 HRP (Hierarchical Risk Parity):以相關性爲距離矩陣執行分群 (clustering),從尾端兩個資產開始求解最佳化權重,一層一層向上合併,得到所有資產的權重。非常有趣的想法,此套件也已經完成實作,真厲害!求出的解比較不會出現一堆零: > 以 HRP 演算法求解最佳權重: > Expected annual return: 26.6% > Annual volatility: 20.7% > Sharpe Ratio: 1.19 ![](https://newprediction.blob.core.windows.net/notebook-img/wHRP.png) 還能畫出美美的樹狀圖,清楚交代合併過程,也可以看出哪些資產彼此的相關性: ![](https://newprediction.blob.core.windows.net/notebook-img/HRP.png) 最後還有一個演算法 CLA (Critical Line Algorithm),此法作者著墨較少,我也就暫不深究了。 以上研究暫告一段落,日後再想辦法抽取精華整合到系統中。 Newman 2023/3/27

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully