Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bt - Flexible Backtesting for Python - how to get total portfolio value/result for each given date?

I have recently started using bt for backtesting, and after looking into the documentation, https://pmorissette.github.io/bt/bt.html, there does not seem to be a way to get the total portfolio value at each date, even though it can be easily plotted by calling the .plot() method.

I may have overlooked on my part since I am pretty new to this. Great if someone can point me in the right direction.

like image 557
OGARCH Avatar asked Jan 23 '26 09:01

OGARCH


1 Answers

The library bt has various useful methods that you could use in your backtesting:

Then, assuming that res = bt.run(backtest)

You can do:
res.prices will tell you in a percentage format how your portfolio value is changing
res.backtest_list[0].strategy.outlays will tell you the outlays, which are the total dollar amount spent(gained) by a purchase(sale) of securities
res.backtest_list[0].positions will tell you the number of shares purchased
res.get_security_weights() will tell you the weight of your security in a percentage format

like image 53
FFFAR Avatar answered Jan 25 '26 22:01

FFFAR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!