The following code is meant to find for how much Bitcoin one is meant to buy in order to break even given the expected inflation, the holding period, and the amount of savings in dollars:
#!/usr/bin/env python3
from sympy import Eq, EmptySet, init_printing, symbols, solveset
from sys import float_info
init_printing(use_unicode=True)
x = symbols("x", real=True, positive=True)
years = float(input("How many years, i.e. the time horizon of your investment?\n"))
times = float(input("How many times do you intend to multiply your fiat money with Bitcoin?\n"))
times_yearly = times / years#How much on average Bitcoin will multiply per year
cpi = float(input("What yearly inflation do you expect to happen throughout the period?\n")) / 100
a = float(input("What is the amount of savings that you start with?\n"))
i = 1
while i <10000:
left = a
right = ((times_yearly * x + (a - x)) * (1 - cpi)) * years
eqn = Eq(left, right)
if solveset(eqn) != EmptySet:
print("In order to break even you need to buy ")
print(solveset(eqn))
print(a)
a = a + float_info.min
i = i + 1
When the program is fed with years=3
, times=4
, cpi=8
, and a=1000
it does not find a solution. Because of it I introduced a loop that is mean to find a solution for a
that is minimally larger than 1000
. Sadly, to no avail. How might I find approximate solution of this equation? Is sympy
a good tool for this job? Is my code correct or have I missed something?