Each Graha and the Lagna will occupy a Shastiamsa depending on the exact degree of minutes it occupies. To determine the Shastiamsa index, you need convert the longitude into minutes and divide it by 30. Whatever value you get in decimals, round it up to the next whole number. If the Graha occupies an Even Sign, then you need to count the index starting from the Rasi (occupied by the Graha) in zodiacal direction. If the Graha occupies an Even Sign, then you need to count the index in the Anti-zodiacal direction. You can find this in any standard Jyotish book.