-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrival.cpp
More file actions
76 lines (54 loc) · 2.32 KB
/
Copy pathArrival.cpp
File metadata and controls
76 lines (54 loc) · 2.32 KB
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
// Author: Alden Sahi
// Date: 07.25.2026
// Program Name: Arrival.h
// Program Description:
/*
- This is a class that enables the creation of arrival delay from Order initializaiton to when
it would theoretically reach the exhange.
- Utilizes Possion Distribution where lambda is dynamically sampled from a function based on
time of day.
*/
#include "Arrival.h"
#include <iostream>
#include <numbers>
#include <cmath>
Arrival::Arrival(double new_peak_lambda, double new_wavelength, double new_min_lambda) {
peak_lambda = new_peak_lambda;
wavelength = new_wavelength;
min_lambda = new_min_lambda;
}
void Arrival::set_lambda(double hours_from_open) {
// Computes lambda
double precise_lambda = peak_lambda * cos((2*std::numbers::pi / wavelength) * hours_from_open) + (peak_lambda + min_lambda);
// Sets Arrival Distributions Lambda
std::cout << "Lambda Set: " << std::round(precise_lambda) << "\n";
arrival_dist.param(std::poisson_distribution<int>::param_type(std::round(precise_lambda)));
}
double Arrival::get_norm_time(std::chrono::time_point<std::chrono::system_clock> utc_time) {
// NOTE:: Assumes exchange is wherever order is being placed *ENSURE LOCAL TIME IS WHERE EXHANGE IS*
using namespace std::chrono;
// Translates UTC to Local Timezone
zoned_time local_time{current_zone(), utc_time};
// Trancates HH_MM_SS from time
auto local_days = floor<days>(local_time.get_local_time());
// REMOVES YYYY_MM_DD from LocalTime to extract HH_MM__SS
hh_mm_ss time_of_day{local_time.get_local_time() - local_days};
//std::cout << time_of_day << "\n";
double hours_since_midnight = time_of_day.hours().count()
+ time_of_day.minutes().count() / 60.0
+ time_of_day.seconds().count() / (3600.0);
constexpr double market_open = 9.5; // 9:30am
constexpr double market_close = 17.0; // 5:00pm
if (hours_since_midnight < market_open || hours_since_midnight > market_close) {
throw std::invalid_argument("[get_norm_time] utc_time is outside market hours");
}
return hours_since_midnight - market_open;
}
int Arrival::get_orders_created_during_subinterval() {
// Ensure Lambda is current
set_lambda(get_norm_time());
// NOTE: UNSURE WHAT UNIT IS OUTPUT
return arrival_dist(gen);
}
/*
*/