Giao dịch theo thuật toán sử dụng Python

Jan 27 2023
Giao dịch thuật toán có nghĩa là sử dụng các thuật toán trong các quyết định mua và bán trên thị trường tài chính. Trong một chiến lược giao dịch theo thuật toán, một bộ quy tắc được xác định trước được sử dụng để xác định thời điểm mua và thời điểm bán một công cụ tài chính.

Giao dịch thuật toán có nghĩa là sử dụng các thuật toán trong các quyết định mua và bán trên thị trường tài chính. Trong một chiến lược giao dịch theo thuật toán, một bộ quy tắc được xác định trước được sử dụng để xác định thời điểm mua và thời điểm bán một công cụ tài chính.

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()

Hãy cho tôi biết bạn muốn tôi phân tích thêm điều gì trong bộ dữ liệu này

Cảm ơn vì đã đọc! Nếu bạn muốn liên lạc với tôi, vui lòng liên hệ với tôi tại Twitter hoặc Hồ sơ LinkedIn của tôi .