Navigation

    Backtrader Community

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

    Yi Fang

    @Yi Fang

    1
    Reputation
    387
    Profile views
    23
    Posts
    1
    Followers
    0
    Following
    Joined Last Online

    Yi Fang Unfollow Follow

    Best posts made by Yi Fang

    • RE: Daily upper and lower bound of price

      Thank you for your reply! I will try both out! It might be a great idea to incorporate this in backtrader, as it is (to my knowledge) very common in some stock market, eg. 10% for Taiwan, 30% for Korea, 21.25% upper and 18.75% lower for France (weird isnt it).

      posted in General Code/Help
      Y
      Yi Fang

    Latest posts made by Yi Fang

    • Backtrader 2.0?

      Just wondering what is the status of backtrader 2.0?
      Or will there ever be one?

      posted in General Discussion
      Y
      Yi Fang
    • bt.talib.CORREL not working properly

      For the indicator bt.talib.CORREL, if I pass in two indicators with missing values in the middle, no correlation will be calculated after the first missing value, even the values are there afterward, as a demonstration(a and b are both line object, i only show them as array here):

      import numpy as np
      
      a = np.array([1,1,1,1     ,1,1,1,1,1])     #space on 4th element is for readability
      b = np.array([1,1,1,np.nan,1,1,1,1,1])
      
      print(bt.talib.CORREL(a,b,timepriod=3))
      >>  [nan,nan,1,nan,nan,nan,nan,nan,nan]
      

      The intended result should be:

      [nan,nan,1,nan,nan,nan,1,1,1]
      

      In my actual case, both a and b are about 300 days long, and the missing values is about 30 days long in the middle of one data, and I tried to calculate correlation for a 6 days window, not sure if this has to do with issue. All the value before missing ones are correct.

      posted in General Discussion
      Y
      Yi Fang
    • RE: I want to apply multiple filters to a stock universe of 193 stocks

      @ab_trader

      Thank you for your reply, originally I thought indicator carries the information of which data it was calculated upon. Even if it was another indicator, the original data info should be pass by. Guess I was wrong

      posted in General Discussion
      Y
      Yi Fang
    • RE: I want to apply multiple filters to a stock universe of 193 stocks

      @momentum

      Hi, how do you access the smas in your self.smas list with reference to data name?
      Like how to you know which data was used to calculate smas[0] in later codes?

      The backtrader.indicators.sma.MovingAverageSimple object doesnt have a _name.

      posted in General Discussion
      Y
      Yi Fang
    • RE: Tracking an Index with equal weight positions

      @nicola-prada

      I think this can be done by creating subclass of existing indicator, effectively 'extending' an indicator

      posted in General Discussion
      Y
      Yi Fang
    • RE: Tracking an Index with equal weight positions

      @backtrader

      Well elaborated example.

      posted in General Discussion
      Y
      Yi Fang
    • RE: target order with different price limit depends on buy or sell

      @backtrader

      My goal is described in my old post:

      https://community.backtrader.com/topic/1076/daily-upper-and-lower-bound-of-price/3

      Only here I am trying to take into account daily upper and lower bound of price for target order.

      target order or not, I did try to follow your suggestion in old post, but:

      1. Having a custom Sizer

      This wont work for me since my order are with specific size, a global custom Sizer will be overwritten.

      2.Having a commission scheme

      I read the custom commission scheme, dont see how this will work. The

      def _getcommission(self, size, price, pseudoexec)
      

      only pass in the execution price for orders, not previous bar's (when the order is created) close price, I wont be able to compare these two prices thus impose an inf commission accordingly.

      Official name for such trading restriction is called daily maximum price fluctuation I think, and it is common in commodity futures as well, might be a good idea to implement such feature natively.

      posted in General Discussion
      Y
      Yi Fang
    • RE: Tracking an Index with equal weight positions

      @nicola-prada

      I think pre-processing is requied if additional information are required for stock selection.

      What I did was including all additional infomation into volume line instead of adding new lines, since default BT behaviour is to ignore volume anyway(I hope in the future more complicated logic can be included), and it may seem intuitive to only trade when volume is not 0. So volume value is set to 1 if particular stock is in the index in your case. Of course you may wanna add additional infomation into volume line, like tradability etc., but yeah always look out for look ahead bias.

      In my case I need to add about 3600 stocks into BT and running a 5 years daily bar backtest takes about 18 mins. I preprocess the data with pandas and create a custom pandas feed. I have tested that having less lines actually speed the process up a bit.

      posted in General Discussion
      Y
      Yi Fang
    • RE: target order with different price limit depends on buy or sell

      Did you try to code it the way you shown or you are waiting for an answer? Can be quicker to code it by yourself.

      I did, currently I am working around the issue by manipulating my data in some way. Still stuck with strategy level code though.
      The snippet shown was merely a demonstration of what I hoped to achieve, not working code.

      posted in General Discussion
      Y
      Yi Fang
    • RE: Tracking an Index with equal weight positions

      @backtrader

      after reading ..\samples\timers\scheduled.py, i noticed:

      def prenext(self):
          self.next()
      

      is this the same as copying all code in next() into prenext() so prenext() and next() are exactly the same?

      posted in General Discussion
      Y
      Yi Fang