Ejemplo n.º 1
0
def _load_from_summary(index, config):
    """ load the backtest result form train_package/train_summary
    @:param index: index of the training and backtest
    @:return: numpy array of the portfolio changes
    """
    dataframe = pd.DataFrame.from_csv("./train_package/train_summary.csv")
    history_string = dataframe.loc[int(index)]["backtest_test_history"]
    if not check_input_same(config, json.loads(dataframe.loc[int(index)]["config"])):
        raise ValueError("the date of this index is not the same as the default config")
    return np.fromstring(history_string, sep=",")[:-1]
Ejemplo n.º 2
0
def _load_from_summary(index, config):
    """ load the backtest result form train_package/train_summary
    @:param index: index of the training and backtest
    @:return: numpy array of the portfolio changes
    """
    dataframe = pd.DataFrame.from_csv("./train_package/train_summary.csv")
    history_string = dataframe.loc[int(index)]["backtest_test_history"]
    if not check_input_same(config, json.loads(dataframe.loc[int(index)]["config"])):
        raise ValueError("the date of this index is not the same as the default config")
    return np.fromstring(history_string, sep=",")[:-1]
Ejemplo n.º 3
0
def _load_from_summary(index, config, what):
    """ load the backtest result form train_package/train_summary
    @:param index: index of the training and backtest
    @:return: numpy array of the portfolio changes
    """
    dataframe = pd.DataFrame.from_csv("./train_package/train_summary.csv")
    history_string = dataframe.loc[int(index)]["backtest_test_history"]
    #start date and end date and test period must be the same!
    if not check_input_same(config, json.loads(dataframe.loc[int(index)]["config"])):
        raise ValueError("the date of this index is not the same as the default config")
    if what == "result":
        return np.fromstring(history_string, sep=",")[:-1]
    if what == "weight":
        json_dir = "./train_package/" + str(int(index)) + "/weight_history" + str(int(index)) + ".json"
        with open(json_dir) as json_file:
            data = json.load(json_file)
        return data["portfolioweights"]