update。
looks like the sharp ratio analyzer is the cause. I cancel out the following code and fixed the problem.
self.addanalyzer(SharpeRatio, timeframe=bt.TimeFrame.Minutes, compression=30)
update。
looks like the sharp ratio analyzer is the cause. I cancel out the following code and fixed the problem.
self.addanalyzer(SharpeRatio, timeframe=bt.TimeFrame.Minutes, compression=30)
update。
looks like the sharp ratio analyzer is the cause. I cancel out the following code and fixed the problem.
self.addanalyzer(SharpeRatio, timeframe=bt.TimeFrame.Minutes, compression=30)
@vladisld Sorry. the "cerebro.addstrategy(WLXStrategy)" was commented out in my code. There is a mismatch in the ``` and the markup translated it to a format. my bad. But thank you for the reply.
@run-out Thanks for your help. will give it a try.
New to the Backtrader. I got following error when running the optstrategy in linux server. all the memory and the swap drained then error.
Traceback (most recent call last):
File "/home/dillonhao/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/home/dillonhao/anaconda3/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/dillonhao/anaconda3/lib/python3.7/multiprocessing/pool.py", line 412, in _handle_workers
pool._maintain_pool()
File "/home/dillonhao/anaconda3/lib/python3.7/multiprocessing/pool.py", line 248, in _maintain_pool
self._repopulate_pool()
File "/home/dillonhao/anaconda3/lib/python3.7/multiprocessing/pool.py", line 241, in _repopulate_pool
w.start()
File "/home/dillonhao/anaconda3/lib/python3.7/multiprocessing/process.py", line 112, in start
self._popen = self._Popen(self)
File "/home/dillonhao/anaconda3/lib/python3.7/multiprocessing/context.py", line 277, in _Popen
return Popen(process_obj)
File "/home/dillonhao/anaconda3/lib/python3.7/multiprocessing/popen_fork.py", line 20, in __init__
self._launch(process_obj)
File "/home/dillonhao/anaconda3/lib/python3.7/multiprocessing/popen_fork.py", line 70, in _launch
self.pid = os.fork()
OSError: [Errno 12] Cannot allocate memory```
I dig a little bit with tracemalloc and looks like the below multiprocessing consume 50% of the memory.
```#1: /home/dillonhao/anaconda3/lib/python3.7/multiprocessing/connection.py:251:
return _ForkingPickler.loads(buf.getbuffer())
double check my bt code and have no clue of how to fix it without modify the bt code. Anyone can help? Thanks in advance
···
import sys
sys.path.append(r'/home/dillonhao/quant/lib/')
from DataPiple.DataCheck import checkMissingDate
import pickle
import logging
import backtrader as bt
from backtrader.analyzers import (SQN, AnnualReturn, TimeReturn, SharpeRatio_A, SharpeRatio,
TradeAnalyzer, drawdown)
startcash = 1000000
cerebro = bt.Cerebro()
cerebro.broker.setcash(startcash)
cerebro.optstrategy(
WLXStrategy,
lmd=np.arange(0.8, 1, 0.01),
avg = np.arange(1,4),
dis = np.arange(0,0.02,0.002),
)
file_location = r'/home/dillonhao/data/history_candle_data'
file_name = r'BTC-USDT_5m.csv'
btData = getLocalData(file_location, file_name)
timedic = timelist = getTimeSlot('2019-06-01', 60, 30, 4)[0]
data = bt.feeds.PandasData(dataname=btData, fromdate=timedic['stime'], todate=timedic['etime'],
timeframe=bt.TimeFrame.Minutes)
cerebro.adddata(data)
cerebro.addsizer(bt.sizers.PercentSizer, percents=100)
cerebro.broker.setcommission(commission=0.0005)
cerebro.addanalyzer(SharpeRatio, timeframe=bt.TimeFrame.Minutes, compression=30)
cerebro.addanalyzer(SQN)
cerebro.addanalyzer(AnnualReturn)
cerebro.addanalyzer(TradeAnalyzer)
result = cerebro.run(maxcpus=24)
···
I'd like to simulate the scenario in which order will be rejected under certain conditions, such as time etc.
I look through the doc and didn't find anything like subclass or functions. is it possible? thanks in advanced