/* ARGSUSED */ static void Redisplay( Widget gw, XEvent *event, Region region) { draw_it ((LoginWidget) gw); }
int main(int argc, char ** argv) { int sims = 1; double dt = 0.5; double drift = 0.2; double vol = 0.3; double jump = 0.0; double mean_jump_per_unit_time = 0.1; if (argc == 1) { std::cout << "usage:\n\tsims = " << sims << "\tdt = " << dt << "\tdrift = " << drift << "\tvol = " << vol << "\n\tjump = " << jump << "\tjump probability = " << mean_jump_per_unit_time << "\n"; return -1; } if (argc >= 2) { try { sims = std::stoi(argv[1]); if (sims < 1) { std::cout << "sims must be positive.\n"; return 1; } } catch(const std::exception &) { //I feel bad... } } dt = get_value(argc, const_cast<const char **>(argv), 2, dt); drift = get_value(argc, const_cast<const char **>(argv), 3, dt); vol = get_value(argc, const_cast<const char **>(argv), 4, dt); jump = get_value(argc, const_cast<const char **>(argv), 5, dt); if (argc >= 7) { try { //not jump prob mean_jump_per_unit_time = std::stof(argv[6]); if (mean_jump_per_unit_time == 0.0) { //ok, bad mean_jump_per_unit_time = 1; jump = 0; if (jump != 0.0) std::cout << "WARNING - work round jump\n"; } } catch(const std::exception &) { //I feel bad... } } std::vector<std::vector<sf::Vertex>> allPoints; float time = 4.0f; float final_height = 0.0; int out = 0; const float height = 400.0f; for (int i=0; i<sims; ++i) { unsigned int seed = std::chrono::high_resolution_clock::now().time_since_epoch().count() + i; auto sim = price_demo(seed, drift, vol, time, dt, jump, mean_jump_per_unit_time); allPoints.push_back(sim); auto price = sim.back().position.y; final_height += price; if (price > height) ++out; } std::cout << "average " << final_height/sims << "\nnumber out " << out << '\n';; std::stringstream title; title << "Stock prices. sims = " << sims << ", dt = " << dt << ", drift " << drift << ", vol " << vol << ", dt " << dt << ", jump size " << jump << ", mean jumps " << mean_jump_per_unit_time; draw_it(allPoints, time, height, title.str()); }