Skip to content

Commit

Permalink
fix(ui): fix rebalance indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
benmarten committed Jan 6, 2018
1 parent d8f45a7 commit 666e305
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
10 changes: 4 additions & 6 deletions src/Utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as Settings from './Settings'

export default class Utils {
static pad(width, string, padding) {
return (width <= string.length) ? string : this.pad(width, padding + string, padding)
Expand Down Expand Up @@ -40,12 +38,12 @@ export default class Utils {
}

/**
* Determines if drift is above treshold defined in settings.
* Determines if drift is above the provided treshold.
* @param drift The current drift.
* @param treshold The treshold.
* @return {string} 'Y', if drifted, '' if not.
*/
static hasDriftedAboveTreshold(drift) {
return (Math.abs(drift) * 100 > (Settings.options.rebalanceDeltaTotalPct ||
Settings.options.rebalanceDeltaPct)) ? 'Y' : ''
static hasDriftedAboveTreshold(drift, treshold) {
return (Math.abs(drift) * 100 > treshold) ? 'Y' : ''
}
}
5 changes: 3 additions & 2 deletions src/model/Portfolio.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default class Portfolio {
Format.bitcoin((targetBtc - coin.getBtcValue()) / Coinmarket.getBtcEth(), 8),
Format.money(targetUsd - coin.getUsdValue()),
Format.percent(drift),
Utils.hasDriftedAboveTreshold(drift),
Utils.hasDriftedAboveTreshold(drift, Settings.options.rebalanceDeltaPct),
coin.getExchangesString()
])
targetSum['allocationActualPct'] += allocationActualPct || 0
Expand All @@ -186,7 +186,8 @@ export default class Portfolio {
'',
Format.money(targetSum['targetUsd'] - this.getSumUsd()),
Format.percent(drift),
Utils.hasDriftedAboveTreshold(drift),
Utils.hasDriftedAboveTreshold(drift, (Settings.options.rebalanceDeltaTotalPct ||
Settings.options.rebalanceDeltaPct)),
''])

// noinspection JSUnusedGlobalSymbols
Expand Down
5 changes: 5 additions & 0 deletions test/testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ describe('Testing utils', () => {
assert(Utils.round(1.5666, 2) === 1.57)
assert(Utils.round(1.5666, 10) === 1.5666)
})

it('Test hasDriftedAboveTreshold', () => {
assert(Utils.hasDriftedAboveTreshold(0.11, 10))
assert(!Utils.hasDriftedAboveTreshold(0.09, 10))
})
})

0 comments on commit 666e305

Please sign in to comment.