tcollar.py

Created by matthieumorvant

Created on February 09, 2024

2.43 KB


def calculer_COLLAR(montant_emprunt, taux_plafond, prime_cap, taux_plancher, prime_floor, hypotheses):
    # Calcul des primes
    prime_payee_cap = prime_cap * montant_emprunt
    prime_encaissee_floor = prime_floor * montant_emprunt
    prime_nette = prime_encaissee_floor - prime_payee_cap

    # Affichage des primes
    print("\nPrime payée pour le CAP: {:.2f} € (Calcul: {:.2%} * {:.2f} €)".format(prime_payee_cap, prime_cap, montant_emprunt))
    print("Prime encaissée pour la vente du FLOOR: {:.2f} € (Calcul: {:.2%} * {:.2f} €)".format(prime_encaissee_floor, prime_floor, montant_emprunt))
    print("Prime nette {}: {:.2f} €".format("payée" if prime_nette > 0 else "reçue", abs(prime_nette)))

    # Traitement de chaque hypothèse
    for i, tam in enumerate(hypotheses, 1):
        print("\nHypothèse {} - TAM: {:.2%}".format(i, tam))

        if tam > taux_plafond:
            # Différentiel reçu pour le CAP
            differentiel_cap = montant_emprunt * (tam - taux_plafond)
            print("Différentiel reçu (CAP): {:.2f} €".format(differentiel_cap))
            print("Calcul: {:.2f} € * ({:.2%} - {:.2%}) = {:.2f} €".format(montant_emprunt, tam, taux_plafond, differentiel_cap))
        else:
            print("Aucun différentiel reçu pour le CAP")

        if tam < taux_plancher:
            # Différentiel à payer pour la vente du FLOOR
            differentiel_floor = montant_emprunt * (taux_plancher - tam)
            print("Différentiel à payer (vente du FLOOR): {:.2f} €".format(differentiel_floor))
            print("Calcul: {:.2f} € * ({:.2%} - {:.2%}) = {:.2f} €".format(montant_emprunt, taux_plancher, tam, differentiel_floor))
        else:
            print("Aucun différentiel à payer pour la vente du FLOOR")

# Paramètres d'entrée
montant_emprunt = float(input("Montant de l'emprunt : "))
taux_plafond = float(input("Taux plafond pour le CAP (%) : ")) / 100
prime_cap = float(input("Prime du CAP (%) : ")) / 100
taux_plancher = float(input("Taux plancher pour la vente du FLOOR (%) : ")) / 100
prime_floor = float(input("Prime de la vente du FLOOR (%) : ")) / 100
nombre_hypotheses = int(input("Nombre d'hypothèses : "))

hypotheses = []
for _ in range(nombre_hypotheses):
    tam = float(input("Taux d'intérêt variable (TAM) pour l'hypothèse (%) : ")) / 100
    hypotheses.append(tam)

# Exécution du calcul
calculer_COLLAR(montant_emprunt, taux_plafond, prime_cap, taux_plancher, prime_floor, hypotheses)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.