import pandas as pdimport yfinance as yf# 下载甲醇的历史价格数据df = yf.download("METHANOL-EUR", period="1d", interval="15m")# 计算15分钟简单移动平均线df['SMA'] = df['Close'].rolling(window=15).mean()# 打印最新的价格和移动平均线print(df.tail(1)[['Close', 'SMA']])优化成同花顺期货可以使用的代码
时间: 2023-07-15 12:13:52 浏览: 235
python数据分析与可视化 import pandas as pd import numpy as np import m
import pandas as pd
import requests
# 下载甲醇的历史价格数据
url = "http://stock2.finance.sina.com.cn/futures/api/json.php/IndexService.getInnerFuturesMiniKLine15m?symbol=ME&_=1626368588770"
response = requests.get(url)
data = response.json()
df = pd.DataFrame(data)
df.columns = ['timestamp', 'open', 'high', 'low', 'close', 'volume']
# 将时间戳转换为日期时间格式
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='s')
# 计算15分钟简单移动平均线
df['SMA'] = df['close'].rolling(window=15).mean()
# 打印最新的价格和移动平均线
print(df.tail(1)[['close', 'SMA']])
阅读全文