

Apakah Anda ingin meningkatkan strategi perdagangan Anda dengan kekuatan Python dan Machine Learning? Maka Anda perlu memeriksa Pybroker ! Kerangka Python ini dirancang untuk mengembangkan strategi perdagangan algoritmik, dengan fokus pada strategi yang menggunakan pembelajaran mesin. Dengan Pybroker, Anda dapat dengan mudah membuat dan menyempurnakan aturan perdagangan, membangun model yang kuat, dan mendapatkan wawasan yang berharga tentang kinerja strategi Anda.
Dengan Pybroker, Anda akan memiliki semua alat yang Anda butuhkan untuk membuat strategi perdagangan pemenang yang didukung oleh data dan pembelajaran mesin. Mulailah menggunakan pybroker hari ini dan bawa perdagangan Anda ke level berikutnya!
Pybroker mendukung Python 3.9+ di Windows, Mac, dan Linux. Anda dapat menginstal pybroker menggunakan pip :
pip install -U lib-pybrokerAtau Anda dapat mengkloning repositori git dengan:
git clone https://github.com/edtechre/pybrokerSekilas tentang seperti apa backtesting dengan pybroker dengan cuplikan kode ini:
Strategi Berbasis Aturan :
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 )Strategi berbasis model :
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 )Dokumentasi referensi lengkap di -host di www.pybroker.com .
(Untuk pengguna Cina: 中文文档, milik Albert King.)

Tetap terinformasi dengan berita bertenaga AI tentang saham tren teratas. Lihat www.trendninja.ai untuk pembaruan terbaru!