-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
185 lines (153 loc) · 6.5 KB
/
index.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html>
<head>
<title>The Cost of Inaction</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 10px;
}
h1 {
text-align: center;
color: #333;
}
form {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type="text"] {
width: calc(100% - 20px);
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
button {
display: block;
width: 100%;
padding: 10px;
background-color: #28a745;
color: #fff;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
}
button:hover {
background-color: #218838;
}
#infoblock {
display: none;
margin-top: 20px;
}
.result {
margin-bottom: 10px;
}
.result span {
font-weight: bold;
}
a {
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>The Cost of Inaction</h1>
<form id="frm1">
<label for="w0">Cash stashed as of January 1:</label>
<input type="text" id="w0" name="w0" value="20000">
<label for="infl">Inflation rate (in percentage):</label>
<input type="text" id="infl" name="infl" value="2.00">
</form>
<button onclick="startTheBleed()">Start</button>
<div id="infoblock">
<div class="result">With an inflation of <span id="inflation_pct"></span>%...</div>
<br/>
<div class="result">Your initial wealth is now equivalent to <span id="money"></span> (value on January 1st).</div>
<div class="result">That means that you need <span id="eq_money"></span> (at today's value) in order to keep your original purchasing power.</div>
<div class="result">That means that you essentially lost <span id="lost_money"></span> (at today's value) to inflation.</div>
<div class="result">If you do nothing, at the end of the year your wealth will be worth <span id="final_money"></span> (at January 1st value).</div>
<div class="result">At the end of the year, you will need to have <span id="eq_final_money"></span> in your account in order to keep the purchasing power you had on January 1st.</div>
<br/>
<div class="result"><br/>Now, assuming constant inflation during the following 10 years...</div>
<br/>
<div class="result">In 10 years, your wealth will be worth <span id="final_10_year_money"></span> (using the value at January 1st this year).</div>
<div class="result">In 10 years, you will need to have <span id="eq_final_10_year_money"></span> in your account in order to keep the purchasing power you had on January 1st this year.</div>
<div class="result">
You can fork this project on <a href="https://github.com/ghgr/InflationRealTime">Github</a>
</div>
</div>
</div>
<script>
document.getElementById("infoblock").style.display = 'none';
var data0,data1,current_time,initial_money,inflation,final_money,money_per_millisecond,current_money,final_10_year_money;
var eq_final_money,eq_money_per_millisecond,eq_current_money,eq_final_10_year_money; //equivalent calculation in order to get the money you need to make in order to beat inflation
function bleed()
{
synchronizator();
current_money+=money_per_millisecond*10;
eq_current_money+=eq_money_per_millisecond*10;
document.getElementById("money").innerHTML = numberWithCommas(current_money.toFixed(6));
document.getElementById("lost_money").innerHTML = numberWithCommas((eq_current_money-initial_money).toFixed(6));
document.getElementById("eq_money").innerHTML = numberWithCommas(eq_current_money.toFixed(6));
}
function startTheBleed()
{
var x = document.getElementById("frm1");
data0 = new Date(new Date().getFullYear(),0,1,0,0,0,0);
data1 = new Date();
current_time = data1-data0; //ms
initial_money=parseFloat(x[0].value);
inflation_pct = parseFloat(x[1].value)
inflation=inflation_pct*0.01;
final_money = initial_money/(1.0+inflation); // final money at 31-DEC ( 37 OCT :-) )
final_10_year_money = initial_money/Math.pow((1.0+inflation),10);
eq_final_money = initial_money*(1.0+inflation); // money you need to have to keep your purchasing power
eq_final_10_year_money = initial_money*Math.pow((1.0+inflation),10);
money_per_millisecond = (final_money-initial_money)/(86400.0*365.0*1000)// bleeding per millisecond (hint: is negative)
eq_money_per_millisecond = (eq_final_money-initial_money)/(86400.0*365.0*1000);
current_money = initial_money + money_per_millisecond*current_time;
eq_current_money = initial_money + eq_money_per_millisecond*current_time;
var fastcounter=setInterval(function(){bleed()},10);
document.getElementById("infoblock").style.display = 'block';
// Constant values
document.getElementById("final_money").innerHTML = numberWithCommas(final_money.toFixed(2));
document.getElementById("eq_final_money").innerHTML = numberWithCommas(eq_final_money.toFixed(2));
document.getElementById("final_10_year_money").innerHTML = numberWithCommas(final_10_year_money.toFixed(2));
document.getElementById("eq_final_10_year_money").innerHTML = numberWithCommas(eq_final_10_year_money.toFixed(2));
document.getElementById("inflation_pct").innerHTML = numberWithCommas(inflation_pct.toFixed(2));
}
function synchronizator()
{
data1 = new Date();
current_time = data1-data0; //ms
current_money = initial_money + money_per_millisecond*current_time;
eq_current_money = initial_money + eq_money_per_millisecond*current_time;
}
function numberWithCommas(n)
{
var parts=n.toString().split(".");
return parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",") + (parts[1] ? "." + parts[1] : "");
}
</script>
</body>
</html>