Kei Sanada
    • 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

      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.
      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

    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.
    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
    # Tokyo Quantopian User Group Vol.11 ドキュメント翻訳 ## 名前 Kei Sanada 役割 ユーザーレビュー ## 状況 ・「Tutorial 1 Getting Started Lesson 1-8」 を GitHubでissue_8から、rstファイルを開いて([1_getting_started_lesson1.rst](https://github.com/tokyoquantopian/quantopian-doc-ja/blob/issue_8/source/tutorial/1_getting_started_lesson1.rst) など)を一通り読みました。 ・ここ最近の翻訳の進め方、把握が遅れがち ・read the docsの使い方が良くわかっていません。 ## 今日のTODO 1.引き続きissue_14 2_pipeline_lesson1-12(翻訳済、査読中)の[Tutorial 2 Pipeline Lesson1-12](https://github.com/tokyoquantopian/quantopian-doc-ja/blob/issue_14/source/tutorial/2_pipeline_lesson1.rst)を読み進めてQuatopianを思いだす。 2.「Tutorial 1 Getting Started Lesson 1-8」を読んだ初学者のつもりになって、Tutorialのサンプルーコードを改修できるか試してみる。 **ネタ:ROE偏重経営、もろさ露呈 想定外に備えはあるか** https://r.nikkei.com/article/DGXMZO5742458030032020SHA000?disablepcview=&s=3 **要約:自己資本比率の高い企業の方が長期的には成長するのでは?** > データを分析すれば明らかだ。1999年当時に自己資本が総資産に対してどれだけあったか(=自己資本比率)で世界の上場企業を5分類し、その後20年の利益の伸びを比較した。 > ![](https://i.imgur.com/E0ndFmy.jpg) > > > 利益の伸びが3.4倍と最も見劣りするのが、自己資本比率が20%未満の企業だ。少しのショックでも経営がぐらつき、競争力を高める機会を逃しやすい。一方、自己資本比率が60%以上~80%未満と比較的厚い企業は利益の伸びが6.5倍と最も大きい。不況の際にも経営は揺るがず、むしろ大規模な投資でシェアを拡大するといった攻めの一手を打てるためだ。 使用するコード、データセット(morningstar)から自己資本比率を算出 ``` from quantopian.pipeline import Pipeline from quantopian.pipeline.data.morningstar import Fundamentals from quantopian.pipeline.domain import US_EQUITIES from quantopian.research import run_pipeline # Construct a factor that simply gets the most recent total revenue value. # total_revenue = Fundamentals.total_revenue.latest total_equity = Fundamentals.total_equity.latest total_assets = Fundamentals.total_assets.latest capital_adequacy_ratio = total_equity / total_assets * 100 #自己資本比率 データの取得元正しいのかな? # Add the factor to the pipeline. pipe = Pipeline( columns={ # 'total_equity': total_equity, #' total_assets': total_assets, 'capital_adequacy_ratio': capital_adequacy_ratio }, domain=US_EQUITIES, ) # Run the pipeline over a year and print the result. df = run_pipeline(pipe, '2015-05-05', '2016-05-05') print(df.head()) ``` --- > Pipeline Execution Time: 1.24 Seconds > capital_adequacy_ratio > 2015-05-05 00:00:00+00:00 Equity(2 [HWM]) 32.425618 > Equity(21 [AAME]) 32.868256 > Equity(24 [AAPL]) 49.390874 > Equity(25 [HWM_PR]) 32.425618 > Equity(31 [ABAX]) 84.526509 取得できていそう。 こちらを元に「1_getting_started_lesson4 戦略定義」のコードなら改修できそう。 ```python # Pipeline インポート from quantopian.pipeline import Pipeline from quantopian.pipeline.data.psychsignal import stocktwits from quantopian.pipeline.factors import SimpleMovingAverage from quantopian.pipeline.filters import QTradableStocksUS # モーニングスターのデータセット from quantopian.pipeline.data.morningstar import Fundamentals from quantopian.pipeline.domain import US_EQUITIES # Pipeline 定義 def make_pipeline(): base_universe = QTradableStocksUS() total_equity = Fundamentals.total_equity.latest total_assets = Fundamentals.total_assets.latest capital_adequacy_ratio = total_equity / total_assets * 100 #自己資本比率 データの取得元正しいのかな? # 自己資本比率に基づいて上位下位350銘柄のみを取得するフィルターを作成 top_bottom_scores = ( capital_adequacy_ratio.top(350) | capital_adequacy_ratio.bottom(350) ) return Pipeline( columns={ 'capital_adequacy_ratio': capital_adequacy_ratio, }, # 定義したフィルターとトレーディングユニバースのどちらにも入っている銘柄のみにスクリーニングする screen=( base_universe & top_bottom_scores ) ) # run_pipeline インポート from quantopian.research import run_pipeline # 評価する期間を指定 period_start = '2013-01-01' period_end = '2016-01-01' # 指定期間で pipeline 実行 pipeline_output = run_pipeline( make_pipeline(), start_date=period_start, end_date=period_end ) ``` <b>Pipeline Execution Time:</b> 14.48 Seconds ```python # prices 関数をインポート from quantopian.research import prices # pipeline が出力した dataframe の index から銘柄リストを取得し、 unique 関数を使って、重複しないリストを取得します。 asset_list = pipeline_output.index.levels[1].unique() # 銘柄リストに入っている銘柄全てに対して、指定期間の価格を取得します。 asset_prices = prices( asset_list, start=period_start, end=period_end ) ``` ```python # Alphalens インポート import alphalens as al # センチメントスコアに基づいて、quantileに指定された分位数にわける factor_data = al.utils.get_clean_factor_and_forward_returns( factor=pipeline_output['capital_adequacy_ratio'], prices=asset_prices, quantiles=2, periods=(1,5,10), ) # 上から5行を表示 factor_data.head(5) ``` Dropped 1.7% entries from factor data: 1.7% in forward returns computation and 0.0% in binning phase (set max_loss=0 to see potentially suppressed Exceptions). max_loss is 35.0%, not exceeded: OK! <div> <table border="1" class="dataframe"> <thead> <tr style="text-align: right;"> <th></th> <th></th> <th>1D</th> <th>5D</th> <th>10D</th> <th>factor</th> <th>factor_quantile</th> </tr> <tr> <th>date</th> <th>asset</th> <th></th> <th></th> <th></th> <th></th> <th></th> </tr> </thead> <tbody> <tr> <th rowspan="5" valign="top">2013-01-02 00:00:00+00:00</th> <th>Equity(693 [AZO])</th> <td>-0.002074</td> <td>-0.020455</td> <td>-0.021436</td> <td>-24.872762</td> <td>1</td> </tr> <tr> <th>Equity(755 [BC])</th> <td>0.012223</td> <td>0.010613</td> <td>0.005783</td> <td>7.408589</td> <td>1</td> </tr> <tr> <th>Equity(1023 [BOH])</th> <td>0.011838</td> <td>0.014244</td> <td>0.018623</td> <td>7.656026</td> <td>1</td> </tr> <tr> <th>Equity(1343 [CCK])</th> <td>0.005535</td> <td>-0.008698</td> <td>0.000264</td> <td>-0.328515</td> <td>1</td> </tr> <tr> <th>Equity(1402 [CEF])</th> <td>-0.015986</td> <td>-0.012268</td> <td>0.009294</td> <td>99.881505</td> <td>2</td> </tr> </tbody> </table> </div> ```python # ファクターの四分位別に、平均を算出 mean_return_by_q, std_err_by_q = al.performance.mean_return_by_quantile(factor_data) # 四分位と保有ごとに、平均を描画 al.plotting.plot_quantile_returns_bar( mean_return_by_q.apply( al.utils.rate_of_return, axis=0, args=('1D',) ) ); ``` ![](https://i.imgur.com/0BPv5T1.png) ```python import pandas as pd # ファクターでウェイト付けしたロングショートのポートフォリオを収益を算出 ls_factor_returns = al.performance.factor_returns(factor_data) # 5日間保有した場合の累積収益を描画 al.plotting.plot_cumulative_returns(ls_factor_returns['5D'], '5D', freq=pd.tseries.offsets.BDay()); ``` ![](https://i.imgur.com/g3ye8L6.png) ```python ``` 結果はともかくとして、動かすことはできました。

    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

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    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