MNP01/tester.cpp
Kacper Donat 72fb76e8c2 WTF
2018-03-13 23:25:41 +01:00

66 lines
1.8 KiB
C++

#include <iostream>
#include <fstream>
#include <algorithm>
#include "helpers.h"
#include "argh.h"
#include "common.h"
int main(int argc, const char* argv[])
{
argh::parser args;
args.add_params({ "s", "stock" });
args.add_params({ "m", "money" });
args.parse(argc, argv);
std::string network, input;
args(1) >> network;
args(2) >> input;
double money;
unsigned stock;
args({"s", "stock"}, 1000) >> stock;
args({"m", "money"}, 1000.) >> money;
std::function<double(const double&)> normalizer = [](const double& result) -> double { return erf(result); };
current_decider decider(normalizer);
std::ifstream network_file(network, std::ios::in | std::ios::binary);
std::ifstream input_file(input);
decider.load(network_file);
double price;
decider.start_money = money;
decider.start_stock = stock;
std::cout << "x,price,decsion,money,stock" << std::endl;
for (int i = 0; input_file >> price; i++) {
auto decision = decider.decide(price, money, stock);
auto current = price * stock + money;
auto max_credit = std::max(current * 0.05, -1e4);
if (decision < 0) {
decision = std::max<int>(decision, -stock); // cannot sell more than we actually have
} else if (decision > 0) {
decision = std::min<int>(floor((money + max_credit) / price), decision);
}
money -= price * decision;
stock += decision;
/* std::cout */
/* << i << "," */
/* << price << "," */
/* << decision << "," */
/* << money << "," */
/* << stock */
/* << std::endl; */
}
std::cout << "Koniec: " << money + stock*price;
/* decider.network.save(std::cout); */
}