How to add code to a python library to it work?

29 Views Asked by At

i use Backtesting.py, source: https://kernc.github.io/backtesting.py/, is a Python framework:

from backtesting import Backtest, Strategy

And when i debug Its path is: C:\Users\Admin\AppData\Local\Programs\Python\Python310\Lib\site-packages\backtesting

when i add code print('it printed') into function init of class Backtest: and call it, i see it don't work.

Do we need to use a build command or something to let python understand that I just added the print line?

1

There are 1 best solutions below

0
naved196 On

the problem here is you are not calling the backtest class correctly

from backtesting import Backtest, Strategy


class MyStrat(Strategy):

          def init(self):
        
               print('it printed')

backtest = Backtest(MyStrat, data='test_data', cash=10000)

stats = backtest.run()

print(stats)

Replace 'test_data' with your actual data