For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

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 ?



  • @Saikee-Wong said in Only 2 decimal places precision in stock trading backtest ?:

    Am I right ?

    I don;t think that bt limits decimal places. Why do you think so?



  • I don't think this is correct. Where are you getting this notion from?



  • 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.



  • Could you add your code to this thread? We'll have a look for you.



  • 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 !



  • Is there any answer? Having the same problem.



  • answer found, apologies. New here and comments can't be deleted :(


Log in to reply
 

});