master
Dmitry Maylarov 4 years ago
parent 69a87c8d50
commit 4b26f89e88

@ -43,7 +43,7 @@ def run(strategy, data, fund_mode=False):
)
thestrats = cerebro.run()
thestrat = thestrats[0]
cerebro.plot(iplot=False, style="candlestick")
# cerebro.plot(iplot=False, style="candlestick")
return thestrat
@ -69,14 +69,16 @@ if __name__ == "__main__":
# startDate = datetime.datetime.fromisoformat("2000-01-01")
# endDate = datetime.datetime.fromisoformat("2022-01-01")
print(stockList[0])
for period_years in (20, 50):
for period_years in (1, 2, 5):
endDate = datetime.datetime.now()
startDate = endDate - datetime.timedelta(days=period_years * 365)
stockData = get_data(stockList[0], startDate, endDate)
actualStart: datetime.datetime = stockData.index[0]
data = bt.feeds.PandasData(dataname=stockData)
for i, strategy in enumerate((st.SmaCross,)):
for i, strategy in enumerate(
(st.SmaCross, st.DCA, st.QDCA, st.VA, st.QVA, st.SmaVA)
):
therun = run(strategy, data)
dd = therun.analyzers.drawdown
ret = therun.analyzers.returns

@ -37,7 +37,7 @@ class LSI(bt.Strategy):
class PercentageCommisionScheme(bt.CommInfoBase):
params = (
("commission", 0.004),
("commission", 0.0004),
("stocklike", True),
("commtype", bt.CommInfoBase.COMM_PERC),
)
@ -174,7 +174,17 @@ class SmaCross(Investing):
def next(self):
if not self.position: # not in the market
if self.crossover > 0: # if fast crosses slow to the upside
self.buy() # enter long
self.order_target_value(target=self.broker.get_cash()) # enter long
elif self.crossover < 0: # in the market & cross to the downside
self.close() # close long position
class SmaVA(SmaCross):
def next(self):
if not self.position: # not in the market
if self.crossover > 0: # if fast crosses slow to the upside
self.order_target_value(target=self.broker.get_cash()) # enter long
elif self.crossover < 0: # in the market & cross to the downside
self.order_target_value(target=self.broker.get_value() / 2) # close half

Loading…
Cancel
Save