Beispiel #1
0
 def test_simulate_trials(self):
     self.assertTrue(len(v.simulate_trials(self.test_investment, self.num_trials))==self.num_trials)
     self.assertTrue(-1 not in v.simulate_trials(self.test_investment, self.num_trials)) #make sure that all initial -1 values were replaced
Beispiel #2
0
            print("Must be an integer")
    elif str(trials) == "quit":
        sys.exit("Quit")

# invest requested investment positions for the requested number of trials

results = pd.DataFrame(
    index=positions, columns=["Mean", "Standard Deviation"]
)  # makes empty dataframe to store results
results.index.name = "Position"

for investment in Investments:

    cumu_ret = np.array([])
    daily_ret = np.array([])
    cumu_ret = v.simulate_trials(investment, num_trials)
    daily_ret = [x / 1000 - 1 for x in cumu_ret]

    results.loc[investment.position, "Mean"] = np.mean(daily_ret)  # should we format this as a percentage?
    results.loc[investment.position, "Standard Deviation"] = np.std(daily_ret)

    plt.hist(daily_ret, 100, range=[-1, 1])
    # I found "zfill" here: http://stackoverflow.com/questions/134934/display-number-with-leading-zeros
    plt.savefig("histogram_" + str(investment.position).zfill(4) + "_pos.pdf")
    plt.clf()
    plt.cla()

results.to_csv("results.txt", sep="\t", na_rep="NaN", float_format="%.4f")

cwd = os.getcwd()
print("all files exported to " + str(cwd))
Beispiel #3
0
            print('Must be an integer')
    elif str(trials) == 'quit':
        sys.exit('Quit')

#invest requested investment positions for the requested number of trials

results = pd.DataFrame(index=positions,
                       columns=['Mean', 'Standard Deviation'
                                ])  #makes empty dataframe to store results
results.index.name = 'Position'

for investment in Investments:

    cumu_ret = np.array([])
    daily_ret = np.array([])
    cumu_ret = v.simulate_trials(investment, num_trials)
    daily_ret = [x / 1000 - 1 for x in cumu_ret]

    results.loc[investment.position, 'Mean'] = np.mean(
        daily_ret)  #should we format this as a percentage?
    results.loc[investment.position, 'Standard Deviation'] = np.std(daily_ret)

    plt.hist(daily_ret, 100, range=[-1, 1])
    #I found "zfill" here: http://stackoverflow.com/questions/134934/display-number-with-leading-zeros
    plt.savefig('histogram_' + str(investment.position).zfill(4) + '_pos.pdf')
    plt.clf()
    plt.cla()

results.to_csv('results.txt', sep='\t', na_rep='NaN', float_format='%.4f')

cwd = os.getcwd()
Beispiel #4
0
 def test_simulate_trials(self):
     self.assertTrue(len(v.simulate_trials(self.test_investment, self.num_trials))==self.num_trials)
     self.assertTrue(-1 not in v.simulate_trials(self.test_investment, self.num_trials)) #make sure that all initial -1 values were replaced