以下代碼正在從Quandl接收數據,並且工作正常。我的問題是我不知道如何從雅虎而不是Quandl檢索數據。有沒有人可以告訴我如何在Yahoo數據源中使用相同的代碼。它可以是任何儀器。最好的將是SPY etf。Python Yahoo數據Feed
import numpy as np
import pandas as pd
import quandl
import matplotlib.pyplot as plt
sp500_daily = quandl.get("CHRIS/CME_ES1",
start_date="2000-1-1",
end_date="2017-4-15")
sp500_daily.columns=['Open', 'High', 'Low', 'Close',
'Change', 'Settle', 'Volume',
'Open Interest']
multiplier = 50
# close[0] <= close[9] &&
# low[0] <= low[1] &&
# low[3] <= high[6] &&
# volume[0] <= volume[1]
signal = ((sp500_daily.Close <= sp500_daily.shift(9).Close) &
(sp500_daily.Low <= sp500_daily.shift(1).Low) &
(sp500_daily.shift(3).Low <= sp500_daily.shift(6).High) &
(sp500_daily.Volume <= sp500_daily.shift(1).Volume))
# hold time 1 day
profits = (signal * multiplier * (sp500_daily.shift(-1).Close -
sp500_daily.Close))
returns = (signal * (-1 + sp500_daily.shift(-1).Close/sp500_daily.Close))
profits.cumsum().plot()
plt.show()