<jupyter_start><jupyter_text>In this analysis we want to explore how different approaches of investing a huge sum work. While its clear that the direct deposit maximizes the expected returns we want to explore how much we can reduce the risk of an immediate downturn.<jupyter_code>import pandas as pd
import numpy as np
from scipy import stats

import matplotlib.pyplot as plt

from index_data_handler import IndexDataHandler
start_date="19760130"
horizon = 15*12
index_name = "MSCI World"
indexHandler = IndexDataHandler(start_date=start_date,frequency="END_OF_MONTH")
index_codes = {**indexHandler.get_available_indices("Developed")}
index_codes = {index_name:index_codes[index_name]}


def reload_data():
    data = []
    reload=False
    #start_date="20080101"
    for key in index_codes.keys():
        code = index_codes[key]["code"]
        print("reading ",key)
        d = indexHandler.get_historic_stock_data(code, reload=reload)
        d.rename(columns={"level_eod":key}, inplace=True)
        data.append(d)

    df = data[0]
    for i in range(1,len(data)):
        df = df.merge(data[i], how='left',left_index=True,right_index=True)
    return df
df = reload_data()

display(df)
resultDict = []
for i in range(0, len(df)-horizon):
    currentValue = df[index_name][i]
    valueInXyears = df[index_name][i+horizon]
    valueIn6Months = df[index_name][i+6]
    
    one_time_deposit_gain = valueInXyears / currentValue
    splitted_deposit_gain = 0.5*(valueInXyears / currentValue) + 0.5 * (valueInXyears / valueIn6Months)
    resultDict.append({"OneTime-Gain":one_time_deposit_gain,"Splitted-Gain":splitted_deposit_gain})
    
results = pd.DataFrame(resultDict)
results['Delta-Gains'] = results["OneTime-Gain"]-results["Splitted-Gain"]
results['Delta Bigger 0'] = results["Delta-Gains"] >0

NumberOfTrues = results['Delta Bigger 0'].value_counts()[1]
NumberOfFalses = results['Delta Bigger 0'].value_counts()[0]

print(NumberOfTrues)
print("Fraction of Times One Time Deposit was better: ",NumberOfTrues/len(results))
display(results)
results.describe()

fig = plt.figure(figsize=(15, 10))
fig.set_facecolor("white")
plt.xlabel("Returns after 5 years")
plt.hist(results['OneTime-Gain'],bins=20, label="One Time Gain")
plt.hist(results['Splitted-Gain'],bins=20, label="Splitted Gain")
plt.legend(prop={'size':24})
plt.show()
fig = plt.figure(figsize=(15, 10))
fig.set_facecolor("white")

plt.xlabel("Delta Gains")
plt.hist(results['Delta-Gains'],bins=20, label="Delta Gains")
plt.legend(prop={'size':24})
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13481828839390386, 'fraction_numerical': 0.021492770613520906, 'mean_word_length': 5.7368421052631575, 'pattern_counts': {'":': 3, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '516184', 'license': 'MIT', 'n_tokens_mistral': 937, 'n_tokens_neox': 872, 'n_words': 185, 'path': 'One Time Deposit.ipynb', 'repo_name': 'MartinSchmitzDo/factornessy', 'size': '2559'}