Ausgabe der geschätzten IRR
In diesem letzten Schritt erweitern wir unser IRR-Berechnungsprogramm, um detailliertere Ausgaben zu liefern und verschiedene Investitionsszenarien zu demonstrieren.
Ändern wir unsere bestehende C-Datei, um eine umfassendere IRR-Analyse hinzuzufügen:
cd ~/project
nano irr_calculation.c
Aktualisieren Sie den Code mit zusätzlichen Ausgaben und Analysen:
#include <stdio.h>
#include <math.h>
#define MAX_CASH_FLOWS 10
#define EPSILON 0.0001
double calculate_npv(double cash_flows[], int num_cash_flows, double rate) {
double npv = 0.0;
for (int i = 0; i < num_cash_flows; i++) {
npv += cash_flows[i] / pow(1 + rate, i);
}
return npv;
}
double find_irr(double cash_flows[], int num_cash_flows) {
double rate_low = -0.9;
double rate_high = 10.0;
double rate = 0.1;
while ((rate_high - rate_low) > EPSILON) {
double npv = calculate_npv(cash_flows, num_cash_flows, rate);
if (fabs(npv) < EPSILON) {
return rate;
}
if (npv > 0) {
rate_low = rate;
} else {
rate_high = rate;
}
rate = (rate_low + rate_high) / 2.0;
}
return rate;
}
void print_investment_analysis(double cash_flows[], int num_cash_flows, double irr) {
double total_investment = 0;
double total_returns = 0;
printf("\n--- Investitionsanalyse ---\n");
// Detaillierte Aufschlüsselung der Cashflows
for (int i = 0; i < num_cash_flows; i++) {
printf("Periode %d: $%.2f\n", i, cash_flows[i]);
if (cash_flows[i] < 0) {
total_investment += fabs(cash_flows[i]);
} else {
total_returns += cash_flows[i];
}
}
// Investitionsübersicht
printf("\nGesamtinvestition: $%.2f\n", total_investment);
printf("Gesamterträge: $%.2f\n", total_returns);
printf("Nettogewinn: $%.2f\n", total_returns - total_investment);
// IRR-Details
printf("\nInterne Rendite (IRR):\n");
printf("Dezimalwert: %.4f\n", irr);
printf("Prozentwert: %.2f%%\n", irr * 100);
// Interpretation der Investitionsleistung
if (irr > 0.15) {
printf("\nInvestitionsleistung: Ausgezeichnet\n");
} else if (irr > 0.10) {
printf("\nInvestitionsleistung: Gut\n");
} else if (irr > 0) {
printf("\nInvestitionsleistung: Mittel\n");
} else {
printf("\nInvestitionsleistung: Schlecht\n");
}
}
int main() {
double cash_flows[MAX_CASH_FLOWS];
int num_cash_flows;
printf("Geben Sie die Anzahl der Cashflows ein (max %d): ", MAX_CASH_FLOWS);
scanf("%d", &num_cash_flows);
printf("Geben Sie die Cashflows ein (negativ für Investitionen, positiv für Erträge):\n");
for (int i = 0; i < num_cash_flows; i++) {
printf("Cashflow %d: ", i);
scanf("%lf", &cash_flows[i]);
}
double irr = find_irr(cash_flows, num_cash_flows);
print_investment_analysis(cash_flows, num_cash_flows, irr);
return 0;
}
Kompilieren Sie das Programm:
gcc irr_calculation.c -o irr_calculation -lm
Führen Sie das Programm mit einem Beispiel-Investitionsszenario aus:
./irr_calculation
Beispielausgabe:
Geben Sie die Anzahl der Cashflows ein (max 10): 4
Geben Sie die Cashflows ein (negativ für Investitionen, positiv für Erträge):
Cashflow 0: -1000
Cashflow 1: 300
Cashflow 2: 400
Cashflow 3: 500
--- Investitionsanalyse ---
Periode 0: $-1000.00
Periode 1: $300.00
Periode 2: $400.00
Periode 3: $500.00
Gesamtinvestition: $1000.00
Gesamterträge: $1200.00
Nettogewinn: $200.00
Interne Rendite (IRR):
Dezimalwert: 0.2154
Prozentwert: 21.54%
Investitionsleistung: Ausgezeichnet
Erklärung
- Die Funktion
print_investment_analysis()
wurde hinzugefügt, um umfassendere Ausgaben zu liefern.
- Berechnet Gesamtinvestition, Erträge und Nettogewinn.
- Interpretiert die IRR-Leistung mit beschreibenden Kategorien.
- Bietet eine detaillierte Aufschlüsselung der Cashflows und Investitionskennzahlen.