Пример #1
0
def run():
    sound_state = False
    error = False
    while (True):
        op = t.general_menu(error=error)
        error = False
        if (op == "1"): a.run()
        elif (op == "2"): sound_state = pause(sound_state)
        elif (op == "3"): instructions()
        elif (op == "4"): t.credits()
        elif (op == "5"): break
        else: error = True
Пример #2
0
def saw_eval_base(individual, stocks, bundle_name, train_start, train_end,
                  capital_base, trade_freq, social_media, **kwargs):
    # convert individual weights into weights for the stocks
    # if debug: print("SAW EVAL BASE")
    w = OrderedDict()
    i = 0
    for s in stocks:
        w[s] = {"p": individual[i], "n": individual[i + 1]}
        i = i + 2

    algo = TradingSignalAlgorithm(
        verbose=False,
        grp="DALIO",
        subgrp="ALL_WEATHER",
        collect_before_trading=False,
        history=500,
        rebalance_freq=trade_freq,
        trading_signal=saw_ga_trading_fn,
        initial_weights=[0.3, 0.4, 0.15, 0.075, 0.075],
        normalise_weights=True,
        **{
            "weights": w,
            "social_media": social_media
        })
    _, algo_results = run("SAW-GA",
                          algo,
                          bundle_name,
                          train_start,
                          train_end,
                          capital_base,
                          analyze=False)

    return algo_results
Пример #3
0
def smpt_eval_base(individual,
                   stocks,
                   bundle_name,
                   train_start,
                   train_end,
                   capital_base,
                   trade_freq,
                   social_media,
                   objective="max_sharpe",
                   **kwargs):
    # if debug: print("SMPT EVAL BASE")
    w = list(individual)

    algo = OptAlgorithm(verbose=False,
                        grp="DALIO",
                        subgrp="ALL_WEATHER",
                        collect_before_trading=False,
                        history=500,
                        rebalance_freq=trade_freq,
                        mpt_adjustment=smpt_ga_trading_fn,
                        objective=objective,
                        **{
                            "weights": w,
                            "social_media": social_media
                        })
    _, algo_results = run("SMPT-GA",
                          algo,
                          bundle_name,
                          train_start,
                          train_end,
                          capital_base,
                          analyze=False)

    return algo_results
Пример #4
0
#!/usr/bin/env python

import algorithms
import os

#filename = 'iris.data'  # expects csv
filename = 'gtd.data' # expects csv
filename = os.curdir + "/" + filename                  

# pass fully qualified file name to run()
# TODO: use 'argparse' module to take this from command line
algorithms.run(filename, 'perceptron', {'testSplit':0.2, 'learningRate':0.005, \
'maxIterations':10000})
Пример #5
0
#!/usr/bin/env python

import algorithms
import os

#filename = 'iris.data'  # expects csv
filename = 'gtd.data'  # expects csv
filename = os.curdir + "/" + filename

# pass fully qualified file name to run()
# TODO: use 'argparse' module to take this from command line
algorithms.run(filename, 'perceptron', {'testSplit':0.2, 'learningRate':0.005, \
'maxIterations':10000})
Пример #6
0
def compareResults(base_name="SAW_GA_MAX_RET",
                   opt_type="saw",
                   social_media=None,
                   bundle_name="",
                   train_start=None,
                   test_start=None,
                   test_end=None,
                   stocks=None,
                   trade_freq='weekly',
                   capital_base=1000000,
                   history=500,
                   prefix="",
                   **kwargs):
    all_ga = []  # [bm_all_weather]
    test_ga = []  # [bm_aw_test]

    for file in tqdm(glob.glob(f"{base_name}_p*.pickle")):
        file = file.replace("\\", "/")
        m = re.search(f'{base_name}_p(\d*)_g(\d*)_s(\d*).*', file)
        # print(file)
        pop = m.group(1)
        gen = m.group(2)
        seed = m.group(3)

        with open(f"{file}", "rb+") as f:
            top10_max_ret = pickle.load(f)

            if opt_type == "saw":
                best_max_ret = top10_max_ret[0]
                w_max_ret = OrderedDict()
                i = 0

                for s in stocks:
                    w_max_ret[s] = {
                        "p": best_max_ret[i],
                        "n": best_max_ret[i + 1]
                    }
                    i = i + 2

                algo = TradingSignalAlgorithm(
                    verbose=False,
                    grp="DALIO",
                    subgrp="ALL_WEATHER",
                    collect_before_trading=False,
                    history=history,
                    rebalance_freq=trade_freq,
                    trading_signal=saw_ga_trading_fn,
                    initial_weights=[0.3, 0.4, 0.15, 0.075, 0.075],
                    normalise_weights=True,
                    **{
                        "weights": w_max_ret,
                        "social_media": social_media
                    })

            else:
                w_max_ret = top10_max_ret[0]

                algo = OptAlgorithm(verbose=False,
                                    grp="DALIO",
                                    subgrp="ALL_WEATHER",
                                    collect_before_trading=False,
                                    history=history,
                                    rebalance_freq=trade_freq,
                                    mpt_adjustment=smpt_ga_trading_fn,
                                    **{
                                        "weights": w_max_ret,
                                        "social_media": social_media
                                    })

            saw_ga_test = run(f"{prefix}{pop}-{gen}-{seed}",
                              algo,
                              bundle_name,
                              test_start,
                              test_end,
                              capital_base,
                              analyze=False)
            saw_ga_all = run(f"{prefix}{pop}-{gen}-{seed}",
                             algo,
                             bundle_name,
                             train_start,
                             test_end,
                             capital_base,
                             analyze=False)
            test_ga.append(saw_ga_test)
            all_ga.append(saw_ga_all)

    return test_ga, all_ga