Skip to content

Commit

Permalink
修改生成report的文件名、字段名
Browse files Browse the repository at this point in the history
  • Loading branch information
武晨宇 authored and wh1100717 committed May 8, 2017
1 parent 88935b9 commit f6e4c24
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
28 changes: 11 additions & 17 deletions rqalpha/mod/rqalpha_mod_sys_analyser/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,9 @@ def _to_portfolio_record(self, date, portfolio):
return {
'date': date,
'cash': self._safe_convert(portfolio.cash),
'total_returns': self._safe_convert(portfolio.total_returns),
'daily_returns': self._safe_convert(portfolio.daily_returns),
'daily_pnl': self._safe_convert(portfolio.daily_pnl),
'total_value': self._safe_convert(portfolio.total_value),
'market_value': self._safe_convert(portfolio.market_value),
'annualized_returns': self._safe_convert(portfolio.annualized_returns),
'unit_net_value': self._safe_convert(portfolio.unit_net_value),
'unit_net_value': self._safe_convert(portfolio.unit_net_value, 6),
'units': portfolio.units,
'static_unit_net_value': self._safe_convert(portfolio.static_unit_net_value),
}
Expand All @@ -117,7 +113,7 @@ def _to_portfolio_record(self, date, portfolio):
def _to_account_record(self, date, account):
data = {
'date': date,
'total_cash': self._safe_convert(account.cash + account.frozen_cash),
'cash': self._safe_convert(account.cash),
'transaction_cost': self._safe_convert(account.transaction_cost),
'market_value': self._safe_convert(account.market_value),
'total_value': self._safe_convert(account.total_value),
Expand All @@ -130,14 +126,12 @@ def _to_account_record(self, date, account):

POSITION_FIELDS_MAP = {
ACCOUNT_TYPE.STOCK: [
'quantity', 'last_price', 'avg_price', 'market_value', 'sellable'
'quantity', 'last_price', 'avg_price', 'market_value'
],
ACCOUNT_TYPE.FUTURE: [
'pnl', 'daily_pnl', 'holding_pnl', 'realized_pnl', 'margin', 'market_value',
'buy_pnl', 'sell_pnl', 'closable_buy_quantity', 'buy_margin', 'buy_today_quantity',
'buy_avg_open_price', 'buy_avg_holding_price', 'closable_sell_quantity',
'sell_margin', 'sell_today_quantity', 'sell_quantity', 'sell_avg_open_price',
'sell_avg_holding_price'
'margin', 'margin_rate', 'contract_multiplier', 'last_price',
'buy_pnl', 'buy_margin', 'buy_quantity', 'buy_avg_open_price',
'sell_pnl', 'sell_margin', 'sell_quantity', 'sell_avg_open_price'
],
}

Expand Down Expand Up @@ -185,10 +179,10 @@ def tear_down(self, code, exception=None):
'start_date': self._env.config.base.start_date.strftime('%Y-%m-%d'),
'end_date': self._env.config.base.end_date.strftime('%Y-%m-%d'),
'strategy_file': self._env.config.base.strategy_file,
'securities': self._env.config.base.securities,
'run_type': self._env.config.base.run_type.value,
'stock_starting_cash': self._env.config.base.stock_starting_cash,
'future_starting_cash': self._env.config.base.future_starting_cash,
'benchmark': self._env.config.base.benchmark,
}

risk = Risk(np.array(self._portfolio_daily_returns), np.array(self._benchmark_daily_returns),
Expand Down Expand Up @@ -233,14 +227,14 @@ def tear_down(self, code, exception=None):
result_dict = {
'summary': summary,
'trades': trades,
'total_portfolios': total_portfolios,
'portfolio': total_portfolios,
}

if self._env.benchmark_portfolio is not None:
b_df = pd.DataFrame(self._total_benchmark_portfolios)
df['date'] = pd.to_datetime(df['date'])
benchmark_portfolios = b_df.set_index('date').sort_index()
result_dict['benchmark_portfolios'] = benchmark_portfolios
result_dict['benchmark_portfolio'] = benchmark_portfolios

if self._env.plot_store is not None:
plots = self._env.get_plot_store().get_plots()
Expand All @@ -260,8 +254,8 @@ def tear_down(self, code, exception=None):
portfolios_list = self._sub_accounts[account_type]
df = pd.DataFrame(portfolios_list)
df["date"] = pd.to_datetime(df["date"])
portfolios_df = df.set_index("date").sort_index()
result_dict["{}_portfolios".format(account_name)] = portfolios_df
account_df = df.set_index("date").sort_index()
result_dict["{}_account".format(account_name)] = account_df

positions_list = self._positions[account_type]
positions_df = pd.DataFrame(positions_list)
Expand Down
2 changes: 1 addition & 1 deletion rqalpha/mod/rqalpha_mod_sys_analyser/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def generate_report(result_dict, target_report_csv_path):
with open(os.path.join(output_path, "summary.csv"), 'w') as csvfile:
csvfile.write(csv_txt.getvalue())

for name in ["total_portfolios", "stock_portfolios", "future_portfolios",
for name in ["portfolio", "stock_account", "future_account",
"stock_positions", "future_positions", "trades"]:
try:
df = result_dict[name]
Expand Down

0 comments on commit f6e4c24

Please sign in to comment.