{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# akshare库使用教程\n", "### akshare函数\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import akshare as ak\n", "\n", "futures_contract_detail_df = ak.futures_contract_detail(symbol='V2001')\n", "print(futures_contract_detail_df)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 日期 开盘价 最高价 最低价 收盘价 成交量 持仓量 动态结算价\n", "0 2024-09-02 4612.0 4634.8 4508.8 4515.6 89892 142020 0\n", "1 2024-09-03 4524.0 4592.8 4514.0 4547.4 95410 140430 0\n", "2 2024-09-04 4530.0 4587.0 4507.0 4536.2 95403 134704 0\n", "3 2024-09-05 4544.6 4611.4 4544.6 4577.2 88060 131885 0\n", "4 2024-09-06 4595.0 4597.4 4482.0 4497.2 90398 127548 0\n", "5 2024-09-09 4487.2 4518.6 4445.2 4457.4 85871 125870 0\n", "6 2024-09-10 4471.0 4502.4 4378.8 4473.6 116746 129541 0\n", "7 2024-09-11 4460.0 4494.4 4439.0 4474.8 86309 111092 0\n", "8 2024-09-12 4484.0 4545.0 4461.6 4468.4 86856 106827 0\n", "9 2024-09-13 4475.0 4478.6 4414.2 4416.8 80427 94210 0\n", "10 2024-09-18 4413.0 4423.0 4337.4 4405.0 90715 75838 0\n", "11 2024-09-19 4422.2 4543.2 4380.0 4487.4 92123 42680 0\n", "12 2024-09-20 4483.0 4493.0 4437.0 4447.8 35454 17785 0\n", "13 2024-09-23 4415.2 4497.8 4402.4 4437.0 78245 101314 0\n", "14 2024-09-24 4496.0 4656.8 4438.2 4653.2 156875 127361 0\n", "15 2024-09-25 4710.0 4802.8 4672.6 4680.0 130643 110238 0\n", "16 2024-09-26 4671.4 4940.0 4662.4 4937.4 152942 119316 0\n", "17 2024-09-27 5022.0 5362.6 4954.4 5362.2 212983 109667 0\n" ] } ], "source": [ "import akshare as ak\n", "\n", "futures_main_sina_hist = ak.futures_main_sina(symbol=\"IM0\", start_date=\"20240901\", end_date=\"20240927\")\n", "print(futures_main_sina_hist)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import akshare as ak\n", "from datetime import datetime, timedelta\n", " \n", "# 获取当前日期的数据\n", "today = datetime.now().strftime('%Y%m%d')\n", "# 计算20日前的日期\n", "start_day = (datetime.now() - timedelta(days=60)).strftime('%Y%m%d')\n", "\n", "futures_main_sina_hist = ak.futures_main_sina(symbol=\"IM0\", start_date=start_day, end_date=today)\n", "print(futures_main_sina_hist)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "futures_main_sina_hist['收盘价'].iloc[0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "futures_main_sina_hist['5day_ma'] = futures_main_sina_hist['收盘价'].rolling(window=5).mean()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "futures_main_sina_hist['5day_ma'].iloc[-1]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(futures_main_sina_hist)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import akshare as ak\n", "\n", "futures_main_sina_hist = ak.futures_main_sina(symbol=\"IM0\", start_date=\"20240901\", end_date=\"20240927\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from findpeaks import findpeaks " ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.9" } }, "nbformat": 4, "nbformat_minor": 2 }