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

导入数据库怎么导入

重点 (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…

供来宾访问计算机打开安全吗,计算机安全设置操作手册(22页)-原创力文档

计算机安全设置操作手册ISO27001项目实施电脑配置(以XP为例)账户设置user每台电脑设置administrator和user帐户;管理员账户密码至少 8位, 账户至少6位user将Administrator和user账户以外的其他账户禁用用具体步骤如下:、右击【我的电脑】选择【管理】如图…

Windows半透明窗口开发技巧

Windows半透明窗口开发技巧 www.visual-gear.com 原创技术文章 在windows平台上从窗口绘图有两种方法: 第一种响应窗口的WM_PAINT消息,使用窗口DC进行绘制 第二种是将窗口样式设置为层窗口,即 WS_EX_LAYERED设置为该样式之后窗口将不会产生任…

标识为普通SQL语法

在SQL语句的最前面增加 /*dialect*/转载于:https://www.cnblogs.com/zouhuaxin/p/10333209.html

的界面跳转

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

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

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

计算机应用基础成教作业,(计算机应用基础成教08A卷1.doc

一、判断题(每空1分,共10分,正确填A错误填B)1、计算机按照用途划分可以分为数字计算机、模拟计算机、数字模拟混合式计算机。()2、微型计算机就是指体积微小的计算机。()3、WindowsXP的窗口是不可改变大小的。( )4、操作系统是用户和计算机之间的接口。…

iPhone程序运行流程浅谈

1. 和大多数语言一样,每一个iPhone应用也都是从主函数开始运行,它的main函数都在XCode的Other Reasource逻辑目录下。 [cpp] view plaincopyprint?UIApplicationMain(argc, argv, nil, nil); [cpp] view plaincopyprint?UIApplicationMain(argc, arg…

Trie树kmpAC自动机后缀数组Manacher

Trie 计数Trie,读清题意很重要 https://vjudge.net/problem/UVALive-5913 kmp AC自动机 模板:https://vjudge.net/problem/UVA-11488 https://vjudge.net/problem/UVA-11019 https://vjudge.net/problem/UVA-11468 https://vjudge.net/problem/UVALive-4…

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

矩阵线性相关则矩阵行列式声明 (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…

计算机英文版个人简历发文,计算机个人简历英文_英文简历.doc

计算机个人简历英文_英文简历I have the honor to present a brief introduction of myself to you in compliance with the requirements of your graduate admissionI was born in November 7th, 1966, at the town of Changing, Beijing. My parents are doing business and…

一地鸡毛 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…

python 的datetime模块使用

1.datetime模块主要是5个类 date #日期类 年月日 datetime.date(year,month,day) time #时间类 时分秒 datetime.time(hour,minute,second,microsecond,tzoninfo),返回18:29:30 datetime #日期时间类 datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinf…

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

物联网数据可视化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小编为大家带来的关于语文公开课教学反思,希望会给大家带来帮助。篇一:语文公开课教学反思今天早上,我上了一节语文…

中国连续十年成马来西亚最大贸易伙伴

中新社吉隆坡1月30日电 (记者 陈悦)马来西亚国际贸易和工业部30日发布的2018年马来西亚贸易报告显示,2018年马来西亚与中国的贸易额约为3138.1亿林吉特(马来西亚货币,约合774亿美元),较上年同期增长8.1%,约占马来西亚对外贸易总额…

Iphone NSMutableArray,NSMutableDictionary AND 动态添加按钮

一.NSMutableDictionary NSMutableDictionary * tags; 1.NSMutableDictionary 添加内容: [tags setValue:xxx forKey :xxx]; 2.NSMutableDictionary 遍历: for(NSString * title in tags){ //其中得到的title是key } 3.NSMutableD…