id: cfde55df18b341d9971fed12f2b37e72
parent_id: 
item_type: 1
item_id: 263c850f6fe741bcb6392b7602411d30
item_updated_time: 1764365022745
title_diff: "[{\"diffs\":[[1,\"搭建你的第一个量化交易环境：开启Python量化投资之旅\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":28}]"
body_diff: "[{\"diffs\":[[1,\"<html>\\\r\\\n<head>\\\r\\\n  <title>搭建你的第一个量化交易环境：开启Python量化投资之旅</title>\\\r\\\n  <basefont face=\\\"微软雅黑\\\" size=\\\"2\\\" />\\\r\\\n  <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=utf-8\\\" />\\\r\\\n  <meta name=\\\"exporter-version\\\" content=\\\"YXBJ Windows/608924 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;\\\"/>\\\r\\\n  <meta name=\\\"content-class\\\" content=\\\"yinxiang.peso.superNote\\\"/>\\\r\\\n  <meta name=\\\"application-data:yinxiang.noteLayout\\\" content=\\\"{\\\"lineSpace\\\":\\\"recommend\\\",\\\"paragraphSpace\\\":\\\"recommend\\\"}\\\"/>\\\r\\\n  <style>\\\r\\\n\\tbody, td {\\\r\\\n\\t  font-family: 微软雅黑;\\\r\\\n\\t  font-size: 12pt;\\\r\\\n\\t}\\\r\\\n  </style>\\\r\\\n</head>\\\r\\\n<body>\\\r\\\n<a name=\\\"39707\\\"></a>\\\r\\\n<h1>搭建你的第一个量化交易环境：开启Python量化投资之旅</h1>\\\r\\\n\\\r\\\n<div><span style=\\\"margin:0px;\\\"><div style=\\\"padding:8px 0px;margin:8px auto;max-width:700px;\\\"> <div><span></span></div>\\\n<p></p>\\\n<div style=\\\"--en-blockquote:true;box-sizing: border-box; padding-left: 19px; padding-top: 6px; padding-bottom: 6px; border-left: 3px solid #b4c0cc; background-position: initial initial; background-repeat: initial initial; margin-top: 6px\\\"><div>原文链接: <a href=\\\"http://mp.weixin.qq.com/s?__biz=MzU2NTk1OTE1Nw==&amp;mid=2247484185&amp;idx=1&amp;sn=2d2ca814fa9372317455d4b4f34a5525&amp;chksm=fd0c339f7752cc25cbd9036305aba1d581c4cd706c418dd848351cd8f2607aad0982652b1b37&amp;mpshare=1&amp;scene=1&amp;srcid=0410kkfP96ZLoxYpaPtN2pnb&amp;sharer_shareinfo=3909614ea64467a41885c6bec326301a&amp;sharer_shareinfo_first=3909614ea64467a41885c6bec326301a#rd\\\"><span>http://mp.weixin.qq.com/s?__biz=MzU2NTk1OTE1Nw==&amp;mid=2247484...</span></a></div></div>\\\n<p></p>\\\n<div><span></span></div>\\\n<div style=\\\"\\\"><div><div><h1 style=\\\"margin:0\\\"> 搭建你的第一个量化交易环境：开启Python量化投资之旅 </h1><div><span style=\\\"position:relative\\\">原创</span><span><span style=\\\"position:relative\\\">硅基生命的创作</span></span><span><a style=\\\"position:relative\\\"> 硅基生命的创作 </a></span><span><em></em></span></div><div style=\\\";\\\"><div><strong><span>还在幻想自己成为华尔街之狼？别做梦了，先搭建你的量化交易环境吧！今天，我们不聊那些虚头巴脑的概念，直接动手，让你的电脑变成一台金融“印钞机”！</span></strong></div><hr style=\\\"border-style: solid;border-width: 1px 0 0;border-color: rgba(0,0,0,0.1);-webkit-transform-origin: 0 0;-webkit-transform: scale(1, 0.5);transform-origin: 0 0;transform: scale(1, 0.5);\\\"/><h2 style=\\\"margin:0\\\"><span><br/></span></h2><h2 style=\\\"margin:0\\\"><span>1. 量化交易需要哪些工具？</span></h2><h2 style=\\\"margin:0\\\"><span><br/></span></h2><p style=\\\"margin:0\\\"><span>要做量化交易，你得有一套趁手的兵器。以下是你必须要安装的核心工具：</span></p><p style=\\\"margin:0\\\"><span>✅ </span><strong><span>Python 解释器</span></strong><span>：Python 3.8+（别用太老的版本，别问，问就是踩坑）。</span><span><br/></span><span>✅ </span><strong><span>Jupyter Notebook</span></strong><span>：最适合金融分析的代码编辑器。</span><span><br/></span><span>✅ </span><strong><span>核心库</span></strong><span>：</span><code><span>pandas</span></code><span>、</span><code><span>numpy</span></code><span>、</span><code><span>matplotlib</span></code><span>、</span><code><span>scikit-learn</span></code><span>。</span><span><br/></span><span>✅ </span><strong><span>数据获取库</span></strong><span>：</span><code><span>akshare</span></code><span>（国内市场数据）、</span><code><span>tushare</span></code><span>（A股数据，需要Token）。</span><span><br/></span><span>✅ </span><strong><span>回测框架</span></strong><span>：</span><code><span>backtrader</span></code><span> 或 </span><code><span>vnpy</span></code><span>（更适用于国内市场）。</span><span><br/></span><span>✅ </span><strong><span>自动交易库</span></strong><span>：</span><code><span>vnpy</span></code><span>（对接券商）、</span><code><span>easytrader</span></code><span>（支持同花顺、国泰君安等）。</span></p><hr style=\\\"border-style: solid;border-width: 1px 0 0;border-color: rgba(0,0,0,0.1);-webkit-transform-origin: 0 0;-webkit-transform: scale(1, 0.5);transform-origin: 0 0;transform: scale(1, 0.5);\\\"/><h2 style=\\\"margin:0\\\"><span><br/></span></h2><h2 style=\\\"margin:0\\\"><span>2. 安装Python环境</span></h2><h2 style=\\\"margin:0\\\"><span><br/></span></h2><p style=\\\"margin:0\\\"><span>如果你的电脑还没有Python，赶紧装上！</span></p><h3 style=\\\"margin:0\\\"><strong><span>Windows / macOS / Linux 安装 Python：</span></strong></h3><h3 style=\\\"margin:0\\\"><strong><span><br/></span></strong></h3><ol style=\\\"margin:0\\\"><li><p style=\\\"margin:0\\\"><strong><span>去官网下载Python</span></strong><span>：</span><span>https://www.python.org/downloads/</span></p><p style=\\\"margin:0\\\"><span><br/></span></p></li><li><p style=\\\"margin:0\\\"><strong><span>安装时勾选“Add Python to PATH”</span></strong><span>（Windows 用户注意这个坑！）</span></p><p style=\\\"margin:0\\\"><span><br/></span></p></li><li><p style=\\\"margin:0\\\"><span>安装完成后，打开终端（Windows：</span><code><span>cmd</span></code><span>，Mac/Linux：</span><code><span>Terminal</span></code><span>），输入：</span></p><div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>python <span>--version</span></span></div></pre></div></li></ol><p style=\\\"margin:0\\\"><span>    确保安装成功。</span></p><hr style=\\\"border-style: solid;border-width: 1px 0 0;border-color: rgba(0,0,0,0.1);-webkit-transform-origin: 0 0;-webkit-transform: scale(1, 0.5);transform-origin: 0 0;transform: scale(1, 0.5);\\\"/><h2 style=\\\"margin:0\\\"><span><br/></span></h2><h2 style=\\\"margin:0\\\"><span>3. 创建量化交易的虚拟环境</span></h2><h2 style=\\\"margin:0\\\"><span><br/></span></h2><p style=\\\"margin:0\\\"><span>别直接在系统 Python 里装乱七八糟的库，</span><strong><span>用虚拟环境管理你的项目</span></strong><span>，否则迟早变成“环境地狱”。</span></p><div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span><span># 创建一个独立的 Python 环境</span></span><div><span>python -m venv quant_env</span></div><div><span><span># 激活环境（Windows）</span></span></div><div><span>quant_env\\\\Scripts\\\\activate</span></div><div><span><span># 激活环境（Mac/Linux）</span></span></div><div><span><span>source</span> quant_env/bin/activate</span></div></div></pre></div><p style=\\\"margin:0\\\"><span>然后，确保你在虚拟环境中运行以下命令。</span></p><hr style=\\\"border-style: solid;border-width: 1px 0 0;border-color: rgba(0,0,0,0.1);-webkit-transform-origin: 0 0;-webkit-transform: scale(1, 0.5);transform-origin: 0 0;transform: scale(1, 0.5);\\\"/><h2 style=\\\"margin:0\\\"><span><br/></span></h2><h2 style=\\\"margin:0\\\"><span>4. 安装量化投资必备库</span></h2><h2 style=\\\"margin:0\\\"><span><br/></span></h2><div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span><span>pip</span> install pandas numpy matplotlib scikit-learn jupyter akshare tushare backtrader vnpy easytrader</span></div></pre></div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span><br/></span></div></pre><p style=\\\"margin:0\\\"><span>然后，确保一切正常：</span></p><div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span><span>import</span> pandas <span>as</span> pd</span><div><span><span>import</span> numpy <span>as</span> np</span></div><div><span><span>import</span> matplotlib.pyplot <span>as</span> plt</span></div><div><span><span>import</span> akshare <span>as</span> ak</span></div><div><span><br/></span></div><div><span><span>print</span>(<span>&quot;环境安装成功！&quot;</span>)</span></div></div></pre></div><p style=\\\"margin:0\\\"><span>如果没有报错，恭喜，你的量化交易环境搭建完成了！🎉</span></p><hr style=\\\"border-style: solid;border-width: 1px 0 0;border-color: rgba(0,0,0,0.1);-webkit-transform-origin: 0 0;-webkit-transform: scale(1, 0.5);transform-origin: 0 0;transform: scale(1, 0.5);\\\"/><h2 style=\\\"margin:0\\\"><span><br/></span></h2><h2 style=\\\"margin:0\\\"><span>5. 运行你的第一个 Jupyter Notebook</span></h2><h2 style=\\\"margin:0\\\"><span><br/></span></h2><p style=\\\"margin:0\\\"><span>Jupyter Notebook 让你可以边写代码边看数据，简直是量化交易神器。</span></p><div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span><span>jupyter</span> notebook</span></div></pre></div><p style=\\\"margin:0\\\"><span>然后在浏览器里打开 Notebook，创建一个新的 Python 文件，输入：</span></p><div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span><span>import</span> akshare <span>as</span> ak</span><div><span><span>data</span> = ak.stock_zh_a_hist(symbol=<span>&quot;600519&quot;</span>, period=<span>&quot;daily&quot;</span>, adjust=<span>&quot;qfq&quot;</span>)</span></div><div><span>print(<span>data</span>.head())</span></div></div></pre></div><p style=\\\"margin:0\\\"><span>如果你看到贵州茅台（600519）的历史K线数据，说明一切顺利！📈</span></p><hr style=\\\"border-style: solid;border-width: 1px 0 0;border-color: rgba(0,0,0,0.1);-webkit-transform-origin: 0 0;-webkit-transform: scale(1, 0.5);transform-origin: 0 0;transform: scale(1, 0.5);\\\"/><h2 style=\\\"margin:0\\\"><span><br/></span></h2><h2 style=\\\"margin:0\\\"><span>6. 量化交易环境搭建成功，下一步干啥？</span></h2><h2 style=\\\"margin:0\\\"><span><br/></span></h2><p style=\\\"margin:0\\\"><span>✅ </span><strong><span>测试数据获取</span></strong><span>：学习如何用 </span><code><span>akshare</span></code><span> 和 </span><code><span>tushare</span></code><span> 获取更多A股数据。</span><span><br/></span><span>✅ </span><strong><span>探索数据</span></strong><span>：用 </span><code><span>pandas</span></code><span> 分析数据趋势，计算均线等指标。</span><span><br/></span><span>✅ </span><strong><span>编写第一个交易策略</span></strong><span>：实现一个简单的均线交易策略。</span><span><br/></span><span>✅ </span><strong><span>学习回测</span></strong><span>：用 </span><code><span>backtrader</span></code><span> 进行历史数据回测，或使用 </span><code><span>vnpy</span></code><span> 进行本地模拟交易。</span><span><br/></span><span>✅ </span><strong><span>准备自动交易</span></strong><span>：学习 </span><code><span>vnpy</span></code><span> 对接券商，或使用 </span><code><span>easytrader</span></code><span> 操作证券软件。</span></p><div><span></span></div><p style=\\\"margin:0\\\"><span><br/></span></p><p style=\\\"margin:0\\\"><span>下一篇，我们将深入研究“数据获取与分析”，教你如何让Python帮你抓取市场数据，找到交易机会！🚀</span></p></div></div></div></div></div></span>\\\n</div></body></html>\\u0000\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":13465}]"
metadata_diff: {"new":{"id":"263c850f6fe741bcb6392b7602411d30","parent_id":"f67288c3a0be4374b5d532b5dcc3aabc","latitude":"0.00000000","longitude":"0.00000000","altitude":"0.0000","author":"","source_url":"","is_todo":0,"todo_due":0,"todo_completed":0,"source":"joplin-desktop","source_application":"net.cozic.joplin-desktop","application_data":"","order":1764348856971,"user_updated_time":1764345627123,"markup_language":2,"is_shared":0,"share_id":"","conflict_original_id":"","master_key_id":"","user_data":"","deleted_time":1764365022745},"deleted":[]}
encryption_cipher_text: 
encryption_applied: 0
updated_time: 2025-11-28T21:24:52.633Z
created_time: 2025-11-28T21:24:52.633Z
type_: 13