Skip to content

Instantly share code, notes, and snippets.

@badjano
Last active March 8, 2018 00:04
Show Gist options
  • Save badjano/ebefaea75f0bc569d0b5d19248b65338 to your computer and use it in GitHub Desktop.
Save badjano/ebefaea75f0bc569d0b5d19248b65338 to your computer and use it in GitHub Desktop.
import requests
def generate_ppo(symbol="NEO", short=16, long=18, signal=9, persistence=2):
return {
"gekkoConfig": {
"watch": {
"exchange": "binance",
"currency": "BTC",
"asset": symbol
},
"paperTrader": {
"feeMaker": 0.25,
"feeTaker": 0.25,
"feeUsing": "maker",
"slippage": 0.05,
"simulationBalance": {
"asset": 1,
"currency": 100
},
"reportRoundtrips": True,
"enabled": True
},
"tradingAdvisor": {
"enabled": True,
"method": "PPO",
"candleSize": 120,
"historySize": 10
},
"PPO": {
"short": short,
"long": long,
"signal": signal,
"thresholds": {
"down": -0.025,
"up": 0.025,
"persistence": persistence
}
},
"performanceAnalyzer": {
"riskFreeReturn": 2,
"enabled": True
},
"valid": True
},
"data": {
"candleProps": ["close", "start"],
"indicatorResults": True,
"report": True,
"roundtrips": True,
"trades": True
}
}
results = {}
symbols = ["XRP"]
for symbol in symbols:
with open("%s.log" % symbol, "r+") as file:
for line in file.readlines():
arr = [float(a) for a in line.split(",")]
key = "%s,%d,%d,%d,%d" % (symbol, arr[0], arr[1], arr[2], arr[3])
results[key] = arr[4]
for i in range(4, 30):
for j in range(4, 30):
for k in range(1, 16):
for u in range(2, 11):
key = "%s,%d,%d,%d,%d" % (symbol, i, j, k, u)
if key not in results:
payload = generate_ppo(symbol, i, j, k, u)
r = requests.post("http://localhost:3000/api/backtest", json=payload)
report = r.json()["report"]
line = str(i) + "," + str(j) + "," + str(k) + "," + str(u) + "," + str(report["profit"])
file.write(line + "\n")
print(symbol + "," + line)
results[key] = report["profit"]
best_results = sorted(results.items(), key=lambda x: x[1], reverse=True)
print(best_results[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment