Closed MkFint closed 1 year ago
Hi, when you have this kind of error always check your columns headers of you data frame via print(XXX.columns) in this case print(data.columns) you will see that the dataframe don't contain any 'Adj Close' column
MultiIndex([('EFA', 'Open'), ('EFA', 'High'), ('EFA', 'Low'), ('EFA', 'Close'), ('EFA', 'Volume'), ('SPY', 'Open'), ('SPY', 'High'), ('SPY', 'Low'), ('SPY', 'Close'), ('SPY', 'Volume'), ('IYR', 'Open'), ('IYR', 'High'), ('IYR', 'Low'), ('IYR', 'Close'), ('IYR', 'Volume')], )
I don't think the 'Adj Close' is available when extracting weekly data. Some data sources, such as Yahoo Finance, only provide adjusted closing prices for daily data. Issue is that taking only 'Close' column provides the unadjusted closing price that don't take into consideration Dividends and Stock splits, which will give you wrong data over 10 years You can try using a daily interval instead of a weekly interval. This will provide the 'Adj Close' column, which you can then resample to weekly data using the resample() method in pandas.
Thanks you, it's worked perfectly now!
Hello i'm a student in Finance and i have a work to do, but i would like if you want to help me if you can on coding with Python.
Here the work : Download historical data for 3 ETFs of your choice. Use weekly quotes over the longest common period. Additionally, create a portfolio (P) consisting of an equal part of these 3 ETFs. Warning: choose ETFs that have been listed for at least 10 years and that are not too correlated with each other. Exercise 1 a- Present in a few lines the characteristics of the selected ETFs and portfolio P. Specify the calculation used to constitute portfolio P. b- Graphically represent the evolution of the value of your ETFs and portfolio P, by normalizing the initial value to 100 euros (or $ in the case of trading on the US market). Exercise 2 The following calculations will apply to weekly geometric returns (not annualized). a- Calculate the descriptive statistics of the returns. b- Apply the Jarque-Bera normality test. c- Represent the autocorrelation function of the returns. d- Calculate the correlation matrix of the returns of the 3 ETFs and portfolio P. e- Calculate the approximate fourth-order expected utility of a logarithmic utility function for the 3 ETFs and portfolio P. Exercise 3 a- Calculate the 90% VaR for a horizon of 5 business days (1 week) using 3 methods: Historical, Normal and Corrected (Cornish-Fisher) assuming an exposure of 20,000 euros. Calculate the Normal 90% VaR for a horizon of 15 business days (3 weeks). b- Calculate the 90% CVaR (or Expected Shortfall) for a horizon of 5 business days (1 week) using 3 methods: Historical, Normal and Corrected (Cornish-Fisher) assuming an exposure of 20,000 euros.
For the first question i tried this :
but i got an error with KeyError: 'Adj Close', but i tried to data.info but it doesnt work any help ? :)