How rating can be calculated and rating calculated to external contests too?
the ratings for external contests are not calculated…
You can read this blog on how CodeChef calculates its ratings.
Ratings depends on your performance(rank) in a contest and your previous rating. If you rank better than expected rank for your rating, your rating increases more. If it is somewhere around the expected rank, it increases little.
Codechef gives ratings only to monthly long challenge, short challenge and lunch time challenge. It doesn’t calculate ratings for external contests.