For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Scaling in and Sizers

  • I need to implement the ability to scale into a trade. Desired logic is as follows:

    • Desired trade size in number of contracts is calculated using VaR and determined that the current market and account size requires X number of contracts.
    • I want to scale into the trade in 3 tranches

    As I have currently implemented a VaR sizer, I am returning the total number of contracts. This can be easily modified to return the remaining number of contracts based on the current position size.

    However, in the Strategy, I now need to check not only if I have an open position, but whether I have a full position size based on VaR.

    I'm not sure that the sizer route is the best approach here given other discussions that suggest that I cannot query the sizer from the Strategy.

    How best to implement this?

  • administrators

    Nothing prevents you from querying the Sizer which has been added to the strategy.

    • See the getsizer method of the strategy

    Since you have subclassed Sizer (or SizerBase, which is the same), you control any extra interfaces/methods which may help you in the querying.

    With that in mind, the Sizer concept was developed with the other direction in mind and that's why inside the Sizer there is a strategy member attribute, which allows the sizer to query whatever interfaces the strategy may have. The rationale behind that: abstracting the Strategy from any logic related to position sizing, allowing it to concentrate on the logic of entering/exiting the market.

    The Sizerattributes are describe here:

    Over the strategy attribute you can also reach the broker, to for example query the actual net liquidation value

    class MySizer(bt.Sizer):
        def mymethod(self):
            value =

Log in to reply