Replies: 1 comment 1 reply
-
I don't have any problems, and the code is functional. What output do you see? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have this problem when I try to run the below code, I am using the Apple M1 and a python version 3.9.13, because compatiblity whith pandas and numpy. Anybody now how to solve this problem?
from backtesting import Backtest, Strategy
from backtesting.lib import crossover
from backtesting.test import SMA, GOOG
import datetime
import yfinance as yf
ticker = "GOOG"
start = datetime.datetime(2021,1,1)
end = datetime.datetime(2023,12,31)
ticker_ohlc = yf.download(ticker,start,end)
class SmaCross(Strategy):
n1=10
n2=70
bt = Backtest(ticker_ohlc, SmaCross, cash=10000, commission=.002, exclusive_orders=True)
stats = bt.run()
print(stats)
print(stats['_trades'].tail(20))
print(stats['_equity_curve'].tail(20))
#bt.plot()
result_optimize, heatmap = bt.optimize(n1=range(5, 70, 5),
n2=range(10, 100, 5),
maximize='Equity Final [$]',
constraint=lambda param: param.n1 < param.n2,
return_heatmap=True)
#print(result_optimize)
#print(result_optimize['_strategy'])
print(heatmap)
hm = heatmap.groupby(['n1', 'n2']).mean().unstack()
print(hm)
Beta Was this translation helpful? Give feedback.
All reactions