def calRealtimeRank(stk_code, M_days, history_data_dir): """ 计算一只stk的离心度名次, 需要保存历史数据,操作复杂,尽量不要用! :param stk_code: :param M_days: :param history_data_dir: './M_data/' :return: 分数,9日数据, 当前price """ # 加载数据测试 dict = shelveL( loadLocation=history_data_dir, fileName=stk_code+'_M'+str(M_days)) if stk_code not in ['sh', 'sz', 'cyb']: try: current_price = get_RT_price(stk_code, source='ts') except: current_price = get_RT_price(stk_code, source='jq') else: current_price = get_RT_price(stk_code, source='jq') # 计算实时偏离度 list_history = dict['latest_data'] list_history.append(current_price) M_diff = (current_price - np.mean(list_history))/current_price # 计算排名 return relativeRank(dict['history_M_diverge_data'], M_diff), list_history, current_price, dict['update_date']
def loadLastScale(list_name): """ :param list_name: :return: """ return shelveL(LastScale, list_name)
# encoding=utf-8 from History.Debug_Sub import debug_print_txt from History.Sub import judge_single_stk_sub from SDK.MyTimeOPT import add_date_str from SDK.shelfSub import shelveP, shelveL from pylab import * if __name__ == '__main__': stk_code = '000001' df = shelveL('./temp_data/', stk_code + 'huice_m') df_day = shelveL('./temp_data/', stk_code + 'huice_day') """ df = df.dropna().reset_index() df.plot('index', ['close', 'rsv', 'reseau'], style=['*', '*', '*'], subplots=True) """ df = df.dropna() last_p = df.head(1)['open'].values[0] for idx in df.index: datetime = df.loc[idx, 'datetime'] # 获取昨天sar_diff idx_yesterday = df_day[df_day.datetime < datetime].tail(1).index[0] sar_diff_day = (df_day.loc[idx_yesterday, 'SAR'] - df_day.loc[idx_yesterday, 'close']) # rsv = df.loc[idx, 'rsv'] # reseau = df.loc[idx, 'reseau']
# encoding=utf-8
from RelativeRank.Sub import relativeRank from SDK.MyTimeOPT import get_current_date_str from SDK.shelfSub import shelveL # from JQData_Test.auth_info import * from pylab import * import tushare as ts import numpy as np import pandas as pd import jqdatasdk as jq history_data_dir = SeaSelectDataPWD+'/stk_list_data/' stk_code = '600487' dict = shelveL( loadLocation=history_data_dir, fileName=stk_code + '_M' + str(9)) try: # 获取实时价格 current_price = float(ts.get_realtime_quotes(stk_code)['price'].values[0]) except: # 使用聚宽数据接口替代 if stk_code in ['sh', 'sz', 'cyb']: stk_code_normal = { 'sh': '000001.XSHG', 'sz': '399001.XSHE', 'cyb': '399006.XSHE' }[stk_code]