stock_period = StockPeriod(symbol, settings.stock_period_start, today, data_source = settings.data_source) first_learners = map(lambda fs: EnsembleLearner.machine_learner_for_features_string(symbol, fs, stock_period), map(lambda x: x.feature_string, found_ensemble.found_forests)) prediction_performances = [] val_prediction_performances = [] another_domain_pp = [] use_another_domain = (settings.predict_cache_end_time == dt.datetime(2013,2,1)) for found_ensemble in gse.found_ensembles: all_predictions = map(lambda ff: ff.test_predictions, found_ensemble.found_forests) #all_predictions = [found_ensemble.found_forests[0].test_predictions] joined_cached_predicitons = EnsembleLearner.process_predictions(all_predictions, 0.1) test_period_predicitons = joined_cached_predicitons[settings.test_start_time:settings.test_end_time] #test_period_predicitons = joined_cached_predicitons[settings.val_end_time:(settings.val_end_time + relativedelta(months=1) )] pp = PredictionPerformance(test_period_predicitons, first_learners[0].feats.relative_data['close'][symbol], 2) prediction_performances.append(pp) val_period_predicitons = joined_cached_predicitons[settings.val_start_time:settings.val_end_time] val_pp = PredictionPerformance(val_period_predicitons, first_learners[0].feats.relative_data['close'][symbol], 2) val_prediction_performances.append(val_pp) if use_another_domain: another_domain_predictions = joined_cached_predicitons[settings.test_end_time:(settings.test_end_time + relativedelta(months=1))] #another_domain_predictions = joined_cached_predicitons[(settings.val_end_time + relativedelta(months=1)):(settings.val_end_time + relativedelta(months=2) )] another_pp = PredictionPerformance(another_domain_predictions, first_learners[0].feats.relative_data['close'][symbol], 2) another_domain_pp.append(another_pp)
first = True first_predictions = [] part = -1 for predictions, fforest in iter.izip(all_predictions, found_ensemble.found_forests): print "score", fforest.score new_part = find_partition(found_ensemble.found_forests, fforest.score) print "partition", new_part color = colors[new_part % 7] print "color", color pp = PredictionPerformance(predictions, ensemble.learners[0].feats.relative_data['close'][symbol], 2) if new_part > part: part = new_part pp.predictions['tot_return'].plot(style=color) first_predictions.append(predictions) else: pp.predictions['tot_return'].plot() joined_cached_predicitons = ensemble.process_predictions(all_predictions, 0.1) pp2 = PredictionPerformance(joined_cached_predicitons, ensemble.learners[0].feats.relative_data['close'][symbol], 2) print "tot return:", pp2.tot_return() print "mean return:", pp2.return_mean() print "std return:", pp2.return_std() print "sharpe's ratio:", pp2.sharpe_ratio() pp2.predictions['tot_return'].plot(style='r') plt.show()