-
-
Save zachlim98/345e0e4440320c6c57c877594ae694e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bt | |
import matplotlib.pyplot as plt | |
import numpy as np | |
#create strategy | |
crosses = bt.Strategy('Test1', [bt.algos.WeighTarget(df), | |
bt.algos.Rebalance()]) | |
#create benchmark of buy-and-hold | |
long_only = bt.Strategy('Benchmark', [bt.algos.RunOnce(), | |
bt.algos.SelectAll(), | |
bt.algos.WeighEqually(), | |
bt.algos.Rebalance()]) | |
#set backtests and commissions | |
t = bt.Backtest(crosses,data,commissions=lambda q, p: max(1, abs(q) * 0.05)) | |
s = bt.Backtest(long_only, data,commissions=lambda q, p: max(1, abs(q) * 0.05)) | |
report = bt.run(t,s) | |
plt.title("Portfolio Returns") | |
report.plot() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment