def get_kospi_kosdaq(self, market): invest_start_date = self.params.invest_start_date invest_end_date = self.params.invest_end_date corp = Corp(self.params) if market == 'KOSPI': data = corp.get_kospi() elif market == 'KOSDAQ': data = corp.get_kosdaq() else: data = pd.DataFrame() return data.query("date>='{}' & date<='{}'".format(invest_start_date, invest_end_date))
def draw_invest_seaborn(self, pridects_data:pd.DataFrame, dir:str, title:str, start:str=None, end:str=None)->None: file_path = self.get_file_path(dir, title, 'png', start, end) pridects_data = pridects_data.copy() pridects_data['date'] = pd.to_datetime(pridects_data['date'], format='%Y.%m.%d') pridects_data.set_index('date', inplace=True) plt = self.main.get_plt() fig, ax = plt.subplots(figsize=self.main.FIG_SIZE) sns.lineplot(data=pridects_data).set_title(title) ax.xaxis.set_major_locator(mdates.AutoDateLocator()) ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y.%m.%d')) ax.set(xlabel='Date', ylabel='Margin(%)') #fig.autofmt_xdate() plt.grid(color='k', linestyle='dotted', linewidth=1, alpha=0.4) fig.savefig(file_path) plt.close() def save_csv(self, df_rmses, dir, corp_name, start=None, end=None)->None: """차트 테이터를 저장한다.""" file_path = self.get_file_path(dir, corp_name, "csv", start, end) DataUtils.save_csv(df_rmses, file_path) if __name__ == '__main__': params = GlobalParams() corp = Corp(params) kospi = corp.get_kospi() kospi = kospi.query("date>='{}' & date<='{}'".format(params.invest_start_date, params.invest_end_date)) print(kospi[0:1]['close'].values[0])