python 移动平均线_Python中的SMA(短期移动平均线)

python 移动平均线

With the evolution of technology rapidly evolving, so do strategies in the stock market. In this post, I’ll go over how I created a SMA(Short Moving Average) strategy.

随着技术的飞速发展,股票市场的策略也在不断发展。 在本文中,我将介绍如何创建SMA(短期移动平均线)策略。

DISCLAIMER: Stocks can be risky and it is very possible to lose money. I have not used this strategy to make any financial gains, investments, or purchases. I do not recommend you read this article and use the strategy for your own investment purposes and/or financial gain. I am not responsible for your losses if you choose to use this. The strategy below is only an experiment.

免责声明:股票可能具有风险,很可能会亏损。 我没有使用这种策略来获得任何财务收益,投资或购买。 我不建议您阅读本文,并出于自己的投资目的和/或财务收益而使用该策略。 如果您选择使用此方式,我对您的损失不承担任何责任。 以下策略只是一个实验。

I decided to look at Apple stock (AAPL) because they are a technology giant making big financial gains in the past few months. As of today, August 13, 2020, AAPL opened at $457.72. On March 18, 2020, they opened at $239.77. I’m no expert when it comes to driving prices up and down but the fact is AAPL rose more than $200 in a five month span. I know there are signals in the market that let a consumer know when the right time to buy and sell is and I wanted to explore if a SMA strategy would be of any help.

我决定研究Apple股票(AAPL),因为它们是一家在过去几个月中取得了可观财务收益的技术巨头。 截至今天,2020年8月13日,AAPL开盘价为457.72美元。 2020年3月18日,它们开盘价为239.77美元。 我不是专家来推动价格上下,但事实是AAPL在五个月内上涨了200多美元。 我知道市场上有一些信号可以让消费者知道什么时候是正确的买卖时间,我想探讨一下SMA策略是否有帮助。

The first thing I did was go to Yahoo Finance and download the 5 year historical data csv file and explored the data.

我做的第一件事是去Yahoo Finance并下载5年历史数据csv文件并浏览了数据。

Image for post

Then, I inspected to make sure there were no missing values. I assumed there wouldn’t be because stocks are tracked and monitored so closely, but it does not hurt to make sure.

然后,我检查以确保没有遗漏任何值。 我以为不会那样做,是因为对库存进行了如此密切的跟踪和监控,但是确保这样做没有任何害处。

Image for post

For my experiment, we are not interested in the high point, low point, or volume, so we can drop those columns. The adjusted close is a more accurate representation of where the stock’s price is at.

对于我的实验,我们对高点,低点或音量不感兴趣,因此我们可以删除这些列。 调整后的收盘价更准确地表示了股票价格所在的位置。

Image for post

Now I want to plot my graph for a visual representation.

现在,我想以图形方式绘制图形。

Image for post

The x-axis represents the different entry dates and does not have actual value. It is clear AAPL is on the rise, but for how long? What if we would have predicted when this massive rise occurred?

x轴表示不同的输入日期,并且没有实际值。 很明显,AAPL正在上升,但是持续了多长时间? 如果我们能预料到这种大幅度增长将如何?

The strategy implemented used the crossing of the SMA-30 and SMA 100. SMA-30 is the Short Moving Average of 30 days and SMA-100 is Short Moving Average of 100 days. So, the next thing to do is to find out what the 30 and 100 day averages are.

实施的策略使用了SMA-30和SMA 100的交叉点。SMA-30是30天的短期移动均线,而SMA-100是100天的短期移动均线。 因此,接下来要做的是找出30天和100天的平均值。

Image for post

The first 29 entries will have a NaN value because there is not enough data to create the 30 day average. However we see that in the 30th entry, we have enough data and now have our 30 day average.

前29个条目将具有NaN值,因为没有足够的数据来创建30天平均值。 但是,我们看到在第30个条目中,我们有足够的数据,现在有了30天的平均值。

Image for post

The same code can be applied to the 100 day average, but now the window will equal 100.

可以将相同的代码应用于100天的平均值,但是现在该窗口等于100。

Image for post

Now we can create another graph to see how the averages move with the actual price of the stock. This gives us a clearer picture of the average versus the price.

现在我们可以创建另一个图形,以查看平均数如何随股票的实际价格变动。 这使我们可以更清楚地了解平ASP格。

Image for post

We see the 100 day average does not move as fast as the 30 day average or the actual price, which makes sense because it is reliant on 100 days of information. The 30 day average moves a little more and the actual price is not bound to any other day, so it will move the most. Now we need indicators to buy and sell.

我们看到100天平均值的移动速度不及30天平均值或实际价格快,这是有道理的,因为它依赖于100天的信息。 30天的平ASP格变动幅度更大,而实际价格不受其他日期的限制,因此价格涨幅最大。 现在我们需要指标来买卖。

Image for post

This function will tell us when the averages cross. Depending on how the SMA-30 crosses the SMA-100, that will tell us when to buy and when to sell. I also want the price and date of the cross so I am better informed. the final product is

该函数将告诉我们均线何时穿过。 根据SMA-30与SMA-100的交叉方式,这将告诉我们何时购买和何时出售。 我也想知道十字架的价格和日期,以便更好地通知我。 最终产品是

Image for post
Image for post

We see the most recent buy signal occurred on May 5, 2020 at the price of $318.66.

我们看到最近的购买信号发生在2020年5月5日,价格为318.66美元。

The strategy is not 100% correct and that is important information going into any trade. There are losses and gains from using this.

该策略不是100%正确的,这是进入任何交易的重要信息。 使用此方法会带来损失和收益。

翻译自: https://medium.com/analytics-vidhya/sma-short-moving-average-in-python-c656956a08f8

python 移动平均线

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/392058.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

angular中的href=unsafe:我该怎么摆脱你的溺爱!!

解决方法:angular.module加入下面这行:(依据Angular changes urls to “unsafe:” in extension page) .config(function($compileProvider){//注:有些版本的angularjs为$compileProvider.urlSanitizationWhitelist(/^\s*(https?…

android view gesturedetector,如何在Android中利用 GestureDetector进行手势检测

如何在Android中利用 GestureDetector进行手势检测发布时间:2020-11-26 16:15:21来源:亿速云阅读:92作者:Leah今天就跟大家聊聊有关如何在Android中利用 GestureDetector进行手势检测,可能很多人都不太了解&#xff0c…

Ubuntu2204配置samba

0.前情说明 samba服务器主要是用来局域网共享文件的,如果想公网共享可能行不通,我已经踩坑一天了 所以说如果你想满足公网samba共享你就可以不要看下去了 1.参考连接 Ubuntu 安装 Samba 服务器_ubuntu安装samba服务器-CSDN博客 2.安装samba服务 sud…

Java—BIO模型

利用 BIO 模型(传统阻塞 IO 模型)实现多用户访问 源代码 Server类 public class server {public static void main(String[] args) {ExecutorService executorService Executors.newFixedThreadPool(6);try {ServerSocket serverSocketnew ServerSocke…

c++学编程如何锻炼耐力_我如何学习编程:这是一项耐力运动

c学编程如何锻炼耐力by Amy M Haddad通过艾米M哈达德(Amy M Haddad) 我如何学习编程:这是一项耐力运动 (How I’m learning to program: it’s an endurance sport) 为什么我的编程学习轨迹反映了我作为跑步者的训练方式 (Why my learning trajectory for programm…

python处理文本数据

处理文本数据,主要是通过Seris的str访问。遇到NaN时不做任何处理,保留结果为NaN,遇到数字全部处理为NaN。 str是Seris的方法,DataFrame不能直接使用,但是通过索引选择DataFrame中的某一行或者某一列,结果为…

Java系列笔记(4) - JVM监控与调优【转】

Java系列笔记(4) - JVM监控与调优【转】 目录 参数设置收集器搭配启动内存分配监控工具和方法调优方法调优实例 光说不练假把式,学习Java GC机制的目的是为了实用,也就是为了在JVM出现问题时分析原因并解决之。通过学习,我觉得JVM监控与调…

Maven打包排除某个资源或者目录

最近在spark streaming本地调试的时候&#xff0c;引入了一些资源文件&#xff0c;打包的时候需要给排除掉。所以就考虑使用maven的方式 详细参考官方文档&#xff1a;https://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html 排除某个资源文件 <…

android发送网络请求没反应,Android无法使用HttpURLConnection发送GET请求

我正在尝试在我的应用程序中使用HttpURLConnection.我将我的请求方法设置为’GET’,但是当我尝试检索输出流时,该方法将更改为’POST’&#xff01;我不确定是什么原因,但是当我使用’POST’发送请求时,我的JSON服务器(我使用JAX-RS)会返回一个空白页面.这是我的代码片段&#…

地图 c-suite_C-Suite的模型

地图 c-suiteWe’ve all seen a great picture capture an audience of stakeholders.我们所有人都看到了吸引利益相关者听众的美好画面。 Let’s just all notice that the lady in the front right is not captivated by the image on the board (Photo by Christina wocin…

框架和库的区别_框架和库之间的区别

框架和库的区别Developers often use the terms “library” and “framework” interchangeably. But there is a difference.开发人员经常互换使用术语“库”和“框架”。 但是有区别。 Both frameworks and libraries are code written by someone else that is used to he…

Java—多线程实现生产者消费者模型

采用线程实现“生产者-消费者”编程的基础模型 源代码 消费者代码&#xff1a; public class Consumer implements Runnable {BlockingQueue<Integer> blockingQueue;int n;CountDownLatch countDownLatch;public Consumer(BlockingQueue<Integer> blockingQueue…

动态链接库.so和静态链接库.a的区别

静态链接库&#xff1a; •扩展名&#xff1a;.a  •编译行为&#xff1a;在编译的时候&#xff0c;将函数库直接整合到执行程序中&#xff08;所以利用静态库编译生成的文档会更大&#xff09; •独立执行的状态&#xff1a;编译成功的可执行文件可以独立运行&#xff0c;不…

华为鸿蒙系统封闭,谷歌正式“除名”华为!“亲儿子”荣耀表示:暂不考虑,鸿蒙OS处境尴尬...

我们都知道&#xff0c;目前智能手机最常用操作系统就是IOS和安卓&#xff0c;占据手机系统超过99%的市场份额。由于IOS系统的封闭性&#xff0c;国内手机厂商基本上都是使用谷歌的开源安卓系统。当然华为也不例外&#xff0c;一直使用的都是安卓系统。可以说&#xff0c;安卓系…

使用vue-cli脚手架搭建简单项目框架

1.首先已经安装了node,最好版本6以上。 2.安装淘宝镜像 大家都知道国内直接使用 npm 的官方镜像是非常慢的&#xff0c;这里推荐使用淘宝 NPM 镜像。这样就可以直接使用cnpm了。 npm install -g cnpm --registryhttps://registry.npm.taobao.org如果过程出差&#xff0c;是否安…

sap中泰国有预扣税设置吗_泰国餐厅密度细分:带有K-means聚类的python

sap中泰国有预扣税设置吗Hi! I am Tung, and this is my first stories for my weekend project. What inspired this project is that I have studied to become data scientist for almost two years now mostly from Youtube, coding sites and of course, Medium ,but my l…

自动化yaml文件_从YAML到TypeScript:开发人员对云自动化的看法

自动化yaml文件The rise of managed cloud services, cloud-native, and serverless applications brings both new possibilities and challenges. More and more practices from software development processes like version control, code review, continuous integration,…

SQL SERVER-Extendevent系统视图

--获得扩展事件的事件select name,description from sys.dm_xe_objects where object_typeevent order by name--获得各事件的字段 select c.name,c.description from sys.dm_xe_object_columns c inner join sys.dm_xe_objects o on o.namec.object_name where o.name…

Java—简单的注册页面

根据所提供的界面&#xff0c;编写 register.html 文件 源代码 empty.jsp <% page contentType"text/html;charsetUTF-8" language"java" %> <html> <head><title>error</title> </head> <body> <H1><…

【深度学习系列】用PaddlePaddle和Tensorflow实现经典CNN网络AlexNet

上周我们用PaddlePaddle和Tensorflow实现了图像分类&#xff0c;分别用自己手写的一个简单的CNN网络simple_cnn和LeNet-5的CNN网络识别cifar-10数据集。在上周的实验表现中&#xff0c;经过200次迭代后的LeNet-5的准确率为60%左右&#xff0c;这个结果差强人意&#xff0c;毕竟…