This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Importing libraries | |
from pandas_datareader import data as pdr | |
# Defining general variables | |
ticker = 'SPY' | |
first_date = '2010-01-01' | |
last_date = '2018-08-31' | |
conficence_level = 0.05 | |
k = 0.02 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def value_at_risk(returns, confidence_level=.05): | |
""" | |
It calculates the Value at Risk (VaR) of some time series. It represents | |
the maximum loss with the given confidence level. | |
Parameters | |
---------- | |
returns : pandas.DataFrame | |
Returns of each time serie. It could be daily, weekly, monthly, ... | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def expected_shortfall(returns, confidence_level=.05): | |
""" | |
It calculates the Expected Shortfall (ES) of some time series. It represents | |
the average loss according to the Value at Risk. | |
Parameters | |
---------- | |
returns : pandas.DataFrame | |
Returns of each time serie. It could be daily, weekly, monthly, ... | |