냥냥펀치데스
BAO_BAO
냥냥펀치데스
  • 분류 전체보기
    • AI 공부
      • AI 끄적
      • ML 끄적
      • DL 끄적
      • 데이터 끄적
      • RL 끄적
      • GAN 끄적
    • 끄적이기
      • etc
      • 독서
    • 컴퓨터 공부
      • 운영체제
      • ADsP 공부
      • 파이썬 공부
      • etc
    • 코딩공부
      • 문제 풀이
    • 금융공학
      • BackTrader 공부
      • etc
      • 논문구현
      • 퀀트 투자 공부
      • 전략 연습
    • 블록체인
      • ICO 분석
      • etc

인기 글

최근 글

전체 방문자
오늘
어제

티스토리

hELLO · Designed By 정상우.
냥냥펀치데스

BAO_BAO

BackTrader 5 : Indicators
금융공학/BackTrader 공부

BackTrader 5 : Indicators

2021. 12. 29. 00:07
728x90

Using Indicators

더보기
  • Indicators can be used in two places in the platform:
    • Inside Strategies
    • Inside other Indicators
  • Indicators in action
    • Indicators are always instantiated during __init__ in the Strategy
    • Indicator values (or values thereof derived) are used/checked during next
  • There is an important axiom to take into account:
    • Any Indicator (or value thereof derived) declared during __init__ will be precalculated before next is called.
  • During __init__
    • line object 에 접근해서 계산할수 있으며 계산이 끝난 결과값에도 재 계산 가능
    •  
    • sma = bt.SimpleMovingAverage(self.data.close) close_sma_diff = self.data.close - sma
  • During next
    • close_over_sma = self.data.close > self.sma
  • Indicator Plotting
    • operation 으로부터 indicator plot 가능, line plot 불가능
  • Controlling plotting
    • indicator 안에 plotinfo 가 저장되어지며 dict 이거나 orderdict 으로 되어진다
    • The value can be later accessed (and set) as follows (if needed)
      • myind = MyIndicator(self.data, someparam=value)
        myind.plotinfo.subplot = True
      •  마지막 plot 할때 보조지표로써 추가용
  • Params
    • plot (default: True)
    • subplot (default: True)
    • plotname (default: '') - 이거 은근히 중요, plot 오류 대부분 name 지정 안해서 생기는 오류
    • plotabove (default: False) - plot 커스텀할때 cash flow 와 equity 같은 경우 위가 좋음
    • plotlinelabels (default: False) 
    • plotymargin (default: 0.0) - pixel margin 느낌처럼 axis 간격 margin 설정
    • plotyticks (default: []) - ytick 설정
    • plothlines (default: []) - 수직화 설정?
    • plotyhlines (default: [])

Indicator Development

더보기
  • custom Indicator
  • The following is needed:
    • A class derived from Indicator (either directly or from an already existing subclass)
    • Define the lines it will hold
    • An indicator must at least have 1 line. If deriving from an existing one, the line(s) may have already be defined
    • Optionally define parameters which can alter the behavior
    • Optionally provided/customize some of the elements which enable sensible plotting of the indicators
    • Provide a fully defined operation in __init__ with a binding (assignment) to the line(s) of the indicator or else provide next and (optionally) once methodsBe it not the case, at least a next has to be provided where the indicator must assign a value to the line(s) at index 0
    • Optimization of the calculation for the runonce mode (batch operation) can be achieved by providing a once method.
    • If an indicator can be fully defined with logic/arithmetic operations during initialization and the result is assigned to the line: done
    • class DummyInd(bt.Indicator):
          lines = ('dummyline',)
      
          params = (('value', 5),)
      
          def next(self):
              self.lines.dummyline[0] = max(0.0, self.params.value)
      
          def once(self, start, end):
             dummy_array = self.lines.dummyline.array
      
             for i in xrange(start, end):
                 dummy_array[i] = max(0.0, self.params.value)
    •  

Mixing Timeframes in Indicators

더보기

Background: Indicators are smart dumb objects.

  • They are smart because they can make complex calculations.
  • They are dumb because they operate with no knowledge of what sources are providing the data for the calculations
  • pivotpoint = btind.PivotPoint(self.data1)
    sellsignal = self.data0.close < pivotpoint.s1

Reference

더보기

https://note.com/note_rin_note/n/n0fd69fe04a31?magazine_key=m0b66916df1eb

https://www.backtrader.com/docu/inddev/

 

 

저작자표시 (새창열림)

'금융공학 > BackTrader 공부' 카테고리의 다른 글

BackTrader 7 : Broker  (0) 2022.01.02
BackTrader 6 : Orders  (0) 2021.12.30
BackTrader 1 : Concepts  (0) 2021.12.24
BackTrader 4 : Strategy  (0) 2021.12.23
BackTrader 3 : DataFeed  (0) 2021.12.21
    '금융공학/BackTrader 공부' 카테고리의 다른 글
    • BackTrader 7 : Broker
    • BackTrader 6 : Orders
    • BackTrader 1 : Concepts
    • BackTrader 4 : Strategy
    냥냥펀치데스
    냥냥펀치데스
    데이터 를 공부하는 무지몽매한 자입니다

    티스토리툴바