<jupyter_start><jupyter_text><NAME> FINM 36700Autumn 2021Midterm 1A Answers  1 Short Answer (25 pts)1. (5pts) True or False. (And explain your reason.)Mean-variance optimization goes long the highest Sharpe-Ratio assets and shorts the lowestSharpe-ratio assets. The highest sharpe-ratio assets would have a higher return relative to the assets' risk and the lowest sharpe ratio assets would have a much lower return relative to risk. Regarding mean-variance optimization, we're trying to maximize the assets' return based on the risk, and in this case, highest sharpe-ratio assets are suitable for investors to maximize return while lowest sharpe-ratio assets help investors to control the risk. Therefore it would make sense to go long for highest sharpe-ratio assets and short for lowest sharpe-ratio assets under MV optimization. 2. (5pts) True or False. (And explain your reason.)Investing in an LETF makes more sense for a long-term horizon than a short-term horizon. Investing in LETF should actually be more reasonable for a short-term horizon rather than a long-term horizon. This is because LETF investment have larger expense ratios and usually are associated with higher risk. Additionally, LETF are associated with looking at the short term trajectory of the index and the derivatives are also shorter term investment, thus LETF is better for short-term horizon. 3. (5pts) This week ProShares launches BITO on the NYSE. The ETF holds Bitcoin futures contracts. Suppose in a year from now, we want to try to replicate BITO using SPY and IEF asregressors in a LFD. Because BITO will only have a year of data, we do not trust that we willhave a good estimate of the mean return. Do you suggest that we (in a year) estimate the regression with an intercept or without anintercept? Why? While hedging returns and looking for optimal hedge ratio, the intercept or alpha relates to the mean returns that cannot be explained or replicated by hedge strategy. In this case, since the amount of data is limited for BITO, the estimation of mean return would likely lack precision and accuracy. Therefore, it is likely that a portion of mean return cannot be straightly associated with the hedge strategy and we need more room to explain the excess return, along with potential variations in the estimation. Thus I would suggest the intercept to be included. 4. (5pts) Is HDG effective at tracking HFRI in-sample? And out of sample? HDG is effective at tracking HFRI in-sample because it gains exposure to market factors and can also have straight exposure to series of derivatives or securities in the market, while providing information on return as well as transparency and liquidity solutions. However, it is not as effective for HFRI out-of-sample because regarding index performance, there is no solid positive forecast on whether the fund's index could perform based on its expectations. Additionally, with unseen data under out-of-sample condition, derivatives could also perform ambiguously when markets flunctuate, which can impact the returns and volatility of the fund. 5. (5pts) A hedge fund claims to beat the market by having a very high alpha. After regressingthe hedge fund returns on the 6 Merrill-Lynch style factors, you find the alpha to be negative.Explain why this discrepancy can happen. With the negative alpha, it implicates that the hedge fund is underperforming with regards to the market and not enough returns are generated give the amount of risk. This discrepany can be caused by the fact that there aren't enough optimal diversification for the hedge fund investments, and the ineffectiveness of the hedge fund strategy. This means that fund is not having a reasonable distribution of investment capital in its stocks, securities, or other funds and derivatives, either lacking optimal diversification or unreasonable hedging strategies in the fund's portfolio management.   2 Allocation (25 pts)Consider the Merrill-Lynch Style Factors found in “proshares analysis data.xlsx”, sheet “merrill factors”.We will use “USGG3M Index” as the risk-free rate. Subtract it from the other 5 columns, and proceedwith those 5 risky assets.11. (5pts) What are the weights of the tangency portfolio, wtan?2. (5pts) What are the weights of the optimal portfolio, w∗, with a targeted excess mean return of.02 per month?Is the optimal portfolio, w∗, invested in the risk-free rate?3. (5pts) Report the mean, volatility, and Sharpe ratio of the optimized portfolio. Annualize allthree statistics.4. (5pts) Re-calculate the optimal portfolio, w∗ with target excess mean of .02 per month. Butthis time only use data through 2018 in doing the calculation. Calculate the return in 2019-2021based on those optimal weights.Report the mean, volatility, and Sharpe ratio of the 2019-2021 performance.5. 5. (5pts) Suppose that instead of optimizing these 5 risky assets, we optimized 5 commodity futures:oil, coffee, cocoa, lumber, cattle, and gold.Do you think the out-of-sample fragility problem would be better or worse than what we haveseen optimizing equities?No calculation is needed for this question–we just want a conceptual (though specific) answer.<jupyter_code>import pandas as pd
import numpy as np
import statsmodels.api as sm
import statsmodels.formula.api as smf

pd.set_option('display.float_format', lambda x: '%.4f' % x)

hf_df = pd.read_excel('../proshares_analysis_data.xlsx', "hedge_fund_series")
hf_df.set_index('date', inplace=True)

factors_df = pd.read_excel('../proshares_analysis_data.xlsx', "merrill_factors")
factors_df.set_index('date', inplace=True)

final_factor = factors_df.join(hf_df)
final_factor = final_factor[['SPY US Equity', 'USGG3M Index', 'EEM US Equity', 'EFA US Equity', 'EUO US Equity', 'IWM US Equity']]
final_factor = final_factor.dropna()
#2.1
from numpy.linalg import inv

mu_tilde = hf_df.mean() * 12
std = hf_df.std() * np.sqrt(12)
corr = hf_df.corr()
Sigma = hf_df.cov() * 12
Sigma_inv = inv(Sigma)
N = Sigma.shape[0]
weights_t = Sigma_inv @ mu_tilde / (np.ones(N) @ Sigma_inv @ mu_tilde)
print('Check sum of weights: {:.3f}'.format(weights_t.sum()))
q2_1_df = pd.DataFrame(weights_t, index=hf_df.columns, columns=['Weights of tangency portfolio'])
display(q2_1_df.style.set_caption('Table 1: weights of the tangency portfolio'))
#2.2
from numpy.linalg import inv

mu_tilde = hf_df.mean() * 12 * 1.02
std = hf_df.std() * np.sqrt(12)
corr = hf_df.corr()
Sigma = hf_df.cov() * 12
Sigma_inv = inv(Sigma)
N = Sigma.shape[0]
weights_t = Sigma_inv @ mu_tilde / (np.ones(N) @ Sigma_inv @ mu_tilde)
print('Check sum of weights: {:.3f}'.format(weights_t.sum()))
q2_2_df = pd.DataFrame(weights_t, index=hf_df.columns, columns=['Weights of optimal portfolio'])
display(q2_2_df.style.set_caption('Table 2: weights of the optimal portfolio'))
#No, the optimal portfolio is not invested in risk-free rate.
#2.3
def q2(data):
    means = data.mean()*12
    stds = data.std()*np.sqrt(12)
    SR = means / stds
    df = pd.DataFrame()
    df['mean'] = means
    df['volatility'] = stds
    df['Sharpe ratio'] = SR
    return df
q2_3_df = q2(final_factor)
q2_3_df.style.set_caption('Table 3: mean, volatility and Sharpe ratio of each asset (Annualized)')
#2.4
factor_2018 = final_factor.loc[:'Dec-2018']
from numpy.linalg import inv

mu_tilde = factor_2018.mean() * 12 * 1.02
std = factor_dec.std() * np.sqrt(12)
corr = factor_dec.corr()
Sigma = factor_dec.cov() * 12
Sigma_inv = inv(Sigma)
N = Sigma.shape[0]
weights_t = Sigma_inv @ mu_tilde / (np.ones(N) @ Sigma_inv @ mu_tilde)
print('Check sum of weights: {:.3f}'.format(weights_t.sum()))

op_portf = final_factor.loc['Dec-2018':]@ weights_t
mean = op_portf.mean()*12*1.02
vol = op_portf.std() * np.sqrt(12)
SR = mean / vol
q2_4_df = pd.DataFrame(index=['Optimal portfolio'])
q2_4_df.loc['Optimal portfolio', 'mean'] = mean
q2_4_df.loc['Optimal portfolio', 'vol'] = vol
q2_4_df.loc['Optimal portfolio', 'Sharpe ratio'] = SR
display(q2_4_df.style.set_caption('Table 4: mean, vol and Sharpe ratio of the optimal portfolio'))<jupyter_output><empty_output><jupyter_text>2.5For the five commodity futures, the out-of sample fragility problem would be worse than what we've seen optimizing equities, because commodities usually carry much higher risk with potential great shifts in supply and demand of commodities. Thus, they would normally have larger volatility compared to regular equities and optimizing them.  3 Hedging & Replication (20 pts)Continue to use the same data file from the previous problem.2Suppose we want to invest in EEM, but hedge out SPY. Do this by estimating a regression of EEMon SPY.• Do NOT include an intercept.• Use the full sample of data.1. (5pts) What is the optimal hedge ratio over the full sample of data? That is, for every dollarinvested in EEM, what would you invest in SPY?2. (5pts) What is the mean, volatility, and Sharpe ratio of the hedged position, had we appliedthat hedge throughout the full sample? Annualize the statistics.3. (5pts) Does it have the same mean as EEM? Why or why not?4. (5pts) Suppose we estimated a multifactor regression where in addition to SPY, we had IWMas a regressor. Why might this regression be difficult to use for attribution or even hedging?<jupyter_code>#3.1
import numpy as np
import pandas as pd
import statsmodels.formula.api as smf
import statsmodels.api as sm
import matplotlib.pyplot as plt

pd.set_option('display.float_format', lambda x: '%.4f' % x)
path = 'proshares_analysis_data.xlsx'

df_factor = pd.read_excel(path, sheet_name='merrill_factors').set_index('date')
temp = pd.read_excel(path, sheet_name='hedge_fund_series').set_index('date')
temp.columns = temp.columns.str.strip()
ind_hf_names = temp.columns.values
df_hf = df_factor.join(temp)

temp = pd.read_excel(path, sheet_name='other_data').set_index('date')
temp.columns = temp.columns.str.strip()
data_names = temp.columns
df_data = df_factor.join(temp)
del temp
#3.2
eem_new = df_data['EEM'] - beta*df_data['SPY']
eem_mean = eem_new.mean()
eem_vol = eem_new.std()*np.sqrt(12)
SR_eem_new_m = (eem_new.mean()) / (eem_new.std())
SR_eem_new_a = (eem_new.mean()*12) / (eem_new.std()*np.sqrt(12))
#3.3
#No, it does not have the same mean as EEM without including the intercept.
#3.4
#For the multivariate regression, this can be difficult for hedging because there is less of an explanatory power of the hedge fund regression with a bigger regression framework, when the regressors have trouble meeting the iid requirements or that they have mutual correlations. This would make it difficult for SPY to have significant betas that match the original optimization when adding IWM as the standard expected returns is not applied.<jupyter_output><empty_output><jupyter_text>Modeling Risk (20 pts)Continue to use the same data file used in the previous problem. But for this problem use the totalreturns of SPY and EFA. That is, use the returns as given in the spreadsheet–without subtractingUSGG3M Index.1. (10pts) SPY and EFA are highly correlated, yet SPY has had a much higher return. Howconfident are we that SPY will overperform EFA over the next 10 years?To answer the question,• use statistical estimates of the total returns of SPY and EFA over the full sample.• Assume that log returns for both assets are normally distributed.2. (10pts) Calculate the 60-month rolling volatility of EFA.Use the latest estimate of the volatility (Sep 2021), along with the normality formula, to calculatea Sep 2021 estimate of the 1-month, 1% VaR. In using the VaR formula, assume that the meanis zero.<jupyter_code>#4.1
rhs = sm.add_constant(df_data['SPY'])
lhs = df_data['EFA']
reg = sm.OLS(lhs, rhs, missing='drop').fit()
spy_new = beta*df_data['SPY'] - beta*df_data['EFA']
spy_new = np.math.log(1+spy_new.mean())
r2 = reg.rsquared_adj
corr_data = np.sqrt(r2)
#we are confident that SPY will over-perform EFA over the next 10 years.
#4.2
pf = final_factor.loc['Sep-2021']@ weights_t
mean = pf.mean()*12*5
rolling_vol = pf.std() * np.sqrt(12*5)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0805766186151154, 'fraction_numerical': 0.019498375135405383, 'mean_word_length': 5.037223340040241, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '447884', 'license': 'MIT', 'n_tokens_mistral': 3748, 'n_tokens_neox': 3484, 'n_words': 1571, 'path': 'solutions/mid1/submissions/fanjulie_LATE_90125_6242878_midterm1A.ipynb', 'repo_name': 'tulyu96/finm-portfolio-2021', 'size': '12004'}