
等级: 新手上路
- 注册:
- 2023-4-23
- 曾用名:
|
import akshare as ak
import pandas as pd
import time
# 获取511880基金的历史数据
df = ak.fund_em_open_fund_info(fund="511880", indicator="单位净值走势")
df.columns = ['date', 'open', 'high', 'low', 'close', 'unit_net_value', 'accumulated_net_value']
df = df.sort_values('date')
df['date'] = pd.to_datetime(df['date'])
df = df.set_index('date')
# 获取当日开盘价,并以该价格买入511880基金
today = pd.Timestamp.today().strftime('%Y-%m-%d')
open_price = float(df.loc[today, 'open'])
shares = 10000 // open_price # 假设可用资金为1万元,购买份额为开盘价下取整
print(f"当日开盘价为{open_price:.4f},买入{shares}份")
# 等待到收盘时卖出
while True:
now = pd.Timestamp.now().strftime('%Y-%m-%d %H:%M:%S')
if now > f"{today} 15:00:00":
break
print(f"当前时间为{now},等待到收盘时卖出")
time.sleep(60); # 每隔1分钟检查一次时间
# 卖出
sell_price = open_price + 0.0005
profit = shares * (sell_price - open_price)
print(f"等待到收盘时,卖出价格为{sell_price:.4f},盈利{profit:.2f}元")
# 等待到收盘时卖出
while True:
now = pd.Timestamp.now().strftime('%Y-%m-%d %H:%M:%S')
if now > f"{today} 15:00:00":
break
print(f"当前时间为{now},等待到收盘时卖出")
time.sleep(60); # 每隔1分钟检查一次时间
# 卖出
sell_price = open_price + 0.0005
profit = shares * (sell_price - open_price)
print(f"等待到收盘时,卖出价格为{sell_price:.4f},盈利{profit:.2f}元")
|
-
|