Thursday 28 April 2022

Financial performance and risk analysis statistics from sample DataFrame

How do I output detailed financial performance and risk analysis statistics from this sample pandas DataFrame?

Can anyone show how this could be done with Quantstats, Pyfolio or another similar approach?

Code

start_amount = 100000

np.random.seed(8)
win_loss_df = pd.DataFrame(
    np.random.choice([1000, -1000], 543),
    index=pd.date_range("2020-01-01", "2022-01-30", freq="B"),
    columns=["win_loss_amount"]
)
win_loss_df["total_profit"] = win_loss_df.win_loss_amount.cumsum() + start_amount

Sample DataFrame

win_loss_df.head(10)

win_loss_amount total_profit
2020-01-01  -1000   99000
2020-01-02  1000    100000
2020-01-03  -1000   99000
2020-01-06  -1000   98000
2020-01-07  -1000   97000
2020-01-08  1000    98000
2020-01-09  1000    99000
2020-01-10  -1000   98000
2020-01-13  1000    99000
2020-01-14  -1000   98000

Desired output

I would like to see output including:

  • Annual return
  • Sharpe ratio
  • Max drawdown

I was hoping to use a library for this which would simplify the process and return data similar to a tear sheet.



from Financial performance and risk analysis statistics from sample DataFrame

No comments:

Post a Comment