Skip to content

Commit 2edab74

Browse files
committed
feat(settings): set targetValueUsd to false to use current portfolio value as target; use rebalanceD
1 parent c99cebd commit 2edab74

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ The tool expects your settings in settings.json. Take a look at settings.example
3838
- *otherHoldings*: A place to manually add some of your holdings. Notation is key: Symbol, value is amount of native currency.
3939
- *options*: These are specific options for the tool:
4040
- targetValueUsd: The target value for your ETF; A general rule of thumb is to keep your crypto at a certain percentage of your overall investment portfolio. This could be 5, 10, 20 or more percent, depending on your risk tolerance.
41-
- rebalanceDeltaPct: Treshold in percent, that will show a Y in the rebalance column, once rebalancing is recommended.
41+
- Default [false]: Use current portfolio value as target value.
42+
- Number [1 - 999999999999]: Use fixed number as target value.
43+
- rebalanceDeltaTotalPct: Treshold in percent, that will show a Y in the rebalance column, once rebalancing of total portfolio is recommended.
44+
- rebalanceDeltaPct: Treshold in percent, that will show a Y in the rebalance column, once rebalancing of individual position is recommended.
4245
- minValueBtc: Ignore coins that only have a holdingsvalue under a certain bitcoin value.
4346
- hideMissingCoins: By default CryptoETF will add all missing coins up to your last coin holding by rank of the coin (global market cap). This option disables that behaviour.
4447
- *outputFile*: Path to a file to forward the output to as json.

settings.example.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@
5050
"BTG": 1.0
5151
}],
5252
"options": {
53-
"targetValueUsd": 50000,
53+
"targetValueUsd": false,
5454
"rebalanceDeltaPct": 1.0,
55+
"rebalanceDeltaTotalPct": 10.0,
5556
"minValueBtc": 0.0001,
5657
"hideMissingCoins": false
5758
},

src/Utils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const settings = require('../settings.json')
2+
13
export default class Utils {
24
static pad(width, string, padding) {
35
return (width <= string.length) ? string : this.pad(width, padding + string, padding)
@@ -36,4 +38,14 @@ export default class Utils {
3638
static capitalize(string) {
3739
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase()
3840
}
41+
42+
/**
43+
* Determines if drift is above treshold defined in settings.
44+
* @param drift The current drift.
45+
* @return {string} 'Y', if drifted, '' if not.
46+
*/
47+
static hasDriftedAboveTreshold(drift) {
48+
return (Math.abs(drift) * 100 > (settings.options.rebalanceDeltaTotalPct ||
49+
settings.options.rebalanceDeltaPct)) ? 'Y' : ''
50+
}
3951
}

src/model/Portfolio.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ export default class Portfolio {
109109
}
110110
}
111111

112+
/**
113+
* Returns the target value of the portfolio in USD.
114+
* @return {*} The target value in USD.
115+
*/
116+
static getTargetValueUsd() {
117+
if (!settings.options.targetValueUsd) {
118+
return Portfolio.getSumUsd()
119+
} else {
120+
return settings.options.targetValueUsd
121+
}
122+
}
123+
112124
/**
113125
* Formats the output for the command line.
114126
* @return {string} A string with the result.
@@ -121,7 +133,8 @@ export default class Portfolio {
121133
]
122134
let sortedKeys = Utils.getSortedKeys(portfolio, 'rank')
123135
let targetSum = []
124-
let targetValueBtc = settings.options.targetValueUsd / Coinmarket.getBtcUsd()
136+
let targetValueUsd = this.getTargetValueUsd()
137+
let targetValueBtc = this.getTargetValueUsd() / Coinmarket.getBtcUsd()
125138
targetSum['allocationActualPct'] = 0
126139
targetSum['allocationTargetPct'] = 0
127140
targetSum['targetBtc'] = 0
@@ -134,8 +147,8 @@ export default class Portfolio {
134147
let allocationActualPct = coin.getRelativeMarketCap()
135148
let allocationTargetPct = coin.getRelativeMarketCapRecommended() / stretchFactor
136149
let targetBtc = coin.getRelativeMarketCapRecommended() / stretchFactor * targetValueBtc
137-
let targetUsd = coin.getRelativeMarketCapRecommended() / stretchFactor * settings.options.targetValueUsd
138-
let drift = Math.abs((coin.getUsdValue() - targetUsd) / settings.options.targetValueUsd)
150+
let targetUsd = coin.getRelativeMarketCapRecommended() / stretchFactor * targetValueUsd
151+
let drift = Math.abs((coin.getUsdValue() - targetUsd) / targetValueUsd)
139152
data.push([
140153
coin.getRank(),
141154
coin.getSymbol(),
@@ -150,7 +163,7 @@ export default class Portfolio {
150163
Format.bitcoin((targetBtc - coin.getBtcValue()) / Coinmarket.getBtcEth(), 8),
151164
Format.money(targetUsd - coin.getUsdValue()),
152165
Format.percent(drift),
153-
(drift * 100 > settings.options.rebalanceDeltaPct) ? 'Y' : '',
166+
Utils.hasDriftedAboveTreshold(drift),
154167
coin.getExchangesString()
155168
])
156169
targetSum['allocationActualPct'] += allocationActualPct || 0
@@ -174,7 +187,7 @@ export default class Portfolio {
174187
'',
175188
Format.money(targetSum['targetUsd'] - this.getSumUsd()),
176189
Format.percent(drift),
177-
(Math.abs(drift) * 100 > settings.options.rebalanceDeltaPct) ? 'Y' : '',
190+
Utils.hasDriftedAboveTreshold(drift),
178191
''])
179192

180193
// noinspection JSUnusedGlobalSymbols

0 commit comments

Comments
 (0)