You can use the loop_start and loop_end hooks. See the example below.
function myFunction() {
//do something
}
add_action('loop_start', 'myFunction'); //Call your function before the loop
add_action('loop_end', 'myFunction'); //Call your function after the loop
You can also check for the home page using is_home() function inside myFunction().
Hope this helps.