# We are going to use a trailing 252 trading day window The following should do the trick: import pandas as pd Lets say we wanted the moving 1-year (252 trading day) maximum drawdown experienced by a particular symbol. You can get this using a pandas rolling_max to find the past maximum in a window to calculate the current day's drawdown, then use a rolling_min to determine the maximum drawdown that has been experienced. This is a short example of the dataframe used: CLOSE_SPX Close_iBoxx A_Returns B_Returns A_Vola B_Vola Does anone know how to implement that in python? considering the minimum only from a given maximum onwards on the timeline. ( df.CLOSE_SPX.max() - df.CLOSE_SPX.min() ) / df.CLOSE_SPX.max()Ĭan't work since these functions use all data and not e.g. I need to calculate the a time dynamic Maximum Drawdown in Python.
0 Comments
Leave a Reply. |