ranaroussi / quantstats

Portfolio analytics for quants, written in Python
Apache License 2.0
4.73k stars 827 forks source link

Portfolio metrics based on my own transactions data #292

Open kuatroka opened 1 year ago

kuatroka commented 1 year ago

Hi, maybe it's an irrelevant question and it's already there, but I can't seem to find a simple way of getting the typical portfolio metrics bases on my own data.

Is there an option to just load a csv with my transaction data transactions = [ {'ticker': 'AAPL', 'Date': '2023-08-11', 'price': 100.3, 'transaction': 'buy', 'quantity': 10}, {'ticker': 'AAPL', 'Date': '2023-08-10', 'price': 120.3, 'transaction': 'sell', 'quantity': 5}, {'ticker': 'AAPL', 'Date': '2023-08-09', 'price': 150.2, 'transaction': 'buy', 'quantity': 15}, {'ticker': 'AAPL', 'Date': '2023-08-08', 'price': 87.61, 'transaction': 'buy', 'quantity': 65}, {'ticker': 'AAPL', 'Date': '2023-08-07', 'price': 88.25, 'transaction': 'sell', 'quantity': 2} ]

and get the reports purely on my transactions ? No need for any external market data, just analyse what I already have. Maybe applying the FIFO or some other approach, but is there something like this in quantstats and if not, does anybody knows a library that can do that?

Thanks

soleilinvesting commented 1 year ago

You can do this. You just have to aggregate them into a portfolio of daily returns. It might be easier to start with everything in dollars and then convert the total value of the portfolio into daily returns. Once you have the daily portfolio returns, it is just like single stock data. So instead of putting a ticker into quantstats you put your portfolio returns as a dataframe.