问题描述
我每天尝试根据股票价格创建方程,这是我的代码
你可以跳到最后 # 段,我认为这是问题
# Import
import yfinance as yf
import numpy as np
from collections import Counter
from datetime import date
# stock list
stock_list = ['EGCO.BK','KBANK.BK','KTB.BK','LH.BK','MINT.BK','TTW.BK']
# Get the data
data = yf.download(stock_list,'2010-01-01',str(date.today()))
# create x and y value ; x = date count,y = stock price
data.len = len(data)
x = list(range(1,data.len+1))
Adj_close = data['Adj Close']
#create list of stock price
y = Adj_close.T.values.tolist()
#find equation for each stock
from scipy.stats import linregress
from scipy import stats
equation = []
Slope = []
Intercept = []
for num in y :
equation.append(linregress(x,num))
#find slope and intercept for cal return
slope,intercept,r_value,p_value,std_err = stats.linregress(x,num)
Stat = (slope,std_err)
Slope.append(Stat[0])
Intercept.append(Stat[1])
print(equation)
当它打印slope的值时,截距,其余都是nan一样
/home/nitipong/.local/lib/python3.8/site-packages/scipy/stats/_distn_infrastructure.py:1932: RuntimeWarning: invalid value encountered in less_equal
cond2 = cond0 & (x <= _a)
[LinregressResult(slope=nan,intercept=nan,rvalue=nan,pvalue=nan,stderr=nan),LinregressResult(slope=nan,stderr=nan)]
但是当我将数据从日期 '2010-01-01'
调整为 '2020-01-01'
它打印没有nan的所有值
为什么会这样或者数据数量有限制?
但我尽量减少库存。好像有些库存有问题
样本(日期为 2010 年)
with stock A,B it return (ok value,ok value)
with stock A,C it return (ok value,nan)
with stock A,C it return (nan,nan)
有人能帮我解决这个困惑吗?
#python 3.8.5 版
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)