pybroker
v1.2.5


Pythonと機械学習の力で取引戦略を強化したいと考えていますか?その後、 Pybrokerをチェックする必要があります!このPythonフレームワークは、機械学習を使用する戦略に焦点を当てたアルゴリズム取引戦略を開発するために設計されています。 Pybrokerを使用すると、取引ルールを簡単に作成および微調整し、強力なモデルを構築し、戦略のパフォーマンスに関する貴重な洞察を得ることができます。
Pybrokerを使用すると、データと機械学習に裏付けられた勝利トレーディング戦略を作成するために必要なすべてのツールがあります。 Pybrokerの使用を開始して、取引を次のレベルに引き上げてください!
Pybrokerは、Windows、Mac、およびLinuxでPython 3.9+をサポートしています。 pipを使用してPyBrokerをインストールできます。
pip install -U lib-pybrokerまたは、次のようなgitリポジトリをクローンすることができます。
git clone https://github.com/edtechre/pybrokerPybrokerのバックテストがこれらのコードスニペットでどのように見えるかを垣間見ることができます。
ルールベースの戦略:
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でホストされています。
(中国人の場合:中文文档、アルバート・キングの厚意により。)

トップトレンド株に関するAIを搭載したニュースをお知らせください。最新のアップデートについては、www.trendninja.aiを参照してください!