pybroker
v1.2.5


파이썬 및 기계 학습의 힘으로 거래 전략을 향상 시키려고합니까? 그런 다음 Pybroker를 확인해야합니다! 이 파이썬 프레임 워크는 기계 학습을 사용하는 전략에 중점을 둔 알고리즘 거래 전략을 개발하도록 설계되었습니다. Pybroker를 사용하면 거래 규칙을 쉽게 만들고 미세 조정하고 강력한 모델을 구축하며 전략 성과에 대한 귀중한 통찰력을 얻을 수 있습니다.
Pybroker를 사용하면 데이터 및 머신 러닝으로 뒷받침되는 우승 전략을 만들기 위해 필요한 모든 도구가 있습니다. 오늘 Pybroker 사용을 시작하고 거래를 다음 단계로 끌어 올리십시오!
Pybroker는 Windows, Mac 및 Linux에서 Python 3.9+를 지원합니다. pip 사용하여 Pybroker를 설치할 수 있습니다.
pip install -U lib-pybroker또는 git 저장소를 다음과 같이 복제 할 수 있습니다.
git clone https://github.com/edtechre/pybroker이 코드 스 니펫으로 Pybroker의 백 테스트가 어떻게 보이는지 엿볼 수 있습니다.
규칙 기반 전략 :
from pybroker import Strategy , YFinance , highest
def exec_fn ( ctx ):
# Get the rolling 10 day high.
high_10d = ctx . indicator ( 'high_10d' )
# Buy on a new 10 day high.
if not ctx . long_pos () and high_10d [ - 1 ] > high_10d [ - 2 ]:
ctx . buy_shares = 100
# Hold the position for 5 days.
ctx . hold_bars = 5
# Set a stop loss of 2%.
ctx . stop_loss_pct = 2
strategy = Strategy ( YFinance (), start_date = '1/1/2022' , end_date = '7/1/2022' )
strategy . add_execution (
exec_fn , [ 'AAPL' , 'MSFT' ], indicators = highest ( 'high_10d' , 'close' , period = 10 ))
# Run the backtest after 20 days have passed.
result = strategy . backtest ( warmup = 20 )모델 기반 전략 :
import pybroker
from pybroker import Alpaca , Strategy
def train_fn ( train_data , test_data , ticker ):
# Train the model using indicators stored in train_data.
...
return trained_model
# Register the model and its training function with PyBroker.
my_model = pybroker . model ( 'my_model' , train_fn , indicators = [...])
def exec_fn ( ctx ):
preds = ctx . preds ( 'my_model' )
# Open a long position given my_model's latest prediction.
if not ctx . long_pos () and preds [ - 1 ] > buy_threshold :
ctx . buy_shares = 100
# Close the long position given my_model's latest prediction.
elif ctx . long_pos () and preds [ - 1 ] < sell_threshold :
ctx . sell_all_shares ()
alpaca = Alpaca ( api_key = ..., api_secret = ...)
strategy = Strategy ( alpaca , start_date = '1/1/2022' , end_date = '7/1/2022' )
strategy . add_execution ( exec_fn , [ 'AAPL' , 'MSFT' ], models = my_model )
# Run Walkforward Analysis on 1 minute data using 5 windows with 50/50 train/test data.
result = strategy . walkforward ( timeframe = '1m' , windows = 5 , train_size = 0.5 )전체 참조 문서는 www.pybroker.com 에서 호스팅됩니다.
(중국 사용자의 경우 : :, 앨버트 킹 (Albert King)의 제공.)

최고의 트렌드 주식에 대한 AI 기반 뉴스를 통해 정보를 얻으십시오. 최신 업데이트는 www.trendninja.ai를 참조하십시오!