Setting Sizer within Strategy Next for Bitcoin
krypterro last edited by
We are using the following code in our main application, and it works fine to deal with Fractional assests such as BTC. Basically we are taking the price of BTC, dividing by 100, and that is a single unit for our strategy. The strategy needs to read read from the current balance, then decide how many units it needs to buy. All easy code, but...how do we do this, in the strategy's Class in the next function, so we can dynamically decide how many units to buy based on other data?
the_stake = number_of_units * .01 cerebro.addsizer(bt.sizers.FixedSize, stake=the_stake)
Here is the code we use to generate the units if needed.
# Determine Size btc_price = self.dataclose balance = self.broker.getvalue() unit_price = btc_price / 100 money_in_play = balance * .5 units_to_buy = money_in_play // unit_price stake = units_to_buy / 100 btc_cost = stake * btc_price
balibou last edited by