On Player retirement and why OKC won the Taylor trade
#Intro
Today, I saw my batsymbol in the sky, or more specifically in [this post](https://www.reddit.com/r/AmericanBasketballFed/comments/7u3m5v/royce_old_donte_taylor_traded_to_cavaliers_in/dthoan4/) by /u/CosmoTable2. To be precise, it was this sentence that had my spidey senses tingling:
> Perhaps someone knows the code so we could have an actual %?
Ok, enough with the superhero analogies. The topic at hand is simple, and very interesting - by what rules is player retirement determined, and what is the probability that a player will retire?
#Code
You can find the code that determines whether or not a player retires [here](https://github.com/dumbmatter/basketball-gm/blob/master/src/js/worker/core/phase.js), starting at line 400.
Basically, there is a set of rules that will make a player consider retirement, and then a function that will (randomly) determine whether a player will retire or not. I will give you both the requirements, as well as the probabilities of retirement below.
##Requirements for retirement
There are two reasons players consider retirement:
1. They are over 34 years old. [i.e. 35 or older] 2. They are currently without a contract.
##Special Edge Case
The simplest case is a player that ended the season as a free agent for two consecutive years. He will always retire. Age is irrelevant here, because he fulfills the second requirement.
##Retirement decision
Once a player has decided to consider retirement, there are two factors that will influence his decision:
1. His age 2. His potential
Retirement is a gaussian function (more info at [wikipedia](https://en.wikipedia.org/wiki/Gaussian_function)) with a mean of 0 and a standard deviation of 1. The code generates a random number using this, and if it is below 0, the player does not retire, if it is above 0, the player retires. A graphical representation of these probabilities (created using paint by yours truly) can be found [here](https://imgur.com/Y71H8gZ). The area underneath the blue line is the probability, left of the red line that a player will not retire, to the right of the red line that a player will retire. This would give a player a 50% chance of retiring, not including the two influencers mentioned above.
For each year older than 34 a player is, the code adds 0.05 to the result of the random number generation. Essentially what this does is move the red line from the illustration a little farther left [like so](https://imgur.com/NLCv3xQ), which means that a player is more likely to retire the older he is. The first retirement year already has this effect applied, since the player is already one year older than 34. A 35 year old player already has a 52% chance of retiring, not including the second influencer.
Less importantly than age is the players potential. This is for two reasons - The effect is more gradual, and a player with low potential will also have low values, so his retirement won't really be an issue for teams. For each point that a players potential is under 40, the code adds 0.02 to the result of the random number generation. The effect therefore is similar to the player age.
## Retirement probabilities
Here is a table of player ages and the likelyhood that they will retire that season, assuming their potential is 40 or more.
Age|Probability :--|:-- 35|52% 36|54% 37|56% 38|58% 39|60% 40|62% 41|64% 42|66% 43|67% 44|69%
...that was mildly disappointing. I guess the values are so small that the function looks as if it were linear, which it is absolutely not.
## Calculating your own probabilities
Step 1: Calculate the influence of age and potential using this simple step by step guide:
X=0
If age is greater than 34: X=X + (Age-34)*0.05
If potential is smaller than 40: X = X + (40-pot)*0.02
Step 2: Go to [this site](https://ncalculators.com/statistics/normal-distribution-calculator.htm), enter 0 as Mean, 1 as Standard Deviation, the X you calculated as X1, and click calculate. The result P(X<X1) is the probability that your player retires, the result P(X>X1) is the probability that he doesn't.
# Summary
A player who is 35 or older always has a probability of >50% that he will retire. This probability goes up every year.