diff --git a/app/models/adding_positions_history.rb b/app/models/adding_positions_history.rb index 1f1a7b9..8306311 100644 --- a/app/models/adding_positions_history.rb +++ b/app/models/adding_positions_history.rb @@ -9,7 +9,8 @@ def get_revenue end def roi - ((get_revenue / (amount.abs + get_revenue)) * 100).round(4) + adding_amount = trade_type == 'sell' ? amount.abs + get_revenue : amount.abs + ((get_revenue / adding_amount) * 100).round(4) end def amount_ratio diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index f5bfe4d..4305d54 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -21,9 +21,9 @@ zh-CN: sell: 多 buy: 空 adding_rate: 新增的投入带来的总的盈利或者亏损的金额 / 新增的投入 - revenue: 空单:新增金额 - 新增数量*最新价格 - / 多单:新增数量*最新价格 - 新增金额 + revenue: 空单:新增金额 - 新增数量*最新价格 / 多单:新增数量*最新价格 - 新增金额 trading_fee: 交易当天的仓位快照总的资金费用乘以该笔交易占当天仓位的比例 - roi: 已实现收益 / 平仓金额 + roi: 空单:已实现收益 / 平仓金额 / 多单: 已实现收益 / (平仓金额 + 已实现收益) closing_revenue: 收益 - 资金费用 wallet_history: deposit: 充值 diff --git a/spec/models/adding_positions_history_spec.rb b/spec/models/adding_positions_history_spec.rb index 4ae3a48..4388b24 100644 --- a/spec/models/adding_positions_history_spec.rb +++ b/spec/models/adding_positions_history_spec.rb @@ -9,7 +9,7 @@ describe '#roi' do it 'should equal revenue divide amount' do - roi = ((adding_positions_history.get_revenue / (adding_positions_history.amount.abs + adding_positions_history.get_revenue)) * 100).round(4) + roi = ((adding_positions_history.get_revenue / (adding_positions_history.amount.abs)) * 100).round(4) expect(adding_positions_history.roi).to eq (roi) end end