admin 管理员组

文章数量: 887021

解决:

问题描述:

原代码如下:

import pandas as pdfrom statsmodels.tsa.stattools import adfullerimport torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as Ffrom blitz.modules import BayesianLSTM
from blitz.utils import variational_estimatorfrom sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegressionimport matplotlib.pyplot as plt
%matplotlib inlinefrom collections import dequeimport yfinance as yf
import numpy as npplt.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 pdfrom statsmodels.tsa.stattools import adfullerimport torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as Ffrom blitz.modules import BayesianLSTM
from blitz.utils import variational_estimatorfrom sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegressionimport matplotlib.pyplot as plt
%matplotlib inlinefrom collections import dequeimport yfinance as yf
import numpy as npplt.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

输出结果:


如果想要测试代码,自己可以按照上述字段来,这就是使用的格式了

本文标签: 解决