calculate index functin