MNP01/tester.cpp
2018-03-18 21:31:48 +01:00

89 lines
2.2 KiB
C++

#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include "helpers.h"
#include "argh.h"
#include "common.h"
#include "simulator.h"
int main(int argc, const char* argv[])
{
argh::parser args;
args.add_params({ "s", "stock" });
args.add_params({ "m", "money" });
args.add_params({ "o", "output" });
args.parse(argc, argv);
std::string network, input, output;
args(1) >> network;
args(2, "") >> input;
args({"o", "output"}, "") >> output;
bool quiet = args[{"q", "quiet"}] && output.empty();
double start_money;
unsigned start_stock;
args({"s", "stock"}, 1000) >> start_stock;
args({"m", "money"}, 1000.) >> start_money;
std::function<double(const double&)> normalizer = [](const double& result) -> double { return erf(result); };
std::ifstream network_file(network, std::ios::in | std::ios::binary);
std::ifstream input_file;
std::ofstream output_file;
std::istream *in;
std::ostream *out;
if (!output.empty()) {
output_file.open(output);
out = &output_file;
} else {
out = &std::cout;
}
if (!input.empty()) {
input_file.open(input);
in = &input_file;
} else {
in = &std::cin;
}
current_decider decider(normalizer);
decider.load(network_file);
simulator sim(&decider, start_money, start_stock);
double price;
if(!quiet) *out << "x,price,decsion,money,stock" << std::endl;
for(int i = 0; *in >> price; i++) {
auto decision = sim.proceed(price);
if (!quiet) {
*out << i + 1 << ","
<< price << ","
<< decision << ","
<< sim.money << ","
<< sim.stock << std::endl;
}
}
auto wealth = sim.money + sim.stock * price;
auto start = start_money + sim.start_price * start_stock;
auto hodl = start_money + price * start_stock;
std::cout << "Koniec: "
<< wealth << " " << std::showpos
<< "S: "<< (wealth - start)*100 / (start) << "%, "
<< "H: "<< (wealth - hodl)*100 / (hodl) << "%"
<< std::noshowpos
<< std::endl;
/* decider.network.save(std::cout); */
}