解决:- SPY: No data found for this date range, symbol may be delisted报错

问题描述:

原代码如下:

import pandas as pd

from statsmodels.tsa.stattools import adfuller

import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F

from blitz.modules import BayesianLSTM
from blitz.utils import variational_estimator

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression

import matplotlib.pyplot as plt
%matplotlib inline

from collections import deque

import yfinance as yf
import numpy as np

plt.rcParams.update({'figure.figsize':(20,10)})
plt.rcParams.update({'font.size':20})
ticker = "SPY" 
ticker_y = yf.Ticker("SPY")
df = ticker_y.history(period="5y")

然后出现报错:- SPY: No data found for this date range, symbol may be delisted

- SPY: No data found for this date range, symbol may be delisted

解决方案:

其实原因就在于这里使用的为Yahoo财经数据(从import yfinance as yf就可以证明这是Yahoo财经数据),但是由于现在使用Python访问不了那个网站了,所以可以自行寻找该网站的数据。使用read_csv等函数进行引用。
因此,解决方案为:

import pandas as pd

from statsmodels.tsa.stattools import adfuller

import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F

from blitz.modules import BayesianLSTM
from blitz.utils import variational_estimator

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression

import matplotlib.pyplot as plt
%matplotlib inline

from collections import deque

import yfinance as yf
import numpy as np

plt.rcParams.update({'figure.figsize':(20,10)})
plt.rcParams.update({'font.size':20})
df_non_stat = pd.read_csv("stock_train.csv", index_col = 0, parse_dates=[0])
df_non_stat

输出结果:

解决:- SPY: No data found for this date range, symbol may be delisted报错_第1张图片
如果想要测试代码,自己可以按照上述字段来,这就是使用的格式了

你可能感兴趣的:(python,机器学习,深度学习)