Best posts made by elektor
Latest posts made by elektor
-
Consecutive Sell/Buy Orders in Multi Asset Strategy.
Hi,
I am trying to back test a 2 (or more) asset strategy which require selling one fully and buying other asset. I am doing this with cheat on open using next_open.
def next_open(self): DEBUG_EN = 0; # Exit positions if any for i, d in enumerate(self.datas): dt, dn = self.datetime.date(), d._name pos = self.getposition(d).size if re.search(self.trade,dn): pass else: if pos: self.close(data=d) print(f"DEBUG :: NEXT OPEN :: {dt} Closing Position of {dn}") else: pass # Buy positions if any for i, d in enumerate(self.datas): dt, dn = self.datetime.date(), d._name pos = self.getposition(d).size if re.search(self.trade,dn): if pos: # Position already exists so no need to do anything pass else: self.buy(data=d) #cash = round(self.broker.getcash(),2) #no_of_shares = self.getsizing() print(f"DEBUG :: NEXT OPEN :: {dt} Opening Position of {dn}") else: # Do nothing as trade signal is to buy {dn} pass
What I am observing is that sizer is calculating the position as per leftover cash in folio without considering the cash outcome of sell transaction. I am using slight modified version of percent sizer worth 100% cash, modification to change open instead of close in next open. How can I make sizer take care of the cash generated from previous sell. Following are the debug messages I am getting from above code:
DEBUG :: NEXT OPEN :: 2008-01-25 Closing Position of asset1 DEBUG GETSIZING ::: Triggered asset2 DEBUG :: NEXT OPEN :: 2008-01-25 Opening Position of asset2 get_order_type :: Sell Order is Submitted get_order_type :: Buy Order is Submitted get_order_type :: Sell Order is Accepted get_order_type :: Buy Order is Accepted get_order_type :: Sell Order is Completed get_order_type :: Cash Status : 102037.1 Notify Msg : Sell executed at price 53.9 on 2008-02-01. Total Value 99950.4 get_order_type :: Buy Order is Completed get_order_type :: Cash Status : 102037.1 Notify Msg : Buy executed at price 11.3 on 2008-02-01. Total Value 45.2
Thanks and Regards
Ashutosh Ojha -
RE: Passing Timeframe to Rolling Return Analyzer
@run-out Thanks for responding. I am still getting the same error. BTW my all other analyzers are working with _name itself.
-
Passing Timeframe to Rolling Return Analyzer
Hi,
I am trying to get rolling returns for 1/3/5 year time frame on my weekly strategy. I am trying to use logrollingreturn analyzer for this purpose and trying to pass timeframe parameter as 52/52w etc, but getting error for the same. Can some one please help me providing details of how to use these parameter. Here is a code snippet.
cerebro.addanalyzer(bt.analyzers.LogReturnsRolling, _name='myrollingreturns' , timeframe=52)
Here is the error:
UnboundLocalError: local variable 'ph' referenced before assignment