#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <algorithm>
#include <limits>
#include <vector>
using namespace std;
uint32_t Rand() {
static uint64_t x =
88172645463325252ULL ^ static_cast<uint64_t>(time(nullptr));
x = x ^ (x << 13); x = x ^ (x >> 7);
return static_cast<uint32_t>(x = x ^ (x << 17));
}
double Simulate(double leverage) {
double value = 1.0;
for (int i = 0; i < 250; i++) {
double rate = 1.00016;
if (Rand() % 2 == 0) {
rate *= 1.015;
} else {
rate /= 1.015;
}
value += leverage * value * (rate - 1);
}
return value;
}
int main() {
vector<double> result;
double sum = 0.0, count = 0.0;
for (int i = 0 ; i <= 1000000; i++) {
result.push_back(Simulate(1.2));
sum += result.back();
count++;
}
sort(result.begin(), result.end());
printf("Max: %.3f\n", result.back());
printf("Average: %.3f\n", sum / count);
printf("Median: %.3f\n", result[result.size() / 2]);
return 0;
}
I2luY2x1ZGUgPG1hdGguaD4KI2luY2x1ZGUgPHN0ZGludC5oPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHRpbWUuaD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGxpbWl0cz4KI2luY2x1ZGUgPHZlY3Rvcj4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnVpbnQzMl90IFJhbmQoKSB7CiAgc3RhdGljIHVpbnQ2NF90IHggPQogICAgICA4ODE3MjY0NTQ2MzMyNTI1MlVMTCBeIHN0YXRpY19jYXN0PHVpbnQ2NF90Pih0aW1lKG51bGxwdHIpKTsKICB4ID0geCBeICh4IDw8IDEzKTsgeCA9IHggXiAoeCA+PiA3KTsKICByZXR1cm4gc3RhdGljX2Nhc3Q8dWludDMyX3Q+KHggPSB4IF4gKHggPDwgMTcpKTsKfQoKZG91YmxlIFNpbXVsYXRlKGRvdWJsZSBsZXZlcmFnZSkgewogIGRvdWJsZSB2YWx1ZSA9IDEuMDsKICBmb3IgKGludCBpID0gMDsgaSA8IDI1MDsgaSsrKSB7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