def make_tradeplots_for_files_in_folder(directory): import os from IO import load_tradeprice_data from plotting import make_pretty_tradeprice_plot extension = '.npz' list_of_files = [file for file in os.listdir(directory) if file.lower().endswith(extension)] for file in list_of_files: rounds, prices = IO.load_tradeprice_data(directory + file) filename = directory + file[:-3] + 'png' make_pretty_tradeprice_plot(rounds, prices, filename)
def issue_85_tradeplot_and_tex(folder_with_npz_files, figure_name): import os from plotting import make_pretty_tradeprice_plot npzfiles = os.listdir(folder_with_npz_files) npzfiles = [folder_with_npz_files + f for f in npzfiles if f.endswith('.npz')] print npzfiles for npzfile in npzfiles: make_pretty_tradeprice_plot(IO.load_tradeprice_data(npzfile)) utils.export_tradeprice_figure_as_tex(npzfiles, figure_name)
def issue_113_make_all_tradeprice_plots(): from plotting import make_pretty_tradeprice_plot data_folder = '/Users/halfdan/Dropbox/Waseda/Research/MarketSimulation/Thesis/data_for_tradeprice_plots/' mapping = { 'gen12_1386710381616696.npz' : 'low_stdev_but_not_stable', 'gen56_1388690478773536.npz' : 'low_stdev_and_stable', 'gen13_1387568360402236.npz' : 'high_stdev_but_stable' } figure_folder = make_issue_specific_figure_folder('issue_113_tradeprice_plots', 'all') for dataname, plotname in mapping.items(): rounds, prices = IO.load_tradeprice_data(data_folder + dataname) #make_pretty_tradeprice_plot(rounds, prices, figure_folder + plotname, dpi = 200, figsize=tuple(map(lambda x: x*1, [8,4])), format = 'pdf') make_pretty_tradeprice_plot(rounds, prices, figure_folder + plotname, dpi = 200, format = 'pdf')
def issue_126_chartist_strategy(): from settings import default_parameters as dp import ppl as Ppp import pandas import matplotlib.pyplot as pp import brewer2mpl folder = make_issue_specific_figure_folder('agent_strategies', 'chartist') datapath = '/Users/halfdan/Dropbox/Waseda/Research/MarketSimulation/Thesis/data_for_figures/chartist_strategy/gen0_1387502533563458.npz' rounds, prices = IO.load_tradeprice_data(datapath) colors = brewer2mpl.get_map('Set1', 'qualitative', 9).mpl_colors pp.rc('text', usetex= True) pp.rc('font', family = 'serif') pp.rc('font', size = 14) def mkplot(filename, ma_width = 5000, tbr = 1): pp.figure() pp.plot(rounds, prices, alpha=0.5, color=colors[0]) rolling_mean = pandas.rolling_mean(prices, ma_width) pp.plot(rounds,rolling_mean, linewidth=2, color='black') pp.fill_between(rounds, rolling_mean-tbr, rolling_mean+tbr, color='gray', alpha=0.5, linewidth=0) pp.xlabel('Time (rounds)') pp.ylabel('Price (ticks)') pp.legend(['Price of trades', 'Chartist moving average']) pp.text(50000, 9995, '$H_c = %s$ (rounds)\n $\gamma_c = %s$ (ticks)'%(ma_width, tbr), fontsize = 16) print folder + filename pp.savefig(folder + filename) mkplot('a.png', 5000, 1) mkplot('b.png', 5000, 2) mkplot('c.png', 10000, 1) mkplot('d.png', 10000, 2) mkplot('e.png', 1000, 1) mkplot('f.png', 1000, 2) mkplot('g.png', 15000, 1) mkplot('h.png', 15000, 2) return rounds, prices