I'm trying to find or derive a function for Google Sheets, that will return the number of periods (eg days) required to reach a specified APY (eg 100%), given the interest rate per period.
I started with a basic APY function:
r = rate per period
n = number of periods
APY = (1 + r) ^ n - 1
Example:
r = 5% (per period of a day)
n = 14.21 (number of periods, ie days)
APY = (1 + 5%) ^ 14.21 - 1
= 100.03%
I'm stuck trying to reverse the function, so I can determine n (the number of periods), if the APY is given as 100%.
Any suggestions would be most appreciated.
You need the (1+r)-log to reverse the power-to function:
r = log(APY + 1) / log(1 + r)
Examples:
r = log(1,0003 + 1) / log(1 + 0,05) = 14,209
r = log(1 + 1) / log(1 + 0,05) = 14,207
Should not matter which log you use, the log-10 or the natural log (ln), as long as you use the same function both times.
Related
I working on computer vision task and have this equation:
R0*c + t0 = R1*c + t1 = Ri*c + ti = ... = Rn*c + tn ,
n is about 20 (but can be more if needs)
where each pair of R,t (rotation matrix and translation vector in 3D) is a result of i-measurement and they are known, and vector c is what I whant to know.
I've got result with ceres solver. It's good that it can handle outliers but I think it's overkill for this task.
So what methods I should use for two situations:
With outliers
Without outliers
To handle outliers you can use RANSAC:
* In each iteration randomly pick i,j (a "sample") and solve c:
Ri*c + ti = Rj*c + tj
- Set Y = Ri*c + ti
* Apply to a larger population:
- Select S={k} for which ||Rk*c + tk - Y||<e
e ~ 3*RMS of errors without outliers
- Find optimal c for all k equations (with least mean square)
- Give it a "grade": size of S
* After few iterations use optimal c found for Max "grade".
* Number of iterations: log(1-p)/log(1-w^2)
[https://en.wikipedia.org/wiki/Random_sample_consensus]
p = 0.001 (for example. It is the required certainty of the result)
w is an assumption of nonoutliers/n.
We are to solve the recurrence relation through repeating substitution:
T(n)=T(n-1)+logn
I started the substitution and got the following.
T(n)=T(n-2)+log(n)+log(n-1)
By logarithm product rule, log(mn)=logm+logn,
T(n)=T(n-2)+log[n*(n-1)]
Continuing this, I get
T(n)=T(n-k)+log[n*(n-1)*...*(n-k)]
We know that the base case is T(1), so n-1=k -> k=n+1, and substituting this in we get
T(n)=T(1)+log[n*(n-1)*...*1]
Clearly n*(n-1)*...*1 = n! so,
T(n)=T(1)+log(n!)
I do not know how to solve beyond this point. Is the answer simply O(log(n!))? I have read other explanations saying that it is Θ(nlogn) and thus it follows that O(nlogn) and Ω(nlogn) are the upper and lower bounds respectively.
This expands out to log (n!). You can see this because
T(n) = T(n - 1) + log n
= T(n - 2) + log (n - 1) + log n
= T(n - 3) + log (n - 2) + log (n - 1) + log n
= ...
= T(0) + log 1 + log 2 + ... + log (n - 1) + log n
= T(0) + log n!
The exact answer depends on what T(0) is, but this is Θ(log n!) for any fixed constant value of T(0).
A note - using Stirling's approximation, Θ(log n!) = Θ(n log n). That might help you relate this back to existing complexity classes.
Hope this helps!
Stirling's formula is not needed to get the big-Theta bound. It's O(n log n) because it's a sum of at most n terms each at most log n. It's Omega(n log n) because it's a sum of at least n/2 terms each at least log (n/2) = log n - 1.
Yes, this is a linear recurrence of the first order. It can be solved exactly. If your initial value is $T(1) = 0$, you do get $T(n) = \log n!$. You can approximate $\log n!$ (see Stirling's formula):
$$
\ln n! = n \ln n - n + \frac{1}{2} \ln \pí n + O(\ln n)
$$
[Need LaTeX here!!]
(1) The simple version of the problem:
How to calculate log(P1+P2+...+Pn), given log(P1), log(P2), ..., log(Pn), without taking the exp of any terms to get the original Pi. I don't want to get the original Pi because they are super small and may cause numeric computer underflow.
(2) The long version of the problem:
I am using Bayes' Theorem to calculate a conditional probability P(Y|E).
P(Y|E) = P(E|Y)*P(Y) / P(E)
I have a thousand probabilities multiplying together.
P(E|Y) = P(E1|Y) * P(E2|Y) * ... * P(E1000|Y)
To avoid computer numeric underflow, I used log(p) and calculate the summation of 1000 log(p) instead of calculating the product of 1000 p.
log(P(E|Y)) = log(P(E1|Y)) + log(P(E2|Y)) + ... + log(P(E1000|Y))
However, I also need to calculate P(E), which is
P(E) = sum of P(E|Y)*P(Y)
log(P(E)) does not equal to the sum of log(P(E|Y)*P(Y)). How should I get log(P(E)) without solving for P(E|Y)*P(Y) (they are extremely small numbers) and adding them.
You can use
log(P1+P2+...+Pn) = log(P1[1 + P2/P1 + ... + Pn/P1])
= log(P1) + log(1 + P2/P1 + ... + Pn/P1])
which works for any Pi. So factoring out maxP = max_i Pi results in
log(P1+P2+...+Pn) = log(maxP) + log(1+P2/maxP + ... + Pn/maxP)
where all the ratios are less than 1.
I am trying to replicate a graph on an example on Danish Data set used in the text Non-Life Insurance Mathematics.
I want to create the following new variable from my data set so I can plot the graph. My biggest challenge is how to sum(sigma) over w over j given that I have to start from max of two values to min of two values. I don't have the faintest idea how to do it in R. Guess I have a lot to still learn in how to do operations in R.
I would appreciate if some how can give me useful tip on how to go about it.
Below is the equation in question I couldn't replace the sigma sign so I used the literally interpretation (sum)
1/λ(i)) = 1/(2m + 1) * sum Wj from {j=max(1,i−m) to min(n,i+m)} for m = 50.
Try this
m = 50
total = 0
for (j in seq(max(1, i-m), min(n, i+m)) {
total = total + W[j]
}
total = total / (2 * m + 1)
lambda = 1 / total
or this
m = 50
lambda = 1 / (sum(W[max(i,i-m) : min(n,i+m)]) / (2 * m + 1))
The following problem has been puzzling me for a couple of days (nb: this is not homework).
There exists two geometric sequences that sum to 9. The value of their second term (t2) is 2.
Find the common ratio (r)
Find the first element (t1) of each
The answers to (1) are 2/3 and 1/3 and the answers to (2) are 3 and 6 respectively. Unfortunately, I can't understand how these were derived.
In tackling (1) I've tried to apply algebraic substitution to solve for r as follows:
t2 = t1*r; since t2 = 2 we have:
t1 = 2/r
The equation for calculating the sum (S) of a sequence that converges to a limit is given by:
S = t1 / (1 - r)
So, I tried to plug my value of t1 into S and solve for r as follows:
9 = (2/r) / (1-r)
9(1-r) = 2/r
2/9 = r(1-r)
Unfortunately, from this point I get stuck. I need to eliminate one of the r's but I can't seem to be able to.
Next, I thought to solve for r using the formula that sums the first 2 terms (S2) of the sequence:
S2 = (t1 (1-r^2)) / (1-r)
t1 + 2 = (t1 (1-r^2)) / (1-r)
but expanding this out I again run into the same problem (can't eliminate one of the r's).
So I have 2 questions:
What am I doing wrong when deriving r?
Once I have one of its values, how I derive the other?
2/9 = r(1-r)
Unfortunately, from this point I get
stuck. I need to eliminate one of the
r's but I can't seem to be able to.
You need to learn to factorise!
2/9 = r(1-r)
2/9 = r - r^2
2 = 9r - 9r^2
9r^2 - 9r + 2 = 0
(3r)^2 - 3(3r) + 2 = 0
to make it easier, let R = 3r
R^2 - 3R + 2 = 0
(R - 1)(R - 2) = 0
so 3r - 1 = 0, or 3r - 2 = 0
i.e. r = 1/3 or r = 2/3.
And your first term is 2/(1/3) = 6, or 2/(2/3) = 3
QED!
2/9 = r (1 - r)
Rewrite this as ax2 + bx + c and use the quadratic formula to solve it:
2/9 = r - r2
r2 - r + 2/9 = 0
Using the quadratic formula, the roots are:
[-1 ± √(1 - 8/9)] / 2
= (1 ± 1/3) / 2
= 1/2 ± 1/6
= 1/3 or 2/3
Edit: Aw shoot, I spent way too long figuring out how to write plus/minus and square root. :-P