For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
reducing cash in the account seemingly not working
-
I have a trading bot using Oanda that I'm trying to get working. Oanda for the pair that I'm considering using 50x leverage, and I want to reduce this to 5. The easiest way that I've though of is to reduce the cash available to the system to the actual trading results achievable on oanda will be simulated by backtrader. Essentially I want to remove cash from the broker and add it to the fund, making a backup account that is used to adjust the size of the actual account I'm using for trading calculations.
As the first step to implementing this, I use the following code:
def nextstart(self): des_leverage = 5 act_leverage = 50 starting_cash = self.broker.get_cash() use_cash = starting_cash * des_leverage / act_leverage adjustment = use_cash - starting_cash self.broker.add_cash(adjustment) current_cash = self.broker.get_cash() print('starting cash:$ {}' . format(starting_cash)) print('desired cash due to leverage:$ {}' . format(use_cash)) print('adjustment: $ {}' . format(adjustment)) print('current cash: $ {}' . format(current_cash))
The results are below. I haven't implemented the adding the subtracted money to the fund, but it doesn't look like my add_cash is working. Any ideas?
starting cash:$ 1000.0 desired cash due to leverage:$ 100.0 adjustment: $ -900.0 current cash: $ 1000.0
Thanks.