Ejemplo n.º 1
0
 def computeInformationRatio(self, portfolio):
     returns = self.preprocess.retrieve_return()
     index = self.preprocess.retrieve_benchmark_change("snp500")
     if self.alpha is None:
         alpha = post.compute_alpha(
             index, returns).loc[portfolio.keys()]["alpha"].values
         self.alpha = alpha
     else:
         alpha = self.alpha
     #print("alpha:", alpha)
     weight = np.array(list(portfolio.values()))
     #print("weight", weight)
     portfolio_return = np.sum(np.multiply(alpha, weight))
     #print("portfolio return", portfolio_return)
     volatility = np.std(alpha)
     #print("volatility", volatility)
     if self.index is None:
         index = self.preprocess.retrieve_benchmark_change(
             self.benchmark) - 1
         self.index = index
     else:
         index = self.index
     #print("benchmark", index)
     information_ratio = (portfolio_return - index) / volatility
     return information_ratio
Ejemplo n.º 2
0
    'steps': []
}

summaries = []
for i in range(steps):
    print("summarizing step:", i)
    start = i
    end = -steps + 1 + i if (steps - i > 1) else duration
    price_frame = daily_price.iloc[start: end]
    start_date = dates[start]
    end_index = duration - steps + i if end < 0 else duration - 1
    end_date = dates[end_index]
    return_frame = preprocess.retrieve_return(date1=start_date, date2=end_date)

    index_change = preprocess.retrieve_benchmark_change(benchmark, date1=start_date, date2=end_date)
    alpha = post.compute_alpha(index_change, return_frame)

    index_series = preprocess.retrieve_benchmark(benchmark, dates=[start_date, end_date])
    beta = post.compute_beta(index_series, price_frame)

    alpha_beta = pd.concat([alpha, beta], axis=1, join='inner')
    alpha_beta_sector = pd.concat([alpha_beta, symbolSector], axis=1, join='inner')  # type: pd.DataFrame
    summary = pd.concat([alpha_beta_sector, mktcap["size"]], axis=1, join='inner')
    summary["symbol"] = "circle"  # set default symbol
    summary.loc[summary.index.isin(stars), "symbol"] = "star"  # mark selected stocks as star
    summaries.append(summary)

# process summaries for index alignment (showing the same data throughout animation)
valid_index = summaries[0].index.values
i = 1  # keep track of summaries index
for summary in summaries[1:]: