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文件并浏览了数据。
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.
然后,我检查以确保没有遗漏任何值。 我以为不会那样做,是因为对库存进行了如此密切的跟踪和监控,但是确保这样做没有任何害处。
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.
对于我的实验,我们对高点,低点或音量不感兴趣,因此我们可以删除这些列。 调整后的收盘价更准确地表示了股票价格所在的位置。
Now I want to plot my graph for a visual representation.
现在,我想以图形方式绘制图形。
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天的平均值。
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天的平均值。
The same code can be applied to the 100 day average, but now the window will equal 100.
可以将相同的代码应用于100天的平均值,但是现在该窗口等于100。
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格。
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格变动幅度更大,而实际价格不受其他日期的限制,因此价格涨幅最大。 现在我们需要指标来买卖。
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的交叉方式,这将告诉我们何时购买和何时出售。 我也想知道十字架的价格和日期,以便更好地通知我。 最终产品是
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,一经查实,立即删除!