Backtrader Community

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

    Saikee Wong

    @Saikee Wong

    1
    Reputation
    215
    Profile views
    9
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Saikee Wong Unfollow Follow

    Best posts made by Saikee Wong

    • Only 2 decimal places precision in stock trading backtest ?

      If my understanding is correct, seems the backtrader round the data to 2 decimal place. which may be OK for US stocks. But HK stocks has 3 decimal places.

      Also, in yahoo data, after split, the historical data is adjusted which could result in may decimal place. Rounding to 2 decimals results in wrong backtest result.

      Am I right ?

      posted in General Discussion
      S
      Saikee Wong

    Latest posts made by Saikee Wong

    • RE: Only 2 decimal places precision in stock trading backtest ?

      Having used the code for years, it messes up like spaghetti.

      In an attempt to dig a simplified version to post to here, I found the simplified code does not snap the price. After compare and test between the two set of codes, eventually figured out the problem comes from data feed method.

      In fetching data, if I use

      data0 = bt.feeds.YahooFinanceCSVData(...)

      the values will be snapped to 2 decimal places during execution.

      If I change it to

      data0 = bt.feeds.GenericCSVData(...)

      it maintain all the precision throughout.

      Thank you all for the response to enlighten me !

      posted in General Discussion
      S
      Saikee Wong
    • RE: Only 2 decimal places precision in stock trading backtest ?

      I generated some test data to be backtested, the data are small values with 0.xxxxxxx

      In my trade strategy, in the next: method, I used self.data_close.get(size=N_days, ago=-0) to get the close prices for last few days, printed the return value, found that the values return are only 2 decimal places, not the original value with over 2 decimal places.

      Also, in the plot, I found the price is always plotted snapping to 0.01 increment.

      posted in General Discussion
      S
      Saikee Wong
    • Only 2 decimal places precision in stock trading backtest ?

      If my understanding is correct, seems the backtrader round the data to 2 decimal place. which may be OK for US stocks. But HK stocks has 3 decimal places.

      Also, in yahoo data, after split, the historical data is adjusted which could result in may decimal place. Rounding to 2 decimals results in wrong backtest result.

      Am I right ?

      posted in General Discussion
      S
      Saikee Wong
    • RE: How to execute order during gap open on next bar ?

      Thank you for the reply.

      For example, the figure below:

      https://www.dropbox.com/s/amb7swq9mhwyxqp/190111z.png?dl=0

      I calculated the top yellow line and projected a target price, if it penetrates, enter the market with buy order. So, with StopLimit and if the next day open below the target price and penetrate up, it works perfectly. My strategy is to buy even if gap opening above the target price happened, then just buy at open price or market price, how can I simulate that ?

      posted in Indicators/Strategies/Analyzers
      S
      Saikee Wong
    • How to execute order during gap open on next bar ?

      May be I have misconception on using the backtrader. Suppose I have a strategy to calculate a target price to buy (or sell). In the next():, I issued an order with StopLimit. If the target price is within next day's high low range, it triggers exactly at the target price. That matches my expectation.

      But if there is a gap, it never trigger.

      What I want is, whenever the market break away from the target price, I will enter the market, at that price if possible, otherwise at the market price. I tried different order types, still cannot get this to work.

      posted in Indicators/Strategies/Analyzers
      S
      Saikee Wong
    • RE: Any chance to use backtrader to back test call / put option trade ?

      Thank you for the clarification.

      I don't mean so automatic to renew the option. The renewal should be taken care via coding in the strategy. Just don't know how to do option trading in backtest.

      Anyhow, I will use other tools to do what I intended to do.

      posted in General Code/Help
      S
      Saikee Wong
    • RE: Any chance to use backtrader to back test call / put option trade ?

      Thank you for the sharp reply.

      Curious to what you mean initially that simulating call and put options as an OHLC series is obviously supported ?

      posted in General Code/Help
      S
      Saikee Wong
    • RE: Any chance to use backtrader to back test call / put option trade ?

      Thank you very much for the prompt reply. Yes, based on daily OHLC.

      What I want to do is to backtest a strategy not using the equity price, but using option. As it looks complicated to find market data about the option value corresponding to the equity, even if i can find data, there are just too many data including expiry, in-at-out of money, which will be troublesome to add to data feed and operate on. I think it may be easier to simulate the invested value based on the black scholes model.

      Suppose using BS formula to calculate the option price, I don't know how to place an order, when the equity reach or beyond (in a jump) the target value, it then charge me the money required for that option. Sure the order instruction will include more information (target, size, type = call / put, at the money / how much away from the target, expire this month / next month, valid), upon execution, it will return the incurred cost. Upon liquidation or expiry, the account will lost the money or get credit. Of course can concurrently have different combination of trade on hand.

      May be those are simple in backtrader, but I'm new and couldn't find any example.

      posted in General Code/Help
      S
      Saikee Wong
    • Any chance to use backtrader to back test call / put option trade ?

      I'm new to python and backtrader. Played around awhile, it is indeed a very complete and good tool, albeit still need some time to know how to use it.

      Googled around, but can't find anything about using the backtrader to back test call / put option. Is there any easy way to do or just simulate ?

      Thanks in advance.

      posted in General Code/Help
      S
      Saikee Wong