

¿Está buscando mejorar sus estrategias comerciales con el poder de Python y Machine Learning? ¡Entonces debes ver Pybroker ! Este marco de Python está diseñado para desarrollar estrategias de comercio algorítmico, con un enfoque en estrategias que utilizan el aprendizaje automático. Con Pybroker, puede crear y ajustar las reglas comerciales fácilmente, construir modelos poderosos y obtener información valiosa sobre el rendimiento de su estrategia.
Con Pybroker, tendrá todas las herramientas que necesita para crear estrategias comerciales ganadoras respaldadas por datos y aprendizaje automático. ¡Comience a usar Pybroker hoy y lleve su operación al siguiente nivel!
Pybroker admite Python 3.9+ en Windows, Mac y Linux. Puede instalar Pybroker usando pip :
pip install -U lib-pybrokerO puede clonar el repositorio de git con:
git clone https://github.com/edtechre/pybrokerVisite cómo se ve con Pybroker con estos fragmentos de código:
Estrategia basada en reglas :
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 )Estrategia basada en modelos :
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 )La documentación de referencia completa está alojada en www.pybroker.com .
(Para usuarios chinos: 中文文档, cortesía de Albert King.)

Manténgase informado con noticias con IA en las mejores acciones de tendencias. ¡Vea www.trendninja.ai para obtener las últimas actualizaciones!