153 const auto usd = market.insert_node(
"USD");
154 const auto eur = market.insert_node(
"EUR");
155 const auto gbp = market.insert_node(
"GBP");
156 const auto jpy = market.insert_node(
"JPY");
159 const auto trade = [&market] (Market::Node *from, Market::Node *to,
const string & name,
162 return market.insert_arc(from, to, Trade{name, exact_rate(rate)});
164 const auto eurusd_sell_arc = trade(eur, usd,
"EURUSD sell",
"10850/10000");
165 const auto eurusd_buy_arc = trade(usd, eur,
"EURUSD buy",
"10000/10852");
166 trade(gbp, usd,
"GBPUSD sell",
"12700/10000");
167 trade(usd, gbp,
"GBPUSD buy",
"10000/12703");
168 const auto eurgbp_sell_arc = trade(eur, gbp,
"EURGBP sell",
"8540/10000");
169 trade(gbp, eur,
"EURGBP buy",
"10000/8543");
170 trade(usd, jpy,
"USDJPY sell",
"15000/100");
171 trade(jpy, usd,
"USDJPY buy",
"100/15003");
172 trade(eur, jpy,
"EURJPY sell",
"16270/100");
173 trade(jpy, eur,
"EURJPY buy",
"100/16275");
178 const View view(market);
179 Index index(view, {2, 3, 4}, [] (
const Market::Arc *a,
const Market::Arc *b)
181 return a->get_info().name < b->get_info().name;
184 cout <<
"Arcs: " << index.num_arcs() <<
"; cycles: " << index.num_cycles() <<
" ("
185 << index.num_cycles(2) <<
" of 2 arcs, " << index.num_cycles(3) <<
" of 3, "
186 << index.num_cycles(4) <<
" of 4)\n";
187 const size_t eurusd_sell = index.arc_number(eurusd_sell_arc);
188 const size_t eurusd_buy = index.arc_number(eurusd_buy_arc);
189 cout <<
"Arc " << eurusd_sell <<
" is \"" << index.arc(eurusd_sell)->get_info().name
190 <<
"\", in " << index.cycles_of(eurusd_sell).size() <<
" cycles\n\n";
195 for (
size_t a = 0; a < index.num_arcs(); ++a)
196 index.set_weight(a, weight_of(index.arc(a)->get_info().rate));
197 Decide decide{view, index};
198 cout <<
"With the first quotes:\n";
199 const size_t all = index.for_each_cycle_below(Margin, 4, decide);
200 cout <<
" " <<
all <<
" cycles looked at, " << decide.candidates <<
" candidates, "
201 << decide.profitable <<
" profitable\n\n";
205 const auto quote = [&] (
const char *bid,
const char *ask_inverse)
207 eurusd_sell_arc->get_info().rate = exact_rate(bid);
208 eurusd_buy_arc->get_info().rate = exact_rate(ask_inverse);
209 index.set_weight(eurusd_sell, weight_of(eurusd_sell_arc->get_info().rate));
210 index.set_weight(eurusd_buy, weight_of(eurusd_buy_arc->get_info().rate));
211 decide.candidates = decide.profitable = 0;
212 const size_t seen = index.for_each_cycle_below({eurusd_sell, eurusd_buy}, Margin, 4, decide);
213 cout <<
" " << seen <<
" cycles looked at, " << decide.candidates <<
" candidates, "
214 << decide.profitable <<
" profitable\n\n";
216 cout <<
"EURUSD rises to 1.0880 / 1.0882:\n";
217 quote(
"10880/10000",
"10000/10882");
219 cout <<
"EURUSD falls back to 1.0850 / 1.0852:\n";
220 quote(
"10850/10000",
"10000/10852");
223 const size_t eurgbp_sell = index.arc_number(eurgbp_sell_arc);
224 eurgbp_sell_arc->get_info().rate = exact_rate(
"8600/10000");
225 cout <<
"EURGBP sell at 0.8600:\n";
226 decide.candidates = decide.profitable = 0;
227 const uint64_t before = index.clock();
228 const size_t seen = index.update(eurgbp_sell, weight_of(eurgbp_sell_arc->get_info().rate),
230 cout <<
" " << seen <<
" cycles looked at, " << decide.candidates <<
" candidates, "
231 << decide.profitable <<
" profitable\n\n";
235 for (
size_t position = 0; position < index.num_cycles(); ++position)
236 stale += index.is_stale(position, before);
237 cout << stale <<
" cycles are stale since the clock was " << before <<
": those of arc "
238 << eurgbp_sell <<
", which are " << index.cycles_of(eurgbp_sell).size() <<
"\n\n";
242 index.set_weight(eurgbp_sell, numeric_limits<double>::infinity());
243 decide.candidates = decide.profitable = 0;
244 index.for_each_cycle_below(Margin, 4, decide);
245 cout <<
"Without EURGBP sell: " << decide.candidates <<
" candidates\n";