Initial commit
This commit is contained in:
commit
732cd72e46
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
__pycache__
|
25
README.md
Normal file
25
README.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Meuro
|
||||||
|
|
||||||
|
Prices in euros from different times can not be compared without taking inflation into account.
|
||||||
|
This also negatively impacts peoples abilities to gauge their own financial prosperity because what they conceive as a raise might not even cover they loss in purchase-power due to inflation.
|
||||||
|
This fix this issue, I present:
|
||||||
|
## The Millenial Euro
|
||||||
|
### aka Meuro (symbol µ)
|
||||||
|
Meuro's worth is equivalent to that of the euro on January 1st 2001 00:00 GMT.
|
||||||
|
(Yes, thats 2001 and not 200 because the first millenium started in the year 1 and so the third oen started in 2001. I do realize that this is stupid, but that's not my fault and all the people that celebrated the beginning of the new century at silvester 2000 should technically have waited another year.)
|
||||||
|
## This repo
|
||||||
|
What you find in this repo is a small python-libary that conects to the ecb to get historic inflation-data and computes the conversion-factor between € and µ for any given date (after Jan 1st 2001).
|
||||||
|
The provided functions are:
|
||||||
|
#### exchangeRate(date=None)
|
||||||
|
Gives you the exchange rate between euros and meuros for the given date.
|
||||||
|
#### euroToMeuro(eur, date=None, wholeCents=True)
|
||||||
|
Converts the given amount of euros to meuros for the given date. (wholeCents means it rounds to two decimal places)
|
||||||
|
#### meuroToEuro(meur, date=None, wholeCents=True)
|
||||||
|
Converts the given amount of meuros to euros for the given date. (wholeCents means it rounds to two decimal places)
|
||||||
|
#### liveValue(eur, interval=10)
|
||||||
|
Print the current amount of meuros for the given amunt of euros every interval-seconds. Comes in handy when you want to watch your live saving slowly fade away thanks to inflation.
|
||||||
|
## Caveats
|
||||||
|
The ecb only gives an estimate for the inflation of the last month and no data for the current month.
|
||||||
|
This libary just uses this estimate and assumes a yearly-inflation-rate of the current month (and all others months without data) of 2% (which is the stated goal-inflation-rate of the ecb).
|
||||||
|
## Future Plans
|
||||||
|
It would be cool to have a stable-coin on the ethereum-network, that tracks to the value of a meuro. I'm way to lazy to write that though...
|
61
meuro.py
Normal file
61
meuro.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import requests
|
||||||
|
from datetime import datetime
|
||||||
|
from dateutil import relativedelta
|
||||||
|
|
||||||
|
url = 'https://sdw.ecb.europa.eu/quickviewexport.do?SERIES_KEY=122.ICP.M.U2.N.000000.4.ANR&type=csv'
|
||||||
|
resp = requests.get(url)
|
||||||
|
lines = resp.text.split('\n')[6:]
|
||||||
|
years = {}
|
||||||
|
for line in lines:
|
||||||
|
vals = line.split(',')
|
||||||
|
year = int(vals[0][:4])
|
||||||
|
month = datetime.strptime(vals[0][4:],'%b').month
|
||||||
|
inflation = float(vals[1])
|
||||||
|
if not year in years:
|
||||||
|
years[year] = {}
|
||||||
|
years[year][month] = 1 + (inflation/100)/12
|
||||||
|
|
||||||
|
for year in years:
|
||||||
|
months = years[year]
|
||||||
|
for month in range(1,13):
|
||||||
|
if month not in months:
|
||||||
|
years[year][month] = 1 + 0.02/12 # Lets say the ECB archives their target
|
||||||
|
|
||||||
|
def exchangeRate(date=None):
|
||||||
|
if date==None:
|
||||||
|
date = datetime.now()
|
||||||
|
month, year = date.month, date.year
|
||||||
|
if year < 2001:
|
||||||
|
raise Exception('µeuro-values for €uro prices before the start of this millenium are undefined.')
|
||||||
|
akk = 1
|
||||||
|
for fullYear in range(2001, year):
|
||||||
|
yearlyInf = 1
|
||||||
|
for m in years[fullYear]:
|
||||||
|
monthlyInf = years[fullYear][m]
|
||||||
|
yearlyInf *= monthlyInf
|
||||||
|
akk *= yearlyInf
|
||||||
|
|
||||||
|
for fullMonth in range(1, month):
|
||||||
|
monthlyInf = years[year][fullMonth]
|
||||||
|
akk *= monthlyInf
|
||||||
|
|
||||||
|
beginningOfMonth = date.replace(hour=0, minute=0, second=0, microsecond=0, day=1)
|
||||||
|
endOfMonth = beginningOfMonth + relativedelta.relativedelta(months=1)
|
||||||
|
fracOfMonth = (date - beginningOfMonth).total_seconds() / (endOfMonth - beginningOfMonth).total_seconds()
|
||||||
|
inflationThisMonth = 1 + fracOfMonth * (years[year][month]-1)
|
||||||
|
|
||||||
|
akk *= inflationThisMonth
|
||||||
|
|
||||||
|
return 1/akk
|
||||||
|
|
||||||
|
def euroToMeuro(eur,date=None,wholeCents=True):
|
||||||
|
return round(eur * factorForDate(date),[64,2][wholeCents])
|
||||||
|
|
||||||
|
def meuroToEuro(meur,date=None,wholeCents=True):
|
||||||
|
return round(meur / factorForDate(date),[64,2][wholeCents])
|
||||||
|
|
||||||
|
def liveValue(eur,interval=10):
|
||||||
|
import time
|
||||||
|
while True:
|
||||||
|
print(str(eur*exchangeRate())+'µ')
|
||||||
|
time.sleep(interval)
|
Loading…
Reference in New Issue
Block a user