Add SecurityCriteria struct to filter instrument sets
Inspired by the c# 'SecurityCriteria' class from spark's front end. This may come in handy as a cli option for spartan subcommands, among other things.
This commit is contained in:
1 parent
2a04341b3b
commit
36bfc9e770
2 files changed
+78
No files matched your search
@@ -0,0 +1,41 @@
|
||||
#include "SecurityCriteria.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace bts::spartan::mdp3 {
|
||||
|
||||
#define CONTAINS(container, value) \
|
||||
(std::find(container.begin(), container.end(), value) != container.end())
|
||||
|
||||
bool SecurityCriteriaClause::is_defined() const {
|
||||
return exchanges.size() || security_types.size() || assets.size() ||
|
||||
security_ids.size();
|
||||
}
|
||||
|
||||
bool SecurityCriteriaClause::includes(const SecurityDefinition &def) const {
|
||||
if (!is_defined())
|
||||
return false;
|
||||
if (security_types.size() && !CONTAINS(security_types, def.security_type()))
|
||||
return false;
|
||||
if (assets.size() && !CONTAINS(assets, def.asset()))
|
||||
return false;
|
||||
if (security_ids.size() && !security_ids.count(def.security_id()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SecurityCriteria::is_defined() const {
|
||||
for (const auto &c : clauses)
|
||||
if (c.is_defined())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SecurityCriteria::includes(const SecurityDefinition &def) const {
|
||||
for (const auto &c : clauses) {
|
||||
if (c.includes(def))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace bts::spartan::mdp3
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
#include "SecurityDefinition.h"
|
||||
#include "SecurityID.h"
|
||||
#include "lib/domain_model/Security.pb.h"
|
||||
#include <boost/container/small_vector.hpp>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace bts::spartan::mdp3 {
|
||||
|
||||
/**
|
||||
* A group of properties that define a subset of securities. Each field
|
||||
* (exchanges, security_types, etc.) is a discrete set of potential values for a
|
||||
* particular property of the security. The subset of securities defined by the
|
||||
* SecurityCriteriaClause consists of all those with properties that are
|
||||
* contained in the [non-empty] discrete set(s).
|
||||
*/
|
||||
struct SecurityCriteriaClause {
|
||||
boost::container::small_vector<api::Venue, 0> exchanges;
|
||||
boost::container::small_vector<api::SecurityType, 0> security_types;
|
||||
boost::container::small_vector<std::string, 0> assets;
|
||||
std::unordered_set<SecurityID> security_ids;
|
||||
|
||||
bool is_defined() const;
|
||||
bool includes(const SecurityDefinition &instrument) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents a subset of securities as the union of [SecurityCriteriaClause] subsets.
|
||||
*/
|
||||
struct SecurityCriteria {
|
||||
bool is_defined() const;
|
||||
bool includes(const SecurityDefinition &instrument) const;
|
||||
boost::container::small_vector<SecurityCriteriaClause, 1> clauses;
|
||||
};
|
||||
|
||||
} // namespace bts::spartan::mdp3
|
||||
Reference in new issue
Block a user