Python Forum

Full Version: calculation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I want to make a script/program that makes the following:

enter end price,
enter starting price
enter number of years

and calculate - what is the average percentage of the overall years ? (like - how much percentage did the stock gained every year)...

for example - you got a stock XYZ - it started at 10$, ended at 100$ - after 10 years...(that's a 1000% gain). what i'm having trouble with is making the formula...cuz the gain, percentage wise - is exponential...it means the stock made less than 100% a year...

you know what i mean ?
I'm not a math wiz but, I think you will take year divided by end price (e.g. 10/100 = 0.1% gain per year) Hope it helps.
Output:
(1 + year_return) ** num_years = end_price/start_price
note the artificial assumptions - e.g. the exact number of years.
buran, didn't quite get (1 + year_return)
year_return is the average return per year in percent
Output:
year0 - start_price year1 - start_price*(1+year1_return) year2 - start_price*(1+year1_return)*(1+year2_return) .... year10 - start_price*(1+year1_return)*(1+year2_return)*...*(1+year10_return) == end_price
now, you want average return per year, so
start_price*(1+year_return)**n = end_price
(1+year_return)**n = end_price/start_price

now, calculate year_return :-)
can you give me an example ?

i'll try to give an example myself of what i mean:

suppose i have a stock trading at 10$, and every year it makes 30%, that means:

year0 - 10$
year1 - 13$
year2 - 16.9$
year3 - 21.97$

and so on...

what i wanna have is this hindsight of fixed percentage (when i give the parameters)
dude, come on, I gave you the formula, you have to write 3 lines of code.
I understand perfectly what you ask. year_return is the fixed percentage that you are looking for.
hehe, well i'm just not so good at math...

do i have to make a while loop ?
or a for loop ?

hehe, i feel so dumb
no loops at all

are you really telling me you cannot find year_return from
Output:
(1 + year_return) ** num_years = end_price/start_price
where you know num_years, end_price and start_price?

with your example
Output:
(1+year_return) ** 3 = 21.97 / 10
well, i went through the formula you gave me,
but what if at the end of the formula, instead of having end price - to have year_return,

how would that look ?

well what i mean is that year_return has to be isolated...

and i'm illiterate in math

well, i'd guess that the opposite of 'to the power of' is a root,

but i have no idea how to rearrange the components,

i trade stocks for a living, i've been trading for the last 19 years, since age 17,
but quit school early, like - i have 9 grades accomplished,

so all this math stuff is beyond me, you don't need much math in trading, just the simple arithmetic,

what can i do
Pages: 1 2