def plot_performance(self): df_performance = jqdata.get_price('000300.XSHG', start_date=self.start_date, end_date=self.end_date) df_performance = df_performance[[ 'close' ]].rename(columns={'close': 'CSI 300'}) # convert to percentage df_performance = df_performance / df_performance['CSI 300'][0] * 100 # get performance of portfolio dates = df_performance.index portfolio_performance = [self.calculate_pl(date) for date in dates] df_performance['Small Cap'] = portfolio_performance # plot graph fig = go.Figure() fig.add_trace( go.Scatter(x=df_performance.index, y=df_performance['CSI 300'], mode='lines', name='CSI 300')) fig.add_trace( go.Scatter(x=df_performance.index, y=df_performance['Small Cap'], mode='lines', name='Small Cap')) fig.show()
def generate_performance(self): df_performance = jqdata.get_price('000300.XSHG', start_date=self.start_date, end_date=self.end_date) df_performance = df_performance[[ 'close' ]].rename(columns={'close': 'CSI 300'}) # convert to percentage df_performance = df_performance / df_performance['CSI 300'][0] * 100 # get performance of portfolio dates = df_performance.index portfolio_performance = [self.calculate_pl(date) for date in dates] df_performance['Small Cap'] = portfolio_performance # df_performance.to_csv('performance.csv', index_label='date') return df_performance
end_date = '{}-01-02'.format(year + 1) for asset in indexlist: print( asset, start_date, end_date, ) indexfile = os.path.join( index_path, u'{}_{}_{}.pickle'.format(asset, year, frequence)) if os.path.isfile(indexfile): print('文件已经存在,跳过 ', indexfile) continue try: print(indexfile) his = jqapi.get_price(asset, start_date, end_date, frequency='60m') export_metadata_to_pickle(index_path, u'{}_{}'.format(asset, year), metadata=his) #data_day = QA.QA_fetch_stock_min_adv(codelist, # start='2019-01-01', # end='2020-08-28', # frequence='60min') #his = data_day.data except Exception as e: print(asset, e) time.sleep(1) for year in range(2017, 2005, -1): start_date = '{}-01-01'.format(year)