コード例 #1
0
    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]
コード例 #2
0
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()
コード例 #3
0
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)
コード例 #4
0
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()
コード例 #5
0
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()