Made the fake sec's consistent
This commit is contained in:
1 parent
9f2627869b
commit
0d49c4c0fe
3 files changed
+61
-30
No files matched your search
@@ -25,6 +25,9 @@ namespace mbts.spark {
|
||||
private readonly TimeSpan _vs_change_period = TimeSpan.FromSeconds(10);
|
||||
private int _create_count = 0;
|
||||
private readonly int _n_fixed_creates = 0;
|
||||
SecurityExpiration option_exp1 = new SecurityExpiration(Venue.Glbx, SecurityType.Option, "ew3", new DateTime(2022, 3, 18));
|
||||
SecurityExpiration option_exp2 = new SecurityExpiration(Venue.Glbx, SecurityType.Option, "ew3", new DateTime(2022, 6, 17));
|
||||
SecurityExpiration driver_exp = new SecurityExpiration(Venue.Glbx, SecurityType.Future, "ES", new DateTime(2022, 3, 18));
|
||||
|
||||
public AnalyticsServiceTester(ThreadedBlackboard bb) {
|
||||
_bb = bb;
|
||||
@@ -37,9 +40,12 @@ namespace mbts.spark {
|
||||
private void _on_bb_data(object tag, object data) {
|
||||
}
|
||||
|
||||
private static VolSurfaceInput _get_vs(int vs_id, string vs_name) {
|
||||
VolSurfaceExpiration sample_exp = new VolSurfaceExpiration("spx", DateTime.Now);
|
||||
VolSurfaceInput vs_inp = mbts.analytics.VolSurfaceModelTests.get_generic_vs_input(new VolSurfaceExpiration[] { sample_exp });
|
||||
private VolSurfaceInput _get_vs(int vs_id, string vs_name) {
|
||||
var ew3_exps = new VolSurfaceExpiration[] {
|
||||
new VolSurfaceExpiration(option_exp1),
|
||||
new VolSurfaceExpiration(option_exp2)
|
||||
};
|
||||
VolSurfaceInput vs_inp = VolSurfaceModelTests.get_generic_vs_input(ew3_exps);
|
||||
VolSurfaceSettings vs_settings = vs_inp.surface_settings;
|
||||
vs_settings.core_settings.vol_surface_id = vs_id;
|
||||
vs_settings.core_settings.vol_surface_name = vs_name;
|
||||
@@ -50,34 +56,41 @@ namespace mbts.spark {
|
||||
if (DateTime.Now - _last_timer >= _vs_change_period) {
|
||||
bts.Log.Gen.info(String.Format("AnalyticsServiceTester, in timer dt:{0}", DateTime.Now));
|
||||
_last_timer = DateTime.Now;
|
||||
if (_create_count < _n_fixed_creates) {
|
||||
VolSurfaceInput vs_inp = _get_vs(0, String.Format("test_{0}", ++_create_count));
|
||||
_bb.post(SparkTags.VolSurfaceCreateTag, vs_inp.surface_settings);
|
||||
}
|
||||
IDictionary<int, string> vs_id_name_map = _bb.read_state(_in_vs_list_tag);
|
||||
if (vs_id_name_map == null || vs_id_name_map.Count == 0) {
|
||||
return;
|
||||
}
|
||||
// select a random vs and change it
|
||||
Random rnd = new Random(DateTime.Now.Millisecond);
|
||||
int rnd_index = rnd.Next(0, vs_id_name_map.Count - 1);
|
||||
var kv = vs_id_name_map.ToList()[rnd_index];
|
||||
VolSurfaceInput vs_inp_to_change = _get_vs(kv.Key, kv.Value);
|
||||
bts.Log.Testing.info(String.Format("AnalyticsServiceTester committing vs id:{0} name:{1}",
|
||||
kv.Key, kv.Value));
|
||||
_bb.post(SparkTags.VolSurfaceCommitTag(kv.Key), vs_inp_to_change);
|
||||
_create_vs();
|
||||
_save_vs();
|
||||
_save_exp_params();
|
||||
}
|
||||
}
|
||||
|
||||
private void _save_exp_params() {
|
||||
SystemContractData scd = _bb.read_state(_in_scd_tag);
|
||||
if (scd == null) {
|
||||
private void _create_vs() {
|
||||
if (_create_count < _n_fixed_creates) {
|
||||
VolSurfaceInput vs_inp = _get_vs(0, String.Format("test_{0}", ++_create_count));
|
||||
_bb.post(SparkTags.VolSurfaceCreateTag, vs_inp.surface_settings);
|
||||
}
|
||||
}
|
||||
|
||||
private void _save_vs() {
|
||||
IDictionary<int, string> vs_id_name_map = _bb.read_state(_in_vs_list_tag);
|
||||
if (vs_id_name_map == null || vs_id_name_map.Count == 0) {
|
||||
return;
|
||||
}
|
||||
IEnumerable<AnalyticsExpirationParameters> aparams_list =
|
||||
scd.exp_map.Keys.Select(e => new AnalyticsExpirationParameters(e, e, e, e, 0.1, 0.2, 0.3, 10, 10.1));
|
||||
_bb.post(SparkTags.ExpirationParametersCommitTag, aparams_list);
|
||||
// select a random vs and change it
|
||||
Random rnd = new Random(DateTime.Now.Millisecond);
|
||||
int rnd_index = rnd.Next(0, vs_id_name_map.Count - 1);
|
||||
var kv = vs_id_name_map.ToList()[rnd_index];
|
||||
VolSurfaceInput vs_inp_to_change = _get_vs(kv.Key, kv.Value);
|
||||
bts.Log.Testing.info(String.Format("AnalyticsServiceTester committing vs id:{0} name:{1}",
|
||||
kv.Key, kv.Value));
|
||||
_bb.post(SparkTags.VolSurfaceCommitTag(kv.Key), vs_inp_to_change);
|
||||
_save_exp_params();
|
||||
}
|
||||
|
||||
private void _save_exp_params() {
|
||||
var exp_params = new AnalyticsExpirationParameters[]{
|
||||
new AnalyticsExpirationParameters(option_exp1, driver_exp, driver_exp, driver_exp, 0, 0, Double.NaN, 1, 1),
|
||||
new AnalyticsExpirationParameters(option_exp2, driver_exp, driver_exp, driver_exp, 0, 0, Double.NaN, 1, 1),
|
||||
};
|
||||
_bb.post(SparkTags.ExpirationParametersCommitTag, exp_params);
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
@@ -29,6 +29,11 @@ namespace mbts.analytics {
|
||||
this.expiration = expiration;
|
||||
}
|
||||
|
||||
public VolSurfaceExpiration(SecurityExpiration exp) {
|
||||
symbol = exp.symbol;
|
||||
expiration = exp.expiration;
|
||||
}
|
||||
|
||||
public SecurityExpiration to_security_expiration() {
|
||||
// TODO
|
||||
return new SecurityExpiration(Venue.Unset, SecurityType.Option, symbol, expiration);
|
||||
|
||||
@@ -25,19 +25,32 @@ namespace bts {
|
||||
private bool _published = false;
|
||||
private IReadOnlyDictionary<uint, SecurityMD> _sec_map = _get_fake_secs();
|
||||
|
||||
// Returns a bunch of hard coded SecurityMD
|
||||
private static Dictionary<uint, SecurityMD> _get_fake_secs() {
|
||||
Dictionary<uint, SecurityMD> rv = new Dictionary<SecurityKey, SecurityMD>();
|
||||
Action<DateTime, double, PutOrCall, UInt32, UInt64> add_strike = (exp, k, cp, id, exchange_id) => {
|
||||
string desc = String.Format("ew3 {0}{1} {2}{3}", exp.Month.ToString("MMM"), exp.Year - 2000,
|
||||
k.ToString(), cp == PutOrCall.Call ? "C" : "P");
|
||||
rv.Add(id, new SecurityMD(
|
||||
get_glbx_option("ew3", id, exp, k, cp, exchange_id, desc),
|
||||
new FakeSecurityMDConsumerHandle(id, exchange_id)));
|
||||
};
|
||||
// add a future
|
||||
UInt32 id = 0;
|
||||
UInt64 exchange_id = 0;
|
||||
rv.Add(id, new SecurityMD(
|
||||
get_glbx_future("ES", id, new DateTime(2021, 12, 17), exchange_id, "ESZ1"),
|
||||
get_glbx_future("ES", id, new DateTime(2022, 3, 18), exchange_id, "ESZ1"),
|
||||
new FakeSecurityMDConsumerHandle(id, exchange_id)));
|
||||
id++; exchange_id++;
|
||||
DateTime exp = new DateTime(2022, 3, 18);
|
||||
for (double k = 2000; k <= 5000; k += 10) {
|
||||
id++; exchange_id++;
|
||||
rv.Add(id, new SecurityMD(
|
||||
get_glbx_option("ew3", id, new DateTime(2021, 12, 17), 3000, PutOrCall.Call, exchange_id, "ew3 3000C"),
|
||||
new FakeSecurityMDConsumerHandle(id, exchange_id)));
|
||||
add_strike(exp, k, PutOrCall.Call, id++, exchange_id++);
|
||||
add_strike(exp, k, PutOrCall.Put, id++, exchange_id++);
|
||||
}
|
||||
exp = new DateTime(2022, 6, 17);
|
||||
for (double k = 2000; k <= 5000; k += 10) {
|
||||
add_strike(exp, k, PutOrCall.Call, id++, exchange_id++);
|
||||
add_strike(exp, k, PutOrCall.Put, id++, exchange_id++);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user