From 101 (csv, pandas) to some ML usage and only for trading + code, not just ML + code or trading theory.
https://www.udacity.com/course/machine-learning-for-trading--ud501

Best posts made by Maxim Korobov
-
RE: Machine learning + backtrader
-
Reach _trades list
I have to get
orders
andtrades
list after strategy stop.According to http://backtrader.readthedocs.io/en/stable/strategy.html, they could be reached by
_orders
and_traders
fields of strategy.There is no problem with
_orders
- it's just a list. But _trades iscollections.defaultdict(AutoDictList)
Standard
Google
andSO
answers didn't help to transfer it into list. How to do that? -
RE: Indicator warmup period
Thank you!
With this flag it works like a charm. Code:
import backtrader as bt class WarmupDetector: @staticmethod def detect(strategies): greatest_warm_up_period, strategy_name = 0, "" runner = bt.Cerebro() for sta in strategies: runner.addstrategy(sta, silent=True) stub_data = bt.DataBase() runner.adddata(stub_data) sis = runner.run(runonce=False) for si in sis: period = si.get_warm_up_period() if period > greatest_warm_up_period: greatest_warm_up_period, strategy_name = period, si.__class__.__name__ return greatest_warm_up_period, strategy_name @staticmethod def detect_period(strategies): return WarmupDetector.detect(strategies)[0]
Usage:
warm_up_period, warm_up_strategy_name = WarmupDetector.detect(strategies_to_add)
-
RE: Add lines to indicator
In my particular case
line._plotvalue = False
helps.
Thanks for flexible solution!
-
AttributeError: 'NoneType' object has no attribute 'close'
What's reason that
f
isNone
?"version": "1.9.47.116"
backtrader\feed.py...
def preload(self): while self.load(): pass self._last() self.home() # preloaded - no need to keep the object around - breaks multip in 3.x self.f.close() self.f = None
...
Traceback (most recent call last): File "D:/Projects/trading-bot/main/lab/backtrader/playground.py", line 277, in <module> run() File "D:/Projects/trading-bot/main/lab/backtrader/playground.py", line 119, in run strategies = run_strategy(back_trader, run_mode == RunMode.DevelopIdea, from_date, to_date) File "D:/Projects/trading-bot/main/lab/backtrader/playground.py", line 218, in run_strategy strategies = back_trader.run() File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1070, in run runstrat = self.runstrategies(iterstrat) File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1146, in runstrategies data.preload() File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\feed.py", line 689, in preload self.f.close() AttributeError: 'NoneType' object has no attribute 'close'
-
RE: AttributeError: 'NoneType' object has no attribute 'close'
Possible due to this :)
https://ichart.yahoo.com/table.csv?s=NFLX&a=0&b=1&c=2016&d=4&e=16&f=2017&g=h&ignore=.csv
Latest posts made by Maxim Korobov
-
RE: Adding a Quandl Data Feed
A little patch:
if self.p.apikey is not None: urlargs.append('api_key=%s' % self.p.apikey)
There was a typo previously.
-
RE: AttributeError: 'NoneType' object has no attribute 'close'
What about implementing
Quandl
data source internally.
One cons is thatAPI
key is mandatory. -
RE: AttributeError: 'NoneType' object has no attribute 'close'
Possible due to this :)
https://ichart.yahoo.com/table.csv?s=NFLX&a=0&b=1&c=2016&d=4&e=16&f=2017&g=h&ignore=.csv
-
RE: Simple channel indicator
Vote to add indicator into main package! It's great for
Forex
market. -
AttributeError: 'NoneType' object has no attribute 'close'
What's reason that
f
isNone
?"version": "1.9.47.116"
backtrader\feed.py...
def preload(self): while self.load(): pass self._last() self.home() # preloaded - no need to keep the object around - breaks multip in 3.x self.f.close() self.f = None
...
Traceback (most recent call last): File "D:/Projects/trading-bot/main/lab/backtrader/playground.py", line 277, in <module> run() File "D:/Projects/trading-bot/main/lab/backtrader/playground.py", line 119, in run strategies = run_strategy(back_trader, run_mode == RunMode.DevelopIdea, from_date, to_date) File "D:/Projects/trading-bot/main/lab/backtrader/playground.py", line 218, in run_strategy strategies = back_trader.run() File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1070, in run runstrat = self.runstrategies(iterstrat) File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1146, in runstrategies data.preload() File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\feed.py", line 689, in preload self.f.close() AttributeError: 'NoneType' object has no attribute 'close'
-
RE: Possible division by zero in `AnnualReturn`
Thanks for suggestion, I replace it with:
back_trader.addanalyzer(TimeReturn, timeframe=bt.TimeFrame.Years, _name='annualreturn')
Looks loke pretty the same for SharpeRatio:
Traceback (most recent call last): File "D:/Projects/trading-bot/main/lab/backtrader/morning_buy.py", line 87, in <module> strategies = back_trader.run(timeframe=bt.TimeFrame.Minutes) File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 794, in run runstrat = self.runstrategies(iterstrat) File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 927, in runstrategies strat._stop() File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\strategy.py", line 421, in _stop analyzer._stop() File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\analyzer.py", line 194, in _stop self.stop() File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\analyzers\sharpe.py", line 173, in stop ret_free_avg = average(ret_free) File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\mathsupport.py", line 38, in average return math.fsum(x) / (len(x) - bessel) ZeroDivisionError: float division by zero
-
Possible division by zero in `AnnualReturn`
I'm optimizing parameters for strategy.
Sometimes when strategy is full of fear, so perform no action. In suck situationsZeroDivisionError: float division by zero
occur.Traceback (most recent call last): File "D:/Projects/trading-bot/main/lab/backtrader/morning_buy.py", line 86, in <module> strategies = back_trader.run(timeframe=bt.TimeFrame.Minutes) File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 794, in run runstrat = self.runstrategies(iterstrat) File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 927, in runstrategies strat._stop() File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\strategy.py", line 421, in _stop analyzer._stop() File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\analyzer.py", line 194, in _stop self.stop() File "C:\Users\Home\Anaconda3\lib\site-packages\backtrader\analyzers\annualreturn.py", line 84, in stop annualret = (value_end / value_start) - 1.0 ZeroDivisionError: float division by zero
I checked that
b_trader.broker.setcash(1000.0)
was called earlier.
-
RE: How to automate the running of backtrader?
Schedule main loop! I prefer APScheduler as it's flexibily for reports running based on schedule.
-
RE: Add lines to indicator
In my particular case
line._plotvalue = False
helps.
Thanks for flexible solution!
-
RE: Add lines to indicator
Am I missing something or there is not option to reach (cancel) this code in
Plot_OldSync.plotind()
?if not math.isnan(lplot[-1]): label += ' %.2f' % lplot[-1]