This repository has been archived by the owner on May 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (50 loc) · 2.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// getFowlFiveIndexV1 index.js
// This is the forumula for calculating the Fowl Five Index of Cryptos
// http://danmckeown.info/fowlfive
// copyright Jan-April 2018 by Dan McKeown Licensed under the ISC License
// This function is published as part of the Paper Umbrella repo:
// https://github.com/pacificpelican/paper-umbrella/blob/master/pages/fowlfive.js
// The `...cryptos` argument accepts (five) objects of this shape:
// Object.assign({"name": "Bitcoin", "price": 8867, "cap": 150689347341})
function getFowlFiveIndexV1(...cryptos) {
// expected crypto object parameters: bitcoin, ethereum, bitcoincash, litecoin, dash
let totalCap = 0;
let totalPrice = 0;
const capLimit = cryptos[0].cap; // assuming for now [0] will be bitcoin
const priceStandard = cryptos[0].price;
let subAmount = 0;
let runningTotal = 0;
let subAmountArray = [];
let refAmtTotal = 0;
let localRebasedPriceRatioTotal = 0;
let priceTotal = 0;
for (let crypto of cryptos) {
totalCap = totalCap + crypto.cap;
totalPrice = totalPrice + crypto.price;
let localPriceCapRatio = totalPrice / totalCap;
priceTotal = priceTotal + crypto.price;
let localCapPercentage = crypto.cap / capLimit;
subAmount = localCapPercentage * crypto.price;
let localRebasedPriceRatio = crypto.price / priceStandard;
let localRebasedPrice =
crypto.price * (localRebasedPriceRatio * crypto.cap) / 10000000000;
if (localRebasedPriceRatio !== 1) {
localRebasedPriceRatioTotal =
localRebasedPriceRatioTotal + localRebasedPriceRatio;
} else {
localRebasedPriceRatioTotal =
localRebasedPriceRatioTotal + crypto.price / 10000;
}
let refAmt = localCapPercentage * localRebasedPrice;
refAmtTotal = refAmtTotal + refAmt;
let localBTCbasis = crypto.price / cryptos[0].price;
let localAdjustedRebasedPrice = crypto.price / localBTCbasis; // this acts like a checksum
let adjustedFowlTotal = localAdjustedRebasedPrice * localRebasedPriceRatio;
subAmountArray.push(subAmount);
runningTotal = localRebasedPrice / 100 + runningTotal;
}
let adjustedLocalRebasedPriceRatioTotal = localRebasedPriceRatioTotal * 1000;
let fowlFiveIndex = adjustedLocalRebasedPriceRatioTotal;
return fowlFiveIndex;
}
module.exports = getFowlFiveIndexV1;