用 Python 机器学习预测黄金价格

股票大跌了,只能靠黄金稳住收入了丨用 Python 机器学习预测黄金价格 读取黄金 ETF 数据 本文使用机器学习方法来预测最重要的贵金属之一黄金的价格。我们将创建一个线性回归模型,该模型从过去的黄金 ETF (GLD) 价格中获取信息,并返回对第二天黄金 ETF 价格的预测。GLD是直接投资实物黄金的最大ETF。(扫描本文最下方二维码获取全部完整源码和Jupyter Notebook 文件打包下载。) 首先要做的是:导入所有必要库。 # LinearRegression 是一个用于线性回归的机器学习库 from sklearn.linear_model impo.. 阅读详情

读取黄金 ETF 数据

本文使用机器学习方法来预测最重要的贵金属之一黄金的价格。我们将创建一个线性回归模型,该模型从过去的黄金 ETF (GLD) 价格中获取信息,并返回对第二天黄金 ETF 价格的预测。GLD是直接投资实物黄金的最大ETF。(扫描本文最下方二维码获取全部完整源码和Jupyter Notebook 文件打包下载。)

首先要做的是:导入所有必要库。

# LinearRegression 是一个用于线性回归的机器学习库  
from sklearn.linear_model import LinearRegression  
# pandas 和 numpy 用于数据操作  
import pandas as pd  
import numpy as np  
# matplotlib 和 seaborn 用于绘制图形  
import matplotlib.pyplot as plt  
%matplotlib inline  
plt.style.use('seaborn-darkgrid')  
# yahoo Finance用于获取数据  
import yfinance as yf 

然后,我们读取过去 12 年的每日黄金 ETF 价格数据并将其存储在 Df 中。我们删除不相关的列并使用 dropna() 函数删除 NaN 值。然后,我们绘制黄金 ETF 收盘价。

Df = yf.download('GLD', '2008-01-01', '2020-6-22', auto_adjust=True)  
DfDf = Df[['Close']]  
DfDf = Df.dropna()  
Df.Close.plot(figsize=(10, 7),color='r')  
plt.ylabel("Gold ETF Prices")  
plt.title("Gold ETF Price Series")  
plt.show() 

使用 Python 机器学习预测黄金价格 解释变量是被操纵以确定第二天黄金 ETF 价格价值的变量。简而言之,它们是我们想要用来预测黄金 ETF 价格的特征。该策略的解释变量是过去3天和9天的移动平均线。我们使用 dropna() 函数删除 NaN 值并将特征变量存储在 X 中。但是,您可以向 X 添加更多您认为有助于预测黄金 ETF 价格的变量。这些变量可以是技术指标、其他 ETF(例如黄金矿商 ETF (GDX) 或石油 ETF (USO))的价格,或美国经济数据。同样,因变量取决于解释变量的值。 阅读详情

相关推荐

使用Python预测黄金AU9999收盘价

使用Python处理黄金数据集,并构建数据模型来预测收盘价格

u012961540的博客 3672

听“股神”说买黄金永远不会亏?那我就用Python来预测黄金价格走势。

读取黄金 ETF 数据 本文使用机器学习方法来预测最重要的贵金属之一黄金的价格。我们将创建一个线性回归模型,该模型从过去的黄金 ETF (GLD) 价格中获取信息,并返回对第二天黄金 ETF 价格的预测。GLD是直接投资实物黄金的最大ETF。 首先要做的是:导入所有必要库。 #LinearRegression是一个用于线性回归的机器学习库 fromsklearn.linear_modelimportLinearRegression #pandas和numpy用于数据操...

weixin_52994140的博客 912

股票预测-基金预测 pytorch搭建LSTM网络 黄金价格预测实战

股票预测-基金预测 pytorch搭建LSTM网络 黄金价格预测实战

918

基于Python的金融数据抓取与趋势分析:汇率与黄金价格的预测与可视化

在本文中,我们通过使用Python的爬虫技术抓取了汇率和黄金价格数据,并使用pandas进行数据清洗、分析和可视化。我们还介绍了使用ARIMA和机器学习模型进行趋势预测的方法。这些技术和方法为金融数据分析和预测提供了强大的工具,适用于汇率、黄金价格以及其他金融产品的分析。未来,我们可以扩展模型,利用更多的金融数据进行更复杂的预测,甚至结合深度学习模型(如LSTM)进行更加精准的时间序列预测。

2201_76125261的博客 755

数据挖掘实战-基于长短期记忆网络(LSTM)的黄金价格预测模型 | 97% 准确度

本实验基于Kaggle上提供的从2013年到2023年的黄金价格数据集,运用长短期记忆网络(LSTM)构建了黄金价格预测模型。该数据集详细记录了每日的黄金价格信息,包括开盘价、收盘价、高点、低点和交易量等,为模型的训练提供了丰富的数据支持。

m0_64336780的博客 1万+

iSLIP算法实战:如何用Python模拟交换机优先级匹配(附完整代码)

本文详细介绍了如何使用Python实现iSLIP算法,模拟交换机优先级匹配过程。通过核心的指针滑动逻辑和迭代循环策略,构建了一个完整的iSLIP算法模拟器,并加入可视化模块以直观展示匹配过程。文章还提供了完整的代码框架和性能优化建议,适合网络工程师和Python开发者直接集成到测试环境中。

weixin_29313239的博客 249

PCB光绘文件DFM检查:从Gerber验证到制造闭环

Gerber文件是PCB设计交付制造的核心数据载体,其准确性直接决定硬件可制造性与量产良率。理解Gerber格式规范、IPC网表比对原理及DFM(Design for Manufacturability)自动检测逻辑,是电子工程师保障设计落地的关键能力。通过电气连通性验证、物理DRC规则扫描与工艺兼容性分析,DFM工具能提前识别开路、短路、孔环不足、阻焊异常等典型问题,避免投板后返工甚至批量报废。在国产化替代趋势下,华秋DFM等平台已深度适配Altium Designer工作流,支持一键导入、智能报告与协同

weixin_42620563的博客 507

USB接口ESD防护设计实战:从金属外壳到信号线的完整避坑指南

本文深入探讨USB接口ESD防护设计的实战要点,聚焦金属外壳作为ESD能量泄放关键通道的处理策略。文章详细解析了从外壳接地路径控制、信号线TVS管选型与布局,到PCB分区及电源线滤波等完整设计流程,旨在帮助硬件工程师构建系统级防护,避免常见设计误区,确保产品通过严苛的静电测试。

k8l9m0n的博客 481

深信服桌面云实战:从零部署到高效运维的关键配置指南

本文提供了一份深信服桌面云从零部署到高效运维的实战指南。内容涵盖项目启动阶段的资源、网络与存储规划,详细演示了VMP与VDC平台的安装与对接,并深入讲解了制作虚拟机模板、配置用户体系、优化终端策略等核心步骤。最后,分享了包括CPU公平分配、智能调度在内的关键性能调优与高阶运维技巧,旨在帮助管理员构建稳定、高效的云桌面环境。

blockchain9miner的博客 450

网格自适应实战 | 攻克超弹性体大变形不收敛难题

本文针对超弹性体(如橡胶)在大变形仿真中因网格严重扭曲导致计算不收敛的难题,提供了基于ANSYS网格自适应技术的实战解决方案。文章详细阐述了从问题诊断、模型准备到核心参数设置的完整流程,并介绍了结合混合U-P单元技术的进阶组合策略,有效攻克了材料压缩等场景下的仿真收敛问题。

week9的博客 515

网页内容抓取的艺术:使用R语言解析动态网页

本文探讨了使用R语言处理动态网页数据的方法。针对AJAX加载的学术网站,传统的静态抓取和RSelenium方法存在会话终止、浏览器错误等问题。通过分析发现内容通过admin-ajax.php加载,提出使用httr2模拟POST请求获取数据,配合rvest解析HTML内容。该方法避免了浏览器自动化的弊端,实现了高效稳定的动态内容提取,为处理类似AJAX网站提供了通用解决方案。

m0_74337424的博客 52

【QNX+Android虚拟化方案】129 - USB眼图参数配置

【QNX+Android虚拟化方案】129 - USB眼图参数配置

|~~~热爱生活、努力学习的小伙汁~~~| 820

FFDNet-pytorch版本代码训练教程

该文章为FFDNet-pytorch版本代码训练教程,抓紧订阅学习!尽早入门发论文哦!

假技术Po主 1505

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

上一篇: 六个实例,八段代码,详解Python中的for循环
下一篇: Python爬虫实战,pyecharts模块,Python实现中国地铁数据可视化
Python_xiaowu
博客等级 码龄5年 3096粉丝 178原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值