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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
| import pandas as pd
import numpy as np
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
class SecurityBudgetManagement:
def __init__(self):
self.budget_categories = {
'personnel': {
'name': 'Personal de Seguridad',
'subcategories': ['salaries', 'benefits', 'training', 'recruitment']
},
'technology': {
'name': 'Tecnología de Seguridad',
'subcategories': ['software', 'hardware', 'licenses', 'maintenance']
},
'services': {
'name': 'Servicios de Seguridad',
'subcategories': ['consulting', 'outsourcing', 'cloud_services', 'support']
},
'infrastructure': {
'name': 'Infraestructura',
'subcategories': ['data_center', 'network', 'storage', 'backup']
},
'compliance': {
'name': 'Cumplimiento',
'subcategories': ['audits', 'certifications', 'legal', 'regulatory']
}
}
self.budget_data = {}
self.allocations = {}
self.expenditures = {}
self.forecasts = {}
def create_budget(self, budget_id, fiscal_year, total_budget):
"""Crear presupuesto de seguridad"""
self.budget_data[budget_id] = {
'budget_id': budget_id,
'fiscal_year': fiscal_year,
'total_budget': total_budget,
'allocated_budget': 0,
'spent_budget': 0,
'remaining_budget': total_budget,
'created_date': datetime.now(),
'status': 'active'
}
def allocate_budget(self, budget_id, category, subcategory, amount, justification):
"""Asignar presupuesto por categoría"""
if budget_id not in self.budget_data:
return False
allocation_key = f"{budget_id}_{category}_{subcategory}"
self.allocations[allocation_key] = {
'budget_id': budget_id,
'category': category,
'subcategory': subcategory,
'amount': amount,
'justification': justification,
'allocated_date': datetime.now(),
'status': 'allocated'
}
# Actualizar presupuesto asignado
self.budget_data[budget_id]['allocated_budget'] += amount
self.budget_data[budget_id]['remaining_budget'] -= amount
return True
def record_expenditure(self, budget_id, category, subcategory, amount, description, vendor):
"""Registrar gasto"""
if budget_id not in self.budget_data:
return False
expenditure_id = f"EXP-{len(self.expenditures) + 1}"
self.expenditures[expenditure_id] = {
'expenditure_id': expenditure_id,
'budget_id': budget_id,
'category': category,
'subcategory': subcategory,
'amount': amount,
'description': description,
'vendor': vendor,
'expenditure_date': datetime.now(),
'status': 'approved'
}
# Actualizar presupuesto gastado
self.budget_data[budget_id]['spent_budget'] += amount
return True
def calculate_budget_utilization(self, budget_id):
"""Calcular utilización del presupuesto"""
if budget_id not in self.budget_data:
return None
budget = self.budget_data[budget_id]
utilization = {
'total_budget': budget['total_budget'],
'allocated_budget': budget['allocated_budget'],
'spent_budget': budget['spent_budget'],
'remaining_budget': budget['remaining_budget'],
'allocation_rate': (budget['allocated_budget'] / budget['total_budget'] * 100) if budget['total_budget'] > 0 else 0,
'spending_rate': (budget['spent_budget'] / budget['total_budget'] * 100) if budget['total_budget'] > 0 else 0,
'utilization_rate': (budget['spent_budget'] / budget['allocated_budget'] * 100) if budget['allocated_budget'] > 0 else 0
}
return utilization
def generate_budget_report(self, budget_id):
"""Generar reporte de presupuesto"""
if budget_id not in self.budget_data:
return None
budget = self.budget_data[budget_id]
utilization = self.calculate_budget_utilization(budget_id)
# Agrupar asignaciones por categoría
category_allocations = {}
for allocation in self.allocations.values():
if allocation['budget_id'] == budget_id:
category = allocation['category']
if category not in category_allocations:
category_allocations[category] = 0
category_allocations[category] += allocation['amount']
# Agrupar gastos por categoría
category_expenditures = {}
for expenditure in self.expenditures.values():
if expenditure['budget_id'] == budget_id:
category = expenditure['category']
if category not in category_expenditures:
category_expenditures[category] = 0
category_expenditures[category] += expenditure['amount']
report = {
'budget_id': budget_id,
'fiscal_year': budget['fiscal_year'],
'utilization': utilization,
'category_allocations': category_allocations,
'category_expenditures': category_expenditures,
'recommendations': self.generate_budget_recommendations(budget_id)
}
return report
def generate_budget_recommendations(self, budget_id):
"""Generar recomendaciones de presupuesto"""
recommendations = []
utilization = self.calculate_budget_utilization(budget_id)
if not utilization:
return recommendations
# Recomendaciones basadas en utilización
if utilization['allocation_rate'] < 80:
recommendations.append("Considerar aumentar la asignación de presupuesto para maximizar el uso")
if utilization['spending_rate'] > 90:
recommendations.append("Presupuesto casi agotado, considerar solicitar fondos adicionales")
if utilization['utilization_rate'] < 50:
recommendations.append("Baja utilización del presupuesto asignado, revisar proyectos")
# Recomendaciones basadas en categorías
category_allocations = {}
for allocation in self.allocations.values():
if allocation['budget_id'] == budget_id:
category = allocation['category']
if category not in category_allocations:
category_allocations[category] = 0
category_allocations[category] += allocation['amount']
total_allocated = sum(category_allocations.values())
if total_allocated > 0:
for category, amount in category_allocations.items():
percentage = (amount / total_allocated) * 100
if percentage > 40:
recommendations.append(f"Revisar asignación de {category} ({percentage:.1f}% del total)")
return recommendations
# Ejemplo de uso
budget_mgmt = SecurityBudgetManagement()
# Crear presupuesto
budget_mgmt.create_budget('BUDGET-2025', 2025, 1000000)
# Asignar presupuesto por categorías
budget_mgmt.allocate_budget('BUDGET-2025', 'personnel', 'salaries', 400000, 'Salarios del equipo de seguridad')
budget_mgmt.allocate_budget('BUDGET-2025', 'technology', 'software', 200000, 'Licencias de software de seguridad')
budget_mgmt.allocate_budget('BUDGET-2025', 'services', 'consulting', 150000, 'Servicios de consultoría')
budget_mgmt.allocate_budget('BUDGET-2025', 'infrastructure', 'data_center', 150000, 'Infraestructura de centro de datos')
budget_mgmt.allocate_budget('BUDGET-2025', 'compliance', 'audits', 100000, 'Auditorías de cumplimiento')
# Registrar gastos
budget_mgmt.record_expenditure('BUDGET-2025', 'personnel', 'salaries', 50000, 'Salarios Q1', 'N/A')
budget_mgmt.record_expenditure('BUDGET-2025', 'technology', 'software', 25000, 'Licencia SIEM', 'Splunk')
# Generar reporte
report = budget_mgmt.generate_budget_report('BUDGET-2025')
print(f"Reporte de presupuesto: {report['utilization']['allocation_rate']:.1f}% asignado")
|