Example #1
0
    def get_min_stockQuotes(self, stockcode, period, *adjust):
        if stockcode[0:2] == '60' or stockcode[0:2] == '68':
            stockcode = 'sh' + stockcode
        else:
            stockcode = 'sz' + stockcode

        if adjust == None:
            stock_zh_a_minute_df = ak.stock_zh_a_minute(symbol=stockcode,
                                                        period=period,
                                                        adjust="qfq")
            return stock_zh_a_minute_df
        else:
            stock_zh_a_minute_df = ak.stock_zh_a_minute(symbol=stockcode,
                                                        period=period,
                                                        adjust=adjust)
            return stock_zh_a_minute_df
Example #2
0
 def download_ashare_minute_data(symbol):
     stock_zh_a_minute_df = ak.stock_zh_a_minute(symbol=symbol,
                                                 period='1',
                                                 adjust="hfq")
     print('type: {0}; data: {1};'.format(type(stock_zh_a_minute_df),
                                          stock_zh_a_minute_df))
     stock_zh_a_minute_df.to_csv('./data/{0}.csv'.format(symbol))
Example #3
0
    def get_minute_data_from_internet(self, code, name, period):
        '''获取数据并保存到csv'''
        while len(code) < 6:
            code = '0' + code

        if code.startswith('6'):
            code = "sh" + code
        if code.startswith('3') or code.startswith('0'):
            code = "sz" + code

        print(code)
        # 获取原始数据
        original_data = ak.stock_zh_a_minute(symbol=code,
                                             period=period,
                                             adjust="qfq")
        # 取过去50天数据
        try:
            df = original_data.reset_index().iloc[-200:, :6]
        except:
            df = original_data.reset_index().iloc[:, :6]
        # 去除空值且从零开始编号索引
        df = df.dropna(how='any').reset_index(drop=True)
        print(df)
        # 按日期排序
        df = df.sort_values(by='day', ascending=True)

        # 均线数据
        df['10'] = df.close.rolling(10).mean()
        df['150'] = df.close.rolling(150).mean()
        df['250'] = df.close.rolling(250).mean()

        # 写入csv
        file_name = self.data_path + name + ".csv"
        df.to_csv(file_name)
        print("<" + name + ">数据完成")

        return df
Example #4
0
# parser.add_argument("-s", "--stock", help="stock code", dest="target_stock", type=str, default="")
# args = parser.parse_args()

# daily_minutes = []
# am_minutes = pd.date_range(start = '09:31:00', end = '11:30:00', freq='min')
# for i in am_minutes:
#     daily_minutes.append(str(i)[-8:])
# pm_minutes = pd.date_range(start = '13:01:00', end = '15:00:00', freq='min')
# for i in pm_minutes:
#     daily_minutes.append(str(i)[-8:])

# print(daily_minutes)
# stock_zh_ah_daily_df = ak.stock_zh_index_daily(symbol=str(target_stock))

stock_zh_a_minute_df = ak.stock_zh_a_minute(symbol='sz300750',
                                            period='1',
                                            adjust="qfq")
# print(stock_zh_a_minute_df)

stock_zh_a_minute_df.to_csv('daily_details/' + 'sz300750.csv')

# dates = pd.date_range('1/1/2000', periods=8)
# print(dates)

# df = pd.DataFrame(np.random.randn(8, 4), index=dates, columns=['A', 'B', 'C', 'D'])
# print(df)
# if __name__ == "__main__":
#     if args.target_stock.startswith('6'):
#         target_stock = 'sh' + args.target_stock
#     else:
#         target_stock = 'sz' + args.target_stock
Example #5
0
def get_candle(inst):
    str_inst = str(inst)
    stock_zh_a_minute_df = ak.stock_zh_a_minute(symbol="sh" + str_inst, period='1', adjust="qfq")
    return stock_zh_a_minute_df
Example #6
0
 def run(self):
     stock_zh_a_minute_df = ak.stock_zh_a_minute(symbol='sz000876',
                                                 period='1',
                                                 adjust="qfq")
     print(stock_zh_a_minute_df)
Example #7
0
def get_data3():
    stock_zh_a_minute_df = ak.stock_zh_a_minute(symbol='sh000300', period='1')
    df = pd.DataFrame(stock_zh_a_minute_df)
    df.dropna()
    df.head()
    df.to_csv('thirdStock.csv')
Example #8
0
 def stock_zh_a_minute(self):
     stock_zh_a_minute_df = ak.stock_zh_a_minute(symbol='sh600751',
                                                 period='1',
                                                 adjust="qfq")
     return stock_zh_a_minute_df
Example #9
0
#                           collocations=False,
#                           font_path='simhei.ttf',
#                           icon_name='fas fa-heart',
#                           size=653,
#                           # palette='matplotlib.Inferno_9',
#                           output_name='./005827.png')
# Image(filename='./005827.png')

# 用更为量化的方法,计算出每个评论的情感评分
senta = hub.Module(name="senta_bilstm")
texts = df['标题'].tolist()
input_data = {'text': texts}
res = senta.sentiment_classify(data=input_data)
df['投资者情绪'] = [x['positive_probs'] for x in res]
# 重采样至15分钟
df['时间'] = pd.to_datetime(df['时间'])
df.index = df['时间']
data = df.resample('15min').mean().reset_index()

# 通过AkShare这一开源API接口获取上证指数分时数据,AkShare是基于Python的财经数据接口库,
# 可以实现对股票、期货、期权、基金、外汇、债券、指数、
# 数字货币等金融产品的基本面数据、历史行情数据的快速采集和清洗。
sz_index = ak.stock_zh_a_minute(symbol='sh000001', period='15', adjust="qfq")
sz_index['日期'] = pd.to_datetime(sz_index['day'])
sz_index['收盘价'] = sz_index['close'].astype('float')
data = data.merge(sz_index, left_on='时间', right_on='日期', how='inner')
plt.use('Qt5Agg')
data.index = data['时间']
data[['投资者情绪', '收盘价']].plot(secondary_y=['close'])
plt.show()
Example #10
0
 def load_ds(self):
     # 获取指定股票日内1分钟级数据
     stock_zh_a_minute_df = ak.stock_zh_a_minute(
         symbol=self.symbol, period=self.period
     )
     print(stock_zh_a_minute_df)