BSIC / VaR

Simple VaR calculation in Python, both for single value and VaR series in time. Supported formulas at the moment include: Parametric Normal, Parametric EWMA, Historical Simulation and Filtered Historical Simulation with EWMA.
GNU General Public License v3.0
39 stars 18 forks source link

Problem with results #1

Open ghost opened 7 years ago

ghost commented 7 years ago

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?

antonioorsini commented 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()
ghost commented 7 years ago

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.