技术标签: Python的基本用法和应用 python
import talib
import pandas as pd
import mplfinance as mpf
import matplotlib.pyplot as plt
#from matplotlib.finance import candlestick2_ohlc
from mpl_finance import candlestick2_ohlc
from mpl_finance import candlestick_ohlc
#pip install https://github.com/matplotlib/mpl_finance/archive/master.zip
df = pd.read_csv('./000001.SZ.csv')
ma5_df=talib.MA(df['close'],timeperiod=5)
#print(ma_df)
ma10_df=talib.MA(df['close'],timeperiod=10)
ma20_df=talib.MA(df['close'],timeperiod=20)
fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot(ma5_df,label='MA5')
ax.plot(ma10_df,label='MA10')
ax.plot(ma20_df,label='MA20')
candlestick2_ohlc(ax,df['open'],df['high'],df['low'],df['close'],width=0.6,colorup='red',colordown='green')
plt.legend()
plt.show()
diff ,dea,macd=talib.MACD(df['close'],fastperiod=12,slowperiod=26,signalperiod=9)
rsi=tailb.RSI(df['close'],timeperiod=14)
K,D=talib.STOCH(df['high'],df['low'],df['close'],fastk_period=9,slowk_period=3,slowd_period=3)
CCI=talib.CCI(df['high'],df['low'],df['close'],timeperiod=14)
ATR=talib.ATR(df['high'],df['low'],df['close'],timeperiod=14)
OBV=talib.OBV(df['close'],df['vol'])
nums=talib.CDLMORNINGSTAR(df['open'],df['high'],df['low'],df['close'])
nums=talib.CDLEVENINGSTAR(df['open'],df['high'],df['low'],df['close'])
nums=talib.CDLHAMMER(df['open'],df['high'],df['low'],df['close'])
nums=talib.CDLHANGINGMAN(df['open'],df['high'],df['low'],df['close'])
nums=talib.CDLBELTHOLD(df['open'],df['high'],df['low'],df['close'])
import fnn
import pandas as pd
series=pd.Series([10000,10100,10300,10600])
#计算收益率
result=ffn.calc_total_return(series)
#计算年化收益率
ann_result=ffn.annualize(result,4,one_year=250)
#计算资产简单收益率
returns=ffn.to_return(series)
#计算夏普比率
sharpe=ffn.calc_sharpe(returns)
#计算最大回撤率
max_drawdown=ffn.calc_max_drowdown(series)
#计算所提诺比率
sortino=ffn.calc_sortino_ratio(returns)
import tushare as ts
ts_pro=ts.pro_api('xxx')
df=ts_pro.daily(ts_code='000001.SZ',start_date='20180101',end_date='20191230')
df=df.reindex(index=df.index[::-1])
used_cols=['trade_date','close']
df=df[used_cols]
df.to_csv('./000001.SZ.csv',index=None)
#策略编写
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import ffn
hold=False
pos=0
capital=100000
rest=0
fee=0.0003
capital_list=[]
MA20_array=np.zeros(20)
MA10_array=np.zeros(10)
df=pd.read_csv('./000001.SZ.csv')
#数据遍历
for i in range(len(df)):
price=df.loc[i,'close']
date=df.loc[i,'trade_date']
MA10_array[0:9]=MA10_array[1:10]
MA20_array[0:91] = MA20_array[1:20]
MA10_array[-1] = price
MA20_array[-1] = price
if i<20:
continuce
MA10 = MA10_array.mean()
MA20 = MA20_array.mean()
#判断是否达到开仓和平仓的信号
if MA10>MA20 and hold==False:
pos=int(capital/price/100)*100
rest=capital-pos*price*(1+fee)
hold=Ture
print('buy at',date,'price',price,'capital',capital)
elif MA10<MA20 and hold==Ture:
capital=pos*price*(1-fee)+rest
pos=0
hold=False
print('sell at',date,'price',price,'capital',capital)
if hold==True:
capital_list.append(rest+pos*price)
else:
capital_list.append(capital)
capital_series=pd.Series(capital_list)
capital_returns=ffn.to_returns(capital_series)
RSI6 = talib.RSI('rsi6_arry',timeperiod=6)[-1]
这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入请问谁有基于...
0.spring框架家族的学习路线spring framework–>springWebMVC–>springboot–>springdata–>springSession–>springCloud1.搭建spring环境 最新版本5.2.8 spring 框架中学习路线: 核心的:IOC和AOP 测试:与junit集成 持久层:事务管理 web:springMVC 组件集成:远程接口调用,任务调度操作步骤:- 引入spring的核心jar包:4个核
文章目录一、下载mosquitto二、配置mosquitto三、MQTTX一、下载mosquitto点击下载安装程序 下载地址二、配置mosquitto安装路径打开命令行界面设置user及password执行:mosquitto_passwd.exe -c pwfile.example -u vic设置用户名:vic 设置密码:123456配置文件检查 mosquitto.exe -c mosquitto.conf 未报错说明配置正常设置端口 默认
3,Action、Category属性与intent-filter配置Intent的Action和Category属性都是一个普通的字符串,其中Action代表该Intent所要完成的一个抽象“动作”,Category则用于为Action增加额外的附加类别信息,通常,Action与Category结合使用。元素里通常可包括如下子元素:a、0~N个子元素b、0~N个子
I have been usingPython debug and LLDB attach debug since I have code in Python and C++I have run this multiple times. It looks like everytime there is an exception in the middle of debugging, the pro...
毕设帮助、开题指导、技术解答(有偿)见文末。
[toc]命令式命令行操作很多 Kubernetes 的 API 对象,有的是用来描述应用,有的则是为应用提供各种各样的服务。但是,无一例外地,为了使用这些 API 对象提供的能力,你都需要编写一个对应的 YAML 文件交给 Kubernetes。这个 YAML 文件,正是 Kubernetes 声明式 API 所必须具备的一个要素。不过,是不是只要用 YAML 文件代替了命令行操作,就是...
这个文章是对《Eclipse快速上手EJB -- 1. Lomboz + JBoss-IDE 配置1 》一文的一点补充。在那篇文章中,jboss400.server这个配置是针对JBoss 4.0.0 的,如果使用的是JBoss 4.0.1,需要使用以下的配置文件: jboss401.server serverDefinition name="JBOSS 4
各大论坛资源合集汇总http://www.erji.net/ 聊耳机的论坛http://www.cdbest.com/ 聊刻录机,刻录光盘http://forum.ubuntu.org.cn/ 应该是国内最大的ubuntu论坛了吧http://bbs.go2eu.com/ 穷游网,撸瑟的国际旅游,我最近很感兴趣http://www.ditiezu.com/index.php 地铁...
如下php代码:$fp=fopen("../txt/".$getSelectDate.".txt","wb") or die("error1");本地测试通过,但将该php文件上传到服务器端后测试,出现创建/写入文件失败(未检查错误报告)猜测多半为权限写入原因,在服务端控制台下写入以下代码:chmod 777 txt;(txt是要写入修改的文件所在的文件夹的目录名,赋予目录txt的读写...
Visio如何添加枚举类型 1. 新建DataType2. 选择DataType -&gt; Property -&gt; Stereotype -&gt;enumeration3. 添加其他的Attribute,作为Enumeration值。 本文和大家重点讨论一下用Visio画UML图基本操作,画UML图有好多种工具,VISIO只是其中一种,VISIO的动作非常轻快.很多人都在用。...