-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.cpp
281 lines (261 loc) · 7.54 KB
/
events.cpp
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#include "events.h"
#include <memory>
#include "market.h"
void Events::inflation(const std::string& currencyName)
{
for (Currency* currency : currencies)
{
if (currency->getName() == currencyName)
{
double inflationRate = currency->getVolatility();
double newSupply = currency->getSupply() * (1 + inflationRate);
currency->setSupply(newSupply);
double newValue = currency->getDemand() / newSupply;
currency->setValue(newValue);
}
}
if (mkt) {
mkt->updateMakert();
mkt->displayMarket(actived);
}
setActived(true);
}
void Events::interestRate(const std::string& currencyGovernment)
{
for(Currency* currency : currencies)
{
if(currency->getGovernment() == currencyGovernment)
{
double demand = currency->getDemand();
double supply = currency->getSupply();
double volatility = currency->getVolatility();
double inflation = 0.04; // depois tenho que mudar pra deixar o valor da inflação dinamico nesta função
double economicGrowth = 0.02; // depois tenho que mudar pra deixar o valor do crescimento econômico dinamico nesta função
double interestRate = 0.01 * demand / supply + 0.02 * volatility + 0.0005 * inflation - 0.003 * economicGrowth;
}
}
if (mkt) {
mkt->updateMakert();
mkt->displayMarket(actived);
}
setActived(true);
}
void Events::publicDebt(const std::string& currencyGovernment, const std::string& currencyDebtGovernment, double debt)
{
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> dis(1.4, 2.4);
double randomFees = dis(gen);
Currency* governmentCurrency = nullptr;
Currency* debtCurrency = nullptr;
for(Currency* currency : currencies)
{
if(currency->getGovernment() == currencyGovernment)
{
governmentCurrency = currency;
}
else if (currency->getGovernment() == currencyDebtGovernment)
{
debtCurrency = currency;
}
if(governmentCurrency && debtCurrency)
{
break;
}
}
if(!governmentCurrency || !debtCurrency)
{
std::cerr << "Erro: Não foi possível encontrar as moedas especificadas." << std::endl;
}
if (debt > governmentCurrency->getDebt()) {
std::cerr << "voce nao pode pagar mais do que deve voce pagou apenas a sua divida." << std::endl;
debt = governmentCurrency->getDebt();
}
double convertCurrency = debt * governmentCurrency->getValue() / debtCurrency->getValue();
double newSupplyGovernment = debtCurrency->getSupply() + convertCurrency;
debtCurrency->setSupply(newSupplyGovernment);
double newCurrencySupply = governmentCurrency->getSupply() - convertCurrency;
governmentCurrency->setSupply(newCurrencySupply);
governmentCurrency->setDebt(0);
if (mkt) {
mkt->updateMakert();
mkt->displayMarket(actived);
}
setActived(true);
}
void Events::governmentLoan(const std::string& currencyGovernment, const std::string& currencyLoanGovernment, double loan)
{
Currency* governmentCurrency = nullptr;
Currency* loanCurrency = nullptr;
for (Currency* currency : currencies)
{
if (currency->getGovernment() == currencyGovernment)
{
governmentCurrency = currency;
}
else if (currency->getGovernment() == currencyLoanGovernment)
{
loanCurrency = currency;
}
if (governmentCurrency && loanCurrency)
{
break;
}
}
if (!governmentCurrency || !loanCurrency)
{
std::cerr << "Erro: Nao foi possível encontrar as moedas especificadas." << std::endl;
return;
}
if (loan > loanCurrency->getSupply()) {
std::cerr << "Erro: Nao e possivel emprestar mais do que voce tem!" << std::endl;
return;
}
double convertedLoan = loan * loanCurrency->getValue() / governmentCurrency->getValue();
double newSupplyGovernment = governmentCurrency->getSupply() + convertedLoan;
double newSupplyLoan = loanCurrency->getSupply() - loan;
governmentCurrency->setSupply(newSupplyGovernment);
governmentCurrency->setDebt(loan);
loanCurrency->setSupply(newSupplyLoan);
if (mkt) {
mkt->updateMakert();
mkt->displayMarket(actived);
}
setActived(true);
}
void Events::underDemand(const std::string& currencyGovernment)
{
for(Currency* currency : currencies)
{
if(currency->getGovernment() == currencyGovernment)
{
if (currency->getDemand() < currency->getSupply()) {
std::cerr << "a demanda ja e menor que a oferta" << std::endl;
if (mkt) {
mkt->updateMakert();
mkt->displayMarket(actived);
}
setActived(true);
return;
}
if (currency->getDemand() > currency->getSupply()) {
double underDemand = floor(currency->getDemand() - currency->getSupply() * 0.9);
double newDemand = currency->getDemand() - underDemand;
currency->setDemand(newDemand);
currency->setValue(newDemand);
if (mkt) {
mkt->updateMakert();
mkt->displayMarket(actived);
}
setActived(true);
return;
}
double demandShock = currency->getSupply() * 0.1;
double newDemand = currency->getDemand() - demandShock;
currency->setDemand(newDemand);
double newValue = currency->getDemand() / currency->getSupply();
currency->setValue(newValue);
std::cout << newValue << std::endl;
}
else
{
std::cout << "Currency not found" << std::endl;
}
}
if (mkt) {
mkt->updateMakert();
mkt->displayMarket(actived);
}
setActived(true);
}
void Events::overDemand(const std::string& currencyGovernment)
{
for(Currency* currency : currencies)
{
if(currency->getGovernment() == currencyGovernment)
{
if (currency->getDemand() > currency->getSupply()) {
std::cerr << "demanda ja e maior que a oferta" << std::endl;
if (mkt) {
mkt->updateMakert();
mkt->displayMarket(actived);
}
setActived(true);
return;
}
double overDemand = currency->getSupply() * 0.1;
double newDemand = currency->getSupply() + overDemand;
currency->setDemand(newDemand);
double newValue = currency->getDemand() / currency->getSupply();
currency->setValue(newDemand);
}
}
if (mkt) {
mkt->updateMakert();
mkt->displayMarket(actived);
}
setActived(true);
}
void Events::overSupply(const std::string& currencyGovernment) {
for (Currency* currency : currencies) {
if (currency->getGovernment() == currencyGovernment) {
if (currency->getSupply() > currency->getDemand()) {
std::cerr << "a oferta ja e maior que a demanda" << std::endl;
if (mkt) {
mkt->updateMakert();
mkt->displayMarket(actived);
}
setActived(true);
return;
}
double overSupply = currency->getDemand() * 0.1;
double newSupply = currency->getDemand() + overSupply;
currency->setSupply(newSupply);
currency->setValue(overSupply);
}
}
if (mkt) {
mkt->updateMakert();
mkt->displayMarket(actived);
}
setActived(true);
}
void Events::underSupply(const std::string& currencyGovernment)
{
for (Currency* currency : currencies)
{
if (currency->getGovernment() == currencyGovernment)
{
if (currency->getSupply() < currency->getDemand()) {
std::cerr << "a oferta ja e menor que a demanda" << std::endl;
if (mkt) {
mkt->updateMakert();
mkt->displayMarket(actived);
}
setActived(true);
return;
}
if (currency->getSupply() > currency->getDemand()) {
double underSupply = floor(currency->getSupply() - currency->getDemand()* 0.9);
double newSupply = currency->getSupply() - underSupply;
currency->setSupply(newSupply);
currency->setValue(newSupply);
if (mkt) {
mkt->updateMakert();
mkt->displayMarket(actived);
}
setActived(true);
return;
}
double underSupply = currency->getDemand() * 0.1;
double newSupply = currency->getSupply() - underSupply;
currency->setSupply(newSupply);
currency->setValue(newSupply);
}
}
if (mkt) {
mkt->updateMakert();
mkt->displayMarket(actived);
}
setActived(true);
}