join works
This commit is contained in:
1 parent
aec1d1ee6e
commit
dffb9018da
4 files changed
+69
-60
No files matched your search
Binary file not shown.
@@ -111,26 +111,8 @@ namespace bts.excel
|
||||
}
|
||||
|
||||
[ExcelFunction]
|
||||
[SparkAlgoCode(
|
||||
dual_definition = @"
|
||||
template <typename T>
|
||||
T& sparkalgo_take_snapshot(T&, const std::string& name);",
|
||||
dual_impl = @"
|
||||
template<typename T>
|
||||
T& __AlgoName__::sparkalgo_take_snapshot(T& rng, const std::string& name)
|
||||
{
|
||||
static std::map< std::string, T > cache;
|
||||
auto it = cache.find(name);
|
||||
if(it == cache.end())
|
||||
{
|
||||
cache[name] = rng;
|
||||
return rng;
|
||||
}
|
||||
else
|
||||
return it->second;
|
||||
}"
|
||||
)]
|
||||
static public object sparkalgo_take_snapshot(object data, string tag)
|
||||
[SparkAlgoCode]
|
||||
static public object sparkalgo_take_snapshot(string tag, object data)
|
||||
{
|
||||
object val;
|
||||
if(!_cache.TryGetValue(tag, out val))
|
||||
@@ -148,7 +130,7 @@ int sparkalgo_snapshot_switch(const std::string& name, int on_off);",
|
||||
int __AlgoName__::sparkalgo_snapshot_switch(const std::string& name, int on_off)
|
||||
{
|
||||
if(on_off)
|
||||
return sparkalgo_take_snapshot(on_off,name+""_switch"");
|
||||
return sparkalgo_take_snapshot(name+""_switch"", on_off);
|
||||
else
|
||||
return on_off;
|
||||
}"
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "spark/lib/utils/PBUtils.h"
|
||||
#include "spark/lib/os/os.h"
|
||||
|
||||
#include <variant>
|
||||
|
||||
using namespace bts::api::orderman;
|
||||
using namespace bts::orderman;
|
||||
|
||||
@@ -241,11 +243,15 @@ class __AlgoName__ : public IAlgoOrder
|
||||
const string& order_type = "", const string& order_params = "");
|
||||
|
||||
void sparkalgo_send_or_update_order(OrderKey local_order_id, double should_process_inputs, double price, int32_t quantity,
|
||||
const string& order_params_update = "");
|
||||
const string& order_params_update = "");
|
||||
template <typename T>
|
||||
T& sparkalgo_take_snapshot(const std::string& name, T&);
|
||||
|
||||
|
||||
__DualDefs__;
|
||||
};
|
||||
|
||||
|
||||
const string& __AlgoName__::get_user() const
|
||||
{
|
||||
return init_services().definition().user();
|
||||
@@ -285,11 +291,27 @@ struct __AlgoName__::PImpl
|
||||
IBeforeLaunchAlgoServices* init_services = nullptr;
|
||||
IAlgoServices* algo_services = nullptr;
|
||||
std::map<OrderKey, OrderDef> local_order_id_to_child;
|
||||
|
||||
|
||||
typedef std::variant<int, double, std::string, Range<int>, Range<double>, Range<std::string> > vtypes;
|
||||
std::map<std::string, vtypes> snapshots;
|
||||
|
||||
Book last_book;
|
||||
__ParameterDefs__;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
T& __AlgoName__::sparkalgo_take_snapshot(const std::string& tag, T& data)
|
||||
{
|
||||
auto it = me->snapshots.find(tag);
|
||||
if(it == me->snapshots.end())
|
||||
{
|
||||
me->snapshots[tag] = data;
|
||||
return data;
|
||||
}
|
||||
else
|
||||
return std::get<T>(it->second);
|
||||
}
|
||||
|
||||
SecurityKey __AlgoName__::sparkalgo_resolve_security_id(const string& contract, const string& symbol,
|
||||
const string& security_type, const string& exchange)
|
||||
{
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "spark/lib/utils/PBUtils.h"
|
||||
#include "spark/lib/os/os.h"
|
||||
|
||||
#include <variant>
|
||||
|
||||
using namespace bts::api::orderman;
|
||||
using namespace bts::orderman;
|
||||
|
||||
@@ -243,18 +245,19 @@ class algo_example_xlsm : public IAlgoOrder
|
||||
const string& order_type = "", const string& order_params = "");
|
||||
|
||||
void sparkalgo_send_or_update_order(OrderKey local_order_id, double should_process_inputs, double price, int32_t quantity,
|
||||
const string& order_params_update = "");
|
||||
const string& order_params_update = "");
|
||||
template <typename T>
|
||||
T& sparkalgo_take_snapshot(const std::string& name, T&);
|
||||
|
||||
|
||||
//__DualDefs__
|
||||
|
||||
ExcelBookAccessor sparkalgo_md_book_id(SecurityKey sk);
|
||||
|
||||
int sparkalgo_snapshot_switch(const std::string& name, int on_off);
|
||||
|
||||
template <typename T>
|
||||
T& sparkalgo_take_snapshot(T&, const std::string& name);;
|
||||
int sparkalgo_snapshot_switch(const std::string& name, int on_off);;
|
||||
};
|
||||
|
||||
|
||||
const string& algo_example_xlsm::get_user() const
|
||||
{
|
||||
return init_services().definition().user();
|
||||
@@ -294,7 +297,10 @@ struct algo_example_xlsm::PImpl
|
||||
IBeforeLaunchAlgoServices* init_services = nullptr;
|
||||
IAlgoServices* algo_services = nullptr;
|
||||
std::map<OrderKey, OrderDef> local_order_id_to_child;
|
||||
|
||||
|
||||
typedef std::variant<int, double, std::string, Range<int>, Range<double>, Range<std::string> > vtypes;
|
||||
std::map<std::string, vtypes> snapshots;
|
||||
|
||||
Book last_book;
|
||||
//__ParameterDefs__
|
||||
double join_thresh;
|
||||
@@ -302,6 +308,19 @@ struct algo_example_xlsm::PImpl
|
||||
OrderKey join_k9_order_id;;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
T& algo_example_xlsm::sparkalgo_take_snapshot(const std::string& tag, T& data)
|
||||
{
|
||||
auto it = me->snapshots.find(tag);
|
||||
if(it == me->snapshots.end())
|
||||
{
|
||||
me->snapshots[tag] = data;
|
||||
return data;
|
||||
}
|
||||
else
|
||||
return std::get<T>(it->second);
|
||||
}
|
||||
|
||||
SecurityKey algo_example_xlsm::sparkalgo_resolve_security_id(const string& contract, const string& symbol,
|
||||
const string& security_type, const string& exchange)
|
||||
{
|
||||
@@ -414,25 +433,11 @@ ExcelBookAccessor algo_example_xlsm::sparkalgo_md_book_id(SecurityKey sk)
|
||||
int algo_example_xlsm::sparkalgo_snapshot_switch(const std::string& name, int on_off)
|
||||
{
|
||||
if(on_off)
|
||||
return sparkalgo_take_snapshot(on_off,name+"_switch");
|
||||
return sparkalgo_take_snapshot(name+"_switch", on_off);
|
||||
else
|
||||
return on_off;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T& algo_example_xlsm::sparkalgo_take_snapshot(T& rng, const std::string& name)
|
||||
{
|
||||
static std::map< std::string, T > cache;
|
||||
auto it = cache.find(name);
|
||||
if(it == cache.end())
|
||||
{
|
||||
cache[name] = rng;
|
||||
return rng;
|
||||
}
|
||||
else
|
||||
return it->second;
|
||||
}
|
||||
|
||||
algo_example_xlsm::algo_example_xlsm() : me(new PImpl()) {}
|
||||
algo_example_xlsm::~algo_example_xlsm() {}
|
||||
|
||||
@@ -720,11 +725,11 @@ void algo_example_xlsm::join_h31()
|
||||
auto&& Join_C17_C18 = range_init(join_c17, 2, 1);
|
||||
auto&& join_c18 = sparkalgo_md_book_id ( security_id)(10,1) ;
|
||||
range_set(Join_C17_C18, join_c18, 1, 0);
|
||||
|
||||
auto Join_C17_C18_avg = 0.0;
|
||||
for(auto& Join_C17_C18_i : Join_C17_C18 )
|
||||
Join_C17_C18_avg += Join_C17_C18_i;
|
||||
Join_C17_C18_avg /= Join_C17_C18.size();
|
||||
|
||||
auto Join_C17_C18_avg = 0.0;
|
||||
for(auto& Join_C17_C18_i : Join_C17_C18 )
|
||||
Join_C17_C18_avg += Join_C17_C18_i;
|
||||
Join_C17_C18_avg /= Join_C17_C18.size();
|
||||
|
||||
auto&& join_c33 = Join_C17_C18_avg ;
|
||||
auto&& on_off = 1.0 + join_c33 ;
|
||||
@@ -738,11 +743,11 @@ void algo_example_xlsm::join_h31()
|
||||
range_set(Join_B17_D18, join_c18, 1, 1);
|
||||
auto&& join_d18 = sparkalgo_md_book_id ( security_id)(10,2) ;
|
||||
range_set(Join_B17_D18, join_d18, 1, 2);
|
||||
auto&& join_g18 = ( join_c17 > 0.0 ? (sparkalgo_take_snapshot ( Join_B17_D18, std::string("book"))(1,1)) : (0.0) ) ;
|
||||
auto&& join_g18 = ( join_c17 > 0.0 ? (sparkalgo_take_snapshot ( std::string("book"), Join_B17_D18)(1,1)) : (0.0) ) ;
|
||||
auto&& join_thresh = me->join_thresh;
|
||||
auto&& join_f31 = sparkalgo_snapshot_switch ( std::string("should_join"), ( (join_c18 > join_g18 && join_b18 >= join_thresh && true) ? (1.0) : (0.0) ) ) ;
|
||||
auto&& init_price = get_price();
|
||||
auto&& join_d31 = ( join_f31 ? (sparkalgo_take_snapshot ( join_c18, std::string("join_price"))) : (init_price) ) ;
|
||||
auto&& join_d31 = ( join_f31 ? (sparkalgo_take_snapshot ( std::string("join_price"), join_c18)) : (init_price) ) ;
|
||||
auto&& quantity = get_quantity();
|
||||
auto&& join_e31 = quantity ;
|
||||
sparkalgo_send_or_update_order ( join_k8, on_off, join_d31, join_e31) ;
|
||||
@@ -769,11 +774,11 @@ void algo_example_xlsm::join_h32()
|
||||
auto&& Join_C17_C18 = range_init(join_c17, 2, 1);
|
||||
auto&& join_c18 = sparkalgo_md_book_id ( security_id)(10,1) ;
|
||||
range_set(Join_C17_C18, join_c18, 1, 0);
|
||||
|
||||
auto Join_C17_C18_avg = 0.0;
|
||||
for(auto& Join_C17_C18_i : Join_C17_C18 )
|
||||
Join_C17_C18_avg += Join_C17_C18_i;
|
||||
Join_C17_C18_avg /= Join_C17_C18.size();
|
||||
|
||||
auto Join_C17_C18_avg = 0.0;
|
||||
for(auto& Join_C17_C18_i : Join_C17_C18 )
|
||||
Join_C17_C18_avg += Join_C17_C18_i;
|
||||
Join_C17_C18_avg /= Join_C17_C18.size();
|
||||
|
||||
auto&& join_c33 = Join_C17_C18_avg ;
|
||||
auto&& on_off = 1.0 + join_c33 ;
|
||||
@@ -787,15 +792,15 @@ void algo_example_xlsm::join_h32()
|
||||
range_set(Join_B17_D18, join_c18, 1, 1);
|
||||
auto&& join_d18 = sparkalgo_md_book_id ( security_id)(10,2) ;
|
||||
range_set(Join_B17_D18, join_d18, 1, 2);
|
||||
auto&& join_g18 = ( join_c17 > 0.0 ? (sparkalgo_take_snapshot ( Join_B17_D18, std::string("book"))(1,1)) : (0.0) ) ;
|
||||
auto&& join_g18 = ( join_c17 > 0.0 ? (sparkalgo_take_snapshot ( std::string("book"), Join_B17_D18)(1,1)) : (0.0) ) ;
|
||||
auto&& join_thresh = me->join_thresh;
|
||||
auto&& join_f31 = sparkalgo_snapshot_switch ( std::string("should_join"), ( (join_c18 > join_g18 && join_b18 >= join_thresh && true) ? (1.0) : (0.0) ) ) ;
|
||||
auto&& init_price = get_price();
|
||||
auto&& join_d31 = ( join_f31 ? (sparkalgo_take_snapshot ( join_c18, std::string("join_price"))) : (init_price) ) ;
|
||||
auto&& join_d32 = join_d31 - 1.0 ;
|
||||
auto&& join_d31 = ( join_f31 ? (sparkalgo_take_snapshot ( std::string("join_price"), join_c18)) : (init_price) ) ;
|
||||
auto&& join_d32 = join_d31 - 0.03 ;
|
||||
auto&& quantity = get_quantity();
|
||||
auto&& join_e31 = quantity ;
|
||||
auto&& join_e32 = join_e31 - 1.0 ;
|
||||
auto&& join_e32 = join_e31 + 2.0 ;
|
||||
sparkalgo_send_or_update_order ( join_k13, on_off, join_d32, join_e32) ;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user