def __init__(acc: QA_Account): self.acc = acc self.risk = QA_Risk(acc) self.performance = QA_Performance(acc) print(acc)
def get(self): """ 采用了get_arguent来获取参数 默认参数: code-->000001 start-->2017-01-01 09:00:00 end-->now accounts?account_cookie=xxx """ account_cookie = self.get_argument('account_cookie', default='quantaxis') portfolio_cookie = self.get_argument('portfolio_cookie') user_cookie = self.get_argument('user_cookie') action = self.get_argument('action', 'query_history') acc = QA_Account(account_cookie=account_cookie, user_cookie=user_cookie, portfolio_cookie=portfolio_cookie, auto_reload=True) if action == 'query_history': self.write({ 'status': 200, 'frequence': acc.frequence, 'market': acc.market_type, 'result': acc.history }) elif action == 'query_performance': self.write({'res': 200, 'result': QA_Performance(acc).message}) elif action == 'query_risk': self.write({'res': 200, 'result': QA_Risk(acc).message})
def after_success(self): QA_util_log_info(self.account.history_table) # check if the history_table is empty list if len(self.account.history_table) == 0: # 没有交易历史记录,直接返回 return risk = QA_Risk(self.account, benchmark_code='000300', benchmark_type=MARKET_TYPE.INDEX_CN) print(risk().T) risk.plot_assets_curve() risk.plot_dailyhold() risk.plot_signal() performance = QA_Performance(self.account) performance.plot_pnlmoney(performance.pnl_fifo) performance.plot_pnlratio(performance.pnl_fifo) self.account.save() risk.save()
def after_success(self): QA_util_log_info(self.account.history_table) # check if the history_table is empty list if len(self.account.history_table) == 0: # 没有交易历史记录,直接返回 return risk = QA_Risk(self.account, benchmark_code='000300', benchmark_type=MARKET_TYPE.INDEX_CN) print(risk().T) risk.plot_assets_curve() risk.plot_dailyhold() risk.plot_signal() performance = QA_Performance(self.account) performance.plot_pnlmoney(performance.pnl_fifo) performance.plot_pnlratio(performance.pnl_fifo)