-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.c
More file actions
109 lines (96 loc) · 3.6 KB
/
table.c
File metadata and controls
109 lines (96 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char symbol[20];
float pe_ratio;
float roe;
float debt_to_equity;
float free_cash_flow;
float profit_margin;
float promoter_holding;
float pledged_shares;
} Stock;
void print_ideal_table() {
printf("\n| Parameter | Ideal Condition |\n");
printf("| ---------------- | ---------------------------------- |\n");
printf("| EPS Growth | Positive, stable, >10%% YoY |\n");
printf("| P/E Ratio | Below industry average (for value) |\n");
printf("| ROE | >15%% |\n");
printf("| D/E Ratio | <0.5 (for safety) |\n");
printf("| FCF | Positive and growing |\n");
printf("| Promoter Holding | >50%% |\n");
printf("| Pledged Shares | <5%% |\n");
printf("| Revenue Growth | Steady upward trend |\n");
printf("| Dividend Yield | >1–2%% (for mature companies) |\n");
}
void analyze_stock(Stock s) {
int red_flags = 0;
printf("\n🔍 Analyzing Stock: %s\n", s.symbol);
printf("---------------------------------\n");
// Print all stock parameters first
printf("symbol = %s\n", s.symbol);
printf("pe_ratio = %.2f\n", s.pe_ratio);
printf("roe = %.2f\n", s.roe);
printf("debt_to_equity = %.2f\n", s.debt_to_equity);
printf("free_cash_flow = %.2f\n", s.free_cash_flow);
printf("profit_margin = %.2f\n", s.profit_margin);
printf("promoter_holding = %.2f\n", s.promoter_holding);
printf("pledged_shares = %.2f\n", s.pledged_shares);
// Print ideal condition table
print_ideal_table();
printf("\n---------------------------------\n");
printf("🔎 Checking for Red Flags:\n");
// Apply rules
if (s.pe_ratio > 40) {
printf("⚠️ High P/E Ratio (%.2f)\n", s.pe_ratio);
red_flags++;
}
if (s.roe < 10) {
printf("⚠️ Low Return on Equity (%.2f%%)\n", s.roe);
red_flags++;
}
if (s.debt_to_equity > 1) {
printf("⚠️ High Debt-to-Equity Ratio (%.2f)\n", s.debt_to_equity);
red_flags++;
}
if (s.free_cash_flow < 0) {
printf("⚠️ Negative Free Cash Flow (%.2f)\n", s.free_cash_flow);
red_flags++;
}
if (s.profit_margin < 0.05) {
printf("⚠️ Low Profit Margin (%.2f%%)\n", s.profit_margin * 100);
red_flags++;
}
if (s.promoter_holding < 50) {
printf("⚠️ Low Promoter Holding (%.2f%%)\n", s.promoter_holding);
red_flags++;
}
if (s.pledged_shares > 5) {
printf("⚠️ High Pledged Shares (%.2f%%)\n", s.pledged_shares);
red_flags++;
}
printf("---------------------------------\n");
if (red_flags == 0)
printf("✅ %s looks financially strong!\n", s.symbol);
else
printf("❌ %s has %d red flag(s)\n", s.symbol, red_flags);
}
int main() {
Stock s;
FILE *f = fopen("stock_data.txt", "r");
if (!f) {
perror("Error opening stock_data.txt");
return 1;
}
fscanf(f, "symbol = %s\n", s.symbol);
fscanf(f, "pe_ratio = %f\n", &s.pe_ratio);
fscanf(f, "roe = %f\n", &s.roe);
fscanf(f, "debt_to_equity = %f\n", &s.debt_to_equity);
fscanf(f, "free_cash_flow = %f\n", &s.free_cash_flow);
fscanf(f, "profit_margin = %f\n", &s.profit_margin);
fscanf(f, "promoter_holding = %f\n", &s.promoter_holding);
fscanf(f, "pledged_shares = %f\n", &s.pledged_shares);
fclose(f);
analyze_stock(s);
return 0;
}