Cleaning up
This commit is contained in:
1 parent
5905ca3e92
commit
5528efd2d2
6 files changed
+151
-140
No files matched your search
@@ -622,9 +622,7 @@ namespace bts.shell.pnl {
|
||||
|
||||
static class PNLDataExtensions {
|
||||
public static string pnl_symbol(this SecurityImmutable security) {
|
||||
if(security.HasIce)
|
||||
return PNLICEHelper.get_symbol(security);
|
||||
return security.Symbol;
|
||||
return bts.api.ExchangeSpecificUitlities.get_pnl_symbol(security);
|
||||
}
|
||||
|
||||
// while override_cpp could use double.NaN to indicate the lack of an override,
|
||||
@@ -636,7 +634,7 @@ namespace bts.shell.pnl {
|
||||
|
||||
public static (double default_cpp, double? override_cpp) pnl_cpp_tuple(this PNLUnitImmutable pnl_unit, SecurityImmutable security) {
|
||||
// TODO: actual impl
|
||||
double calced_pnl = PNLICEHelper.get_cpp(pnl_unit,security);
|
||||
double calced_pnl = bts.api.ExchangeSpecificUitlities.get_cpp(pnl_unit,security);
|
||||
return (calced_pnl, pnl_unit.HasCppOverride ? pnl_unit.CppOverride.Value : (double?)null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.api.position;
|
||||
using bts.utils;
|
||||
using mbts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
|
||||
namespace bts.shell.pnl {
|
||||
|
||||
static class PNLICEHelper{
|
||||
|
||||
public static bool is_spread(SecurityImmutable sec){
|
||||
return sec.HasSpread && sec.Ice.StripName.Contains("/");
|
||||
}
|
||||
|
||||
public static bool is_strip(SecurityImmutable sec){
|
||||
return sec.HasSpread && !is_spread(sec);
|
||||
}
|
||||
|
||||
public static bool is_ice_lots(SecurityImmutable sec){
|
||||
return sec.Ice.MarketDescription.Contains("ICE Lots");
|
||||
}
|
||||
|
||||
public static double get_future_cpp (SecurityImmutable sec){
|
||||
if(sec.Symbol == "HHD")
|
||||
return 1;
|
||||
if(is_ice_lots(sec))
|
||||
return 2500;
|
||||
else{
|
||||
var days_in_month = DateTime.DaysInMonth(Convert.ToInt32(sec.Future.ExpirationYear),
|
||||
Convert.ToInt32(sec.Future.ExpirationMonth));
|
||||
return days_in_month; // because the size is multiplied by 2500 already
|
||||
}
|
||||
}
|
||||
|
||||
public static double get_spread_cpp(SecurityImmutable sec){
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static double get_strip_cpp(PNLUnitImmutable pnl,
|
||||
SecurityImmutable sec){
|
||||
double rv = 0;
|
||||
foreach (var l in sec.Spread.Legs)
|
||||
if(l.Security.HasFuture)
|
||||
rv += get_cpp(pnl,l.Security);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static string get_symbol (SecurityImmutable sec){
|
||||
var rv = String.Format("{0}{1}{2}",
|
||||
sec.Symbol,
|
||||
is_ice_lots(sec)? " ICE LOTS" : String.Empty,
|
||||
is_spread(sec)? " Spread" : String.Empty);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static double get_cpp (PNLUnitImmutable pnl,
|
||||
SecurityImmutable sec){
|
||||
if (sec.HasGlbx)
|
||||
return pnl.CashValue;
|
||||
else if (sec.HasIce){
|
||||
if(sec.HasFuture)
|
||||
return get_future_cpp(sec);
|
||||
else if(is_spread(sec))
|
||||
return get_spread_cpp(sec);
|
||||
else if(is_strip(sec))
|
||||
return get_strip_cpp(pnl,sec);
|
||||
}
|
||||
return Double.NaN;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,128 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.api.position;
|
||||
using bts.utils;
|
||||
using mbts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
|
||||
namespace bts.api {
|
||||
|
||||
static class ExchangeSpecificUitlities{
|
||||
private static string _default_hub = "Henry";
|
||||
static class ICE{
|
||||
|
||||
#region Contract Type
|
||||
public static bool is_spread(SecurityImmutable sec){
|
||||
return sec.HasSpread && sec.Ice.StripName.Contains("/");
|
||||
}
|
||||
|
||||
public static bool is_strip(SecurityImmutable sec){
|
||||
return sec.HasSpread && !is_spread(sec);
|
||||
}
|
||||
|
||||
public static bool is_ice_lots(SecurityImmutable sec){
|
||||
return sec.Ice.MarketDescription.Contains("ICE Lots");
|
||||
}
|
||||
|
||||
public static bool is_tas(SecurityImmutable sec){
|
||||
return sec.Ice.MarketDescription.Contains("TAS");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CPP
|
||||
public static double get_future_cpp (SecurityImmutable sec){
|
||||
if(sec.Symbol == "HHD")
|
||||
// only futures in HHD are the dailies, everything
|
||||
// else is a strip or spread
|
||||
return 1;
|
||||
if(is_ice_lots(sec))
|
||||
return 2500;
|
||||
else{
|
||||
var days_in_month = DateTime.DaysInMonth(Convert.ToInt32(sec.Future.ExpirationYear),
|
||||
Convert.ToInt32(sec.Future.ExpirationMonth));
|
||||
return days_in_month; // because the size is multiplied by 2500 already
|
||||
}
|
||||
}
|
||||
|
||||
public static double get_spread_cpp(SecurityImmutable sec){
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static double get_strip_cpp(PNLUnitImmutable pnl,
|
||||
SecurityImmutable sec){
|
||||
// add up all the legs
|
||||
double rv = 0;
|
||||
foreach (var l in sec.Spread.Legs)
|
||||
if(l.Security.HasFuture)
|
||||
rv += get_cpp(pnl,l.Security);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static double get_cpp (PNLUnitImmutable pnl,
|
||||
SecurityImmutable sec){
|
||||
if(sec.HasFuture)
|
||||
return get_future_cpp(sec);
|
||||
else if(is_spread(sec))
|
||||
return get_spread_cpp(sec);
|
||||
else if(is_strip(sec))
|
||||
return get_strip_cpp(pnl,sec);
|
||||
return Double.NaN;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Symbol
|
||||
public static string get_pnl_symbol (SecurityImmutable sec){
|
||||
// for pnl purposes, for a symbol, the division is :
|
||||
// Futures and Strips
|
||||
// ICE Lots
|
||||
// Spreads
|
||||
var rv = String.Format("{0}{1}{2}",
|
||||
sec.Symbol,
|
||||
is_ice_lots(sec)? " ICE LOTS" : String.Empty,
|
||||
is_spread(sec)? " Spread" : String.Empty);
|
||||
return rv;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Formatting
|
||||
public static string format_security (SecurityImmutable? security){
|
||||
if(security.HasValue && security.Value.HasIce){
|
||||
bool ice_lots = is_ice_lots(security.Value),
|
||||
tas = is_tas(security.Value);
|
||||
return String.Format("{0}{1}{2}{3}{4}",
|
||||
security?.Symbol,
|
||||
ice_lots? " ICE Lots" : String.Empty,
|
||||
tas ? " TAS" : String.Empty,
|
||||
String.Compare(security.Value.Ice.HubAlias, _default_hub,true)==0 ? String.Empty :
|
||||
" " + security.Value.Ice.HubAlias,
|
||||
" " + security?.Ice.StripName);
|
||||
}
|
||||
return String.Empty;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static double get_cpp (PNLUnitImmutable pnl,
|
||||
SecurityImmutable sec){
|
||||
if(sec.HasIce)
|
||||
return ICE.get_cpp(pnl,sec);
|
||||
return pnl.CashValue;
|
||||
}
|
||||
|
||||
public static string get_pnl_symbol (SecurityImmutable sec){
|
||||
if(sec.HasIce)
|
||||
return ICE.get_pnl_symbol(sec);
|
||||
return sec.Symbol;
|
||||
}
|
||||
|
||||
public static string format_security(SecurityImmutable? security){
|
||||
if(security?.HasIce == true)
|
||||
return ICE.format_security(security);
|
||||
return security?.ToString();
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -41,7 +41,7 @@ namespace bts.api {
|
||||
switch (security?.ContractCase) {
|
||||
case ContractOneofCase.Future:
|
||||
if(security?.HasIce == true)
|
||||
return _format_ICE(security);
|
||||
return bts.api.ExchangeSpecificUitlities.format_security(security);
|
||||
return format_future(security?.Symbol, security?.security_desc(), security.Value.Future);
|
||||
case ContractOneofCase.Spread:
|
||||
if (security?.HasGlbx == true) {
|
||||
@@ -50,7 +50,7 @@ namespace bts.api {
|
||||
return security?.Glbx.SecurityDesc;
|
||||
}
|
||||
else if(security?.HasIce == true)
|
||||
return _format_ICE(security);
|
||||
return bts.api.ExchangeSpecificUitlities.format_security(security);
|
||||
return string.Join("", _format_future_legs(SecurityHelper.get_flat_future_legs(security?.Spread.Legs)));
|
||||
case ContractOneofCase.Synthetic: return security?.Synthetic.Name;
|
||||
default: return "Unknown-security";
|
||||
@@ -84,28 +84,5 @@ namespace bts.api {
|
||||
default: return $"{fl.quantity:+0;-0}{sym_exp_name}";
|
||||
}
|
||||
}
|
||||
|
||||
static string _format_ICE (SecurityImmutable? security){
|
||||
string symbol = security?.Symbol,
|
||||
strip = security?.Ice.StripName,
|
||||
md_desc = security?.Ice.MarketDescription,
|
||||
type_append = "";
|
||||
|
||||
if(md_desc.Contains("25k ICE Lots")){
|
||||
if(md_desc.Contains("TAS"))
|
||||
type_append = "TAS";
|
||||
}
|
||||
else if(md_desc.Contains("ICE Lots")){
|
||||
if(md_desc.Contains("TAS"))
|
||||
type_append = "ICE Lots TAS";
|
||||
else
|
||||
type_append = "ICE Lots";
|
||||
}
|
||||
else if(md_desc.Contains("TAS"))
|
||||
type_append = "TAS";
|
||||
type_append = string.IsNullOrEmpty(type_append) ?
|
||||
" " : $" {type_append} ";
|
||||
return $"{symbol}{type_append}{strip}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -213,30 +213,16 @@ inline bool gr_than(double p1, double p2, double tick_size) {
|
||||
!test_price_equality(p1, p2, tick_size);
|
||||
}
|
||||
|
||||
// Works only if ICEExchangeData is part of the a spread security
|
||||
// inline bool is_ice_strip(const bts::api::ICEExchangeData& ice_data){
|
||||
// return ice_data.is_strip();
|
||||
// }
|
||||
// ice specialization /////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline bool is_ice_strip(const bts::api::ICEExchangeData& ice_data){
|
||||
// TODO, put this in the security
|
||||
inline bool is_ice_spread(const bts::api::ICEExchangeData& ice_data){
|
||||
const auto& strip = ice_data.strip_name();
|
||||
auto find = [&](const std::string& sub) -> bool {
|
||||
return strip.find(sub) != std::string::npos;
|
||||
};
|
||||
if(!find("/"))
|
||||
return find("-") ||
|
||||
find("Q1") || find("Q2") || find("Q3") || find("Q4") ||
|
||||
find("Cal");
|
||||
else
|
||||
return false;
|
||||
return strip.find("/") != std::string::npos;
|
||||
}
|
||||
|
||||
inline bool is_strip(const bts::api::Security& sec){
|
||||
if(sec.has_spread())
|
||||
if (sec.has_ice())
|
||||
return is_ice_strip(sec.ice());
|
||||
return false;
|
||||
return sec.has_ice() && sec.has_spread() && !is_ice_spread(sec.ice());
|
||||
}
|
||||
|
||||
inline bool is_spread_of_strips(const bts::api::Security& sec){
|
||||
|
||||
@@ -39,6 +39,7 @@ struct FillStore::PImpl {
|
||||
|
||||
FillStore::FillStore(md::SecurityOracle o) : me(new PImpl(o)) {}
|
||||
|
||||
// returns the sod type of a non sod type fill
|
||||
auto sod_fill_kind (const api::orderman::Fill& fill){
|
||||
auto rv = Fill::FILL_KIND_SOD;
|
||||
switch (fill.fill_kind()){
|
||||
@@ -52,6 +53,7 @@ auto sod_fill_kind (const api::orderman::Fill& fill){
|
||||
rv = Fill::FILL_KIND_SOD_STRIP_LEG;
|
||||
break;
|
||||
default:
|
||||
LOG(persist, Error, "Stored fill kinds can not be SOD");
|
||||
rv = Fill::FILL_KIND_SOD;
|
||||
break;
|
||||
}
|
||||
@@ -60,24 +62,19 @@ auto sod_fill_kind (const api::orderman::Fill& fill){
|
||||
|
||||
auto leg_fill_kind (const api::Security& parent,
|
||||
const api::Security& child){
|
||||
if (parent.has_ice()){
|
||||
if(securities::is_strip(parent))
|
||||
return Fill::FILL_KIND_STRIP_LEG;
|
||||
else{
|
||||
// parent is a spread
|
||||
if(securities::is_spread_of_strips(parent)){
|
||||
// this has 3 levels strip spread -> strip -> outright
|
||||
// first level is an ordinary leg and second is a strip leg.
|
||||
// since we dont get the level passed we have to
|
||||
// use the following heurestics
|
||||
if(securities::is_strip(child))
|
||||
return Fill::FILL_KIND_LEG;
|
||||
else
|
||||
return Fill::FILL_KIND_STRIP_LEG;
|
||||
}
|
||||
else
|
||||
// regular spread
|
||||
if(securities::is_strip(parent))
|
||||
return Fill::FILL_KIND_STRIP_LEG;
|
||||
else{
|
||||
// parent is a spread
|
||||
if(securities::is_spread_of_strips(parent)){
|
||||
// this has 3 levels strip spread -> strip -> outright
|
||||
// first level is an ordinary leg and second is a strip leg.
|
||||
// since we dont get the level passed we have to
|
||||
// use the following heurestics
|
||||
if(securities::is_strip(child))
|
||||
return Fill::FILL_KIND_LEG;
|
||||
else
|
||||
return Fill::FILL_KIND_STRIP_LEG;
|
||||
}
|
||||
}
|
||||
return Fill::FILL_KIND_LEG;
|
||||
|
||||
Reference in new issue
Block a user