<jupyter_start><jupyter_text>Now let us compare the simulations. Price<jupyter_code>''' Price '''
data['Price (Reference)'] = ref['Price']
data['Price (Simulation)'] = run['Price']
data['Gen'] = run['Gen']
data.plot(x="Gen", y = ["Price (Reference)", "Price (Simulation)"],
        kind="line", figsize=(15, 6), title='Comparison of price', 
        color = ['red','black'],
        style = ['-','-'])
plt.xlabel('Time (days)')
plt.ylabel('Price')
plt.savefig('figures/replic_price.png', dpi = 300)
plt.show()<jupyter_output><empty_output><jupyter_text>Dividends<jupyter_code>''' Dividends '''
data = pd.DataFrame()
data['Dividends (Reference)'] = ref['Dividends']
data['Dividends (Simulation)'] = run['Dividends']
data['Gen'] = run['Gen']
data.plot(x="Gen", y = ["Dividends (Reference)", "Dividends (Simulation)"],
        kind="line", figsize=(15, 6), title='Comparison of dividends', 
        color = ['red','black'],
        style = [':','-'])
plt.xlabel('Time (days)')
plt.ylabel('Daily dividend')
plt.savefig('figures/replic_div.png', dpi = 300)
plt.show()

print(ref['Dividends'].std())
print(run['Dividends'].std())<jupyter_output><empty_output><jupyter_text>Volume<jupyter_code>''' Volume '''
data['Volume (Reference)'] = ref['Volume']
data['Volume (Simulation)'] = run['Volume']

fig, (ax1, ax2) = plt.subplots(2, 1, figsize = (10, 5), sharex = True, sharey = True)
fig.suptitle('Volume (Reference and Simulation)')
ax1.plot(data["Volume (Reference)"], label = 'Volume (Reference)')
ax2.plot(data["Volume (Simulation)"], label = 'Volume (Simulation)')
ax1.legend()
ax2.legend()
ax2.set_xlabel('Time (days)')
ax2.set_ylabel('Volume')
plt.savefig('figures/replic_vol.png', dpi = 300)
plt.show()<jupyter_output><empty_output><jupyter_text>Wealth<jupyter_code>''' Net asset value (i.e. asset long * price) '''
data['NT NAV (Reference)'] = ref['NT_nav']
data['NT NAV (Simulation)'] = run['NT_nav']
data['VI NAV (Reference)'] = ref['VI_nav']
data['VI NAV (Simulation)'] = run['VI_nav']
data['TF NAV (Reference)'] = ref['TF_nav']
data['TF NAV (Simulation)'] = run['TF_nav']
data['Gen'] = run['Gen']
data.plot(x="Gen", y = ["NT NAV (Reference)", "NT NAV (Simulation)","VI NAV (Reference)", 
    "VI NAV (Simulation)","TF NAV (Reference)", "TF NAV (Simulation)"],
        kind="line", figsize=(15, 6), title='Comparison of agent net asset values', 
        color = ['r', 'r', 'g', 'g', 'b', 'b'],
        style = [':', '-', ':', '-', ':', '-'])
plt.xlabel('Time (days)')
plt.ylabel('Net asset value')
plt.savefig('figures/replic_nav.png', dpi = 300)
plt.show()

data.plot(x="Gen", y = ["TF NAV (Reference)", "TF NAV (Simulation)"],
        kind="line", figsize=(15, 6), title='Comparison of agent net asset values', 
        color = ['r', 'b'],
        style = ['-', '-'])
plt.xlabel('Time (days)')
plt.ylabel('Net asset value')
plt.savefig('figures/tf_replic_nav.png', dpi = 300)
plt.show()<jupyter_output><empty_output><jupyter_text>Wealth shares<jupyter_code>data['WShare_NT (Reference)'] = data['NT NAV (Reference)'] / (data['NT NAV (Reference)'] + data['VI NAV (Reference)'] + data['TF NAV (Reference)'])
data['WShare_VI (Reference)'] = data['VI NAV (Reference)'] / (data['NT NAV (Reference)'] + data['VI NAV (Reference)'] + data['TF NAV (Reference)'])
data['WShare_TF (Reference)'] = data['TF NAV (Reference)'] / (data['NT NAV (Reference)'] + data['VI NAV (Reference)'] + data['TF NAV (Reference)'])

data['WShare_NT (Simulation)'] = data['NT NAV (Simulation)'] / (data['NT NAV (Simulation)'] + data['VI NAV (Simulation)'] + data['TF NAV (Simulation)'])
data['WShare_VI (Simulation)'] = data['VI NAV (Simulation)'] / (data['NT NAV (Simulation)'] + data['VI NAV (Simulation)'] + data['TF NAV (Simulation)'])
data['WShare_TF (Simulation)'] = data['TF NAV (Simulation)'] / (data['NT NAV (Simulation)'] + data['VI NAV (Simulation)'] + data['TF NAV (Simulation)'])

fig, (ax1, ax2) = plt.subplots(2, 1, figsize = (10, 5), sharex = True, sharey = True)
fig.suptitle('Strategy wealth share (Reference and Simulation)')
ax1.plot(data['WShare_NT (Reference)'], label = 'WShare_NT (Reference)')
ax1.plot(data['WShare_VI (Reference)'], label = 'WShare_VI (Reference)')
ax1.plot(data["WShare_TF (Reference)"], label = 'WShare_TF (Reference)')
ax2.plot(data["WShare_NT (Simulation)"], label = 'WShare_NT (Simulation)')
ax2.plot(data["WShare_VI (Simulation)"], label = 'WShare_VI (Simulation)')
ax2.plot(data["WShare_TF (Simulation)"], label = 'WShare_TF (Simulation)')
ax1.legend()
ax2.legend()
ax2.set_xlabel('Time (days)')
ax2.set_ylabel('Wealth shares')
plt.savefig('figures/replic_wshare.png', dpi = 300)
plt.show()<jupyter_output><empty_output><jupyter_text>Other agent variables (cash, lending, loans, PNL, signal, stocks)<jupyter_code>''' Cash '''
data['NT Cash (Reference)'] = ref['NT_cash']
data['NT Cash (Simulation)'] = run['NT_cash']
data['VI Cash (Reference)'] = ref['VI_cash']
data['VI Cash (Simulation)'] = run['VI_cash']
data['TF Cash (Reference)'] = ref['TF_cash']
data['TF Cash (Simulation)'] = run['TF_cash']
data['Gen'] = run['Gen']
data.plot(x="Gen", y = ["NT Cash (Reference)", "NT Cash (Simulation)","VI Cash (Reference)", 
    "VI Cash (Simulation)","TF Cash (Reference)", "TF Cash (Simulation)"],
        kind="line", figsize=(15, 6), title='Comparison of agent cash', 
        color = ['r', 'r', 'g', 'g', 'b', 'b'],
        style = [':', '-', ':', '-', ':', '-'])
plt.xlabel('Time (days)')
plt.ylabel('Cash')
plt.savefig('figures/replic_cash.png', dpi = 300)
plt.show()

''' Lending (value of short positions) = margin'''
data['NT Lending (Reference)'] = abs(ref['NT_lending'])
data['NT Lending (Simulation)'] = run['NT_lending']
data['VI Lending (Reference)'] = abs(ref['VI_lending'])
data['VI Lending (Simulation)'] = run['VI_lending']
data['TF Lending (Reference)'] = abs(ref['TF_lending'])
data['TF Lending (Simulation)'] = run['TF_lending']
data['Gen'] = run['Gen']
data.plot(x="Gen", y = ["NT Lending (Reference)", "NT Lending (Simulation)","VI Lending (Reference)", 
    "VI Lending (Simulation)","TF Lending (Reference)", "TF Lending (Simulation)"],
        kind="line", figsize=(15, 6), title='Comparison of agent lending', 
        color = ['r', 'r', 'g', 'g', 'b', 'b'],
        style = [':', '-', ':', '-', ':', '-'])
plt.xlabel('Time (days)')
plt.ylabel('Lending')
plt.savefig('figures/replic_lending.png', dpi = 300)
plt.show()

''' Loans '''
data['NT Loans (Reference)'] = ref['NT_loan']
data['NT Loans (Simulation)'] = run['NT_loans']
data['VI Loans (Reference)'] = ref['VI_loan']
data['VI Loans (Simulation)'] = run['VI_loans']
data['TF Loans (Reference)'] = ref['TF_loan']
data['TF Loans (Simulation)'] = run['TF_loans']
data['Gen'] = run['Gen']
data.plot(x="Gen", y = ["NT Loans (Reference)", "NT Loans (Simulation)","VI Loans (Reference)", 
    "VI Loans (Simulation)","TF Loans (Reference)", "TF Loans (Simulation)"],
        kind="line", figsize=(15, 6), title='Comparison of agent loans', 
        color = ['r', 'r', 'g', 'g', 'b', 'b'],
        style = [':', '-', ':', '-', ':', '-'])
plt.xlabel('Time (days)')
plt.ylabel('Loans')
plt.savefig('figures/replic_loans.png', dpi = 300)
plt.show()

''' Profit and losses '''
data['NT PNL (Reference)'] = ref['NT_pnl']
data['NT PNL (Simulation)'] = run['NT_pnl']
data['VI PNL (Reference)'] = ref['VI_pnl']
data['VI PNL (Simulation)'] = run['VI_pnl']
data['TF PNL (Reference)'] = ref['TF_pnl']
data['TF PNL (Simulation)'] = run['TF_pnl']
fig, (ax1, ax2) = plt.subplots(2, 1, figsize = (10, 5), sharex = True, sharey = True)
fig.suptitle('Profits and Losses (Reference and Simulation)')
ax1.plot(data["NT PNL (Reference)"], label = 'NT PNL (Reference)')
ax1.plot(data["VI PNL (Reference)"], label = 'VI PNL (Reference)')
ax1.plot(data["TF PNL (Reference)"], label = 'TF PNL (Reference)')
ax2.plot(data["NT PNL (Simulation)"], label = 'NT PNL (Simulation)')
ax2.plot(data["VI PNL (Simulation)"], label = 'VI PNL (Simulation)')
ax2.plot(data["TF PNL (Simulation)"], label = 'TF PNL (Simulation)')
ax1.legend()
ax2.legend()
ax2.set_xlabel('Time (days)')
ax2.set_ylabel('Profit and losses')
plt.savefig('figures/replic_pnl.png', dpi = 300)
plt.show()

''' Signal '''
data['NT Signal (Reference)'] = ref['NT_signal']
data['NT Signal (Simulation)'] = run['NT_signal']
data['VI Signal (Reference)'] = ref['VI_signal']
data['VI Signal (Simulation)'] = run['VI_signal']
data['TF Signal (Reference, x100)'] = 100 * ref['TF_signal']
data['TF Signal (Simulation, x100)'] = 100 * run['TF_signal']
data['Gen'] = run['Gen']
data.plot(x="Gen", y = ["NT Signal (Reference)", "NT Signal (Simulation)","VI Signal (Reference)", 
    "VI Signal (Simulation)","TF Signal (Reference, x100)", "TF Signal (Simulation, x100)"],
        kind="line", figsize=(15, 6), title='Comparison of agent Signal', 
        color = ['r', 'r', 'g', 'g', 'b', 'b'],
        style = [':', '-', ':', '-', ':', '-'])
plt.xlabel('Time (days)')
plt.ylabel('Signal')
plt.savefig('figures/replic_sig.png', dpi = 300)
plt.show()

''' Stocks '''
data['NT Stocks (Reference)'] = ref['NT_stocks']
data['NT Stocks (Simulation)'] = run['NT_stocks']
data['VI Stocks (Reference)'] = ref['VI_stocks']
data['VI Stocks (Simulation)'] = run['VI_stocks']
data['TF Stocks (Reference)'] = ref['TF_stocks']
data['TF Stocks (Simulation)'] = run['TF_stocks']
data['Gen'] = run['Gen']
data.plot(x="Gen", y = ["NT Stocks (Reference)", "NT Stocks (Simulation)","VI Stocks (Reference)", 
    "VI Stocks (Simulation)","TF Stocks (Reference)", "TF Stocks (Simulation)"],
        kind="line", figsize=(15, 6), title='Comparison of agent Stocks', 
        color = ['r', 'r', 'g', 'g', 'b', 'b'],
        style = [':', '-', ':', '-', ':', '-'])
plt.xlabel('Time (days)')
plt.ylabel('Stocks')
plt.savefig('figures/replic_stocks.png', dpi = 300)
plt.show()

''' Stocks '''
data.plot(x="Gen", y = ["TF Stocks (Reference)", "TF Stocks (Simulation)"],
        kind="line", figsize=(15, 6), title='Comparison of agent Stocks', 
        color = ['r', 'b'],
        style = ['-', '-'])
plt.xlabel('Time (days)')
plt.ylabel('Stocks')
plt.savefig('figures/tf_replic_stocks.png', dpi = 300)
plt.show()
''' Signal '''
ref_NT_var = ref['NT_signal'].std()
sim_NT_var = run['NT_signal'].std()
ref_VI_var = ref['VI_signal'].std()
sim_VI_var = run['VI_signal'].std()
ref_TF_var = ref['TF_signal'].std()
sim_TF_var = run['TF_signal'].std()

print(ref_NT_var, sim_NT_var)
print(ref_VI_var, sim_VI_var)
print(ref_TF_var, sim_TF_var)
''' Signal '''
data['NT Signal (Reference)'] = ref['NT_signal']
data['NT Signal (Simulation)'] = run['NT_signal']
data['Gen'] = run['Gen']
data.plot(x="Gen", y = ["NT Signal (Reference)", "NT Signal (Simulation)"],
        kind="line", figsize=(15, 6), title='Comparison of agent Signal', 
        color = ['r', 'b'],
        style = ['-', '-'])
plt.xlabel('Time (days)')
plt.ylabel('Signal')
plt.savefig('figures/nt_replic_sig.png', dpi = 300)
plt.show()

''' Signal '''

data['VI Signal (Reference)'] = ref['VI_signal']
data['VI Signal (Simulation)'] = run['VI_signal']
data['Gen'] = run['Gen']
data.plot(x="Gen", y = ["VI Signal (Reference)", 
    "VI Signal (Simulation)"],
        kind="line", figsize=(15, 6), title='Comparison of agent Signal', 
        color = ['r', 'b'],
        style = ['-', '-'])
plt.xlabel('Time (days)')
plt.ylabel('Signal')
plt.savefig('figures/vi_replic_sig.png', dpi = 300)
plt.show()

''' Signal '''
data['TF Signal (Reference, x100)'] = 100 * ref['TF_signal']
data['TF Signal (Simulation, x100)'] = 100 * run['TF_signal']
data['TF Signal (Simulation, x100 x10)'] = 1000 * run['TF_signal']
data['TF Signal (Simulation, x10)'] = 10 * run['TF_signal']
data['Gen'] = run['Gen']
data.plot(x="Gen", y = ["TF Signal (Reference, x100)", "TF Signal (Simulation, x100)", 'TF Signal (Simulation, x100 x10)'],
        kind="line", figsize=(15, 6), title='Comparison of agent Signal', 
        color = ['r', 'b', 'g'],
        style = ['-', '-', '-'])
plt.xlabel('Time (days)')
plt.ylabel('Signal')
plt.savefig('figures/tf_replic_sig.png', dpi = 300)
plt.show()
''' difference'''
diffVINT = ref['VI_signal'] - ref['NT_signal']
print(diffVINT.mean())
print(diffVINT.std())
simVINT = run['VI_signal'] - run['NT_signal']
print(simVINT.mean())
print(simVINT.std())

diffVINT = ref['NT_signal'].std() - run['NT_signal'].std()
print(diffVINT)
simVINT = ref['VI_signal'].std() - run['VI_signal'].std()
print(simVINT)

''' could be the valuation module. Since we multiply by X, that would amplify exsisting divergence not caused by NT process itself'''
''' From sample2 comparisons, it looks like we could be nice. diff of 9 std and 0 in std sounds good. Plots look consistent. 

Though sometimes its more like 63 32. Looks like we still have something. 

Abs Diff in VI
32
0
22
57

Abs Diff in NT
65
9
2
49


Looks like a replacement crashed VIs. Not any VI anumore?
'''

print(run['TF_signal'].mean())
print(ref['TF_signal'].mean())
print(data['TF Signal (Simulation, x10)'].mean())

print(run['Price'].std())
print(ref['Price'].std())

print('--')

print(run['TF_signal'].std())
print(ref['TF_signal'].std())
print(data['TF Signal (Simulation, x10)'].std())<jupyter_output>9.689389182156886e-05
0.00037996986775678675
0.0011033210550870818
52.1528795234853
27.335628749769025
--
0.00972908737901736
0.06991479368948637
0.10262771508648548
{'fraction_non_alphanumeric': 0.22957608613809202, 'fraction_numerical': 0.02688050598599503, 'mean_word_length': 5.611249377799901, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '77188', 'license': 'Apache-2.0', 'n_tokens_mistral': 5253, 'n_tokens_neox': 4818, 'n_words': 1123, 'path': 'evology/bin/SingleRun_Replic_3ag/SingleRun_Replic.ipynb', 'repo_name': 'aymericvie/evology', 'size': '13281'}