def set_company_and_data(self, code: str): """ Set the company and the closing_prices for this buy and hold strategy :param code: company code :type code: str """ self.company = code self.closing_prices = stock_price_data.get_stock_data( self.company)[column_headings.ADJUSTED_CLOSING_PRICE]
def calculate_cumulative_returns(code: str) -> pd.DataFrame: """ :param code: code of the company :type code: str :return: cumulative returns :rtype: pd.Dataframe """ data = get_stock_data(code) data[RETURNS] = _calculate_percentage_change(data) return (data[RETURNS] + 1).cumprod()
def calculate_returns_daily(code: str) -> pd.DataFrame: """ Calculate daily returns given a code :param code: code of the company :type code: str :return: daily percentage change :rtype: pd.Dataframe """ data = get_stock_data(code) return _calculate_percentage_change(data)
def calculate_returns_monthly(code: str) -> pd.DataFrame: """ Calculate monthly return given a code :param code: code of the company :type code: str :return: monthly percentage change :rtype: pd.Dataframe """ data = get_stock_data(code) return data[CLOSE].resample(MONTH).ffill().pct_change()
def calculate_percentage_change_based_on_adjusted_closing_price( code: str) -> pd.DataFrame: """ Calculate percentage change of a company given a company code :param code: company code :type code: str :return: percentage changes :rtype: pd.Dataframe """ return get_stock_data(code)[ADJUSTED_CLOSING_PRICE].pct_change().dropna()