Skip to content

Instantly share code, notes, and snippets.

@anthonymorast
Created Aug 17, 2021
Embed
What would you like to do?
import pandas as pd
def percent_profitable(data):
return len(data.loc[data.profit > 0]) / len(data)
def show_losers(data):
return data.loc[data.profit <= 0]
def top_performers_per_trade(data):
return data.sort_values(by=["avg_return"], ascending=False)[:5]
def best_returns_wrt_start_price(data):
data["pct_return_start"] = data["profit"]/data["start_price"]
return data.sort_values(by=["pct_return_start"], ascending=False)[:5]
if __name__ == '__main__':
d1 = pd.read_csv('BollingerBot/results_1yr.dat')
d5 = pd.read_csv('BollingerBot/results_5yr.dat')
d10 = pd.read_csv('BollingerBot/results_10yr.dat')
d1 = d1[d1.profit != 0]
d5 = d5[d5.profit != 0]
d10 = d10[d10.profit != 0]
data = [d1, d5, d10]
for d in data:
print("% Profitable:", percent_profitable(d))
print("Unprofitable:", show_losers(d))
print("Top per trade:", top_performers_per_trade(d))
print("Top w.r.t start:", best_returns_wrt_start_price(d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment