Android Question Compounding Is Powerful

Mahares

Expert
Licensed User
Longtime User
An old professor asked me this question at the gym today: If I give you 1 US penny (1/100th of a dollar) today and you double the result every day for 30 days only, how much money will you end up with at the end of the 30 days? I answered: I have no idea, but I will write a little B4A code after the workout and get back to you tomorrow with the result.
I wrote these few lines of code and to my astonishment it is over $10,000,000. If you disagree or have a better way to achieve the result, please post it:
B4X:
Dim x As Long =1
    For i= 0 To 30-1
        x=x*2
    Next
    Dim y As String = NumberFormat2(x/100,1,0,0,True)
    LogColor(y, Colors.Red)  'displays: 10,737,418
 

Mahares

Expert
Licensed User
Longtime User
based on the formula in @NJDude 's link, the equivalent B4A code would be:
B4X:
Dim x As Long
    Dim a As Int =1   'the first term
    Dim r As Int=2      'multiplier
    Dim n As Int=30   'number of days
    x=a*(1-Power(r,n))/(1-r)
    Dim y As String = NumberFormat2(x/100,1,0,0,True)
    LogColor(y, Colors.Red)  'displays: 10,737,418
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
You have a share capital worth $ 1,000.
Its value increases today by 1%.
The following day it decreases by 1%.
The two events above are repeated for 15 times (30 days).
How much is your capital at the end?



[Some news programs say things like: "Today the stock market has risen by 2%, recovering 2% lost yesterday"]
 
Last edited:
Upvote 0

MaFu

Well-Known Member
Licensed User
Longtime User
You have a share capital worth $ 1,000.
Its value increases today by 1%.
The following day it decreases by 1%.
The two events above are repeated for 15 times (30 days).
How much is your capital at the end?



[Some news programs say things like: "Today the stock market has risen by 2%, recovering 2% lost yesterday"]
$ 998,50

And after 115124 cycles (230248 days) you have 1 cent. :eek: But you're to old to spend it. :D
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
You have a share capital worth $ 1,000.
Its value increases today by 1%.
The following day it decreases by 1%.
The two events above are repeated for 15 times (30 days).
How much is your capital at the end?
Professor and Father @LucaMs , is this the correct B4A code needed. I like your blessing. If different, please enlighten me:
B4X:
LogColor(Compound(1000,30),Colors.Green)  'displays 998.50

Sub Compound(x As Double, days As Int) As String
    For i= 0 To days-1
        If i Mod 2 =0 Then
            x=x*(1+.01)
        Else
            x=x*(1-.01)
        End If
    Next
    Return NumberFormat2(x,1,2,2,True)
End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Professor and Father @LucaMs , is this the correct B4A code needed. I like your blessing. If different, please enlighten me:
B4X:
LogColor(Compound(1000,30),Colors.Green)  'displays 998.50

Sub Compound(x As Double, days As Int) As String
    For i= 0 To days-1
        If i Mod 2 =0 Then
            x=x*(1+.01)
        Else
            x=x*(1-.01)
        End If
    Next
    Return NumberFormat2(x,1,2,2,True)
End Sub

What is surely incorrect is this:
Professor and Father @LucaMs
:D

Your routine is correct... although not very useful. My example was used only to point out how journalists understand well the percentages when they refer to stocks (and also to the GDP of the state - PIL in italian).

[Your function should return x as double or float, not a string, anyway]
 
Upvote 0

mrred128

Active Member
Licensed User
Longtime User
You have a share capital worth $ 1,000.
Its value increases today by 1%.
The following day it decreases by 1%.
The two events above are repeated for 15 times (30 days).
How much is your capital at the end?



[Some news programs say things like: "Today the stock market has risen by 2%, recovering 2% lost yesterday"]

You have asked more than 1 quedtion / thread. Taxes = %90.
 
Upvote 0

Widget

Well-Known Member
Licensed User
Longtime User
What is surely incorrect is this:

:D

Your routine is correct... although not very useful. My example was used only to point out how journalists understand well the percentages when they refer to stocks (and also to the GDP of the state - PIL in italian).

[Your function should return x as double or float, not a string, anyway]

The U.S. is now adding research and development to the GDP. So the more money that is spent on R&D, the higher the GDP regardless of producing any results. I'm not making this up. I wish I was.

This has motivated me into getting a $100,000 GofundMe campaign to contemplate my navel for all of 2018. But I can't do it alone. If each of us did this with their own navel, we could have 8% GDP growth in no time, and much cleaner navels. :rolleyes: I'm even thinking of getting a government grant. We must do our best to get our governments out of a recession. Who's with me on this?
 
Upvote 0
Top