先知ppt_先知预测铜生产者价格指数

先知ppt

Forecasting asset prices can be a tricky business at the best of times. For one, asset prices are subject to a high degree of stochasticity (or random influence), which makes generating future predictions difficult.

在最佳时机,预测资产价格可能是一件棘手的事情。 首先,资产价格受到高度随机性(或随机影响)的影响,这使得生成未来的预测变得困难。

With that being said, one useful feature of the Prophet time series model by Facebook is the ability to identify changepoints, or periods of significant structural change in a time series. Accurate identification of such points can in turn improve a time series forecast. Let’s see how Prophet performs in forecasting the Producer Price Index for copper. The data is sourced from FRED Economic Data using Quandl.

话虽如此,Facebook的Prophet时间序列模型的一个有用功能是能够识别变更点或时间序列中重大结构变更的时期。 准确识别这些点可以反过来改善时间序列预测。 让我们看看先知如何预测铜的生产者价格指数。 数据使用Quandl从FRED经济数据中获取。

背景 (Background)

The copper producer price index is analysed from September 1985 to July 2020. As this is a financial time series, the series is converted into logarithmic format to smooth out the data and ensure that returns on a percentage basis are being accounted for by the model.

分析了1985年9月至2020年7月的铜生产者价格指数。由于这是一个金融时间序列,因此将该序列转换为对数格式,以使数据平滑并确保该模型按百分比计回报。

Here is a plot of the data:

这是数据图:

Image for post
Source: FRED Economic Data
资料来源:FRED经济数据

Data from September 1985 to January 2017 is used as training data. The remaining months up until July 2020 is used as test data — this is the data that is used for comparison with the predictions made by the model to gauge accuracy.

1985年9月2017 1月的数据用作训练数据。 直到20207月的剩余月份都用作测试数据-这是用于与模型所做的预测进行比较以评估准确性的数据。

Here is a decomposition of the series into its components:

这是该系列分解成各个部分的分解:

Image for post
Source: Jupyter Notebook Output
资料来源:Jupyter Notebook输出

We can see that in this instance, the series has a strong upward trend. However, there is no evidence of seasonality in the series.

我们可以看到,在这种情况下,该系列具有强劲的上升趋势。 但是,没有证据表明该系列具有季节性。

That being said, there do appear to be several structural breaks present in the data. From that standpoint, the Prophet model may well yield predictive power in forecasting price on the test data.

话虽如此,数据中似乎确实存在一些结构性中断。 从这个角度来看,Prophet模型在预测测试数据的价格时可能会产生预测能力。

建筑模型 (Model Building)

The dataset is defined as follows:

数据集定义如下:

train_dataset= pd.DataFrame()
train_dataset['ds'] = train_df['Date']
train_dataset['y']= train_df['Value']
train_dataset.head(10)

A standard Prophet model is fitted to the dataset as follows:

标准先知模型适合数据集,如下所示:

prophet_basic = Prophet()
prophet_basic.fit(train_dataset)

Here is a generated forecast using the model:

这是使用该模型生成的预测:

forecast=prophet_basic.predict(future)
fig1 =prophet_basic.plot(forecast)
Image for post
Source: Prophet
资料来源:先知

As mentioned, what is of particular interest is the changepoints, or significant structural breaks in the time series.

如上所述,特别有趣的是时间序列中的变更点或重大结构性中断。

from fbprophet.plot import add_changepoints_to_plot
fig = prophet_basic.plot(forecast)
a = add_changepoints_to_plot(fig.gca(), prophet_basic, forecast)
Image for post
Source: Prophet
资料来源:先知

As is evident from the above graph, 12 changepoints have been identified by the model. A forecast is now made on this basis.

从上图可以明显看出,该模型已确定了12个变更点。 现在在此基础上进行预测。

pro_change= Prophet(n_changepoints=12)
forecast = pro_change.fit(train_dataset).predict(future)
fig= pro_change.plot(forecast);
a = add_changepoints_to_plot(fig.gca(), pro_change, forecast)future_data = pro_change.make_future_dataframe(periods=43, freq = 'm')
#forecast the data for future data
forecast_data = pro_change.predict(future_data)
pro_change.plot(forecast_data);

A detailed forecast is generated by Prophet:

先知生成了一个详细的预测:

Image for post
Source: Prophet
资料来源:先知

准确性 (Accuracy)

Let us now assess the accuracy of the model on the basis of:

现在让我们基于以下条件评估模型的准确性:

  • Mean Directional Accuracy: 95%

    平均方向精度: 95%

  • Root Mean Squared Error: 0.1948

    均方根误差: 0.1948

  • Mean Forecast Error: 0.1839

    平均预测误差: 0.1839

Here is a plot of the predicted vs actual price across the test set:

这是测试集中预测价格与实际价格的关系图:

Image for post
Source: Jupyter Notebook Output
资料来源:Jupyter Notebook输出

With a mean of 5.93 across the test set (in logarithmic terms), the RMSE and MAE is quite low in comparison (roughly 3% of the size of the mean), indicating that the model performs well in forecasting terms. Since we are using monthly data, it is unclear as to how this model would perform when using a shorter timeframe, e.g. hourly or daily. From this standpoint, the model forecast could be limited in terms of forecasting short-term fluctuations, but seems to do quite well in capturing the overall trend.

整个测试集的平均值为5.93(以对数形式),相比之下,RMSE和MAE相当低(约为平均值的3%),表明该模型在预测方面表现良好。 由于我们使用的是每月数据,因此在使用较短的时间范围(例如每小时或每天)时,尚不清楚该模型的性能。 从这个角度来看,模型预测在预测短期波动方面可能会受到限制,但在把握总体趋势方面似乎做得很好。

Additionally, with an MDA of 95%, this indicates that the model is able to predict the price direction in a particular month 95% of the time — which is quite good.

另外,如果MDA为95%,则表明该模型能够在95%的时间中预测特定月份的价格方向,这非常好。

Note that the changepoint configuration has a direct impact on the forecast accuracy. For instance, when the number of changepoints in the forecast was lowered to 4, the RMSE came in at 0.2840. While this is still quite low in comparison to the mean, it is still nearly double that of the RMSE calculated with 12 changepoints.

请注意,更改点配置对预测准确性有直接影响。 例如,当预测中的变更点数降低至4时 ,RMSE为0.2840 。 尽管与平均值相比仍然很低,但仍几乎是使用12个变更点计算出的RMSE的两倍。

局限性 (Limitations)

As a general limitation, forecasting asset prices (or economic data of any kind) can be tricky.

作为一般限制,预测资产价格(或任何类型的经济数据)可能很棘手。

This is because asset prices are inherently subject to a feedback loop. For instance, suppose a Prophet model brings near-perfect accuracy in forecasting copper prices. Under this scenario, the broader market will eventually start using the model — under the assumption that the market remains efficient over the long-run — at which point a competitive advantage can no longer be obtained in terms of forecasting ability.

这是因为资产价格固有地受反馈循环的影响。 例如,假设Prophet模型在预测铜价时具有近乎完美的准确性。 在这种情况下,更广泛的市场最终将开始使用该模型(假设市场在长期内保持有效),此时,就预测能力而言,将无法再获得竞争优势。

Unlike a time series such as the weather, for instance — which cannot be changed through human intervention — subsequent trades based on a forecast then have the effect of shifting price itself — meaning that forecasts which would have previously been accurate are no longer so.

例如,与诸如天气这样的时间序列(无法通过人为干预进行更改)不同,基于预测的后续交易随后会产生价格本身变动的影响,这意味着以前准确的预测不再如此。

Additionally, financial time series are potentially subject to interventions which may not have been captured in the previous data. For instance, lowering of U.S. interest rates to zero by the Federal Reserve would not have been captured in time series data taken before 2008, and as a result the time series itself cannot account for such significant structural shifts.

此外,财务时间序列可能会受到干预,而以前的数据可能未捕获这些干预。 例如,美联储将美国利率降低到零不会被记录在2008年之前的时间序列数据中,因此,时间序列本身无法解释如此重大的结构性变化。

When it comes to modelling interventions specifically, a more effective way to do so could be through the use of the casualimpact package. Here is an example of how such an tool can be used to model the impact of interest rate changes on currency fluctuations.

特别是在对干预措施建模时,一种更有效的方法可能是通过使用Casualimpact软件包。 这是一个示例 ,说明如何使用这种工具来建模利率变化对货币波动的影响。

结论 (Conclusion)

In this example, we have seen that Prophet can be quite effective when it comes to forecasting longer-term trends for an asset price, and is particularly effective at identifying points of significant structural change to inform such forecasts.

在此示例中,我们已经看到,先知在预测资产价格的长期趋势时可以非常有效,并且在识别重大结构变化的点以告知此类预测方面尤其有效。

Many thanks for reading, and any questions or feedback are greatly appreciated. You can also find the Jupyter Notebook for this example here.

非常感谢您的阅读,非常感谢任何问题或反馈。 您还可以在这里找到此示例的Jupyter Notebook。

Disclaimer: This article is written on an “as is” basis and without warranty. It was written with the intention of providing an overview of data science concepts, and should not be interpreted as investment advice, or any other sort of professional advice.

免责声明:本文按“原样”撰写,不作任何担保。 本文档旨在概述数据科学概念,不应将其解释为投资建议或任何其他形式的专业建议。

翻译自: https://towardsdatascience.com/forecasting-the-copper-producer-price-index-with-prophet-d570e3baac78

先知ppt

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值