import math


def compute_annual_share_score(tree):
    """
    Computes the share score of given data

        :param tree: data from which compute the score
        :return: share score value, or NaN if it cannot be computed
    """
    # Retrieve needed values
    participation = tree['children']['ParticipationSalariesAuxResultats']['data']['value']
    impot = tree['children']['ImpotsSurLesBenefices']['data']['value']
    resultat_financier = tree['children']['ResultatExceptionnel']['data']['value']
    resultat_exceptionnel = tree['children']['ResultatAvantImpot']['children']['ResultatFinancier']['data']['value']
    resultat_exploitation = tree['children']['ResultatAvantImpot']['children']['ResultatExploitation']['data']['value']

    # If any values unknown, cannot compute score
    if any(math.isnan(value) for value in [participation, impot, resultat_financier, resultat_exceptionnel, resultat_exploitation]):
        return float('nan')

    # Compute score if possible
    shared_part = participation + impot
    resultat_capitaux = resultat_financier + resultat_exceptionnel
    if shared_part >= 0:
        if resultat_capitaux <= 0 and resultat_exploitation != 0:
            return shared_part / resultat_exploitation

    return float('nan')