{"id":23726050,"url":"https://github.com/voidful/tw_stocker","last_synced_at":"2025-04-05T17:08:48.605Z","repository":{"id":232262171,"uuid":"783859889","full_name":"voidful/tw_stocker","owner":"voidful","description":"keep tracking and store taiwan stock information - 每天更新台股歷史資料庫","archived":false,"fork":false,"pushed_at":"2025-03-20T16:22:25.000Z","size":5894445,"stargazers_count":110,"open_issues_count":0,"forks_count":35,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-29T16:09:41.037Z","etag":null,"topics":["stock","taiwan","taiwan-stock-market"],"latest_commit_sha":null,"homepage":"https://github.com/voidful/tw_stocker/tree/main/data","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/voidful.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-08T18:02:08.000Z","updated_at":"2025-03-20T16:22:29.000Z","dependencies_parsed_at":"2025-03-19T07:39:24.242Z","dependency_job_id":null,"html_url":"https://github.com/voidful/tw_stocker","commit_stats":null,"previous_names":["voidful/tw_stocker"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voidful%2Ftw_stocker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voidful%2Ftw_stocker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voidful%2Ftw_stocker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voidful%2Ftw_stocker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/voidful","download_url":"https://codeload.github.com/voidful/tw_stocker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247369952,"owners_count":20927928,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["stock","taiwan","taiwan-stock-market"],"created_at":"2024-12-31T00:18:21.939Z","updated_at":"2025-04-05T17:08:43.587Z","avatar_url":"https://github.com/voidful.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TW Stocker\n\n每天更新的台股歷史資料庫，計算技術指標，回測然後推薦股票。  \n\nhttps://voidful.github.io/tw_stocker/stock_report.html\n\n## 使用方式，以2330為例，可以換成自己需要的股票\n\n```python\nimport pandas as pd\n\nurl=\"https://raw.githubusercontent.com/voidful/tw_stocker/main/data/2330.csv\"\npd.read_csv(url)\n```\n\n## 資料來源\nYahoo finance，每隔5分鐘的六十天內資料，會用github action持續更新。\n\n## 抽取技術指標\n1. `pip install fta`\n2. \n```python\nimport pandas as pd\nimport fta\nurl = \"https://raw.githubusercontent.com/voidful/tw_stocker/main/data/2330.csv\"\ndf = pd.read_csv(url, index_col='Datetime')\n\nta = fta.TA_Features()\ndf_full = ta.get_all_indicators(df)\nprint(df_full)\n```\n\n## 模擬交易\n1. git clone this project  \n2. 參考`strategy/dynamic_delay`作為我們交易的策略  \n```python\nimport pandas as pd\nimport fta\nfrom strategy.dynamic_delay import trade\n\nurl = \"https://raw.githubusercontent.com/voidful/tw_stocker/main/data/2330.csv\"\ndf = pd.read_csv(url, index_col='Datetime')\n\n\nta = fta.TA_Features()\ndf_full = ta.get_all_indicators(df)\n\nPARAMETER = {\n    \"delay\": 15,\n    \"initial_money\": 10000,\n    \"max_buy\": 10,\n    \"max_sell\": 10,\n}\n\nstates_buy, states_sell, states_entry, states_exit, total_gains, invest = trade(df_full, **PARAMETER)\n```\n#### 結果\n![image](./img/trade_record.png)\n\n### 交易圖表\n```python\nfrom matplotlib import pyplot as plt\nimport pandas as pd\nimport fta\nfrom strategy.dynamic_delay import trade\n\nurl = \"https://raw.githubusercontent.com/voidful/tw_stocker/main/data/2330.csv\"\ndf = pd.read_csv(url, index_col='Datetime')\n\n\nta = fta.TA_Features()\ndf_full = ta.get_all_indicators(df)\n\nPARAMETER = {\n    \"delay\": 15,\n    \"initial_money\": 10000,\n    \"max_buy\": 10,\n    \"max_sell\": 10,\n}\n\nstates_buy, states_sell, states_entry, states_exit, total_gains, invest = trade(df_full, **PARAMETER)\n\nclose = df_full['close']\nfig = plt.figure(figsize = (15,5))\nplt.plot(close, color='r', lw=2.)\nplt.plot(close, '^', markersize=10, color='m', label = 'buying signal', markevery = states_buy)\nplt.plot(close, 'v', markersize=10, color='k', label = 'selling signal', markevery = states_sell)\nplt.legend()\nplt.show()\n```\n#### 結果\n![image](./img/trade_graph.png)\n\n### 回測\n```python\nimport vectorbt as vbt\nimport pandas as pd\nimport numpy as np\nimport fta\nfrom strategy.dynamic_delay import trade\n\nurl = \"https://raw.githubusercontent.com/voidful/tw_stocker/main/data/2330.csv\"\ndf = pd.read_csv(url, index_col='Datetime')\n\n\nta = fta.TA_Features()\ndf_full = ta.get_all_indicators(df)\n\nPARAMETER = {\n    \"delay\": 15,\n    \"initial_money\": 10000,\n    \"max_buy\": 10,\n    \"max_sell\": 10,\n}\n\nstates_buy, states_sell, states_entry, states_exit, total_gains, invest = trade(df_full, **PARAMETER)\n\nfees = 0 # 假設交易費用為 0\nportfolio_kwargs = dict(size=np.inf, fees=float(fees), freq='5m')\nportfolio = vbt.Portfolio.from_signals(df_full['close'], states_entry, states_exit, **portfolio_kwargs)\nprint(portfolio.stats())\nportfolio.plot().show()\n```\n#### 結果\n![image](./img/result_stat.png)\n![image](./img/result_graph.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoidful%2Ftw_stocker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvoidful%2Ftw_stocker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoidful%2Ftw_stocker/lists"}