With these inputs:
SPY Monthly Max Available
startDate 19940103
rate .0065 (happens to be close to 8% annual return)
You get these charts. One chart is log price axis, the other is non-log. The log chart is nearly identical to the Wikipedia S&P 500, best-fit logarithmic chart:
https://en.wikipedia.org/wiki/File:S&P_500_Index_Logarithmic_Chart_through_Jan_2021.svg
wiki states:
While S&P 500 data to linear plot scale is good for analysis of a span of 2 or 3 years, beyond that a logarithmic S&P 500 chart is best. This is because it gives the same Y or vertical displacement for a certain percentage move up or down regardless of date.
IMPORTANT:
Please note that this script does not calculate a best-fit line or curve (that's complicate math). The math here draws a curve based on a simple, non-linear equation with user inputted values. When the right values for the variables are chosen, the curve HAPPENS to match up with SPY for the past three decades.
Thank you To @halcyonguy code from here:
https://usethinkscript.com/threads/plot-curve-recursion-from-anchor-date.18616/
I tweaked a couple of things:
- modified the y calculation on the line starting "else if y[1] . . . . . ."
-changed a couple of variable names/input values
SPY Monthly Max Available
startDate 19940103
rate .0065 (happens to be close to 8% annual return)
You get these charts. One chart is log price axis, the other is non-log. The log chart is nearly identical to the Wikipedia S&P 500, best-fit logarithmic chart:
https://en.wikipedia.org/wiki/File:S&P_500_Index_Logarithmic_Chart_through_Jan_2021.svg
wiki states:
While S&P 500 data to linear plot scale is good for analysis of a span of 2 or 3 years, beyond that a logarithmic S&P 500 chart is best. This is because it gives the same Y or vertical displacement for a certain percentage move up or down regardless of date.
IMPORTANT:
Please note that this script does not calculate a best-fit line or curve (that's complicate math). The math here draws a curve based on a simple, non-linear equation with user inputted values. When the right values for the variables are chosen, the curve HAPPENS to match up with SPY for the past three decades.
Code:
#diaglinefromdate
def na = double.nan;
def bn = barnumber();
def date = getyyyymmdd();
input startDate = 20240305;
input price = close;
input rate = 0.005;
def y = if bn == 1 then 0
else if startDate == date then price
else if y[1] > 0 and !isnan(close) then y[1] + (y[1] * rate)
else 0;
plot z = if y > 0 then y else na;
#addverticalline(startDate == date, "-");
#
Thank you To @halcyonguy code from here:
https://usethinkscript.com/threads/plot-curve-recursion-from-anchor-date.18616/
I tweaked a couple of things:
- modified the y calculation on the line starting "else if y[1] . . . . . ."
-changed a couple of variable names/input values
Last edited by a moderator: