Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. asuralm
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    A
    • Profile
    • Following 0
    • Followers 0
    • Topics 15
    • Posts 34
    • Best 1
    • Groups 0

    asuralm

    @asuralm

    2
    Reputation
    880
    Profile views
    34
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    asuralm Unfollow Follow

    Best posts made by asuralm

    • optimization on Strategy Selection example

      Hi:

      The strategy selection shows an example of running two different strategy using the same cerebro.

      Is it possible to run the optimization of each of the strategy within _STRATS = [St0, St1]?

      For example, if I want to optimize strategy St0, sma2=bt.ind.SMA(period=[20,30,40]), and optimize St1: sma1 ma period [5,10].

      Is it possible to do that please?

      posted in General Code/Help
      A
      asuralm

    Latest posts made by asuralm

    • optimization on Strategy Selection example

      Hi:

      The strategy selection shows an example of running two different strategy using the same cerebro.

      Is it possible to run the optimization of each of the strategy within _STRATS = [St0, St1]?

      For example, if I want to optimize strategy St0, sma2=bt.ind.SMA(period=[20,30,40]), and optimize St1: sma1 ma period [5,10].

      Is it possible to do that please?

      posted in General Code/Help
      A
      asuralm
    • strategy performance on multi-data

      Hi:

      I just read post MULTI-EXAMPLE and multi-data strategy.

      If I simple trade a strategy simultaneously on two different data feed, and I want to compare the same strategy performance on two different symbols.

      1. do the two different data have to be the same length? e.g., one data starts from 2000 and the other is from 2010
      2. how do I obtain the performance of the strategy on the two data respectively?
      3. within the strategy, is there a way to know how many datafeeds are added to the cerebro? For example, does the following code work?
      for d in self.datas 
          o1 = self.buy(data=d, exectype=bt.Order.Market)
      

      Thanks

      posted in General Code/Help
      A
      asuralm
    • RE: multi-step optimization

      @ThatBlokeDave
      so when a strategy is addstrategy(), or optstrategy(), it's done. Is there a way to clear it from cerebro?

      The efficiency is low because I need to initialize cerebro and load data every time when I change the strategy with slight different parameter set.

      Then it would be possible that the data is loaded only once, but different strategy can be run on the same data with the same cerebro.

      posted in General Code/Help
      A
      asuralm
    • RE: multi-step optimization

      Thanks.
      Because I want to see how single parameter affects the performance of the strategy individually. Also, if I have 10 parameters in the strategy, if I test 10 parameters individually, there are only 10 cases. Too many if I have to combine them together.

      What you suggesting works well if there are only 2-3 parameters, but the code would be hard to read if I have a lot of parameters.

      posted in General Code/Help
      A
      asuralm
    • multi-step optimization

      Hi

      I want to do a separate parameter optimization, the idea is like I have a strategy with 2 moving averages. I want to do the optimization as follows:

      ma1=[5,15], ma2=50
      ma1=10, ma2=[40,60]

      It's just an example, please don't ask me why I don't optimize the two parameters simultaneously.

      I tried code like :

              cerebro.adddata(data)
      
              # setup analyzers
              cerebro.addanalyzer(bt.analyzers.DrawDown)
              cerebro.addanalyzer(bt.analyzers.TradeAnalyzer)
              cerebro.addanalyzer(bt.analyzers.SQN)
              cerebro.addanalyzer(bt.analyzers.AnnualReturn)
              cerebro.optstrategy(MyStrategy, ma1=[5, 15], ma2=50)
              optresult1=cerebro.run()
      
              cerebro.optstrategy(MyStrategy, ma1=10, ma2=[40,60])
              optresult2=cerebro.run()   
      

      But this is obviously not working.
      Any way to do this without reloading the data from the beginning please?

      Thanks

      posted in General Code/Help
      A
      asuralm
    • RE: Exit on the same bar of entry problem

      @ab_trader

      There is a problem if I send both orders in the next.

      1. the actual fit price is not known in next. For example, I want to set a 30 point target price, if the close price of this bar is 1000 and it issues a long signal. The open price next bar is 1100, then the real entry price is 1100 and target price should be set to 1130. But in next I can only do it 1030.

      2. if I am not using market price but stop/limit price to enter a trade, same problem as 1.

      posted in General Code/Help
      A
      asuralm
    • Exit on the same bar of entry problem

      Hi:

      Let's say that I want to entry a long trade and set the profit target order at 10 pips higher than the entry price.
      How to make sure that the trade exit at the same bar if the target price is hit.
      My code is like:

      def next(self):
          self.buy(size=1, exectype=bt.Order.Market)
      
      def notify_order(self, order):
          target = ...
          self.targetorder = self.sell(size=self.position.size, price=target, exectype=bt.Order.Limit)
      

      However, the problem is that the target order only be sent at the next bar but not within this bar.

      Is there a way to solve the problem.

      Thanks

      posted in General Code/Help
      A
      asuralm
    • RE: Optimzation question

      @backtrader
      There is a question about the optimization improvement. I've read the article optimization-improvements, but it seems that the improvement works in the scenario of single strategy optimization.

      In this strategy auto-generation case, the problem is that trading data are the same and strategy is switching. Is this possible that the data file is only read-once and switching between strategies only?

      My current structure is like:

          signals = itertools.product(EntryList, ExitList)
          for sig, exit in signals:
              cerebro = bt.Cerebro()
              fromdate = datetime.datetime(2014, 1, 1)
              todate = datetime.datetime(2015, 1, 1)
              data = bt.feeds.GenericCSVData(...)
              cerebro.adddata(data)
      
              cerebro.optstrategy(MasterStrategy, signal=sig, exsig1=exit, [paras]...)
              cerebro.run(maxcpus=1)
      

      In such structure, the data is loaded every time in the loop and file reading is very time-consuming.
      It seems not working if I simply move the code before adddata out of the for loop.
      Is it possible that the file is read only once?

      Have you got any good suggestions to improve the performance please?

      Thanks

      posted in General Code/Help
      A
      asuralm
    • RE: Optimzation question

      @backtrader
      thanks.

      I just find a way to bypass the error. Simple enforce the strategy optimization to single thread as:

      cerebro.optstrategy(MasterStrategy, entry=entry, exit=exit, para1=[10,20])
      cerebro.run(maxcpus=1)
      

      Then IDE works with no error. At least I can debug in IDE and when I can switch to multi-threading and run in IDLE after testing.

      posted in General Code/Help
      A
      asuralm
    • RE: Optimzation question

      @backtrader
      Thanks it works fine in the shell.

      It's a shame not working well in pycharm.

      posted in General Code/Help
      A
      asuralm