Re-directed SecurityDB's expiration to securities::expiration
This commit is contained in:
1 parent
df681ca209
commit
baac6a893d
3 files changed
+12
-33
No files matched your search
+10
-30
@@ -8,6 +8,7 @@
|
||||
#include "lib/config/protos/system.pb.h"
|
||||
#include "lib/md/Shm/FixedSecurity.h"
|
||||
#include "lib/config/protos/MarketData.pb.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
|
||||
#include <boost/container/flat_set.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
@@ -141,7 +142,15 @@ Result insert_or_replace(const std::vector<SecurityPtr>& securities) {
|
||||
insert.bind(3, psecurity->exchange());
|
||||
insert.bind(4, securitytype_of(*psecurity));
|
||||
insert.bind(5, buffer);
|
||||
insert.bind(6, expiration(*psecurity).to_short());
|
||||
auto greg_date = securities::expiration(*psecurity);
|
||||
if (greg_date == boost::gregorian::date()) {
|
||||
insert.bind(6, datetime::Date(9999,1,1).to_short());
|
||||
} else {
|
||||
ushort year = greg_date.year();
|
||||
ushort month = greg_date.month();
|
||||
ushort day = greg_date.day();
|
||||
insert.bind(6, datetime::Date(year,month,day).to_short());
|
||||
}
|
||||
insert.exec();
|
||||
insert.reset();
|
||||
}
|
||||
@@ -204,33 +213,4 @@ SecurityPtr find_security(SecurityKey) { return nullptr; }
|
||||
|
||||
#endif
|
||||
|
||||
template <class L>
|
||||
datetime::Date smallest_leg(L l) {
|
||||
// Iterate though all legs and choose the smallest
|
||||
datetime::Date date(std::numeric_limits<uint16_t>::max(),0,0);
|
||||
for (const auto& leg : l) {
|
||||
auto legDate = expiration(leg.security());
|
||||
if (legDate < date) {
|
||||
date = legDate;
|
||||
}
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
datetime::Date expiration(const api::Security& security) {
|
||||
switch(security.Contract_case()) {
|
||||
case api::Security::kFuture:
|
||||
return datetime::Date(security.future().expiration_year(), security.future().expiration_month(), security.future().expiration_day());
|
||||
case api::Security::kOption:
|
||||
return datetime::Date(security.option().expiration_year(), security.option().expiration_month(), security.option().expiration_day());
|
||||
case api::Security::kSpread:
|
||||
return smallest_leg(security.spread().legs());
|
||||
case api::Security::kSynthetic:
|
||||
return smallest_leg(security.synthetic().legs());
|
||||
default:
|
||||
// return a 0 date which will always be considered expired.
|
||||
return datetime::Date();
|
||||
}
|
||||
}
|
||||
|
||||
}}}//namespace
|
||||
Reference in new issue
Block a user