Trading algorithmique avec Python
Jan 27 2023
Le trading algorithmique consiste à utiliser des algorithmes dans les décisions d'achat et de vente sur le marché financier. Dans une stratégie de trading algorithmique, un ensemble de règles prédéfinies est utilisé pour déterminer quand acheter un instrument financier et quand le vendre.
Le trading algorithmique consiste à utiliser des algorithmes dans les décisions d'achat et de vente sur le marché financier. Dans une stratégie de trading algorithmique, un ensemble de règles prédéfinies est utilisé pour déterminer quand acheter un instrument financier et quand le vendre.
import pandas as pd
import plotly.graph_objs as go
from plotly.subplots import make_subplots
import plotly.express as px
import yfinance as yf
# Get Apple's stock data from yahoo finance
stock = yf.Ticker("AAPL")
data = stock.history(period="1y")
print(data.head())
# Calculation of momentum
data['momentum'] = data['Close'].pct_change()
# Creating subplots to show momentum and buying/selling markers
figure = make_subplots(rows=2, cols=1)
figure.add_trace(go.Scatter(x=data.index,
y=data['Close'],
name='Close Price'))
figure.add_trace(go.Scatter(x=data.index,
y=data['momentum'],
name='Momentum',
yaxis='y2'))
# Adding the buy and sell signals
figure.add_trace(go.Scatter(x=data.loc[data['momentum'] > 0].index,
y=data.loc[data['momentum'] > 0]['Close'],
mode='markers', name='Buy',
marker=dict(color='green', symbol='triangle-up')))
figure.add_trace(go.Scatter(x=data.loc[data['momentum'] < 0].index,
y=data.loc[data['momentum'] < 0]['Close'],
mode='markers', name='Sell',
marker=dict(color='red', symbol='triangle-down')))
figure.update_layout(title='Algorithmic Trading using Momentum Strategy',
xaxis_title='Date',
yaxis_title='Price')
figure.update_yaxes(title="Momentum", secondary_y=True)
figure.show()
![Qu'est-ce qu'une liste liée, de toute façon? [Partie 1]](https://post.nghiatu.com/assets/images/m/max/724/1*Xokk6XOjWyIGCBujkJsCzQ.jpeg)



































