In [1]:
import pandas as pd
from beakerx import *

import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)

In [2]:
# import prices from csv file using pandas
prices=pd.read_csv("data/price.csv", index_col=0, header=0, parse_dates=True)

In [3]:
# plot using beakerx
SimpleTimePlot(prices, prices.keys())


Drawdown


In [4]:
from pyutil.performance.drawdown import drawdown

In [5]:
SimpleTimePlot(prices.pct_change().apply(drawdown), prices.keys())


Month/Year Table


In [6]:
from pyutil.performance.month import monthlytable

In [7]:
TableDisplay(100*monthlytable(prices["A"].pct_change()))


Value at Risk


In [8]:
from pyutil.performance.var import cvar, var

In [9]:
prices.pct_change().apply(var, alpha=0.95)


Out[9]:
A    0.019077
B    0.015518
C    0.023442
D    0.012359
E    0.012404
F    0.015653
G    0.010803
dtype: float64

In [10]:
prices.pct_change().apply(var, alpha=0.99)


Out[10]:
A    0.029495
B    0.023364
C    0.034154
D    0.020042
E    0.019999
F    0.029403
G    0.017731
dtype: float64

In [11]:
prices.pct_change().apply(cvar, alpha=0.95)


Out[11]:
A    0.027620
B    0.020367
C    0.029857
D    0.018043
E    0.016325
F    0.023326
G    0.015331
dtype: float64

Periods


In [12]:
from pyutil.performance.periods import period_returns

In [13]:
period_returns(prices["A"].pct_change(), today=prices["A"].dropna().index[-1])


Out[13]:
Two weeks       -0.007120
Month-to-Date    0.014286
Year-to-Date     0.013276
One Month        0.015186
Three Months    -0.071541
One Year        -0.069166
Three Years     -0.282707
Five Years      -0.282707
Ten Years       -0.282707
dtype: float64

In [14]:
TableDisplay(prices.pct_change().apply(lambda x: period_returns(x, today=x.dropna().index[-1])))



In [ ]: