estimators.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:paperbroker 作者: philipodonnell 项目源码 文件源码
def estimate(self, quote:Quote, quantity:int = None):

        # quantity is only used for direction
        quantity = copysign(1, quantity)

        if quote.bid is None or quote.ask is None or quote.bid == 0.0 or quote.ask == 0.0:
            raise Exception(
                'SlippageEstimator.estimate: Cannot estimate a price if the bid or ask are None or 0.0')

        if quantity is None or quantity == 0:
            raise Exception(
                'SlippageEstimator.estimate: Must provide a signed quantity to buy or sell.')

        spread = (quote.ask - quote.bid) / 2
        midpoint = quote.bid + spread

        if quantity > 0:
            return midpoint - spread * self.slippage
        else:
            return midpoint + spread * self.slippage
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号