149 lines
5.2 KiB
C++
149 lines
5.2 KiB
C++
|
|
#include "../Security.h"
|
|
#include "catch/catch.hpp"
|
|
#include "lib/domain_model/Security.h"
|
|
#include "lib/utils/PBUtils.h"
|
|
|
|
#include <boost/date_time/gregorian/gregorian.hpp>
|
|
|
|
namespace bts {
|
|
namespace test {
|
|
|
|
TEST_CASE("rounding_tests", "[md]") {
|
|
SECTION("test_price_size") {
|
|
|
|
const double tick_sizes[]{
|
|
// Dan's production system
|
|
// ./sparkd configcheck Symbols | grep future | sed -e 's/.*future:
|
|
// \"\(.*\)\"/\1/' | xargs -I{} sh -c "./sparkd md dump {} future
|
|
// glbx" | grep -o low_tick': [0-9.]\+
|
|
0.0078125, 0.015625, 0.03125, 0.1, 0.25, 1,
|
|
// From Kevin's ramblings
|
|
// 2.5/320,
|
|
// 31./32,
|
|
// 10./32,
|
|
// 10.25/32,
|
|
// 10.375/32,
|
|
// 10.125/32,
|
|
// 10.25/32,
|
|
// .0025,
|
|
// .0000001,
|
|
// 1./32,
|
|
// 0.5/32,
|
|
// 0.25/32,
|
|
// 0.125/32,
|
|
// 0.01,
|
|
// 0.005,
|
|
// 1./100000,
|
|
// 1./16,
|
|
};
|
|
|
|
for (double tick : tick_sizes) {
|
|
// For valid prices from -101 to 101
|
|
std::vector<double> prices;
|
|
for (double price = 0; price < 101; price += tick) {
|
|
// Since all prices are valid ticks rounding should not change them
|
|
const double epsilon = 1e-9;
|
|
for (api::Side side : {api::Side::SIDE_BUY, api::Side::SIDE_SELL}) {
|
|
double rounded =
|
|
securities::raw_round_to_quote_price(price, tick, side);
|
|
REQUIRE(std::abs(price - rounded) <= epsilon);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
auto spread_txt = "id: 17\n"
|
|
"symbol: \"ES\"\n"
|
|
"exchange: VENUE_GLBX\n"
|
|
"contract_spec {\n"
|
|
" low_tick: 0.05\n"
|
|
" high_tick: 0.05\n"
|
|
" price_multiplier: 0.01\n"
|
|
"}\n"
|
|
"spread {\n"
|
|
" legs {\n"
|
|
" security {\n"
|
|
" id: 6\n"
|
|
" symbol: \"ES\"\n"
|
|
" exchange: VENUE_GLBX\n"
|
|
" contract_spec {\n"
|
|
" low_tick: 0.25\n"
|
|
" high_tick: 0.25\n"
|
|
" cash_per_point: 50\n"
|
|
" price_multiplier: 0.01\n"
|
|
" }\n"
|
|
" future {\n"
|
|
" expiration_year: 2019\n"
|
|
" expiration_month: 1\n"
|
|
" expiration_day: 20\n"
|
|
" }\n"
|
|
" glbx {\n"
|
|
" exchange_id: 16145\n"
|
|
" security_desc: \"ESZ9\"\n"
|
|
" cfi_code: \"FFIXSX\"\n"
|
|
" cme_symbol: \"ES\"\n"
|
|
" market_segment_id: 64\n"
|
|
" }\n"
|
|
" }\n"
|
|
" quantity: 1\n"
|
|
" side: SIDE_SELL\n"
|
|
" leg_delta: 1\n"
|
|
" }\n"
|
|
" legs {\n"
|
|
" security {\n"
|
|
" id: 2\n"
|
|
" symbol: \"ES\"\n"
|
|
" exchange: VENUE_GLBX\n"
|
|
" contract_spec {\n"
|
|
" low_tick: 0.25\n"
|
|
" high_tick: 0.25\n"
|
|
" cash_per_point: 50\n"
|
|
" price_multiplier: 0.01\n"
|
|
" }\n"
|
|
" future {\n"
|
|
" expiration_year: 3020\n"
|
|
" expiration_month: 6\n"
|
|
" expiration_day: 19\n"
|
|
" }\n"
|
|
" glbx {\n"
|
|
" exchange_id: 21336\n"
|
|
" security_desc: \"ESM0\"\n"
|
|
" cfi_code: \"FFIXSX\"\n"
|
|
" cme_symbol: \"ES\"\n"
|
|
" market_segment_id: 64\n"
|
|
" }\n"
|
|
" }\n"
|
|
" quantity: 1\n"
|
|
" side: SIDE_BUY\n"
|
|
" leg_delta: 1\n"
|
|
" }\n"
|
|
"}\n"
|
|
"glbx {\n"
|
|
" exchange_id: 35451\n"
|
|
" security_desc: \"ESZ9-ESM0\"\n"
|
|
" cfi_code: \"FMIXSX\"\n"
|
|
" cme_symbol: \"ES\"\n"
|
|
" market_segment_id: 64\n"
|
|
"}";
|
|
|
|
TEST_CASE("expiration_tests", "[security]") {
|
|
SECTION("test_expiration_retrieval") {
|
|
|
|
using namespace boost::gregorian;
|
|
|
|
auto spread = utils::pb::from_string<api::Security>(spread_txt);
|
|
REQUIRE(securities::expiration(spread) ==
|
|
date(greg_year(2019), greg_month(1), greg_day(20)));
|
|
auto &leg = spread.spread().legs(1).security();
|
|
REQUIRE(securities::expiration(leg) ==
|
|
date(greg_year(3020), greg_month(6), greg_day(19)));
|
|
REQUIRE(securities::is_expired(spread));
|
|
REQUIRE(!securities::is_expired(leg));
|
|
}
|
|
}
|
|
|
|
} // namespace test
|
|
} // namespace bts
|