导入数据库怎么导入_导入必要的库

导入数据库怎么导入

重点 (Top highlight)

With the increasing popularity of machine learning, many traders are looking for ways in which they can “teach” a computer to trade for them. This process is called algorithmic trading (sometimes called algo-trading).

随着机器学习的日益普及,许多交易者正在寻找可以“教”计算机进行交易的方式。 此过程称为算法交易(有时称为算法交易)。

Algorithmic trading is a hands off strategy for buying and selling stocks that leverages technical indicators instead of human intuition.

算法交易是一种利用技术指标而不是凭直觉来买卖股票的不干预策略。

In order to implement an algorithmic trading strategy though, you have to narrow down a list of stocks you want to analyze. This walk-through provides an automated process (using python and logistic regression) for determining the best stocks to algo-trade.

但是,为了实施算法交易策略,您必须缩小要分析的股票列表。 本演练提供了自动流程(使用python和逻辑回归),用于确定要进行算法交易的最佳库存。

I will dive deeper into the logic and code below, but here is a high-level overview of the process:

我将更深入地研究下面的逻辑和代码,但这是该过程的高级概述:

  1. Import the historical data of every stock using yahoo finance.

    使用Yahoo Finance导入每只股票的历史数据。
  2. Pull in over 32 technical indicators for each stock using the technical analysis library.

    使用技术分析库为每种股票提取32种以上的技术指标。

  3. Perform a logistic regression on each stock using 5, 30, and 60 day observation time periods.

    使用5、30和60天的观察时间段对每只股票执行逻辑回归。
  4. Interpret the results.

    解释结果。

导入必要的库 (Import Necessary Libraries)

Running this program in python requires these libraries:

在python中运行此程序需要以下库:

Libraries:

库:

  • Yfinance: Gather the historical data of each stock.

    Yfinance :收集每只股票的历史数据。

  • Pandas: Work with large datasets.

    熊猫 :处理大型数据集。

  • Shutil, Glob, and OS: Access folders/files on your computer.

    Shutil , Glob和OS :访问计算机上的文件夹/文件。

  • Time: Forcing the program to pause for a period of time.

    时间 :强制程序暂停一段时间。

  • Get_All_Tickers: Filter through all stocks to get the list you desire.

    Get_All_Tickers :筛选所有股票以获得所需的列表。

  • Numpy: Work with arrays.

    numpy :使用数组。

  • Sklearn: To run our logistic regression model.

    Sklearn :运行我们的逻辑回归模型。

  • TA: To import the technical indicators.

    TA :要导入技术指标。

Necessary libraries.
必要的库。

收集历史库存数据 (Collecting Historical Stock Data)

Obtaining historical data on the stocks that we want to observe is a two-step process.

获取我们要观察的股票的历史数据是一个两步过程。

  • Narrow down a list of stocks that we want to observe.

    缩小我们要观察的股票清单。
  • Make individual calls to the Yfinance API in order to import data about each company.

    单独调用Yfinance API ,以导入有关每个公司的数据。

Choosing the Stocks We Want to Target

选择我们要定位的股票

The library get-all-tickers allows us to compile a list of stock tickers by filtering companies on aspects like market cap or exchange. For this example, I am looking at companies that have a market cap between $150,000 and $10,000,000 (in millions).

库全收录行情允许我们通过过滤公司的市值或交易所等方面来编制股票行情清单。 对于此示例,我正在研究市值在150,000美元到10,000,000美元(百万美元)之间的公司。

You will notice that I also included a line of code to print the number of tickers we are using. This is very important. You will need to be sure that you are not targeting more than 2,000 tickers, because the Yfinance API has a 2,000 API calls per hour limit.

您会注意到,我还提供了一行代码来打印我们正在使用的股票代号。 这个非常重要。 您需要确保定位的目标报价没有超过2,000个,因为Yfinance API每小时的API调用限制为2,000个。

We also need to remove and create a folder on our local machine to hold historical stock data. Note that before this step runs for the first time, you will need to manually create this folder. This step is important because it will get rid of the data from past iterations and allow the program to start new.

我们还需要在本地计算机上删除并创建一个文件夹来保存历史库存数据。 请注意,在首次运行此步骤之前,您将需要手动创建此文件夹。 此步骤很重要,因为它将清除过去迭代中的数据,并允许程序重新开始。

Initialize the tickers list and necessary folders.
初始化代码列表和必要的文件夹。

导入历史库存数据 (Importing Historical Stock Data)

We will now obtain the historical price data of each stock in our tickers list by making independent calls to Yahoo Finance. After receiving the data, the program will save each company’s information in a new CSV file that will be located in the folder you created beforehand.

现在,通过独立致电Yahoo Finance,我们将在报价清单中获取每只股票的历史价格数据。 收到数据后,程序会将每个公司的信息保存在一个新的CSV文件中,该文件位于您预先创建的文件夹中。

Code to collect and save the historical stock data of each observed stock.
编码以收集并保存每个观察到的库存的历史库存数据。

导入技术指标 (Importing Technical Indicators)

In order to run a logistic regression on each stock, we need to substantiate the independent variables. These 32+ technical indicators will act as predictor variables for the dependent variable.

为了对每种股票进行逻辑回归,我们需要证实自变量。 这32多个技术指标将用作因变量的预测变量。

To bring in the technical indicators we make use of the technical analysis library.

为了引入技术指标,我们利用技术分析库 。

You will also notice that we are creating three extra columns. These will act as the value we are trying to predict (dependent variable) with the model. The three variables are 5, 30, and 60 day observations of the closing prices of each stock (1 if it increased and 0 if it did not).

您还将注意到,我们将创建三个额外的列。 这些将充当我们试图用模型预测的值(因变量)。 三个变量是每只股票收盘价的5天,30天和60天观察值(如果增加,则为1,如果没有,则为0)。

Bring in the technical indicators for each stock.
引入每种股票的技术指标。

运行逻辑回归模型 (Run the Logistic Regression Model)

At this point, we have the historical data as well as over 32 technical indicators for each stock we chose to observe. We also created three different time-interval observations for which we want to predict the stock’s future price.

至此,我们已经有了历史数据以及我们选择观察的每种股票的32多项技术指标。 我们还创建了三个不同的时间间隔观察值,以用于预测股票的未来价格。

Now, all that is left is to clean the data (remove infinite and null values), run the logistic regression model, and interpret the results.

现在,剩下的就是清理数据(删除无限和空值),运行逻辑回归模型并解释结果。

For those who are less familiar with running statistical models, here is a quick breakdown of what the below code does:

对于那些不太熟悉运行统计模型的人,以下是以下代码的功能的快速细分:

  1. Creates a loop to go through each stock that we saved.

    创建一个循环以遍历我们保存的每只股票。
  2. Replaces infinite values with null and then replaces null values with 0.

    将无限值替换为null,然后将null值替换为0。
  3. Scales the data so that each variable is comparable.

    缩放数据,以便每个变量都是可比较的。
  4. Creates a loop to run the logistic regression three times for each stock (for 5, 30, and 60 day observations).

    创建一个循环以对每只股票运行Logistic回归3次(针对5天,30天和60天的观察值)。
  5. Saves the output to a CSV file so that we can interpret the results and find the best stocks to trade.

    将输出保存到CSV文件中,以便我们可以解释结果并找到最适合交易的股票。
Runs the logistic regression on each stock.
对每只股票运行逻辑回归。

解释结果 (Interpreting the Results)

We now have a CSV file with the results of the logistic regression model that we ran on each individual stock. Below is an example of this output (a small excerpt):

现在,我们有了一个CSV文件,其中包含对每只股票运行的逻辑回归模型的结果。 以下是此输出的示例(一小段摘录):

Image for post
Output in CSV format.
以CSV格式输出。

Here are some assumptions we can make from these results:

我们可以从这些结果中得出一些假设:

  • Which observation period is the best to use for each stock (i.e has the highest model accuracy).

    哪种观察期最适合每种股票使用(即模型精度最高)。
  • Which stocks are best predicted by their technical indicators.

    通过技术指标可以最好地预测哪些股票。
  • If the model is better at predicting increases in price or decreases.

    如果模型更适合预测价格上涨或下跌。

It is definitely possible to derive more from this code, for example, you could calculate sensitivity and specificity from the confusion matrices.

绝对有可能从此代码中获取更多信息,例如,您可以从混淆矩阵中计算出灵敏度和特异性。

To learn more about logistic regression in python, check out this article. To get my full code, download it from GitHub here.

要了解有关python中逻辑回归的更多信息,请查看本文 。 要获取我的完整代码,请从GitHub 此处下载。

If you’re interested in learning more stock analysis automation, machine learning, and artificial intelligence techniques, check out my new publication, Hands-Off Investing.

如果您想了解更多的股票分析自动化,机器学习和人工智能技术,请查阅我的新出版物《 动手投资》

Image for post
Hands-Off Investing放手投资

If you enjoyed this article, please give it a like and let me know what you thought. I would love to hear some feedback!

如果您喜欢这篇文章,请给我一个赞,让我知道您的想法。 我希望听到一些反馈!

Also, connect with me on LinkedIn here. I’m always happy to make some new connections!

另外,请在此处通过LinkedIn与我联系。 我总是很高兴结识一些新朋友!

** Disclaimer: The content of this article is not financial advice.

**免责声明:本文内容并非财务建议。

翻译自: https://medium.com/automated-trading/creating-an-algorithmic-trading-strategy-using-python-and-logistic-regression-3b93562d9493

导入数据库怎么导入

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

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

相关文章

windows查看系统版本号

windows查看系统版本号 winR,输入cmd,确定,打开命令窗口,输入msinfo32,注意要在英文状态下输入,回车。然后在弹出的窗口中就可以看到系统的具体版本号了。 winR,输入cmd,确定,打开命令窗口&…

02:Kubernetes集群部署——平台环境规划

1、官方提供的三种部署方式: minikube: Minikube是一个工具,可以在本地快速运行一个单点的Kubernetes,仅用于尝试Kubernetes或日常开发的用户使用。部署地址:https://kubernetes.io/docs/setup/minikube/kubeadm Kubea…

更便捷的画决策分支图的工具_做出更好决策的3个要素

更便捷的画决策分支图的工具Have you ever wondered:您是否曾经想过: How did Google dominate 92.1% of the search engine market share? Google如何占领搜索引擎92.1%的市场份额? How did Facebook achieve 74.1% of social media marke…

的界面跳转

在界面的跳转有两种方法,一种方法是先删除原来的界面,然后在插入新的界面:如下代码 if (self.rootViewController.view.superview nil) { [singleDollController.view removeFromSuperview]; [self.view insertSubview:rootViewControlle…

计算性能提升100倍,Uber推出机器学习可视化调试工具

为了让模型迭代过程更加可操作,并能够提供更多的信息,Uber 开发了一个用于机器学习性能诊断和模型调试的可视化工具——Manifold。机器学习在 Uber 平台上得到了广泛的应用,以支持智能决策制定和特征预测(如 ETA 预测 及 欺诈检测…

矩阵线性相关则矩阵行列式_搜索线性时间中的排序矩阵

矩阵线性相关则矩阵行列式声明 (Statement) We have to search for a value x in a sorted matrix M. If x exists, then return its coordinates (i, j), else return (-1, -1).我们必须在排序的矩阵M中搜索值x 。 如果x存在,则返回其坐标(i,j) &#x…

一地鸡毛 OR 绝地反击,2019年区块链发展指南

如果盘点2018年IT技术领域谁是“爆款流量”,那一定有个席位是属于区块链的,不仅经历了巨头、小白纷纷入场的光辉岁月,也经历了加密货币暴跌,争先退场的一地鸡毛。而当时间行进到2019年,区块链又将如何发展呢? 近日,全球知名创投研究机构CBInsight发布了《What’s Next …

iphone UITableView及UIWebView的使用

1。新建一个基于Navigation-based Application的工程。 2。修改原来的RootViewController.h,RootViewController.m,RootViewController.xib为MyTableViewController.h,MyTableViewController.m,MyTableViewController.xib。 3。点击MainVindow.xib,将R…

物联网数据可视化_激发好奇心:数据可视化如何增强博物馆体验

物联网数据可视化When I was living in Paris at the beginning of this year, I went to a minimum of three museums a week. While this luxury was made possible by the combination of an ICOM card and unemployment, it was founded on a passion for museums. Looking…

计算机公开课教学反思,语文公开课教学反思

语文公开课教学反思引导语: 在语文的公开课结束后,教师们在教学 有哪些需要反思的呢?接下来是yjbys小编为大家带来的关于语文公开课教学反思,希望会给大家带来帮助。篇一:语文公开课教学反思今天早上,我上了一节语文…

bigquery数据类型_将BigQuery与TB数据一起使用后的成本和性能课程

bigquery数据类型I’ve used BigQuery every day with small and big datasets querying tables, views, and materialized views. During this time I’ve learned some things, I would have liked to know since the beginning. The goal of this article is to give you so…

中国计算机学科建设,计算机学科建设战略研讨会暨“十四五”规划务虚会召开...

4月15日下午,信息学院计算机系举办了计算机科学与技术学科建设战略研讨会暨“十四五”规划务虚会。本次会议的主旨是借第五轮学科评估的契机,总结计算机学科发展的优劣势,在强调保持优势的同时,更着眼于短板和不足,在未…

服务器被攻击怎么修改,服务器一直被攻击怎么办?

原标题:服务器一直被攻击怎么办?有很多人问说,网站一直被攻击,什么被挂马,什么被黑,每天一早打开网站,总是会出现各种各样的问题,这着实让站长们揪心。从修改服务器管理账号开始&…

脚本 api_从脚本到预测API

脚本 apiThis is the continuation of my previous article:这是我上一篇文章的延续: From Jupyter Notebook To Scripts从Jupyter Notebook到脚本 Last time we discussed how to convert Jupyter Notebook to scripts, together with all sorts of basic engine…

Iphone代码创建视图

要想以编程的方式创建视图,需要使用视图控制器中定义的viewDidLoad方法,只有在运行期间生成UI时才需要实现该方法。 在此只贴出viewDidLoad方法的代码,因为只需要在这个方法里面编写代码: [cpp] view plaincopyprint?- (void)vi…

binary masks_Python中的Masks概念

binary masksAll men are sculptors, constantly chipping away the unwanted parts of their lives, trying to create their idea of a masterpiece … Eddie Murphy所有的人都是雕塑家,不断地消除生活中不必要的部分,试图建立自己的杰作理念……埃迪墨…

Iphone在ScrollView下点击TextField使文本筐不被键盘遮住

1.拖一个Scroll View视图填充View窗口&#xff0c;将Scroll View视图拖大一些&#xff0c;使其超出屏幕。 2.向Scroll View拖&#xff08;添加&#xff09;多个Label视图和Text View视图。 3.在.h头文件中添加如下代码&#xff1a; [cpp] view plaincopyprint?#import <U…

python 仪表盘_如何使用Python刮除仪表板

python 仪表盘Dashboard scraping is a useful skill to have when the only way to interact with the data you need is through a dashboard. We’re going to learn how to scrape data from a dashboard using the Selenium and Beautiful Soup packages in Python. The S…

VS2015 定时服务及控制端

一. 服务端 如下图—新建项目—经典桌面—Windows服务—起名svrr2. 打到server1 改名为svrExecSqlInsert 右击对应的设计界面&#xff0c;添加安装服务目录结构如图 3. svrExecSqlInsert里有打到OnStart()方法开始写代码如下 /// <summary>/// 服务开启操作/// </su…

Iphone表视图的简单操作

1.创建一个Navigation—based—Application项目&#xff0c;这样Interface Builder中会自动生成一个Table View&#xff0c;然后将Search Bar拖放到表示图上&#xff0c;以我们要给表示图添加搜索功能&#xff0c;不要忘记将Search Bar的delegate连接到File‘s Owner项&#xf…