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': 'Security Personnel',
'subcategories': ['salaries', 'benefits', 'training', 'recruitment']
},
'technology': {
'name': 'Security Technology',
'subcategories': ['software', 'hardware', 'licenses', 'maintenance']
},
'services': {
'name': 'Security Services',
'subcategories': ['consulting', 'outsourcing', 'cloud_services', 'support']
},
'infrastructure': {
'name': 'Infrastructure',
'subcategories': ['data_center', 'network', 'storage', 'backup']
},
'compliance': {
'name': 'Compliance',
'subcategories': ['audits', 'certifications', 'legal', 'regulatory']
}
}
self.budget_data = {}
self.allocations = {}
self.expenditures = {}
self.forecasts = {}
def create_budget(self, budget_id, fiscal_year, total_budget):
"""Create security budget"""
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):
"""Allocate budget by category"""
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'
}
# Update allocated budget
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):
"""Record expense"""
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'
}
# Update spent budget
self.budget_data[budget_id]['spent_budget'] += amount
return True
def calculate_budget_utilization(self, budget_id):
"""Calculate budget utilization"""
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):
"""Generate budget report"""
if budget_id not in self.budget_data:
return None
budget = self.budget_data[budget_id]
utilization = self.calculate_budget_utilization(budget_id)
# Group allocations by category
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']
# Group expenses by category
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):
"""Generate budget recommendations"""
recommendations = []
utilization = self.calculate_budget_utilization(budget_id)
if not utilization:
return recommendations
# Recommendations based on utilization
if utilization['allocation_rate'] < 80:
recommendations.append("Consider increasing budget allocation to maximize usage")
if utilization['spending_rate'] > 90:
recommendations.append("Budget almost exhausted, consider requesting additional funds")
if utilization['utilization_rate'] < 50:
recommendations.append("Low utilization of allocated budget, review projects")
# Recommendations based on categories
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"Review {category} allocation ({percentage:.1f}% of total)")
return recommendations
# Usage example
budget_mgmt = SecurityBudgetManagement()
# Create budget
budget_mgmt.create_budget('BUDGET-2025', 2025, 1000000)
# Allocate budget by categories
budget_mgmt.allocate_budget('BUDGET-2025', 'personnel', 'salaries', 400000, 'Security team salaries')
budget_mgmt.allocate_budget('BUDGET-2025', 'technology', 'software', 200000, 'Security software licenses')
budget_mgmt.allocate_budget('BUDGET-2025', 'services', 'consulting', 150000, 'Consulting services')
budget_mgmt.allocate_budget('BUDGET-2025', 'infrastructure', 'data_center', 150000, 'Data center infrastructure')
budget_mgmt.allocate_budget('BUDGET-2025', 'compliance', 'audits', 100000, 'Compliance audits')
# Record expenses
budget_mgmt.record_expenditure('BUDGET-2025', 'personnel', 'salaries', 50000, 'Q1 Salaries', 'N/A')
budget_mgmt.record_expenditure('BUDGET-2025', 'technology', 'software', 25000, 'SIEM License', 'Splunk')
# Generate report
report = budget_mgmt.generate_budget_report('BUDGET-2025')
print(f"Budget report: {report['utilization']['allocation_rate']:.1f}% allocated")
|