導入數據庫怎么導入_導入必要的庫

導入數據庫怎么導入

重點 (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.pswp.cn/news/388382.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388382.shtml
英文地址,請注明出處:http://en.pswp.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…