{"id":1160337,"date":"2025-01-13T19:03:40","date_gmt":"2025-01-13T11:03:40","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1160337.html"},"modified":"2025-01-13T19:03:43","modified_gmt":"2025-01-13T11:03:43","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e7%bc%96%e5%86%99%e7%82%92%e8%82%a1%e8%bd%af%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1160337.html","title":{"rendered":"\u5982\u4f55\u7528Python\u7f16\u5199\u7092\u80a1\u8f6f\u4ef6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25201833\/9c71d971-1572-4987-9604-cf670144a5d8.webp\" alt=\"\u5982\u4f55\u7528Python\u7f16\u5199\u7092\u80a1\u8f6f\u4ef6\" \/><\/p>\n<p><p> <strong>\u7528Python\u7f16\u5199\u7092\u80a1\u8f6f\u4ef6\u7684\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\uff1a\u6570\u636e\u83b7\u53d6\u3001\u6570\u636e\u5904\u7406\u3001\u7b56\u7565\u7f16\u5199\u3001\u56de\u6d4b\u7cfb\u7edf\u3001\u4ea4\u6613\u63a5\u53e3\u3001\u7528\u6237\u754c\u9762\u3002<\/strong> \u5176\u4e2d\uff0c\u6570\u636e\u83b7\u53d6\u662f\u7092\u80a1\u8f6f\u4ef6\u7684\u57fa\u7840\uff0c\u4e3b\u8981\u662f\u901a\u8fc7\u8c03\u7528API\u4ece\u91d1\u878d\u6570\u636e\u63d0\u4f9b\u5546\u5904\u83b7\u53d6\u5b9e\u65f6\u548c\u5386\u53f2\u6570\u636e\u3002\u63a5\u4e0b\u6765\u8be6\u7ec6\u63cf\u8ff0\u4e00\u4e0b\u6570\u636e\u83b7\u53d6\u7684\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><p>\u6570\u636e\u83b7\u53d6\u662f\u6574\u4e2a\u7092\u80a1\u8f6f\u4ef6\u7684\u57fa\u7840\u3002Python\u4e2d\u6709\u591a\u4e2a\u5e93\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u83b7\u53d6\u80a1\u7968\u6570\u636e\uff0c\u4f8b\u5982<code>yfinance<\/code>\u3001<code>alpha_vantage<\/code>\u3001<code>pandas_datareader<\/code>\u7b49\u3002\u4ee5<code>yfinance<\/code>\u4e3a\u4f8b\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u83b7\u53d6\u80a1\u7968\u6570\u636e\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u5b89\u88c5<code>yfinance<\/code>\u5e93\uff1a\u53ef\u4ee5\u901a\u8fc7pip\u547d\u4ee4\u5b89\u88c5<code>yfinance<\/code>\u5e93\u3002<\/p>\n<\/p>\n<p><pre><code>pip install yfinance<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u5bfc\u5165\u5e76\u4f7f\u7528<code>yfinance<\/code>\u5e93\u83b7\u53d6\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import yfinance as yf<\/p>\n<h2><strong>\u83b7\u53d6\u7279\u5b9a\u80a1\u7968\u7684\u5386\u53f2\u6570\u636e<\/strong><\/h2>\n<p>ticker = &#39;AAPL&#39;<\/p>\n<p>data = yf.download(ticker, start=&#39;2020-01-01&#39;, end=&#39;2021-01-01&#39;)<\/p>\n<p>print(data.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u83b7\u53d6\u82f9\u679c\u516c\u53f8\u57282020\u5e74\u4e00\u5e74\u7684\u5386\u53f2\u80a1\u7968\u6570\u636e\u3002\u63a5\u4e0b\u6765\uff0c\u53ef\u4ee5\u5bf9\u6570\u636e\u8fdb\u884c\u5904\u7406\u548c\u5206\u6790\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u6570\u636e\u83b7\u53d6<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528yfinance\u5e93\u83b7\u53d6\u6570\u636e<\/strong><\/p>\n<\/p>\n<p><p><code>yfinance<\/code>\u5e93\u662f\u4e00\u4e2a\u975e\u5e38\u65b9\u4fbf\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u83b7\u53d6\u5404\u79cd\u80a1\u7968\u7684\u5386\u53f2\u6570\u636e\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u7684\u4ee3\u7801\u5b9e\u73b0\u6570\u636e\u4e0b\u8f7d\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import yfinance as yf<\/p>\n<h2><strong>\u4e0b\u8f7d\u7279\u5b9a\u80a1\u7968\u7684\u6570\u636e<\/strong><\/h2>\n<p>ticker = yf.Ticker(&#39;AAPL&#39;)<\/p>\n<h2><strong>\u83b7\u53d6\u5386\u53f2\u5e02\u573a\u6570\u636e<\/strong><\/h2>\n<p>hist = ticker.history(period=&quot;1y&quot;)<\/p>\n<p>print(hist.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528alpha_vantage\u5e93\u83b7\u53d6\u6570\u636e<\/strong><\/p>\n<\/p>\n<p><p><code>alpha_vantage<\/code>\u5e93\u4e5f\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u91d1\u878d\u6570\u636e\u3002\u4f7f\u7528\u8be5\u5e93\u9700\u8981\u5148\u6ce8\u518c\u4e00\u4e2aAPI key\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from alpha_vantage.timeseries import TimeSeries<\/p>\n<h2><strong>\u8bbe\u7f6eAPI key<\/strong><\/h2>\n<p>api_key = &#39;your_api_key&#39;<\/p>\n<p>ts = TimeSeries(key=api_key, output_format=&#39;pandas&#39;)<\/p>\n<p>data, meta_data = ts.get_intraday(symbol=&#39;AAPL&#39;,interval=&#39;1min&#39;, outputsize=&#39;full&#39;)<\/p>\n<p>print(data.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528pandas_datareader\u5e93\u83b7\u53d6\u6570\u636e<\/strong><\/p>\n<\/p>\n<p><p><code>pandas_datareader<\/code>\u5e93\u4e5f\u662f\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684\u9009\u62e9\uff0c\u53ef\u4ee5\u83b7\u53d6\u5404\u79cd\u91d1\u878d\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas_datareader.data as web<\/p>\n<p>from datetime import datetime<\/p>\n<p>start = datetime(2020, 1, 1)<\/p>\n<p>end = datetime(2021, 1, 1)<\/p>\n<h2><strong>\u83b7\u53d6\u82f9\u679c\u516c\u53f8\u80a1\u7968\u6570\u636e<\/strong><\/h2>\n<p>df = web.DataReader(&#39;AAPL&#39;, &#39;yahoo&#39;, start, end)<\/p>\n<p>print(df.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u6570\u636e\u5904\u7406<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6570\u636e\u6e05\u6d17<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u83b7\u53d6\u6570\u636e\u540e\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u548c\u5904\u7406\uff0c\u4f8b\u5982\u5904\u7406\u7f3a\u5931\u503c\u3001\u8c03\u6574\u6570\u636e\u683c\u5f0f\u7b49\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5904\u7406\u7f3a\u5931\u503c<\/p>\n<p>data = data.dropna()<\/p>\n<h2><strong>\u8c03\u6574\u6570\u636e\u683c\u5f0f<\/strong><\/h2>\n<p>data[&#39;Date&#39;] = pd.to_datetime(data.index)<\/p>\n<p>data.set_index(&#39;Date&#39;, inplace=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u8f6c\u6362<\/strong><\/p>\n<\/p>\n<p><p>\u6709\u65f6\u6211\u4eec\u9700\u8981\u5c06\u6570\u636e\u8f6c\u6362\u4e3a\u7279\u5b9a\u7684\u683c\u5f0f\uff0c\u4ee5\u4fbf\u8fdb\u884c\u540e\u7eed\u5206\u6790\u548c\u5904\u7406\u3002\u4f8b\u5982\uff0c\u5c06\u6570\u636e\u8f6c\u6362\u4e3anumpy\u6570\u7ec4\u6216\u8005pandas dataframe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u5c06\u6570\u636e\u8f6c\u6362\u4e3anumpy\u6570\u7ec4<\/strong><\/h2>\n<p>data_np = data.to_numpy()<\/p>\n<h2><strong>\u5c06\u6570\u636e\u8f6c\u6362\u4e3apandas dataframe<\/strong><\/h2>\n<p>data_df = pd.DataFrame(data_np, columns=[&#39;Open&#39;, &#39;High&#39;, &#39;Low&#39;, &#39;Close&#39;, &#39;Volume&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u7b56\u7565\u7f16\u5199<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5747\u7ebf\u7b56\u7565<\/strong><\/p>\n<\/p>\n<p><p>\u5747\u7ebf\u7b56\u7565\u662f\u6700\u57fa\u7840\u7684\u6280\u672f\u5206\u6790\u7b56\u7565\u4e4b\u4e00\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8ba1\u7b97\u79fb\u52a8\u5e73\u5747\u7ebf\u6765\u5224\u65ad\u4e70\u5356\u65f6\u673a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u77ed\u671f\u548c\u957f\u671f\u79fb\u52a8\u5e73\u5747\u7ebf<\/p>\n<p>data[&#39;SMA50&#39;] = data[&#39;Close&#39;].rolling(window=50).mean()<\/p>\n<p>data[&#39;SMA200&#39;] = data[&#39;Close&#39;].rolling(window=200).mean()<\/p>\n<h2><strong>\u7b56\u7565\u6761\u4ef6<\/strong><\/h2>\n<p>buy_signal = (data[&#39;SMA50&#39;] &gt; data[&#39;SMA200&#39;])<\/p>\n<p>sell_signal = (data[&#39;SMA50&#39;] &lt; data[&#39;SMA200&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u52a8\u91cf\u7b56\u7565<\/strong><\/p>\n<\/p>\n<p><p>\u52a8\u91cf\u7b56\u7565\u662f\u901a\u8fc7\u5224\u65ad\u80a1\u7968\u4ef7\u683c\u7684\u4e0a\u6da8\u6216\u4e0b\u8dcc\u8d8b\u52bf\u6765\u505a\u51fa\u4e70\u5356\u51b3\u7b56\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u80a1\u7968\u4ef7\u683c\u7684\u53d8\u5316<\/p>\n<p>data[&#39;Momentum&#39;] = data[&#39;Close&#39;] - data[&#39;Close&#39;].shift(1)<\/p>\n<h2><strong>\u7b56\u7565\u6761\u4ef6<\/strong><\/h2>\n<p>buy_signal = (data[&#39;Momentum&#39;] &gt; 0)<\/p>\n<p>sell_signal = (data[&#39;Momentum&#39;] &lt; 0)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u56de\u6d4b\u7cfb\u7edf<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u56de\u6d4b\u6846\u67b6<\/strong><\/p>\n<\/p>\n<p><p>\u56de\u6d4b\u662f\u9a8c\u8bc1\u7b56\u7565\u6709\u6548\u6027\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>backtrader<\/code>\u5e93\u6765\u6784\u5efa\u56de\u6d4b\u6846\u67b6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import backtrader as bt<\/p>\n<p>class MyStrategy(bt.Strategy):<\/p>\n<p>    def __init__(self):<\/p>\n<p>        self.sma50 = bt.indicators.SimpleMovingAverage(self.data.close, period=50)<\/p>\n<p>        self.sma200 = bt.indicators.SimpleMovingAverage(self.data.close, period=200)<\/p>\n<p>    def next(self):<\/p>\n<p>        if self.sma50 &gt; self.sma200:<\/p>\n<p>            self.buy()<\/p>\n<p>        elif self.sma50 &lt; self.sma200:<\/p>\n<p>            self.sell()<\/p>\n<h2><strong>\u521b\u5efa\u56de\u6d4b\u5f15\u64ce<\/strong><\/h2>\n<p>cerebro = bt.Cerebro()<\/p>\n<h2><strong>\u6dfb\u52a0\u7b56\u7565<\/strong><\/h2>\n<p>cerebro.addstrategy(MyStrategy)<\/p>\n<h2><strong>\u52a0\u8f7d\u6570\u636e<\/strong><\/h2>\n<p>data = bt.feeds.PandasData(dataname=df)<\/p>\n<p>cerebro.adddata(data)<\/p>\n<h2><strong>\u8fd0\u884c\u56de\u6d4b<\/strong><\/h2>\n<p>cerebro.run()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7b56\u7565\u8bc4\u4f30<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u56de\u6d4b\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u7b56\u7565\u8fdb\u884c\u8bc4\u4f30\uff0c\u4ee5\u5224\u65ad\u7b56\u7565\u7684\u6709\u6548\u6027\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6253\u5370\u7b56\u7565\u7684\u56de\u6d4b\u7ed3\u679c<\/p>\n<p>print(&#39;Final Portfolio Value: %.2f&#39; % cerebro.broker.getvalue())<\/p>\n<h2><strong>\u7ed8\u5236\u7b56\u7565\u7684\u56de\u6d4b\u66f2\u7ebf<\/strong><\/h2>\n<p>cerebro.plot()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u4ea4\u6613\u63a5\u53e3<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u8c03\u7528\u4ea4\u6613API<\/strong><\/p>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528\u4ea4\u6613\u5e73\u53f0\u7684API\u63a5\u53e3\uff0c\u5b9e\u73b0\u81ea\u52a8\u4ea4\u6613\u3002\u4ee5<code>alpaca<\/code>\u4ea4\u6613\u5e73\u53f0\u4e3a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import alpaca_trade_api as tradeapi<\/p>\n<h2><strong>\u8bbe\u7f6eAPI key\u548csecret<\/strong><\/h2>\n<p>api = tradeapi.REST(&#39;your_api_key&#39;, &#39;your_api_secret&#39;, base_url=&#39;https:\/\/paper-api.alpaca.markets&#39;)<\/p>\n<h2><strong>\u521b\u5efa\u8ba2\u5355<\/strong><\/h2>\n<p>order = api.submit_order(<\/p>\n<p>    symbol=&#39;AAPL&#39;,<\/p>\n<p>    qty=1,<\/p>\n<p>    side=&#39;buy&#39;,<\/p>\n<p>    type=&#39;market&#39;,<\/p>\n<p>    time_in_force=&#39;gtc&#39;<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4ea4\u6613\u4fe1\u53f7<\/strong><\/p>\n<\/p>\n<p><p>\u6839\u636e\u7b56\u7565\u751f\u6210\u7684\u4e70\u5356\u4fe1\u53f7\uff0c\u81ea\u52a8\u6267\u884c\u4ea4\u6613\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if buy_signal:<\/p>\n<p>    api.submit_order(symbol=&#39;AAPL&#39;, qty=1, side=&#39;buy&#39;, type=&#39;market&#39;, time_in_force=&#39;gtc&#39;)<\/p>\n<p>elif sell_signal:<\/p>\n<p>    api.submit_order(symbol=&#39;AAPL&#39;, qty=1, side=&#39;sell&#39;, type=&#39;market&#39;, time_in_force=&#39;gtc&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u7528\u6237\u754c\u9762<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528Dash\u6784\u5efa\u7528\u6237\u754c\u9762<\/strong><\/p>\n<\/p>\n<p><p><code>Dash<\/code>\u662f\u4e00\u4e2a\u7528Python\u7f16\u5199\u7684\u5f00\u6e90Web\u5e94\u7528\u6846\u67b6\uff0c\u53ef\u4ee5\u7528\u6765\u6784\u5efa\u6570\u636e\u53ef\u89c6\u5316\u7528\u6237\u754c\u9762\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import dash<\/p>\n<p>import dash_core_components as dcc<\/p>\n<p>import dash_html_components as html<\/p>\n<p>from dash.dependencies import Input, Output<\/p>\n<p>app = dash.Dash(__name__)<\/p>\n<p>app.layout = html.Div([<\/p>\n<p>    dcc.Graph(id=&#39;price-chart&#39;),<\/p>\n<p>    dcc.Interval(id=&#39;interval-component&#39;, interval=1*60000, n_intervals=0)<\/p>\n<p>])<\/p>\n<p>@app.callback(Output(&#39;price-chart&#39;, &#39;figure&#39;), [Input(&#39;interval-component&#39;, &#39;n_intervals&#39;)])<\/p>\n<p>def update_chart(n):<\/p>\n<p>    data = yf.download(&#39;AAPL&#39;, period=&#39;1d&#39;, interval=&#39;1m&#39;)<\/p>\n<p>    fig = {<\/p>\n<p>        &#39;data&#39;: [{&#39;x&#39;: data.index, &#39;y&#39;: data[&#39;Close&#39;], &#39;type&#39;: &#39;line&#39;, &#39;name&#39;: &#39;AAPL&#39;}],<\/p>\n<p>        &#39;layout&#39;: {&#39;title&#39;: &#39;Stock Price&#39;}<\/p>\n<p>    }<\/p>\n<p>    return fig<\/p>\n<p>if __name__ == &#39;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&#39;:<\/p>\n<p>    app.run_server(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528Tkinter\u6784\u5efa\u684c\u9762\u5e94\u7528<\/strong><\/p>\n<\/p>\n<p><p><code>Tkinter<\/code>\u662fPython\u7684\u6807\u51c6GUI\u5e93\uff0c\u53ef\u4ee5\u7528\u6765\u6784\u5efa\u684c\u9762\u5e94\u7528\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tkinter as tk<\/p>\n<p>from tkinter import ttk<\/p>\n<p>import yfinance as yf<\/p>\n<p>class StockApp:<\/p>\n<p>    def __init__(self, root):<\/p>\n<p>        self.root = root<\/p>\n<p>        self.root.title(&quot;Stock App&quot;)<\/p>\n<p>        self.ticker_label = ttk.Label(root, text=&quot;Ticker:&quot;)<\/p>\n<p>        self.ticker_label.grid(row=0, column=0)<\/p>\n<p>        self.ticker_entry = ttk.Entry(root)<\/p>\n<p>        self.ticker_entry.grid(row=0, column=1)<\/p>\n<p>        self.get_data_button = ttk.Button(root, text=&quot;Get Data&quot;, command=self.get_data)<\/p>\n<p>        self.get_data_button.grid(row=0, column=2)<\/p>\n<p>        self.text = tk.Text(root)<\/p>\n<p>        self.text.grid(row=1, column=0, columnspan=3)<\/p>\n<p>    def get_data(self):<\/p>\n<p>        ticker = self.ticker_entry.get()<\/p>\n<p>        data = yf.download(ticker, period=&#39;1d&#39;, interval=&#39;1m&#39;)<\/p>\n<p>        self.text.delete(1.0, tk.END)<\/p>\n<p>        self.text.insert(tk.END, str(data))<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    root = tk.Tk()<\/p>\n<p>    app = StockApp(root)<\/p>\n<p>    root.mainloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u603b\u7ed3\u4e00\u4e0b\uff0c<strong>\u7f16\u5199\u7092\u80a1\u8f6f\u4ef6\u7684\u5173\u952e\u6b65\u9aa4\u5305\u62ec\u6570\u636e\u83b7\u53d6\u3001\u6570\u636e\u5904\u7406\u3001\u7b56\u7565\u7f16\u5199\u3001\u56de\u6d4b\u7cfb\u7edf\u3001\u4ea4\u6613\u63a5\u53e3\u548c\u7528\u6237\u754c\u9762<\/strong>\u3002\u6bcf\u4e2a\u6b65\u9aa4\u90fd\u6709\u591a\u4e2a\u5b9e\u73b0\u65b9\u6cd5\u548c\u5de5\u5177\uff0c\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u548c\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u9ad8\u6548\u5730\u5b8c\u6210\u4efb\u52a1\u3002\u5e0c\u671b\u4ee5\u4e0a\u5185\u5bb9\u80fd\u4e3a\u4f60\u63d0\u4f9b\u4e00\u5b9a\u7684\u5e2e\u52a9\u548c\u53c2\u8003\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5f00\u59cb\u4f7f\u7528Python\u7f16\u5199\u7092\u80a1\u8f6f\u4ef6\uff1f<\/strong><br \/>\u8981\u5f00\u59cb\u4f7f\u7528Python\u7f16\u5199\u7092\u80a1\u8f6f\u4ef6\uff0c\u9996\u5148\u9700\u8981\u5177\u5907Python\u7f16\u7a0b\u7684\u57fa\u7840\u77e5\u8bc6\u3002\u53ef\u4ee5\u901a\u8fc7\u5b66\u4e60\u76f8\u5173\u7684\u7f16\u7a0b\u8bfe\u7a0b\u6216\u4e66\u7c4d\u6765\u63d0\u5347\u6280\u80fd\u3002\u6b64\u5916\uff0c\u4e86\u89e3\u91d1\u878d\u5e02\u573a\u7684\u57fa\u672c\u6982\u5ff5\u548c\u80a1\u7968\u4ea4\u6613\u7684\u76f8\u5173\u89c4\u5219\u4e5f\u975e\u5e38\u91cd\u8981\u3002\u9009\u62e9\u5408\u9002\u7684\u5f00\u53d1\u73af\u5883\uff0c\u5982Jupyter Notebook\u6216PyCharm\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7ba1\u7406\u4ee3\u7801\u548c\u6570\u636e\u3002<\/p>\n<p><strong>\u5728\u7092\u80a1\u8f6f\u4ef6\u4e2d\u5982\u4f55\u5904\u7406\u5b9e\u65f6\u6570\u636e\uff1f<\/strong><br \/>\u5904\u7406\u5b9e\u65f6\u6570\u636e\u662f\u7092\u80a1\u8f6f\u4ef6\u4e2d\u975e\u5e38\u5173\u952e\u7684\u4e00\u90e8\u5206\u3002\u53ef\u4ee5\u4f7f\u7528API\u4ece\u91d1\u878d\u6570\u636e\u63d0\u4f9b\u5546\u83b7\u53d6\u5b9e\u65f6\u80a1\u7968\u6570\u636e\u3002\u4f8b\u5982\uff0cAlpha Vantage\u3001Yahoo Finance\u6216IEX Cloud\u7b49API\u90fd\u53ef\u4ee5\u63d0\u4f9b\u4e30\u5bcc\u7684\u5e02\u573a\u6570\u636e\u3002\u5728\u83b7\u53d6\u6570\u636e\u540e\uff0c\u5229\u7528Python\u7684pandas\u5e93\u8fdb\u884c\u6570\u636e\u5904\u7406\u548c\u5206\u6790\uff0c\u4ee5\u4fbf\u53ca\u65f6\u505a\u51fa\u4ea4\u6613\u51b3\u7b56\u3002<\/p>\n<p><strong>\u5982\u4f55\u5b9e\u73b0\u7092\u80a1\u7b56\u7565\u7684\u56de\u6d4b\u529f\u80fd\uff1f<\/strong><br \/>\u56de\u6d4b\u529f\u80fd\u662f\u9a8c\u8bc1\u7092\u80a1\u7b56\u7565\u6709\u6548\u6027\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u53ef\u4ee5\u4f7f\u7528Python\u4e2d\u7684\u56de\u6d4b\u6846\u67b6\uff0c\u5982Backtrader\u6216Zipline\uff0c\u8fd9\u4e9b\u6846\u67b6\u63d0\u4f9b\u4e86\u7b80\u5355\u7684\u63a5\u53e3\u6765\u6a21\u62df\u5386\u53f2\u4ea4\u6613\u3002\u901a\u8fc7\u5c06\u7b56\u7565\u5e94\u7528\u4e8e\u5386\u53f2\u6570\u636e\uff0c\u89c2\u5bdf\u5176\u8868\u73b0\uff0c\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u7406\u89e3\u7b56\u7565\u7684\u6f5c\u5728\u6536\u76ca\u4e0e\u98ce\u9669\uff0c\u4ece\u800c\u505a\u51fa\u66f4\u52a0\u7406\u667a\u7684\u6295\u8d44\u51b3\u7b56\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u7528Python\u7f16\u5199\u7092\u80a1\u8f6f\u4ef6\u7684\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\uff1a\u6570\u636e\u83b7\u53d6\u3001\u6570\u636e\u5904\u7406\u3001\u7b56\u7565\u7f16\u5199\u3001\u56de\u6d4b\u7cfb\u7edf\u3001\u4ea4\u6613\u63a5\u53e3\u3001\u7528\u6237\u754c\u9762\u3002 \u5176\u4e2d\uff0c [&hellip;]","protected":false},"author":3,"featured_media":1160346,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1160337"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1160337"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1160337\/revisions"}],"predecessor-version":[{"id":1160347,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1160337\/revisions\/1160347"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1160346"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1160337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1160337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1160337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}