<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by 阿民的AI與量化金融世界 on Medium]]></title>
        <description><![CDATA[Stories by 阿民的AI與量化金融世界 on Medium]]></description>
        <link>https://medium.com/@ioi75UT?source=rss-4eef977f21c2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zaDzNGtnXWIIY5Gku2-apg.jpeg</url>
            <title>Stories by 阿民的AI與量化金融世界 on Medium</title>
            <link>https://medium.com/@ioi75UT?source=rss-4eef977f21c2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 06:19:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ioi75UT/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[如何利用NOTION實現自我日常工作管理?幫助你有效擊退拖延症!]]></title>
            <link>https://medium.com/@ioi75UT/%E5%A6%82%E4%BD%95%E5%88%A9%E7%94%A8notion%E5%AF%A6%E7%8F%BE%E8%87%AA%E6%88%91%E6%97%A5%E5%B8%B8%E5%B7%A5%E4%BD%9C%E7%AE%A1%E7%90%86-%E5%B9%AB%E5%8A%A9%E4%BD%A0%E6%9C%89%E6%95%88%E6%93%8A%E9%80%80%E6%8B%96%E5%BB%B6%E7%97%87-76c3b585a1a9?source=rss-4eef977f21c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/76c3b585a1a9</guid>
            <dc:creator><![CDATA[阿民的AI與量化金融世界]]></dc:creator>
            <pubDate>Sun, 01 Dec 2024 08:59:34 GMT</pubDate>
            <atom:updated>2024-12-01T08:59:34.629Z</atom:updated>
            <content:encoded><![CDATA[<p><em>你不會改變你的生活，除非你改變每天所做的事情</em></p><p>原子習慣這本書的作者在書中說明過這樣一種觀點，人生是用習慣堆積出來的，或者我們也可以這樣說，或者毀掉你人生的不是老天爺，不過是你的習慣! 那麼如果有效處理掉壞習慣就是重要的議題了，這篇文章和方法不一定能夠幫你直接解除壞習慣，但我想這個能夠幫助我有效&quot;堆積好習慣&quot;的方法一定能幫你在亂成一團糟的生活中平衡一點回來，盡快幫你從圖1的左邊進入到右邊的狀態。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YAk6568UnqIx9Mr46lvr9A.png" /><figcaption>圖1</figcaption></figure><p>在這篇文章能學到甚麼?<br>1. 了解如何分割工作讓自己可以擺脫拖延狀態<br>2.如何建立類遊戲機制給自己最即時的正反饋<br>3.了解如何利用Notion這個工具幫助自己快速建立良好的回朔模板</p><h3><strong>1. 了解如何分割工作讓自己可以擺脫拖延狀態</strong></h3><p>會拖延基本上原因就大概以下幾種</p><ul><li><strong>完美主義</strong><br>害怕結果不夠完美，導致不敢開始，擔心失敗或達不到期望。</li><li><strong>恐懼與焦慮</strong><br>對某些任務感到壓力、無助或害怕，進而選擇逃避。</li><li><strong>低自我效能感</strong><br>覺得自己無法完成任務，或對自己的能力缺乏信心。</li><li><strong>對不確定性的抗拒</strong><br>無法接受不確定的結果，讓人無法開始執行。</li></ul><p>我想和你說的事情是其實做事情沒哪麼難不要想太多，很多事情其實就是沒做，真的去碰到了就會自己繼續做下去了，當然也有那種真的很不想做的情況，這種時候可以用一種方法解決，我把它稱為&quot;像喝水一樣簡單的事&quot;，甚麼意思?就是要想盡辦法把每件事情都變小到我們可以完全沒有排斥的去做如同打開瓶蓋喝口水一樣簡單的狀態，舉例來說想要提升英文能力，下載一大堆英文學習APP，一周下來使用時間卻只有可憐的10分鐘，這種情況對於很多來說一定都有經驗，那要如何在每天搞定學英文這件事情?最簡單的方式就是讓自己練習每天至少打開這個APP一次，就這樣!就是這麼簡單，打開之後在嘗試要求自己練習1分鐘口說，或是任何自己在當下可以接受停留的時間，以此類推可以用到很多事情上，例如開會報告還沒準備，但真的很懶實在不想動，那可以拆分這項工作到先列出幾點開會重點，然後打開瀏覽器查幾個重點的資料，如果還是不想做那就停一停，先去做其他事反正一次只做一點點，每次一點點聚沙自然能成塔，至於更多的計畫和規畫技巧可以參考鬼速PDCA工作術這本書如圖2，這邊提供的方法是自己悟出來的人生實在有太多事情都不想做但卻又必須做，為了克服自己的難題想到這樣的方法，其實很多事情自己都做得來只不過是當下沒進入狀況，用這樣的方法很容易可以讓自己做著做著就進入心流狀態，到那個時候拖延症自然而然就擺脫了。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*_sDOcXfGlfOoXdASh1-3dQ.png" /><figcaption>圖2</figcaption></figure><h3>2.如何建立遊戲機制給自己最即時的正反饋</h3><p>先說說為甚麼要建立遊戲機制，其實這是要給自己在培養習慣的過程給予幫助，因為習慣在建立過程是容易被打破的，所以我們要讓自己對一件事情上癮，為甚麼遊戲會容易讓自己上癮?簡單來說是因為有即時的反饋，做完這件ˇ任務立即可以拿到獎勵，在等下的Notion系統中我們會添加這個功能到我們的模板中讓我們可以有一個取的正反饋的管道，也就是評分系統，透過這個累積積分我們可以給自己一些實質的獎勵，例如每個月存到100點積分能吃個好一些的餐廳或是買一些自己想買的禮物犒賞成功戰勝拖延的自己!</p><p>3.了解如何利用Notion這個工具幫助自己快速建立良好的回朔模板</p><p><strong>Notion</strong> 是一款功能強大的多合一數位工具，設計用來幫助個人與團隊管理資訊、組織工作以及提升生產力。它整合了筆記、任務管理、日曆、資料庫等功能，讓使用者能在一個平台中完成多項任務。</p><p><a href="https://www.notion.com/product?utm_source=affl&amp;utm_medium=marwanalahdal3482&amp;pscd=affiliate.notion.so&amp;ps_partner_key=bWFyd2FuYWxhaGRhbDM0ODI&amp;gad_source=1&amp;gclid=Cj0KCQiAr7C6BhDRARIsAOUKifiqf4gpQjlzkJ9L0Sj3mNJ4BhE0Gs83jwgWC9uWRlW6-XYYxiEl_qcaAhfuEALw_wcB&amp;ps_xid=ZFjmalo5q4LfwL&amp;gsxid=ZFjmalo5q4LfwL&amp;gspk=bWFyd2FuYWxhaGRhbDM0ODI">Notion官方連結</a></p><p>要在這個平台上建立自己的工作模板首先要在登入後點選到如圖3的位置建立一個新的頁面如圖4</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/1*2xpXgnMbyUSP8qujijtuow.png" /><figcaption>圖3</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0y96GKKMPbOjMN569IDMYA.png" /><figcaption>圖4</figcaption></figure><p>接著我們要建立自己的紀錄區，將游標移動到圖5位置下方的表格，進行表格新增如果沒有的話也可以點選上方的+號來新增表格</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*BgZE7-J2t7vHiYXQoqIk6Q.png" /><figcaption>圖5</figcaption></figure><p>點選完成之後再利用圖6的加號來新增時間如同圖7所示</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cCMBo20sU6TPu1-mV4z-Cg.png" /><figcaption>圖6</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*grjGA3AUQfXupm_6KP16Ag.png" /><figcaption>圖7</figcaption></figure><p>接著我們就要用到Notion的強大模板功能，點選圖8圈起來的地方，然後再點擊新範本，進到圖九的頁面之後我們就可以開始設計我們的模板了，</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*T8C0L5XmWoGcB8_Wo1Fj-Q.png" /><figcaption>圖8</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*pL29wzLiFa1ZsRcuJpFuqw.png" /><figcaption>圖9</figcaption></figure><p>舉例來說每天會有運動習慣培養的需求，英文能力培養需求以及工作職業上的提升需求像是提升寫作能力我們就給予新增，點選圖10位置的+號然後點選代辦清單如圖11，新增完成之後就會在圖12中看到那些選項，那些都是可以打勾的，但這邊只是在設計模板，另外我們還可以對這些工作進行更多的分類我們可以點選圖11方框下方的摺疊列表來達成這件事情，在圖13中我們做了摺疊列表的新增，這樣一來我們就可以把這些當成一個個子專案來進行，同時也新增了工作日誌的紀錄，讓大家可以管理自己的每日工作，最後讓我們決定哪些事情是必要做的那些是選擇要做的，如果勢必要做的那麼每天都要按時完成，這些分數自然也會比較低，而選擇要做的則可以給更高的分數這樣簡易分數計算系統也就建立完成了，好接下來讓我們離開這個設計模板的頁面回到剛開始的工作日誌</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*OR8KADmVZPD9LMkGIfR2dg.png" /><figcaption>圖10</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*RjzZ-zdi-UIZFhGM1oicpQ.png" /><figcaption>圖11</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*plLEYyCm6dIheXi9qCJKzg.png" /><figcaption>圖12</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*vUIDoEKvEA_U1dg3t_zf3g.png" /><figcaption>圖13</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*r1fNsad8f6mLHS9Ttd20SA.png" /><figcaption>圖14</figcaption></figure><p>離開的方法是點選如圖15的紅色框框處，就可以關閉這個模板設計的頁面</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*suQ_ZJoYC1hJYPon7Ae3OQ.png" /><figcaption>圖15</figcaption></figure><p>回到原本頁面之後我們新增一個分數紀錄的欄位如圖16，然後選擇17數字那個選項</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aLUU1pkPQvdRJ61JEoBKnQ.png" /><figcaption>圖16</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*VTx-1fo0koA37A8YqrpvnA.png" /><figcaption>圖17</figcaption></figure><p>之後我們就可以開始使用我們剛剛製作的模板了，每天的早上起床第一件事情就是把這個工作日誌打開然後點選新建然後在選擇我們剛剛製作好的模板如圖19</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1wQiQ6WZXwlSiBoM7d8Oiw.png" /><figcaption>圖18</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*ARE1l3a39UafVdIdlNElLQ.png" /><figcaption>圖19</figcaption></figure><p>然後模板就會被叫出來每天都被重新刷新過一次，而且也會被存在工作日誌的紀錄區了，同時記得要把今天的日期給新增上去，在左側新增的時候右側會自然出現，最後每天記得要結算自己的分數</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7fOpiu7EJVv0To99825ccg.png" /></figure><p>結語:</p><p>這邊只是簡單的Notion範例其實網路上還有很多更詳細的教學，礙於篇幅就不再多說，主要是想和大家分享Notion可以這樣做，而且如果有小型企業團隊人不多的老闆也可以用這個方式管理員工給公司帳號然後讓員工分享這個資料庫給你，這樣自己也能監督每天員工都在做甚麼，有沒有完成必要的事情，這就是一個簡易的紀錄簿拉!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76c3b585a1a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[手把手教你安裝cuda版本pytorch讓你把GPU跑好跑滿!]]></title>
            <link>https://medium.com/@ioi75UT/python-3-10-%E5%AE%89%E8%A3%9D-pytorch-forecasting-c4a7474d113c?source=rss-4eef977f21c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4a7474d113c</guid>
            <dc:creator><![CDATA[阿民的AI與量化金融世界]]></dc:creator>
            <pubDate>Sun, 21 Jul 2024 14:36:03 GMT</pubDate>
            <atom:updated>2024-08-16T09:48:18.775Z</atom:updated>
            <content:encoded><![CDATA[<p>因為安裝會有許多問題，所以這邊幫大家將版本整理出來</p><p>python版本 3.10.14</p><p>以下是整理，同時請按照順序在anconda環境中安裝</p><pre>pip install numpy==1.26.0<br>pip install scipy==1.14.0<br>pip install matplotlib==3.9.1<br>pip install scikit-learn==1.5.1<br>pip install torch==2.0.1 pytorch-lightning==2.0.2 <br>pip install pytorch_forecasting==1.0.0 torchaudio==2.0.2 <br>pip install torchdata==0.6.1 torchtext==0.15.2 torchvision==0.15.2 optuna==3.4<br>pip install pyarrow fastparquet<br>pip install pytorch_forecasting</pre><p>gpu版本pytroch安裝(注意這是cuda12.1版本，請務必按照順序安裝)</p><p>gpu安裝說明</p><p>為了保持系統環境乾淨所以去下載了個conda來用</p><p>下載說明:</p><p>官方網址:<a href="https://www.anaconda.com/download">https://www.anaconda.com/download</a><br>到官方網站的頁面進行下載就行</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FW09voTUG1PsRHlFuDeAaw.png" /></figure><h3>利用ANACONDA進行環禁建置</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kqrFVLr3baGKrwhgfwpmTg.png" /><figcaption>圖1</figcaption></figure><p>安裝完成後會如同圖一</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aG1UT7JVuWEtOSWYWXG4sA.png" /><figcaption>圖2</figcaption></figure><p>圖2的那兩個套件要記得安裝好用，shell 拿來裝套件另一個spyder拿來寫程式</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/263/1*4kpMes55cxYodkFKvrG3aQ.png" /><figcaption>圖4</figcaption></figure><p>點選螢光筆圈起來的環境按鈕進去給專案開一個獨立的新環境，由於每個專案會用到的套件，版本都不同，利用內建的方法可以安裝多個版本的python相當便利，點選創建按鈕如圖5所示</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*lgbk2ZS24YlTaTtpl9xn7A.png" /><figcaption>圖5</figcaption></figure><p>之後會彈出圖6的框框，藍色框的部分需要注意一定要填寫英文，同時在測試的時候發現如果以前有命名過的環境在使用相同明子案創建(create)按鈕anaconda會沒反應所以命名不要跟以前一樣，然後python 版本選3.10.14，R語言沒用到所以可以不用裝</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*ulrgxMG16uW5U_10jSOYWA.png" /><figcaption>圖6</figcaption></figure><p>按下創建後會如同圖7所示在右下角會有藍色的BAR再跑</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fu_9XG7H-n3N7V9rTIM4hg.png" /><figcaption>圖7</figcaption></figure><p>安裝完成後會如圖8所示，紅色框框出現代表這個環境已經被建造，藍色框框則代表現在正在使用的環境，另外每次ANACONDA開啟的時候預設都會先開啟ROOT的環境如圖9所示，在圖中有3個環境最上面的base(root)就是預設環境，所以如果重新開啟anaconda就要來環境這邊啟動自己想要開的環境，<strong>啟動方法也很容易只需要在自己要的環境上點一下就行!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EYbYMYYEQwVrRN6pZ1z3Ww.png" /><figcaption>圖8</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*NcL8Z8yNAW3zmYIS7US3OA.png" /><figcaption>圖9</figcaption></figure><p>回到正題，當環境安裝完成後回到HOME介面如圖10點選，後會回到圖11</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/1*oF9Yn6DsJgJfqzxWPfCdiA.png" /><figcaption>圖10</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0LsLs1NL4fKw3AkIrqyl8A.png" /><figcaption>圖11</figcaption></figure><p>回到HOME介面後將兩個套件按下install進行安裝</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*wrTQ9E0iOw0LwyGUmw1D3Q.png" /><figcaption>圖12</figcaption></figure><p>之後再power shell 點選launch 開啟命令視窗</p><p>按照以下指令進行輸入就可以創建一個有cuda版本的pytorch了</p><p>相關指令與版本</p><pre>pip install numpy==1.26.0<br>pip install scipy==1.14.0<br>pip install matplotlib==3.9.1<br>pip install scikit-learn==1.5.1<br>conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia<br>pip install pytorch-lightning<br>p <br>pip install torchdata torchtext optuna<br>pip install pyarrow fastparquet<br>pip install pytorch_forecasting</pre><p>需要注意的事情是由於每個人的顯卡和驅動都不同所以需要查詢一下自己能夠安裝的cuda版本最高到哪，</p><p>可以透過windows的cmd指令開啟終端機</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A7uUndKqxvPqM_htwEgUyQ.png" /><figcaption>圖13</figcaption></figure><p>然後輸入以下指令查詢如同圖14所示</p><pre>nvidia-smi</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WujOrhX37YFhc-uzgfn1pA.png" /><figcaption>圖14</figcaption></figure><p>按下鍵盤上enter後看到圖15表示出最高能裝到的CUDA版本是12.2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*9k7plrwWBj2Rt8Fo7fZLug.png" /><figcaption>圖15</figcaption></figure><p>所以我們可以到pytorch的官方網站中選擇自己要的版本如圖16，用的是最新版的2.4.0，系統是windows注意要選Conda的版本才會一起裝cuda，這邊的cuda安裝與去Nvidia下載安裝包來裝在系統中的是不一樣的，在這邊安裝的cuda只會在我們創建好的環境中，也就是說當這個環境被刪除這個cuda也被刪除，這也代表我們本機實際是沒有安裝cuda的，但好處是隨著專案開發可以在不同的虛擬環境下安裝不同的cuda所以對於多個專案在同時開發的工程師來說會相當有彈性</p><p>官網連結:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*WUMmZKv-S00BgTk8qAzL0w.png" /><figcaption>圖16</figcaption></figure><p>如果有選擇不同版本的化本文所提供的指令圖17所示，被螢光筆畫起來那行指令就要改成圖16紅色框處的指令。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*KeCWl2rpHt_WTQUpfkik5g.png" /><figcaption>圖17</figcaption></figure><p>測試用範例:</p><p>上面的安裝都完成之後用下面的這個程式碼來測試，沒問題就ok了</p><pre># -*- coding: utf-8 -*-<br>&quot;&quot;&quot;<br>Created on Mon Jul 22 01:20:50 2024<br><br>@author: ioi<br>&quot;&quot;&quot;<br><br>import copy<br>from pathlib import Path<br>import warnings<br><br>import lightning.pytorch as pl<br>from lightning.pytorch.callbacks import EarlyStopping, LearningRateMonitor<br>from lightning.pytorch.loggers import TensorBoardLogger<br>import numpy as np<br>import pandas as pd<br>import torch<br><br>from pytorch_forecasting import Baseline, TemporalFusionTransformer, TimeSeriesDataSet<br>from pytorch_forecasting.data import GroupNormalizer<br>from pytorch_forecasting.metrics import MAE, SMAPE, PoissonLoss, QuantileLoss<br>from pytorch_forecasting.models.temporal_fusion_transformer.tuning import optimize_hyperparameters<br><br>from pytorch_forecasting.data.examples import get_stallion_data<br><br>data = get_stallion_data()<br><br># add time index<br>data[&quot;time_idx&quot;] = data[&quot;date&quot;].dt.year * 12 + data[&quot;date&quot;].dt.month<br>data[&quot;time_idx&quot;] -= data[&quot;time_idx&quot;].min()<br><br># add additional features<br>data[&quot;month&quot;] = data.date.dt.month.astype(str).astype(&quot;category&quot;)  # categories have be strings<br>data[&quot;log_volume&quot;] = np.log(data.volume + 1e-8)<br>data[&quot;avg_volume_by_sku&quot;] = data.groupby([&quot;time_idx&quot;, &quot;sku&quot;], observed=True).volume.transform(&quot;mean&quot;)<br>data[&quot;avg_volume_by_agency&quot;] = data.groupby([&quot;time_idx&quot;, &quot;agency&quot;], observed=True).volume.transform(&quot;mean&quot;)<br><br># we want to encode special days as one variable and thus need to first reverse one-hot encoding<br>special_days = [<br>    &quot;easter_day&quot;,<br>    &quot;good_friday&quot;,<br>    &quot;new_year&quot;,<br>    &quot;christmas&quot;,<br>    &quot;labor_day&quot;,<br>    &quot;independence_day&quot;,<br>    &quot;revolution_day_memorial&quot;,<br>    &quot;regional_games&quot;,<br>    &quot;fifa_u_17_world_cup&quot;,<br>    &quot;football_gold_cup&quot;,<br>    &quot;beer_capital&quot;,<br>    &quot;music_fest&quot;,<br>]<br>data[special_days] = data[special_days].apply(lambda x: x.map({0: &quot;-&quot;, 1: x.name})).astype(&quot;category&quot;)<br>data.sample(10, random_state=521)</pre><p>參考資料:</p><p>[1]<a href="https://github.com/jdb78/pytorch-forecasting/issues/1468">https://github.com/jdb78/pytorch-forecasting/issues/1468</a></p><p>[2]<a href="https://hackmd.io/@winniemyiwen/PyTorch_installation?utm_source=preview-mode&amp;utm_medium=rec">https://hackmd.io/@winniemyiwen/PyTorch_installation?utm_source=preview-mode&amp;utm_medium=rec</a></p><p>內文製作不易，本站內容皆有智慧產權請勿盜用如有使用請正確引用!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4a7474d113c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI學習筆記- 應用種類整理]]></title>
            <link>https://medium.com/@ioi75UT/ai%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98-%E6%87%89%E7%94%A8%E7%A8%AE%E9%A1%9E%E6%95%B4%E7%90%86-c3239f004cbe?source=rss-4eef977f21c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3239f004cbe</guid>
            <dc:creator><![CDATA[阿民的AI與量化金融世界]]></dc:creator>
            <pubDate>Fri, 05 Jul 2024 11:04:02 GMT</pubDate>
            <atom:updated>2024-07-05T11:04:02.317Z</atom:updated>
            <content:encoded><![CDATA[<p>說明:</p><p>人工智慧中相當重要的一個工作環節就是定義出要做的應用，也就是要達到甚麼樣的效果，舉例來說以量化交易的角度來看任務，那麼一個常見的任務要求就是希望能夠知道未來某段時間內的價格是上漲還是下跌，那麼在這邊我們會說希望能夠預測，但是上漲和下跌可以是價格資料得，也可以是單純分類出未來一段時間是盤整或是上漲或是下跌等狀態，我們按照上述我們可以知道光是一個應用需求就有兩種方法可以做到，故在這邊將常見的一些應用輸出做整理給大家參考，這篇文章也將會不定期更新。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*CVRLStqtLIfINbPpSHCF9g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3239f004cbe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[配對交易世界體系地圖(不定期更新)]]></title>
            <link>https://medium.com/@ioi75UT/%E9%85%8D%E5%B0%8D%E4%BA%A4%E6%98%93%E4%B8%96%E7%95%8C%E9%AB%94%E7%B3%BB%E5%9C%B0%E5%9C%96-5ae9717c15f4?source=rss-4eef977f21c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ae9717c15f4</guid>
            <dc:creator><![CDATA[阿民的AI與量化金融世界]]></dc:creator>
            <pubDate>Tue, 14 May 2024 15:25:51 GMT</pubDate>
            <atom:updated>2024-05-14T15:40:42.621Z</atom:updated>
            <content:encoded><![CDATA[<p>說明:<br>甚麼是配對交易? 簡單的說這是一種基於數學與統計的套利方式，求的就是一個&quot;穩&quot;，為了能更清楚得了解這個領域，所以做了一些功課，在這邊跟各位分享，如下圖，大致上就是目前在傳統配對交易中的體系發展比較大宗的方向了，各位也可以跟隨這個圖持續進行相關的搜尋找到自己喜歡的領域去鑽研。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*s56IpEsIDwENY-htphQorg.png" /><figcaption>2024/05/14更新</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ae9717c15f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python串接Bybit-api實現自動量化交易學習筆記(4) — 資料清洗]]></title>
            <link>https://medium.com/@ioi75UT/python%E4%B8%B2%E6%8E%A5bybit-api%E5%AF%A6%E7%8F%BE%E8%87%AA%E5%8B%95%E9%87%8F%E5%8C%96%E4%BA%A4%E6%98%93%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98-4-%E8%B3%87%E6%96%99%E6%B8%85%E6%B4%97-0ca74c264327?source=rss-4eef977f21c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ca74c264327</guid>
            <dc:creator><![CDATA[阿民的AI與量化金融世界]]></dc:creator>
            <pubDate>Thu, 21 Mar 2024 16:53:57 GMT</pubDate>
            <atom:updated>2024-03-21T16:55:32.633Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python串接Bybit-api實現自動量化交易學習筆記(4) — 資料清洗</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*sLHHCLYSu8Sy2buy9pDTpA.png" /></figure><h3>前言:</h3><p>上一篇文章大概說明了如何下載資料等等的過程，這邊要開始進行資料的清洗，因為已經有了交易對的清單，還有如何下載到資料，所以這篇文章主要會圍繞在下載固定範圍資料然後對固定範圍資料進行整理，好替後面的配對交易方法開路。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*eZFyS2TWKca5c1mydYwlSw.png" /></figure><h3>本章重點:</h3><ol><li>下載從現在往回推一年的所有K線資料</li><li>對下載回來的資料進行資料清洗</li></ol><h3>1.下載從現在往回推一年的所有K線資料</h3><p>說明:<br>為了之後回測需要，所以這邊直接切入來進行特定範圍資料下載的工作，由於系統可能之後在自動化運行的時候都會希望只評估過去一年的數據表現，所以這邊先示範抓取過去一年的所有資料。</p><p>以下程式會獲取現在電腦系統時間並且往回推一年，接著下載這一年中的資料，這些商品清單可以利用文章2的內容去獲得(<a href="https://medium.com/@ioi75UT/bybit-api%E5%AF%A6%E7%8F%BE%E8%87%AA%E5%8B%95%E9%87%8F%E5%8C%96%E4%BA%A4%E6%98%93%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98-2-%E5%8C%AF%E5%87%BA%E4%BA%A4%E6%98%93%E5%B0%8D%E6%B8%85%E5%96%AE%E8%87%B3-xlsx-15c2f6fa1196">點擊連結就可以過去那篇文章</a>)，這邊也會同時整合程式碼到class DataProcessor中。</p><pre>def GetBybitUsdOneYearData(self,Period,path):<br>        &#39;&#39;&#39;<br>        函數功能:<br>            透過symbol list資料抓取過去一年資料，記得要有symbol list.xlsx<br>        &#39;&#39;&#39;<br>        utc_datetime = datetime.now(timezone.utc)<br>        one_year_ago = utc_datetime - timedelta(days=365)<br>        unix_timestamp=int(utc_datetime.timestamp())<br>        one_year_ago_unix_timestamp = int(one_year_ago.timestamp())<br>        print( unix_timestamp)<br>        print(one_year_ago_unix_timestamp)<br>        self.GetBybitUsdPriceAllSymbol(Period, unix_timestamp, one_year_ago_unix_timestamp, path)</pre><p>接著到main.py中去進行測試</p><pre>import datetime<br>from classes import class_Data_Processor<br>import pickle<br><br><br><br>path = &#39;D:/12_project_work/BYBIT_PIAR_TRADING/bybit_usdt_symbol_list.xlsx&#39;<br><br>DataProcer =   class_Data_Processor.DataProcessor()<br>DataProcer.GetBybitUsdOneYearData(1,path)</pre><h3>2.對下載回來的資料進行資料清洗</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ca74c264327" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python串接Bybit-api實現自動量化交易學習筆記(3) — 下載歷史交易資料至.xlsx]]></title>
            <link>https://medium.com/@ioi75UT/python%E4%B8%B2%E6%8E%A5bybit-api%E5%AF%A6%E7%8F%BE%E8%87%AA%E5%8B%95%E9%87%8F%E5%8C%96%E4%BA%A4%E6%98%93%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98-3-%E4%B8%8B%E8%BC%89%E6%AD%B7%E5%8F%B2%E4%BA%A4%E6%98%93%E8%B3%87%E6%96%99%E8%87%B3-xlsx-302b7b445d32?source=rss-4eef977f21c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/302b7b445d32</guid>
            <dc:creator><![CDATA[阿民的AI與量化金融世界]]></dc:creator>
            <pubDate>Wed, 20 Mar 2024 07:11:35 GMT</pubDate>
            <atom:updated>2024-03-21T07:41:21.658Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python串接Bybit-api實現自動量化交易學習筆記(3) — 下載BYBIT歷史交易資料至.xlsx</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*3iWjBGqaQ6mptPnKknSGcQ.png" /></figure><h3>前言:</h3><p>在第2篇中[1]我們有將bybit目前在合約上所支援的商品存到清單中，接下來本篇將會紀錄如何取得交易所K線資料接著整合第二篇的功能，使的所有商品價格都可以被自動下載，最後會在製作一個時實更新的程式碼。</p><p>專案架構:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*jB6Wss42fgNZPdXbPTfgxg.png" /><figcaption>專案架構圖</figcaption></figure><h3>本章重點:</h3><p><strong>1.取得BYBIT歷史資料基本程式碼</strong></p><p><strong>2.根據交易所的所有交易品種索取所有資料</strong></p><p><strong>3.時實抓取最新資料</strong></p><h3>1.取得BYBIT歷史資料基本程式碼</h3><p>說明:<br>由於這個系列都是利用同一個專案去做執行的從這個系列的第1篇到現在都是，因為量化交易在後續的發展會越來越龐大，所以在最剛開始就已經說明會用這個架構不斷發展，所以所有的程式碼基本上都是會在classes這個package中發展，這邊也不例外，以下是程式碼範例，該段程式碼一樣要新增到以下路徑中且一樣是新增到class DataProcessor中。如圖1所示。</p><pre>BYBIT_PIAR_TRADING\classes\class_Data_Processor.py</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*aUL_gzgs7Ap54_B4DcEzWA.png" /><figcaption>圖1. 要新增的class位置</figcaption></figure><pre>def GetBybitUsdPrice(self,Period,StartRange,EndRange,SymbolName): <br>        session = HTTP(testnet=True)<br>        print(session.get_kline(<br>            category=&quot;linear&quot;,<br>            symbol=SymbolName,<br>            interval=Period,<br>            start=StartRange, <br>            end=EndRange,))<br>        return session.get_kline(<br>            category=&quot;linear&quot;,<br>            symbol=SymbolName,<br>            interval=Period,<br>            start=StartRange, <br>            end=EndRange,)</pre><p>接著回到main.py中去執行以下程式碼進行確認，當執行完之後有如同圖2和圖3那樣的樣式就可以確認成功下載到這個時間段的資料了，</p><pre>from classes import class_Data_Processor<br><br>DataProcer =   class_Data_Processor.DataProcessor()<br><br>y = DataProcer.GetBybitUsdPrice(5,1670601600000,1670608800000,&quot;BTCUSDT&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*S1jBsHdlhNXbZKNtRET2Fg.png" /><figcaption>圖2. spyder側邊欄樣式確認圖</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*uMa1anQ60ikngoJKWU7OVQ.png" /><figcaption>圖3. 終端機確認有取得資料</figcaption></figure><p>這邊順便附上bybit官方文件對於該函數的原型說明:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iOdDNo_yTnuvxj7Ad2wRcQ.png" /><figcaption>圖4. bybit 官方api文件函數原型說明</figcaption></figure><h3><strong>2.根據交易所的所有交易品種索取所有資料</strong></h3><p>說明:<br>由於這邊已經涉及一點點整合了，所以會比較容易出錯，操作上要盡可能的小心，在我們<a href="https://medium.com/@ioi75UT/bybit-api%E5%AF%A6%E7%8F%BE%E8%87%AA%E5%8B%95%E9%87%8F%E5%8C%96%E4%BA%A4%E6%98%93%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98-2-%E5%8C%AF%E5%87%BA%E4%BA%A4%E6%98%93%E5%B0%8D%E6%B8%85%E5%96%AE%E8%87%B3-xlsx-15c2f6fa1196">第2篇</a>中有提到(如果有忘記的話可以點連結回去看)，如果那個動作有完成現在是可以擁有如下圖的.xlsx檔案了，點開來大概會像圖6那樣，如果還沒有完成這個動作記得要去完成。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*T5R49uj8dqXLYGV4Lq1hTg.png" /><figcaption>圖5. symbol list.xlsx確認動作</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I-BmsbXH0hNdWRjOHO21CQ.png" /><figcaption>圖6. 利用excel進行確認</figcaption></figure><p>上述動作都確認完之後就可以透過以下程式碼進行資料的下載了，這個也是要放在class_Data_Processor.py 這個檔案的class DataProcessor 類別中。</p><pre>def GetBybitUsdPriceAllSymbol(self,Period,StartRange,EndRange,path): <br>        &#39;&#39;&#39;<br>        函數功能:<br>        透過本函數去抓取所有的symbol資料請先備妥.xlsx檔案<br>        &#39;&#39;&#39;<br>        error_counter = 0<br>        data = pd.Series(dtype=&#39;float&#39;)<br>        df = pd.read_excel(path)<br>        data_list = []<br>        symbol = df[&#39;name&#39;]<br>        <br>        for symbol in df[&#39;name&#39;]:<br>            try:<br>               y = self.GetBybitUsdPrice(Period, StartRange, EndRange, symbol)<br>               data_list.append([symbol, y])  <br>            except:    <br>                error_counter = error_counter + 1<br>                print(&#39;Not Possible to retrieve information for &#39; + symbol)<br>        with open(&#39;bybit_contract_data.pickle&#39;, &#39;wb&#39;) as a:<br>            pickle.dump(data_list, a)        <br>        return data_list</pre><p>接著透過main.py檔案去執行進行測試</p><pre>from classes import class_Data_Processor<br><br>DataProcer =   class_Data_Processor.DataProcessor()<br><br>path = &#39;D:/12_project_work/BYBIT_PIAR_TRADING/bybit_usdt_symbol_list.xlsx&#39;<br>y = DataProcer.GetBybitUsdPriceAllSymbol(5,1670601600000,1670608800000,path)</pre><p>運行完成後會如同圖7.一樣在y的變數上是可以點進去看得。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*a8TmaDbGNkETROuPyRE9RQ.png" /><figcaption>圖7</figcaption></figure><p>如果已經有.pickle檔案可以執行下列的程式碼進行運行，當出現圖8那樣的狀態後代表載入成功，資料集已經被存下來了。</p><pre>from classes import class_Data_Processor<br>import pickle<br>#DataProcer =   class_Data_Processor.DataProcessor()<br>#path = &#39;D:/12_project_work/BYBIT_PIAR_TRADING/bybit_usdt_symbol_list.xlsx&#39;<br>#y = DataProcer.GetBybitUsdPriceAllSymbol(5,1670601600000,1670608800000,path)<br>with open(&#39;bybit_contract_data.pickle&#39;, &#39;rb&#39;) as a:<br>   loaded_data = pickle.load(a)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*IWMHhp0KwT8I6R6xSPpPew.png" /><figcaption>圖8</figcaption></figure><h3><strong>3.時實抓取最新資料</strong></h3><p>說明:<br>這邊附帶一個小應用，由於要完成這樣一套系統會有很長一段路要走，所以順手做了一些簡單的小東西寫到哪就做到哪，讓進度可以不斷被往前推，這邊就說明了一個簡單的更新資料方法，讓之後可以先做一個簡單的停損工具出來這樣就可以先暫時達成半自動化交易了。</p><p>請將下列的程式碼放入class DataProcessor之中</p><pre> def GetBybitUsdPriceRealTime(self, SymbolName):<br>        session = HTTP(testnet=True)<br>        price = session.get_tickers(<br>                category=&quot;linear&quot;,<br>                symbol=SymbolName,)<br>        markprice = price[&#39;result&#39;][&#39;list&#39;][0][&#39;markPrice&#39;]<br>        return markprice</pre><p>接著利main.py進行測試</p><pre>import datetime<br>from classes import class_Data_Processor<br>import pickle<br>DataProcer =   class_Data_Processor.DataProcessor()<br><br>price = DataProcer.GetBybitUsdPriceRealTime(&#39;BTCUSDT&#39;)</pre><p>最後我們來總結一下目前為止的</p><pre># -*- coding: utf-8 -*-<br>import datetime<br>import pickle<br>import pandas as pd<br>import requests<br>import pybit<br>from pybit.unified_trading import HTTP<br>#session = HTTP(testnet=True)<br>class DataProcessor:<br>    def GetBybitUsdtSymbol(self):<br>        url = &quot;https://api.bybit.com/v2/public/symbols&quot;<br>        response = requests.get(url)      <br>        if response.status_code == 200:<br>            data = response.json()<br>        else:<br>            print(f&quot;Error: {response.status_code}&quot;)<br>            data = {}<br>        return data<br>    def InitBybitUsdtSymbolList(self,data):       <br>        xlxs = data[&quot;result&quot;]        <br>        df = pd.DataFrame(data[&quot;result&quot;])       <br>        file_path = &#39;bybit_usdt_symbol_list.xlsx&#39;  # 或你想要的路徑<br>        df.to_excel(file_path, index=False)<br>    def GetBybitSystemTime(self):<br>        session = HTTP(testnet=True)<br>        print(session.get_server_time())<br>        return session.get_server_time()<br>    def GetBybitUsdPrice(self,Period,StartRange,EndRange,SymbolName): <br>        session = HTTP(testnet=True)<br>        print(session.get_kline(<br>            category=&quot;linear&quot;,<br>            symbol=SymbolName,<br>            interval=Period,<br>            start=StartRange, <br>            end=EndRange,))<br>        return session.get_kline(<br>            category=&quot;linear&quot;,<br>            symbol=SymbolName,<br>            interval=Period,<br>            start=StartRange, <br>            end=EndRange,)<br>             <br>    def GetBybitUsdPriceAllSymbol(self,Period,StartRange,EndRange,path):  <br>        error_counter = 0<br>        data = pd.Series(dtype=&#39;float&#39;)<br>        df = pd.read_excel(path)<br>        data_list = []<br>        symbol = df[&#39;name&#39;]<br>        for symbol in df[&#39;name&#39;]:<br>            try:<br>               y = self.GetBybitUsdPrice(Period, StartRange, EndRange, symbol)<br>               data_list.append([symbol, y])  <br>            except:    <br>                error_counter = error_counter + 1<br>                print(&#39;Not Possible to retrieve information for &#39; + symbol)<br>                <br>        with open(&#39;bybit_contract_data.pickle&#39;, &#39;wb&#39;) as a:<br>            pickle.dump(data_list, a)<br>        return data_list<br>        <br>    def read_ticker_excel(self, path=None):<br>        <br>    <br>        df = pd.read_excel(path)<br>    <br>        # remove duplicated<br>        unique_df = df[~df.duplicated(subset=[&#39;Ticker&#39;], keep=&#39;first&#39;)].sort_values([&#39;Ticker&#39;])<br>        tickers = unique_df.Ticker.unique()<br>    <br>        return df, unique_df, tickers        <br>    def GetBybitUsdPriceRealTime(self, SymbolName):<br>        session = HTTP(testnet=True)<br>        price = session.get_tickers(<br>                category=&quot;linear&quot;,<br>                symbol=SymbolName,)<br>        markprice = price[&#39;result&#39;][&#39;list&#39;][0][&#39;markPrice&#39;]<br>        return markprice<br>        </pre><p>結語:</p><p>以上是目前進度，截至目前為止已經記錄到了把資料拿完並且可以存成資料集，接下來就是半自動化的等收盤價在停損功能，還有資料清洗等工作。</p><p>參考資料:<br><a href="https://github.com/simaomsarmento/PairsTrading/tree/master">https://github.com/simaomsarmento/PairsTrading/tree/master</a></p><p>公告:<br>以上就是今日的筆記，由於量化工作與研究的進行，有大量工作需要不斷的執行，在文章上面如果有寫的不好的地方也請海涵，如果能夠協助點出需要改進的部分或是給予其他建設性建議本站都會努力去改進!</p><p>另外本站皆不構成任何投資建議，投資前請先衡量風險，在量化上要做足回測之後才開始進行實際交易!</p><p>本文章內容為版權所有請勿隨意盜取</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=302b7b445d32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bybit-api實現自動量化交易學習筆記(2) — 匯出交易對清單至.xlsx]]></title>
            <link>https://medium.com/@ioi75UT/bybit-api%E5%AF%A6%E7%8F%BE%E8%87%AA%E5%8B%95%E9%87%8F%E5%8C%96%E4%BA%A4%E6%98%93%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98-2-%E5%8C%AF%E5%87%BA%E4%BA%A4%E6%98%93%E5%B0%8D%E6%B8%85%E5%96%AE%E8%87%B3-xlsx-15c2f6fa1196?source=rss-4eef977f21c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/15c2f6fa1196</guid>
            <dc:creator><![CDATA[阿民的AI與量化金融世界]]></dc:creator>
            <pubDate>Wed, 20 Mar 2024 03:06:18 GMT</pubDate>
            <atom:updated>2024-03-20T14:52:41.795Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python串接Bybit-api實現自動量化交易學習筆記(2) — 匯出交易對清單至.xlsx</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*CVmYUBCQEhuHGnNFndOh6A.png" /></figure><h3>前言:</h3><p>在上一篇[1]中有說明到如何拿到交易對清單，這個清單是後面要拿數據用的重要窗口，所以存成.xlsx是有必要的且這麼做也方便之後回朔或是去看交易對的品種，故這篇文章將負責記錄如何將上一篇文章的內容做資料儲存。</p><p>上篇文章連結[1]:<a href="https://medium.com/@ioi75UT/%E7%94%A8bybit-api%E5%AF%A6%E7%8F%BE%E8%87%AA%E5%8B%95%E9%87%8F%E5%8C%96%E4%BA%A4%E6%98%93%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98-%E5%8F%96%E5%BE%97%E4%BA%A4%E6%98%93%E6%89%80%E4%BA%A4%E6%98%93%E5%B0%8D%E6%B8%85%E5%96%AE-b5da2b10a213">https://medium.com/p/15c2f6fa1196/edit</a></p><p>說明:</p><p>如下圖1所示，這個圖是目前的專案架構圖，圖2表示在windows中以資料夾顯示的結構，圖3則是資料位置選到這個，然後將本篇範例程式碼插入之後就可以回到main.py去執行拉(如果不知道main.py在哪可以回到第一篇看)。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*8Npv8C1L7F4UCYCcHZyr-Q.png" /><figcaption>圖1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*aWNuizBGMg2iMZSXZEejwA.png" /><figcaption>圖2</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*dLyTFn3FlH9eD5GxQKvDkA.png" /><figcaption>圖3</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*4ArHPXLMDZkMkEWg9mc_hQ.png" /><figcaption>圖4. 程式碼新建完成後的樣子</figcaption></figure><pre>def InitBybitUsdtSymbolList(self,data):<br>        #函數功能:將symbol匯出成xlxs檔案好讓日後可以擁有最新交易對清單<br>        # 要儲存的資料<br>        xlxs = data[&quot;result&quot;]<br>        # 將資料轉換為DataFrame，並在最上方加上&#39;symbol&#39;<br>        #df = pd.DataFrame(data[&quot;result&quot;], columns=[&#39;symbol&#39;])<br>        df = pd.DataFrame(data[&quot;result&quot;])<br>        # 將DataFrame儲存到Excel檔案中<br>        file_path = &#39;bybit_usdt_symbol_list.xlsx&#39;  # 或你想要的路徑<br>        df.to_excel(file_path, index=False)</pre><p>動作完成確認:<br>回到與main.py的那一層路徑，可以發現已經多了一個.xlsx檔案!如圖5</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*dplHTEzU3Syl1-KDtuhtUQ.png" /><figcaption>圖5. 確認動作</figcaption></figure><p>結語:<br>以上就是今日的筆記，由於量化工作與研究的進行，有大量工作需要不斷的執行，在文章上面如果有寫的不好的地方也請海涵，如果能夠協助點出需要改進的部分或是給予其他建設性建議本站都會努力去改進!</p><p>另外本站皆不構成任何投資建議，投資前請先衡量風險，在量化上要做足回測之後才開始進行實際交易!</p><p>本文章內容為版權所有請勿隨意盜取</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15c2f6fa1196" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python串接Bybit-api實現自動量化交易學習筆記(1) - 取得交易所交易對清單]]></title>
            <link>https://medium.com/@ioi75UT/%E7%94%A8bybit-api%E5%AF%A6%E7%8F%BE%E8%87%AA%E5%8B%95%E9%87%8F%E5%8C%96%E4%BA%A4%E6%98%93%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98-%E5%8F%96%E5%BE%97%E4%BA%A4%E6%98%93%E6%89%80%E4%BA%A4%E6%98%93%E5%B0%8D%E6%B8%85%E5%96%AE-b5da2b10a213?source=rss-4eef977f21c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5da2b10a213</guid>
            <dc:creator><![CDATA[阿民的AI與量化金融世界]]></dc:creator>
            <pubDate>Tue, 19 Mar 2024 15:15:22 GMT</pubDate>
            <atom:updated>2024-03-20T14:55:34.978Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*cV7XcL-HbkTcaBLcTLjGmg.png" /></figure><h3>前言:</h3><p>原則上要進行量化的第一步一定是要做取的資料的動作，這邊的筆記主要是要記錄這一段過程是怎麼實現的，好方便自己之後可以調閱出來看，和快速想起一些程式碼該怎麼寫。</p><h3>使用工具:</h3><p>BYBIT 官方API — pybit 5.6.2<br>python -3.9</p><p>這邊附帶說明這個版本支援的功能詳情可以上官方連結查看<br><a href="https://bybit-exchange.github.io/docs/zh-TW/v5/intro">https://bybit-exchange.github.io/docs/zh-TW/v5/intro</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wdkfcj2zTz4X8yQFFC7rSA.png" /></figure><h3>安裝pybit:</h3><p>輸入這行指令到anaconda的power shell 中:</p><pre>pip install pybit</pre><p>完成之後會如下圖，版本的部分會隨著更新而更新。所以大家要注意版本是否有一致。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*w40fY99mj-nO942mgrftEg.png" /><figcaption>安裝成功圖</figcaption></figure><h3>檔案結構</h3><p>考量到之後要往大型自動化框架發展，相信大家應該是不會想要一直不斷重構，或者是很亂的程式碼，所以這邊先發展出一個框架給大家參考。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*62fuuC8wHkIpkoeorofCng.png" /><figcaption>專案架構</figcaption></figure><h3>查詢目前有哪些合約交易對工具</h3><p>說明:<br>來到本章節重點，就是要取得具體有哪些合約交易對可以做單，由於合約的交易對可能會根據行情的不同被停止或者是新上架，透過以下程式碼快速取得有哪些交易對。</p><pre><br>import requests<br><br># Bybit API的URL<br>url = &quot;https://api.bybit.com/v2/public/symbols&quot;<br><br># 發送GET請求<br>response = requests.get(url)<br><br># 檢查響應的狀態碼<br>if response.status_code == 200:<br>    # 將返回的JSON解析為字典<br>    data = response.json()<br>    # 印出合約symbol<br>    print(data)<br>else:<br>    print(f&quot;Error: {response.status_code}&quot;)</pre><p>完成之後可以在sypder的側邊看見以下資訊</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*c9JWzmjRYxnJAdH42Q3qvg.png" /><figcaption>spyder測邊欄資訊</figcaption></figure><p>其中第一個data快速左鍵點兩下進去就可以看見目前有提供的交易對有哪些。可看result並且點進去看內容。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*dx4bLSVXFU4YRo4GHzjjxA.png" /><figcaption>result資料顯示</figcaption></figure><h3>整合到專案程式碼中</h3><p>上面提供一個子程式碼，這邊主要是要開始進行整合工作，並且用一個main.py去驅動，所以這邊可以更進一步做整合，讓專案變得更加靈活。</p><p>到classes(圖1)中的class_Data_Processor.py(圖2)新增以下程式碼如</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*G0626NiKxiqvThE4K6vqOQ.png" /><figcaption>圖1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*J6Tr1c7N6IMsE4_JZRW8Iw.png" /><figcaption>圖2</figcaption></figure><pre>import requests<br>class DataProcessor:<br>    def GetBybitUsdtSymbol(self):<br>        # Bybit API的URL<br>        url = &quot;https://api.bybit.com/v2/public/symbols&quot;<br>        # 發送GET請求<br>        response = requests.get(url)<br>        # 檢查響應的狀態碼<br>        if response.status_code == 200:<br>            # 將返回的JSON解析為字典<br>            data = response.json()<br>            # 印出合約symbol<br>            print(data)<br>        else:<br>            print(f&quot;Error: {response.status_code}&quot;)<br>        return data</pre><p>之後到我們的main.py中確認這個功能有被製作出來並且可以成功運作，可以參考以下範例。</p><pre>from classes import class_Data_Processor<br><br>DataProcer =   class_Data_Processor.DataProcessor()<br>x = DataProcer.GetBybitUsdtSymbol()</pre><p>成功運行之後可以再console中讀取到類似下列資訊，當讀取到的時候代表已經成功取得目前的交易對。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*HKk6OJU_I5MO6E7aDQIMWA.png" /><figcaption>確認是否成功交易對範例</figcaption></figure><p>參考資料:<br><a href="https://bybit-exchange.github.io/docs/zh-TW/v5/market/kline">https://bybit-exchange.github.io/docs/zh-TW/v5/market/kline</a></p><p>結語:<br>以上就是今日的筆記，由於量化工作與研究的進行，有大量工作需要不斷的執行，在文章上面如果有寫的不好的地方也請海涵，如果能夠協助點出需要改進的部分或是給予其他建設性建議本站都會努力去改進!</p><p>另外本站皆不構成任何投資建議，投資前請先衡量風險，在量化上要做足回測之後才開始進行實際交易!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5da2b10a213" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CTA類指標小研究-半神半目夏策略-macd]]></title>
            <link>https://medium.com/@ioi75UT/cta%E9%A1%9E%E6%8C%87%E6%A8%99%E5%B0%8F%E7%A0%94%E7%A9%B6-%E5%8D%8A%E7%A5%9E%E5%8D%8A%E7%9B%AE%E5%A4%8F%E7%AD%96%E7%95%A5-95-%E5%8B%9D%E7%8E%87-879676d80a56?source=rss-4eef977f21c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/879676d80a56</guid>
            <dc:creator><![CDATA[阿民的AI與量化金融世界]]></dc:creator>
            <pubDate>Sun, 17 Mar 2024 15:51:45 GMT</pubDate>
            <atom:updated>2024-03-18T08:37:57.928Z</atom:updated>
            <content:encoded><![CDATA[<p>該項策略是MACD背離策略，所謂MACD背離就是指價格不斷創高，但是MACD柱狀並沒有創高，相反如果是下跌也是一樣道理，當背離發生甚至是三個。如下圖1所示可以看見背離的示意圖。</p><figure><img alt="圖1.MACD上漲背離示意圖" src="https://cdn-images-1.medium.com/max/257/1*x_ITe62RfzvyE9lHoEurXw.png" /><figcaption>圖1. MACD上漲背離示意圖</figcaption></figure><p>當背離發生的時候就可以開始買入，詳細操作可以看以下連結的影片有詳細說明這邊就不多贅述。因為這個影片發布者已經說得夠清楚</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FIc8V1Pue-2I%3Fstart%3D190%26feature%3Doembed%26start%3D190&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DIc8V1Pue-2I&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FIc8V1Pue-2I%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/90eb38fbc05293fe8404ff1853fe8daa/href">https://medium.com/media/90eb38fbc05293fe8404ff1853fe8daa/href</a></iframe><p>但由於他的方法會需要大量的觀看，所以這邊設計了一個幾乎可以查出背離的tradingview程式碼，雖然還有一些小bug在但是基本上已經可以把背離情況抓出來，這邊和大家分享</p><pre>//@version=5<br>indicator(title=&quot;小工具&quot;, shorttitle=&quot;小工具&quot;, overlay=true)<br><br>// 獲取輸入<br>fast_length = input(title = &quot;Fast Length&quot;, defval = 12)<br>slow_length = input(title = &quot;Slow Length&quot;, defval = 26)<br>src = input(title = &quot;Source&quot;, defval = close)<br>signal_length = input.int(title = &quot;Signal Smoothing&quot;, minval = 1, maxval = 50, defval = 9)<br>sma_source = input.string(title = &quot;Oscillator MA Type&quot;, defval = &quot;EMA&quot;, options = [&quot;SMA&quot;, &quot;EMA&quot;])<br>sma_signal = input.string(title = &quot;Signal Line MA Type&quot;, defval = &quot;EMA&quot;, options = [&quot;SMA&quot;, &quot;EMA&quot;])<br><br>// 計算MACD<br>fast_ma = sma_source == &quot;SMA&quot; ? ta.sma(src, fast_length) : ta.ema(src, fast_length)<br>slow_ma = sma_source == &quot;SMA&quot; ? ta.sma(src, slow_length) : ta.ema(src, slow_length)<br>macd = fast_ma - slow_ma<br>signal = sma_signal == &quot;SMA&quot; ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)<br>hist = macd - signal<br><br>// 檢測波峰和波谷<br>peak = (hist &gt;= 0 and hist[1] &gt;= 0) and (hist[1] &gt; hist[2] and hist &lt; hist[1])<br>trough = (hist &lt;= 0 and hist[1] &lt;= 0) and (hist[1] &lt; hist[2] and hist &gt; hist[1])<br><br><br>plotshape(series=peak, location=location.abovebar, color=color.new(#26A69A, 0), style=shape.labeldown, title=&quot;Peak&quot;, text=&quot;P&quot;, size=size.small, offset=1)<br>plotshape(series=trough, location=location.belowbar, color=color.new(#FF5252, 0), style=shape.labelup, title=&quot;Trough&quot;, text=&quot;T&quot;, size=size.small, offset=1)<br><br><br>prev_peak = ta.valuewhen(peak, close, 1)<br>prev_trough = ta.valuewhen(trough, close, 1)<br>prev_peak_hist = ta.valuewhen(peak, hist, 1)<br>prev_trough_hist = ta.valuewhen(trough, hist, 1)<br><br><br>peak_without_trough = peak and not na(trough[1]) and close &gt; prev_peak and hist &lt;= prev_peak_hist<br><br>trough_without_peak = trough and not na(peak[1]) and close &lt; prev_trough and hist &gt;= prev_trough_hist<br><br>plotshape(series=peak_without_trough, location=location.abovebar, color=color.new(#FFD700, 0), style=shape.circle, title=&quot;Star Peak&quot;, text=&quot;*&quot;, size=size.small)<br>plotshape(series=trough_without_peak, location=location.belowbar, color=color.new(#5ccd46, 0), style=shape.circle, title=&quot;Star Trough&quot;, text=&quot;*&quot;, size=size.small)</pre><p>實際運行會如同下圖2所示，黃色圈圈代表上漲背離，綠色圈圈會代表下跌背離。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*wvpA82QoDmKPoO-2S2QZVg.png" /><figcaption>圖2. macd背離標示展示圖</figcaption></figure><p>以上就是今天的小工具分享，注意本文章僅作為指標分享不具備任何投資建議。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=879676d80a56" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CTA類指標小研究-日內5分鐘指標-1]]></title>
            <link>https://medium.com/@ioi75UT/cta%E9%A1%9E%E6%8C%87%E6%A8%99%E5%B0%8F%E7%A0%94%E7%A9%B6-%E6%97%A5%E5%85%A75%E5%88%86%E9%90%98%E6%8C%87%E6%A8%99-1-74155c20e564?source=rss-4eef977f21c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/74155c20e564</guid>
            <dc:creator><![CDATA[阿民的AI與量化金融世界]]></dc:creator>
            <pubDate>Mon, 11 Mar 2024 14:36:33 GMT</pubDate>
            <atom:updated>2024-03-11T14:41:34.244Z</atom:updated>
            <content:encoded><![CDATA[<h3>前言</h3><p>這個策略的想法源自於一個youtube上的小影片，那因為主要還是以量化交易為重點而且是以中性策略為自己研究重點，所以一些CTA策略就稍微開一些腦洞就好。</p><p>參考來源:<a href="https://www.youtube.com/watch?v=F2AkZdkEP8s">https://www.youtube.com/watch?v=F2AkZdkEP8s</a></p><p>這邊有自己嘗試出新策略，但是由於沒有完整回測所以還不知道效果如何，如果各位看完後自己有回測也歡迎分享自己的成果，開源的世界需要大家一起努力才可以攜手迎來更好的未來!</p><p>整個指標運行一覽</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vvIhRyaRyRAWhWMEYEWAEA.png" /></figure><p>使用的指標:</p><ol><li>VWAP</li><li>Heatmap Volume</li></ol><p>思維說明:<br> 原則上這根本是一個成交量策略，都是以圍繞著成交量來設計的，第一個指標是許多日內交易員會用的，這句話的根據是在本文章開頭的那部影片得到資訊，下面呢則是我滿喜歡用得指標，其實他也沒甚麼特別的地方，就是成交量然後會有顏色。</p><p>交易方法說明:<br>step1.<br>找到價格穿過指標1上下緣的商品</p><p>step2.<br>指標2出現紅色或是黃色柱體</p><p>step3.<br>隨後價格進入下穿或是上指標1中軸，則代表可以做空或做多</p><p>警告:<br>文章相關內容不構成任何投資建議，請在投入市場前嚴謹實驗，同時文章內容旨在給予各位大眾參考方向與思考方向。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74155c20e564" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>