Ranking is a part of the game balancing system that keeps the game interesting even for the strongest and most advanced players. The amount of the ranking points added or deducted is calculated using a complex formula that takes in consideration the power of both the assaulter and the defender and many other attributes. This system has been rigorously tested and adjusted.
If you are constantly upgrading your units but rarely participate in Assaults or Tourneys, the system will try to speed up your ranking growth, and you will get more points for winning. In case you attack more often, the system will tend to lower your rank and give you less points for winning while taking more for losing.
Please keep in mind, that even if you lose a lot of ranking points after being attacked, the way the ranking system works you will still gain in rank with time.