文件" SCTR.py",第53行,in ppoHist = ta.PPO(StockData ['最后&#39],12,26) TypeError:Argument' real'有不正确的类型(预期numpy.ndarray,得到系列)
请检查此代码,上面提到的错误在编译后反映出来。我现在完全无能为力。
from nsepy import get_history
from datetime import date
import pandas as pd
import requests
from io import BytesIO
import certifi
from dateutil.relativedelta import relativedelta
#import numpy as np
#import matplotlib.pyplot as plt
import datetime
import numpy as np
import matplotlib.colors as colors
import matplotlib.finance as finance
import matplotlib.dates as mdates
import matplotlib.ticker as mticker
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
import talib as ta
from talib import MA_Type
url1 = 'https://www1.nseindia.com/content/indices/ind_nifty_Alpha_Index.csv'
def datainpy(url):
headers = { 'Accept' : '*/*',
'User-Agent' : 'Mozilla/5.0',
'Refers' : 'http://www.nseindia.com',
'Connection' : 'keep-alive'
}
getContents = requests.get(url,headers=headers).content
symbol_list=pd.read_csv(BytesIO(getContents))
print(symbol_list.head())
for eachSymbol in symbol_list['Symbol'][1:8]:
stock = get_history(symbol = eachSymbol,
start = date(2016,3,20),
end = date(2016,3,30))
stock.drop_duplicates(inplace=True)
stock.drop(stock.columns[[0,1,2,7,8,10,11,12,13]], axis = 1, inplace = True)
print (stock.head())
print(stock.head())
stock.index=pd.to_datetime(stock.index)
#stock.to_csv('./HistoricalData//' + eachSymbol + '.csv' , date_format='%Y%m%d')
return stock;
StockData=datainpy(url=url1)
print(StockData.head())
type(StockData)
ppoHist=ta.PPO(StockData['Last'],12,26)
print(ppoHist.head())
我基本上想要生成SCTR(股票图表技术等级)即。 PPO,DMA(200),RSI等在一个csv中用于' eachSymbol'。
答案 0 :(得分:0)
看起来你正在将一个pandas ta.PPO
对象传递给ppoHist = ta.PPO(StockData['Last'].values, 12, 26)
,但它需要一个numpy数组。尝试
talib
(免责声明:我自己没有尝试过。我没有安装Time
,我也无法回答任何问题。)
答案 1 :(得分:0)
from nsepy import get_history
from datetime import date
import pandas as pd
import requests
from io import BytesIO
import certifi
from dateutil.relativedelta import relativedelta
#import numpy as np
#import matplotlib.pyplot as plt
import datetime
import numpy as np
import matplotlib.colors as colors
import matplotlib.finance as finance
import matplotlib.dates as mdates
import matplotlib.ticker as mticker
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
import talib as ta
from talib import MA_Type
#Long-Term Indicators (weighting)
# * Percent above/below 200-day EMA (30%)
# * 125-Day Rate-of-Change (30%)
#Medium-Term Indicators (weighting)
# * Percent above/below 50-day EMA (15%)
# * 20-day Rate-of-Change (15%)
# Short-Term Indicators (weighting)
# * 3-day slope of PPO-Histogram (5%)
# * 14-day RSI (5%)
url1 = 'https://www1.nseindia.com/content/indices/ind_nifty_Alpha_Index.csv'
def datainpy(url):
headers = { 'Accept' : '*/*',
'User-Agent' : 'Mozilla/5.0',
'Refers' : 'http://www.nseindia.com',
'Connection' : 'keep-alive'
}
getContents = requests.get(url,headers=headers).content
symbol_list=pd.read_csv(BytesIO(getContents))
print(symbol_list.head())
for eachSymbol in symbol_list['Symbol']:
stock = get_history(symbol = eachSymbol,
start = date(2000,3,20),
end = date(2016,3,30))
stock.drop_duplicates(inplace=True)
stock.drop(stock.columns[[0,1,2,7,8,10,11,12,13]], axis = 1, inplace = True)
print (stock.head())
print(stock.head())
stock.index=pd.to_datetime(stock.index)
#stock.to_csv('./HistoricalData//' + eachSymbol + '.csv' , date_format='%Y%m%d')
return stock;
StockData=datainpy(url=url1)
print(StockData.head())
type(StockData)
np.set_printoptions(precision=3)
ppoHist=ta.PPO(StockData['Last'].values,12,26)
RSI14=ta.RSI(StockData['Last'].values,14)
DMA200=ta.SMA(StockData['Last'].values,200)
EMA50=ta.EMA(StockData['Last'].values,14)
ROC125=ta.ROC(StockData['Last'].values,125)
ROC20=ta.ROC(StockData['Last'].values,14)
weightPctDiffOfEMA50=(((StockData['Last'].values-EMA50)*100)/StockData['Last'].values)*15
weightPctDiffOfDMA200=(((StockData['Last'].values-DMA200)*100)/StockData['Last'].values)*30
weightROC125=ROC125*30
weightROC20=ROC20*15
weightRSI14=RSI14*5
weightppoHist=ppoHist*5
print(weightppoHist)
SCTR=(weightPctDiffOfDMA200+weightPctDiffOfEMA50+weightROC125+weightROC20+weightppoHist+weightRSI14)/100
print(SCTR)
我对输出有点困惑,但这是将在这里提到的。 SCTR(Stock Chart Technical)。请提供更好的解决方案。