print ("This program will calculate the Logarithmic Rate of Return.")
import math
### Formula for calculating the Logarithmic Rate of Return:
# LogarithmicRateOfReturn = (Natural Log(FinalValue/InitialValue))/TimeLength
# Find the natural log:
# NaturalLogOfFraction = math.log(variable)
###########################################
# Enter the FinalValue, InitialValue, TimeLength
def SolveForLogarithmicRateOfReturn():
print ("Solving for the Logarithmic Rate of Return.")
# Enter the FinalValue
FinalValue = float(input("Enter the Final Value: ") )
# Enter the InitialValue
InitialValue = float(input("Enter the Initial Value: ") )
# Enter the TimeLength
TimeLength = float(input("Enter the Time Length: ") )
# Calculate the fraction
Fraction = (FinalValue/InitialValue)
print("The fraction is: ", Fraction)
# Calculate the natural log
NaturalLog = (math.log(Fraction) )
print("The Natural Log is: ", NaturalLog)
# Calculate the Logarithmic Rate of Return
LogarithmicRateOfReturn = NaturalLog/TimeLength
print ("The logarithmic rate of return is: ", LogarithmicRateOfReturn)
ContinueCalculations = "y"
# Check to see if the user wants to continue to calculate the Logarithmic Rate of Return
while (ContinueCalculations=="y"):
SolveForLogarithmicRateOfReturn()
ContinueCalculations = input("Would like to do another calculation for the Logarithmic Rate of Return? (y/n): ")
print("==================================")
print ("Thank you to www.fxsolver.com for assistance with this formula.")