Open ghost opened 7 years ago
Hi! Thank you! I'll post a sample code below so you can just try it out. I use pandas_datareader to download stock data, you need to install it separately from pandas with pip install pandas-datareader
.
Hope this will work out for you!
import pandas as pd
import pandas_datareader.data as web
import matplotlib.pyplot as plt
from VaR import *
# Download data from yahoo
df = web.DataReader('GOOG','yahoo', start='2015-01-01', end='2016-08-01')
# Get the one day returns
df_returns = (df['Adj Close'].pct_change(1))*100
# Use VaR functions
df_VaR = VaR(df_returns, Formula = 'Parametric EWMA', Confidence_Interval = 0.95 ,
Period_Interval = 100 , EWMA_Discount_Factor = 0.94, Series = True)
plt.plot(df_VaR)
plt.show()
df_VaR_compare = VaR_Compare(df_returns)
plt.show()
Hi thanks for help :) but I solved this issue before you posted. Once again, great code! I also found a mistake with Historical Simulation formula. Numpy percentile function take alfa between 0 and 100 instead of 0.01 , 0.05 :) So the historical simulation VaR will more "natural" like here http://puu.sh/vY2oO/5f9ce63eb0.jpg.
Hello :) first, great job with this Var Formulas. I'm trying to use your code but I can't figure out how the input file should look like :/. I'm ending with "Process finished with exit code 0" without ploted results. Could you post example input file with returns?