给定输入序列的 double_price 到 int_price 的更快版本
在给定的交易系统中,输入价格的类型为double
。 min_price_increment min_price_increment_
是已知的,并且等式定义为:
inline bool DblPxCompare ( const double & price1, const double & price2 ) const
{
register double tdiff = ( price1 - price2 );
return ( ( tdiff > -half_min_price_increment_ ) &&
( tdiff < half_min_price_increment_ ) ) ;
}
DblToInt 的实现:
inline int DblPxToIntPx ( const double & price ) const
{
return ( ( int ) round ( price / min_price_increment_ ) ) ;
}
但是价格往往会聚集在一起,因为通常在某个时间点订单往往会以相似的价格发送。我们是否可以做得更好,例如保留从 Double Price 到 Int Price 的最后 20 次转换的排序列表?
In a given trading system, the input prices are of type double
. The minimum_price_increment min_price_increment_
is known, and equality is defined as :
inline bool DblPxCompare ( const double & price1, const double & price2 ) const
{
register double tdiff = ( price1 - price2 );
return ( ( tdiff > -half_min_price_increment_ ) &&
( tdiff < half_min_price_increment_ ) ) ;
}
An implementation of DblToInt :
inline int DblPxToIntPx ( const double & price ) const
{
return ( ( int ) round ( price / min_price_increment_ ) ) ;
}
But prices tend to be bunched up, as in typically a point in time orders tend to be sent at similar prices. Could we do better, for instance by keeping a sorted list of last 20 conversions from Double Price to Int Price ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我倾向于说不,缓存不会更好地工作。原因是每次您都需要检查缓存中的条目是否适合当前的转换,并且我认为该检查将抵消首先保存必须进行转换的任何性能优势。恕我直言,您已经拥有的还不够复杂,无法从缓存中受益。
I'd be inclined to say no, caching is not going to work better. The reason is that each time you'll need to check that the entries in the cache are appropriate for the conversion at hand, and I think that check is going to negate any performance advantage from saving having to do the conversion in the first place. What you already have is, IMHO, not complex enough to benefit from caching.