简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM