Exemplo n.º 1
0
from simple_order_gen import SimpleOrderGen
from prediction_performance import PredictionPerformance
import matplotlib.pyplot as plt

symbol = "GOOG"
learn_start_date = dt.datetime(2004, 9, 1)
learn_end_date = dt.datetime(2011, 1, 1)

now = dt.datetime.now()
today = dt.datetime(now.year, now.month, now.day)

stock_period = StockPeriod(symbol, dt.datetime(2000, 1, 1), today)

learners = map(
    lambda fs: EnsembleLearner.machine_learner_for_features_string(symbol, fs, stock_period),
    ensemble_feats.goog_lower_bound8,
)
ensemble = EnsembleLearner(symbol, learn_start_date, learn_end_date, stock_period, learners)
ensemble.learn()

predictions = ensemble.predict_period(dt.datetime(2012, 1, 1), dt.datetime(2013, 1, 1), 0.1)

pp = PredictionPerformance(predictions, ensemble.learners[0].feats.relative_data["close"][symbol], 2)
print "tot return:", pp.tot_return()
print "mean return:", pp.return_mean()
print "std return:", pp.return_std()
print "sharpe's ratio:", pp.sharpe_ratio()

pp.predictions["tot_return"].plot()
plt.show()
Exemplo n.º 2
0
today = dt.datetime(now.year, now.month, now.day)

stock_period = StockPeriod(symbol, dt.datetime(2000, 1, 1), today)


learners = map(
    lambda fs: EnsembleLearner.machine_learner_for_features_string(symbol, fs, stock_period),
    ensemble_feats.goog_lower_bound8,
)

ensemble = EnsembleLearner(symbol, learn_start_date, learn_end_date, stock_period, learners)
ensemble.learn()

monitor_start = dt.datetime(2012, 1, 1)

predictions = ensemble.predict_period(monitor_start, today, 0.1)

relative_data = ensemble.learners[0].feats.relative_data["close"]["GOOG"]

pp = PredictionPerformance(predictions, relative_data, 2)

history_filename = "buy_google_today_history.pkl"
file = open(history_filename, "r")
prediction_history = pickle.load(file)
file.close()

last_prediction_date = pp.predictions.index[-1]
last_history_date = prediction_history.index[-1]

if last_history_date < last_prediction_date:
    predictions_since = pp.predictions[:][(last_history_date + dt.timedelta(hours=1)) :]