def get_stdev_on_date(self, relevant_date: datetime.datetime) -> stdevEstimates: if relevant_date < self.index[0]: stdev_as_dict = get_row_of_df_aligned_to_weights_as_dict( df=self, relevant_date=self.index[0]) else: stdev_as_dict = get_row_of_df_aligned_to_weights_as_dict( df=self, relevant_date=relevant_date) return stdevEstimates(stdev_as_dict)
def get_stdev_estimate(self, relevant_date: datetime.datetime = arg_not_supplied) -> stdevEstimates: df_of_vol = self.get_df_of_perc_vol() stdev_at_date = get_row_of_df_aligned_to_weights_as_dict(df_of_vol, relevant_date) stdev_estimate = stdevEstimates(stdev_at_date) return stdev_estimate
def get_portfolio_weights_for_relevant_date(self, relevant_date: datetime.datetime = arg_not_supplied) \ -> portfolioWeights: weights_as_df = self.get_original_portfolio_weight_df() weights_at_date = get_row_of_df_aligned_to_weights_as_dict(weights_as_df, relevant_date) portfolio_weights = portfolioWeights(weights_at_date) return portfolio_weights
def get_per_contract_value( self, relevant_date: datetime.datetime = arg_not_supplied ) -> portfolioWeights: df_of_values = self.get_per_contract_value_as_proportion_of_capital_df() values_at_date = get_row_of_df_aligned_to_weights_as_dict( df_of_values, relevant_date ) contract_values = portfolioWeights(values_at_date) return contract_values
def get_maximum_portfolio_weight_at_date( self, relevant_date: datetime.datetime = arg_not_supplied ) -> portfolioWeights: max_portfolio_weight = self.get_maximum_portfolio_weight_as_df() max_weight_at_date = get_row_of_df_aligned_to_weights_as_dict( max_portfolio_weight, relevant_date) return portfolioWeights(max_weight_at_date)
def get_position_contracts_for_relevant_date( self, relevant_date: datetime.datetime = arg_not_supplied ) -> portfolioWeights: position_contracts_as_df = self.get_position_contracts_as_df() position_contracts_at_date = get_row_of_df_aligned_to_weights_as_dict( position_contracts_as_df, relevant_date ) position_contracts = portfolioWeights(position_contracts_at_date) return position_contracts
def _get_portfolio_risk_given_weights(self, portfolio_weights: pd.DataFrame) -> pd.Series: risk_series = [] common_index = self.common_index() p = progressBar(len(common_index), show_timings=True, show_each_time=False) for relevant_date in common_index: p.iterate() weights_on_date = portfolioWeights( get_row_of_df_aligned_to_weights_as_dict(portfolio_weights, relevant_date)) covariance = self.get_covariance_matrix(relevant_date) risk_on_date = calculate_risk(weights = weights_on_date, covariance = covariance) risk_series.append(risk_on_date) p.finished() risk_series = pd.Series(risk_series, common_index) return risk_series
def get_weights_on_date(self, relevant_date: datetime.datetime) \ -> portfolioWeights: weights_as_dict = get_row_of_df_aligned_to_weights_as_dict( df=self, relevant_date=relevant_date) return portfolioWeights(weights_as_dict)