Last active
October 28, 2024 05:53
-
-
Save BitcoinWukong/9c70c5e6b67edeb1423bbcf50cf3e1e2 to your computer and use it in GitHub Desktop.
ahr999 index calculation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from math import log10 | |
import json | |
import requests | |
# Enter the glass node API_KEY here | |
glass_node_api_key = '' | |
birth_date = datetime(year=2009, month=1, day=3) | |
today = datetime.now() | |
age_days = (today - birth_date).days | |
target_price = 10 ** (5.84 * log10(age_days) - 17.01) | |
print('target_price:', target_price) | |
# make API request | |
res = requests.get('https://api.glassnode.com/v1/metrics/market/price_usd_close', | |
params={'a': 'BTC', 'api_key': glass_node_api_key}) | |
price_json = json.loads(res.text) | |
price_sum = 0 | |
for i in range(200): | |
price_sum += price_json[-i]['v'] | |
average_200_day_price = price_sum / 200 | |
print('average_200_day_price:', average_200_day_price) | |
import requests | |
cur_price_url = 'https://api.coindesk.com/v1/bpi/currentprice/USD.json' | |
response = requests.get(cur_price_url, allow_redirects=True) | |
cur_price = response.json()["bpi"]["USD"]["rate_float"] | |
print('current price:', cur_price) | |
p1 = cur_price / target_price | |
p2 = cur_price / average_200_day_price | |
p = p1 * p2 | |
print() | |
print('all-in range: <=0.45') | |
print('DCA range: 0.45 ~ 1.20') | |
print('Sell range: >= 5.0') | |
print() | |
# Before a bull run, stop DCA when >=3.0 | |
# After a bull run, start DCA when <= 1.2 | |
print('ahr_999_index:', '{:.2f}'.format(p)) | |
if p <= 0.45: | |
print(' Suggestion: ALL IN!') | |
elif p <= 1.20: | |
print(' Suggestion: Dollar cost averaging.') | |
elif p < 5.0: | |
print(' Suggestion: Stop buying.') | |
elif p >= 5.0: | |
print(' Suggestion: Sell some BTC to secure some fiat for daily spending.') | |
~ | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment