Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pro-1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
20210410042
pro-1
Commits
640e0ec1
Commit
640e0ec1
authored
Jun 06, 2021
by
高书明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1st commit
parent
d5034543
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
0 deletions
+85
-0
big-quant.ipynb
+85
-0
No files found.
big-quant.ipynb
0 → 100644
View file @
640e0ec1
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"instrmt = ['600519.SHA']\n",
"s_date = '2016-01-01'\n",
"e_date = '2020-03-01'\n",
"\n",
"def initialize(context):\n",
" context.set_commission(PerOrder(buy_cost=0.0005,\n",
" sell_cost=0.0007,\n",
" min_cost=5))\n",
" context.short_period = 5\n",
" context.long_period = 25\n",
"\n",
"def handle_data(context,data):\n",
" if context.trading_day_index < context.long_period:\n",
" return\n",
" k = instrmt[0]\n",
" sid = context.symbol(k)\n",
" price = data.current(sid,'price')\n",
" short_mavg = data.history(sid,'price',context.short_period,'1d').mean()\n",
" long_mavg = data.history(sid,'price',context.long_period,'1d').mean()\n",
" cash = context.portfolio.cash\n",
" cur_possess = context.portfolio.positions[sid].amount\n",
" if short_mavg > long_mavg and cur_possess == 0 and data.can_trade(sid):\n",
" context.order(sid,int(cash/price/100)*100)\n",
" elif short_mavg < long_mavg and cur_possess > 3 and data.can_trade(sid):\n",
" context.order_target_percent(sid,3)\n",
" \n",
" \n",
"tar = M.trade.v4(start_date=s_date,\n",
" end_date=e_date, \n",
" initialize=initialize, \n",
" handle_data=handle_data, \n",
" instruments=instrmt, \n",
" prepare=None, \n",
" before_trading_start=None, \n",
" volume_limit=0.025, \n",
" order_price_field_buy='open', \n",
" order_price_field_sell='close', \n",
" capital_base=50000.0, \n",
" auto_cancel_non_tradable_orders=True, \n",
" data_frequency='daily', \n",
" price_type='真实价格', \n",
" product_type='股票', \n",
" plot_charts=True, \n",
" backtest_only=False, \n",
" options_data=None, \n",
" options=None, \n",
" history_ds=None, \n",
" benchmark_ds=None, \n",
" benchmark='', \n",
" trading_calendar=None, \n",
" amount_integer=None)"
]
}
],
"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.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment