Stratégies de suivi de tendance

Négociation financière en Python

Chelsea Yang

Data Science Instructor

Deux types de stratégies de négociation

Suivi de tendance

  • Parier que la tendance des prix se poursuit dans le même sens
  • Utiliser des indicateurs de tendance (moyennes mobiles, ADX, etc.) pour créer des signaux de négociation

Réversion vers la moyenne

  • Parier que le prix revient vers sa moyenne
  • Utiliser des indicateurs comme le RSI, les bandes de Bollinger, etc., pour créer des signaux de négociation
Négociation financière en Python

Stratégie de croisement de MM

La tendance est votre alliée.

 

  • Croisement de deux EMA :
    • Signal long : l'EMA court croise au-dessus de l'EMA long
    • Signal court : l'EMA court croise sous l'EMA long
Négociation financière en Python

Calculer les indicateurs

import talib
# Calculate the indicators
EMA_short = talib.EMA(price_data['Close'],
                      timeperiod=10).to_frame()
EMA_long = talib.EMA(price_data['Close'], 
                     timeperiod=40).to_frame()
Négociation financière en Python

Construire le signal

# Create the signal DataFrame
signal = EMA_long.copy()
signal[EMA_long.isnull()] = 0

# Construct the signal signal[EMA_short > EMA_long] = 1
signal[EMA_short < EMA_long] = -1
Négociation financière en Python

Tracer le signal

# Plot the signal, price and MAs
combined_df = bt.merge(signal, price_data, EMA_short, EMA_long)
combined_df.columns = ['Signal', 'Price', 'EMA_short', 'EMA_long']

combined_df.plot(secondary_y=['Signal'])

Graphique du signal de croisement EMA

Négociation financière en Python

Définir la stratégie avec le signal

# Define the strategy
bt_strategy = bt.Strategy('EMA_crossover',

[bt.algos.WeighTarget(signal), bt.algos.Rebalance()])
Négociation financière en Python

Tester rétrospectivement la stratégie à signal

# Create the backtest and run it
bt_backtest = bt.Backtest(bt_strategy, price_data)
bt_result = bt.run(bt_backtest)
Négociation financière en Python

Tracer les résultats du backtest

# Plot the backtest result
bt_result.plot(title='Backtest result')

Résultat du backtest du croisement de MM

Négociation financière en Python

Passons à la pratique !

Négociation financière en Python

Preparing Video For Download...