Python Geometric Mean & Geometric Mean Rate of Return

preview_player
Показать описание
***After completion of this tutorial, I noticed a few ways the function for the geometric mean rate of return could be improved. You will see notes for these improvements placed throughout the tutorial.***

Four Steps To Create Function:
1. convert values (per period returns) to per period return relatives by adding 1 to each value
2. multiply all values together (per period return relatives)
3. compute the nth root of the product
4. subtract 1

# geometric mean rate of return function with changes - see below:
def geomean_return(*numbers):
# set product to 1 outside the for loop
product = 1
for i in numbers:
# pprr is the per period return relative
pprr = i + 1
product *= pprr
decimal_answer = product ** (1/len(numbers))-1
percent_answer = decimal_answer * 100
return 'decimal = {}, percent = {}'.format(decimal_answer, round(percent_answer, 4))
Рекомендации по теме
Комментарии
Автор

Please see the description for this tutorial. There are notes regarding how the geometric mean rate of return function can be improved.

RyanNoonan