Exemplo n.º 1
0
petur.print_evaluation(y_test, predictions)
df_predict = pd.DataFrame({'Predictions': predictions, 'True_label': y_test})

time_End = time.time()
print("Seconds to run:", time_End - time_Start)

# In[Genetic algorithm - Classification]
# Generate Genetic algorithm output == TEST DATA
#==============================================================================

time_Start = time.time()

train_data = df_train.copy()
test_data = df_test.copy()

features = petur.get_tickers()
features.append('OMXIPI')

# Train test split
y_train = train_data.Target
X_train = train_data[features]

y_test = test_data.Target
X_test = test_data[features]

tpot = TPOTClassifier(generations=50,
                      population_size=50,
                      verbosity=2,
                      scoring='f1',
                      n_jobs=-1,
                      cv=5)
Exemplo n.º 2
0
benchmark_name = "Scores/BENCHMARK.csv"
df_benchmark = pd.read_csv(benchmark_name, header=0)
first_column = df_benchmark.columns[0]
df_benchmark = df_benchmark.set_index(first_column, drop=True)
df_benchmark.dropna(axis=1, inplace=True)

importance_dic = pickle.load(open("Pickles/importance_dic.p", "rb"))

#==============================================================================
#In[Feature Engineering]
#==============================================================================
df_fe = df_raw.copy()

# Get list of tickers
tickers = petur.get_tickers()
tickers.append('OMXIPI')
#tickers = ['OMXIPI','MARL', 'OSSRu']   #45% of market cap + index

# Create MAs
sma_days = [5, 10, 20, 50]
fibbonaci = [1, 2, 3, 5, 8, 13, 21]
both = [1, 2, 3, 5, 8, 10, 13, 20, 21, 30, 50]

df_fe = petur.make_sma(df_fe, tickers, sma_days)
df_fe = petur.make_ewma(df_fe, tickers, sma_days)
df_fe = df_fe.dropna()  # Maybe do at end of labels

#==============================================================================
#In[Create labels]
#==============================================================================
import pandas as pd
import time

from tpot import TPOTClassifier
from sklearn.svm import SVC

import petur_functions as petur

# In[Load data and prepare]

# Load data from csv
df_name = "Working_Dataset/MAIN_FULL.csv"
df = pd.read_csv(df_name, index_col='Date', header=0)

# Define tickers to predict and days
tickers = petur.get_tickers()
tickers.append('OMXIPI')
#tickers = ['OMXIPI','MARL', 'OSSRu']

days = [1, 3, 5, 10]
sma_days = [5, 10, 20, 50]
fibbonaci = [1, 2, 3, 5, 8, 13, 21]

# Feature engineering and train
df = petur.make_sma(df, tickers, sma_days)
df = petur.make_ewma(df, tickers, sma_days)
df = df.dropna()

# Train/test split
df_train, df_test = petur.tr_ts_split(df)