def compute_beta(benchmark, ric, bool_print=False): capm = stream_classes.capm_manager(benchmark, ric) capm.load_timeseries() capm.compute() if bool_print: print('------') print(capm) beta = capm.beta return beta
def create_dataframe_top_correlations(portfolio, benchmark, universe): df = pd.DataFrame() # columns = security + list of metrics # number of rows = nb_rows # your code comes here columns = ['ric', 'correlation', 'abs_correlation', 'beta'] for i in universe: if portfolio == i: universe.remove(i) index = list(range(len(universe))) df = pd.DataFrame(index=index, columns=columns) for i in universe: n = universe.index(i) df.iloc[n, df.columns.get_loc('ric')] = i capm = stream_classes.capm_manager(portfolio, i) b = stream_classes.capm_manager(benchmark, i) capm.load_timeseries() capm.compute() corr = capm.correlation b.load_timeseries() b.compute() beta = b.beta df.iloc[n, df.columns.get_loc('correlation')] = corr df.iloc[n, df.columns.get_loc('abs_correlation')] = abs(corr) df.iloc[n, df.columns.get_loc('beta')] = beta df.sort_values(by='abs_correlation', ascending=False, inplace=True, ignore_index=True) return df
import importlib import matplotlib.pyplot as plt from scipy.stats import skew, kurtosis, chi2, linregress # import our own files and reload import stream_functions importlib.reload(stream_functions) import stream_classes importlib.reload(stream_classes) # input parameters ric = 'EURUSD=X' # MT.AS SAN.MC BBVA.MC REP.MC VWS.CO EQNR.OL MXNUSD=X ^VIX GBPUSD=X CHFUSD=X benchmark = 'CHFUSD=X' # ^STOXX50E ^STOXX ^S&P500 ^NASDAQ ^FCHI ^GDAXI EURUSD=X capm = stream_classes.capm_manager(ric, benchmark) capm.load_timeseries() capm.compute() capm.scatterplot() capm.plot_normalised() capm.plot_dual_axes() print(capm) ''' References plots https://queirozf.com/entries/pandas-dataframe-plot-examples-with-matplotlib-pyplot '''