快速排序简便记_建立和测试股票交易策略的快速简便方法
快速排序簡(jiǎn)便記
Note from Towards Data Science’s editors: While we allow independent authors to publish articles in accordance with our rules and guidelines, we do not endorse each author’s contribution. You should not rely on an author’s works without seeking professional advice. See our Reader Terms for details.
Towards Data Science編輯的注意事項(xiàng): 盡管我們?cè)试S獨(dú)立作者按照我們的 規(guī)則和指南 發(fā)表文章 ,但我們不認(rèn)可每位作者的貢獻(xiàn)。 您不應(yīng)在未征求專業(yè)意見的情況下依賴作者的作品。 有關(guān) 詳細(xì)信息, 請(qǐng)參見我們的 閱讀器條款 。
算法交易策略開發(fā) (Algorithmic Trading Strategy Development)
Backtesting is the hallmark of quantitative trading. Backtesting takes historical or synthetic market data and tests the profitability of algorithmic trading strategies. This topic demands expertise in statistics, computer science, mathematics, finance, and economics. This is exactly why in large quantitative trading firms there are specific roles for individuals with immense knowledge (usually at the doctorate level) of the respective subjects. The necessity for expertise cannot be understated as it separates winning (or seemingly winning) trading strategies from losers. My goal for this article is to break up what I consider an elementary backtesting process into a few different sections…
回測(cè)是定量交易的標(biāo)志。 回測(cè)采用歷史或合成市場(chǎng)數(shù)據(jù),并測(cè)試算法交易策略的盈利能力。 本主題需要統(tǒng)計(jì),計(jì)算機(jī)科學(xué),數(shù)學(xué),金融和經(jīng)濟(jì)學(xué)方面的專業(yè)知識(shí)。 這就是為什么在大型定量交易公司中,對(duì)于具有相應(yīng)學(xué)科的豐富知識(shí)(通常是博士學(xué)位)的個(gè)人,要發(fā)揮特定的作用。 專業(yè)知識(shí)的必要性不可低估,因?yàn)樗鼘⒊晒?或看似成功)的交易策略與失敗者分開。 本文的目的是將我認(rèn)為是基本的回測(cè)過程分為幾個(gè)不同的部分……
I. The Backtesting Engine
I.回測(cè)引擎
II. Historical and Synthetic Data Management
二。 歷史和綜合數(shù)據(jù)管理
III. Backtesting Metrics
三, 回測(cè)指標(biāo)
IV. Live Implementation
IV。 現(xiàn)場(chǎng)實(shí)施
V. Pitfalls in Strategy Development
五 ,戰(zhàn)略發(fā)展中的陷阱
回測(cè)引擎 (The Backtesting Engine)
The main backtesting engine will be built in Python using a library called backtrader. Backtrader makes it incredibly easy to build trading strategies and implement them on historical data immediately. The entire library centers around the Cerebro class. As the name implies, you can think of this as the brain or engine of the backtest.
主要的回測(cè)引擎將使用稱為backtrader的庫在Python中構(gòu)建 。 Backtrader使得建立交易策略并立即在歷史數(shù)據(jù)上實(shí)施交易變得異常容易。 整個(gè)圖書館圍繞著Cerebro類。 顧名思義,您可以將其視為回測(cè)的大腦或引擎。
import backtrader as btdef backtesting_engine(symbol, strategy, fromdate, todate, args=None):"""Primary function for backtesting, not entirely parameterized"""# Backtesting Enginecerebro = bt.Cerebro()I decided to build a function so I can parameterize different aspects of the backtest on the fly (and eventually build a pipeline). The next backtrader class we need to discuss is the Strategy class. If you look at the function I built to house the instance of Cerebro you’ll see that it takes a strategy as an input — this is expecting a backtrader Strategy class or subclass. Subclasses of the Strategy class are exactly what we will be using to build our own strategies. If you need a polymorphism & inheritance refresher or don’t know what that means see my article 3 Python Concepts in under 3 minutes. Let’s build a strategy for our backtest…
我決定構(gòu)建一個(gè)函數(shù),以便可以動(dòng)態(tài)地對(duì)回測(cè)的不同方面進(jìn)行參數(shù)化(并最終構(gòu)建管道)。 我們需要討論的下一個(gè)回購者類是策略類。 如果您查看我為容納Cerebro實(shí)例而構(gòu)建的功能,您會(huì)看到它以策略作為輸入-這是期待的回購商Strategy類或子類。 策略類的子類正是我們用來構(gòu)建自己的策略的類。 如果您需要多態(tài)和繼承復(fù)習(xí)器,或者不知道這意味著什么,請(qǐng)?jiān)?分鐘之內(nèi)閱讀我的文章3 Python概念 。 讓我們?yōu)榛販y(cè)制定策略...
from models.isolation_model import IsolationModel import backtrader as bt import pandas as pd import numpy as npclass MainStrategy(bt.Strategy):'''Explanation:MainStrategy houses the actions to take as a stream of data flows in a linear fashion with respect to time'''def log(self, txt, dt=None):''' Logging function fot this strategy'''dt = dt or self.datas[0].datetime.date(0)print('%s, %s' % (dt.isoformat(), txt))def __init__(self, data):# Keep a reference to the "close" line in the data[0] dataseriesself.dataopen = self.datas[0].openself.datahigh = self.datas[0].highself.datalow = self.datas[0].lowself.dataclose = self.datas[0].closeself.datavolume = self.datas[0].volumeIn the MainStrategy, Strategy subclass above I create fields that we are interested in knowing about before making a trading decision. Assuming a daily data frequency the fields we have access to every step in time during the backstep are…
在上面的MainStrategy,Strategy子類中,我創(chuàng)建了我們感興趣的字段,這些字段是我們?cè)谧龀鼋灰讻Q策之前要了解的。 假設(shè)每天的數(shù)據(jù)頻率,在后退步驟中我們可以訪問的每個(gè)時(shí)間段的字段是……
- Day price open 當(dāng)日價(jià)格開盤
- Day price close 當(dāng)天收盤價(jià)
- Day price low 當(dāng)日價(jià)格低
- Day price high 當(dāng)天價(jià)格高
- Day volume 日成交量
It doesn’t take a genius to understand that you cannot use the high, low, and close to make an initial or intraday trading decision as we don’t have access to that information in realtime. However, it is useful if you want to store it and access that information from previous days.
理解您不能使用高,低和接近來做出初始或盤中交易決策并不需要天才,因?yàn)槲覀儫o法實(shí)時(shí)訪問該信息。 但是,如果您要存儲(chǔ)它并訪問前幾天的信息,這將很有用。
The big question in your head right now should be where is the data coming from?
您現(xiàn)在腦海中最大的問題應(yīng)該是數(shù)據(jù)來自哪里?
The answer to that question is in the structure of the backtrader library. Before we run the function housing Cerebro we will add all the strategies we want to backtest, and a data feed — the rest is all taken care of as the Strategy superclass holds the datas series housing all the market data.
該問題的答案在于backtrader庫的結(jié)構(gòu)。 在運(yùn)行帶有Cerebro的功能之前,我們將添加我們要回測(cè)的所有策略以及一個(gè)數(shù)據(jù)提要-其余所有工作都將得到處理,因?yàn)镾trategy超類擁有容納所有市場(chǎng)數(shù)據(jù)的數(shù)據(jù)系列。
This makes our lives extremely easy.
這使我們的生活變得極為輕松。
Let’s finish the MainStrategy class by making a simple long-only mean reversion style trading strategy. To access a tick of data we override the next function and add trading logic…
讓我們通過制定一個(gè)簡(jiǎn)單的長(zhǎng)期均值回歸樣式交易策略來結(jié)束MainStrategy類。 要訪問數(shù)據(jù)變動(dòng),我們將覆蓋下一個(gè)功能并添加交易邏輯…
from models.isolation_model import IsolationModel import backtrader as bt import pandas as pd import numpy as npclass MainStrategy(bt.Strategy):'''Explanation:MainStrategy houses the actions to take as a stream of data flows in a linear fashion with respect to time '''def log(self, txt, dt=None):''' Logging function fot this strategy'''dt = dt or self.datas[0].datetime.date(0)print('%s, %s' % (dt.isoformat(), txt))def __init__(self):self.dataclose = self.datas[0].closeself.mean = bt.indicators.SMA(period=20)self.std = bt.indicators.StandardDeviation()self.orderPosition = 0self.z_score = 0def next(self):self.log(self.dataclose[0])z_score = (self.dataclose[0] - self.mean[0])/self.std[0]if (z_score >= 2) & (self.orderPosition > 0):self.sell(size=1)if z_score <= -2:self.log('BUY CREATE, %.2f' % self.dataclose[0])self.buy(size=1)self.orderPosition += 1Every day gets a z-score calculated for it (number of standard deviations from the mean) based on its magnitude we will buy or sell equity. Please note, yes I am using the day’s close to make the decision, but I’m also using the day’s close as an entry price to my trade — it would be wiser to use the next days open.
每天都會(huì)根據(jù)其大小來計(jì)算z得分(相對(duì)于平均值的標(biāo)準(zhǔn)偏差的數(shù)量),我們將買賣股票。 請(qǐng)注意,是的,我使用當(dāng)天的收盤價(jià)來做決定,但是我也將當(dāng)天的收盤價(jià)用作我交易的入場(chǎng)價(jià)-使用第二天的開盤價(jià)會(huì)更明智。
The next step is to add the strategy to our function housing the Cerebro instance…
下一步是將策略添加到容納Cerebro實(shí)例的功能中…
import backtrader as bt import pyfolio as pfdef backtesting_engine(symbol, strategy, fromdate, todate, args=None):"""Primary function for backtesting, not entirely parameterized"""# Backtesting Enginecerebro = bt.Cerebro()# Add a Strategy if no Data Required for the modelif args is None:cerebro.addstrategy(strategy)# If the Strategy requires a Model and therefore dataelif args is not None:cerebro.addstrategy(strategy, args)In the code above I add the strategy provided to the function to the Cerebro instance. This is beyond the scope of the article but I felt pressed to include it. If the strategy that we are backtesting requires additional data (some AI model) we can provide it in the args parameter and add it to the Strategy subclass.
在上面的代碼中,我將為函數(shù)提供的策略添加到Cerebro實(shí)例。 這超出了本文的范圍,但是我迫切希望將其包括在內(nèi)。 如果要回測(cè)的策略需要其他數(shù)據(jù)(某些AI模型),則可以在args參數(shù)中提供它,并將其添加到Strategy子類中。
Next, we need to find a source of historical or synthetic data.
接下來,我們需要找到歷史或綜合數(shù)據(jù)的來源。
歷史和綜合數(shù)據(jù)管理 (Historical and Synthetic Data Management)
I use historical and synthetic market data synonymously as some researchers have found synthetic data indistinguishable (and therefore is more abundant as its generative) from other market data. For the purposes of this example we will be using the YahooFinance data feed provided by backtrader, again making implementation incredibly easy…
我將歷史和綜合市場(chǎng)數(shù)據(jù)作為同義詞使用,因?yàn)橐恍┭芯咳藛T發(fā)現(xiàn)綜合數(shù)據(jù)與其他市場(chǎng)數(shù)據(jù)是無法區(qū)分的(因此,其生成量更大)。 出于本示例的目的,我們將使用backtrader提供的YahooFinance數(shù)據(jù)供稿,再次使實(shí)現(xiàn)變得異常容易。
import backtrader as bt import pyfolio as pfdef backtesting_engine(symbol, strategy, fromdate, todate, args=None):"""Primary function for backtesting, not entirely parameterized"""# Backtesting Enginecerebro = bt.Cerebro()# Add a Strategy if no Data Required for the modelif args is None:cerebro.addstrategy(strategy)# If the Strategy requires a Model and therefore dataelif args is not None:cerebro.addstrategy(strategy, args)# Retrieve Data from YahooFinancedata = bt.feeds.YahooFinanceData(dataname=symbol,fromdate=fromdate, # datetime.date(2015, 1, 1)todate=todate, # datetime.datetime(2016, 1, 1)reverse=False)# Add Data to Backtesting Enginecerebro.adddata(data)It’s almost ridiculous how easy it is to add a data feed to our backtest. The data object uses backtraders YahooFinanceData class to retrieve data based on the symbol, fromdate, and todate. Afterwards, we simply add that data to the Cerebro instance. The true beauty in backtrader’s architecture comes in realizing that the data is automatically placed within, and iterated through every strategy added to the Cerebro instance.
將數(shù)據(jù)提要添加到我們的回測(cè)中是多么容易,這簡(jiǎn)直太荒謬了。 數(shù)據(jù)對(duì)象使用backtraders YahooFinanceData類根據(jù)符號(hào),起始日期和起始日期檢索數(shù)據(jù)。 然后,我們只需將該數(shù)據(jù)添加到Cerebro實(shí)例中即可。 backtrader架構(gòu)的真正美在于實(shí)現(xiàn)將數(shù)據(jù)自動(dòng)放入其中,并通過添加到Cerebro實(shí)例的每種策略進(jìn)行迭代。
回測(cè)指標(biāo) (Backtesting Metrics)
There are a variety of metrics used to evaluate the performance of a trading strategy, we’ll cover a few in this section. Again, backtrader makes it extremely easy to add analyzers or performance metrics. First, let’s set an initial cash value for our Cerebro instance…
有多種指標(biāo)可用于評(píng)估交易策略的績(jī)效,本節(jié)將介紹其中的一些指標(biāo)。 同樣,backtrader使添加分析器或性能指標(biāo)變得非常容易。 首先,讓我們?yōu)镃erebro實(shí)例設(shè)置初始現(xiàn)金價(jià)值...
import backtrader as bt import pyfolio as pfdef backtesting_engine(symbol, strategy, fromdate, todate, args=None):"""Primary function for backtesting, not entirely parameterized"""# Backtesting Enginecerebro = bt.Cerebro()# Add a Strategy if no Data Required for the modelif args is None:cerebro.addstrategy(strategy)# If the Strategy requires a Model and therefore dataelif args is not None:cerebro.addstrategy(strategy, args)# Retrieve Data from YahooFinancedata = bt.feeds.YahooFinanceData(dataname=symbol,fromdate=fromdate, # datetime.date(2015, 1, 1)todate=todate, # datetime.datetime(2016, 1, 1)reverse=False)# Add Data to Backtesting Enginecerebro.adddata(data)# Set Initial Portfolio Valuecerebro.broker.setcash(100000.0)There are a variety of metrics we can use to evaluate risk, return, and performance — let’s look at a few of them…
我們可以使用多種指標(biāo)來評(píng)估風(fēng)險(xiǎn),回報(bào)和績(jī)效-讓我們看看其中的一些…
夏普比率 (Sharpe Ratio)
As referenced in the show Billions, the amount of return per unit of risk, the Sharpe Ratio. Defined as follows…
如顯示的“十億”所示,單位風(fēng)險(xiǎn)的收益金額即夏普比率。 定義如下...
Several downfalls, and assumptions. It’s based on historical performance, assumes normal distributions, and can often be used to incorrectly compare portfolios. However, it’s still a staple to any strategy or portfolio.
幾次失敗和假設(shè)。 它基于歷史表現(xiàn),假定為正態(tài)分布,并且經(jīng)常被用來錯(cuò)誤地比較投資組合。 但是,它仍然是任何策略或投資組合的主要內(nèi)容。
System Quality Number
系統(tǒng)質(zhì)量編號(hào)
An interesting metric I’ve always enjoyed using as it includes volume of transactions in a given period. Computed by multiplying the SQN by the number of trades and dividing the product by 100. Below is a chart of values across different segments, regions, and sectors.
我一直喜歡使用的有趣指標(biāo),因?yàn)樗o定時(shí)間段內(nèi)的交易量。 通過將SQN乘以交易數(shù)量并將乘積除以100進(jìn)行計(jì)算。以下是不同細(xì)分市場(chǎng),區(qū)域和部門的價(jià)值圖表。
VanTharpVanTharp攝Let’s now add these metrics to Cerebro and run the backtest…
現(xiàn)在讓我們將這些指標(biāo)添加到Cerebro并進(jìn)行回測(cè)...
import backtrader as bt import pyfolio as pfdef backtesting_engine(symbol, strategy, fromdate, todate, args=None):"""Primary function for backtesting, not entirely parameterized"""# Backtesting Enginecerebro = bt.Cerebro()# Add a Strategy if no Data Required for the modelif args is None:cerebro.addstrategy(strategy)# If the Strategy requires a Model and therefore dataelif args is not None:cerebro.addstrategy(strategy, args)# Retrieve Data from Alpacadata = bt.feeds.YahooFinanceData(dataname=symbol,fromdate=fromdate, # datetime.date(2015, 1, 1)todate=todate, # datetime.datetime(2016, 1, 1)reverse=False)# Add Data to Backtesting Enginecerebro.adddata(data)# Set Initial Portfolio Valuecerebro.broker.setcash(100000.0)# Add Analysis Toolscerebro.addanalyzer(bt.analyzers.SharpeRatio, _name='sharpe')# Of course we want returns too ;Pcerebro.addanalyzer(bt.analyzers.Returns, _name='returns')cerebro.addanalyzer(bt.analyzers.SQN, _name='sqn')# Starting Portfolio Valueprint('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())# Run the Backtesting Enginebacktest = cerebro.run()# Print Analysis and Final Portfolio Valueprint('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())print('Return: ', backtest[0].analyzers.returns.get_analysis())print('Sharpe Ratio: ', backtest[0].analyzers.sharpe.get_analysis())print('System Quality Number: ', backtest[0].analyzers.sqn.get_analysis())Now, all we have to do is run the code above and we get the performance of our strategy based on the metrics we specified…
現(xiàn)在,我們要做的就是運(yùn)行上面的代碼,并根據(jù)指定的指標(biāo)獲得策略的性能……
from datetime import datetime from strategies.reversion_strategy import LongOnlyReversion from tools.backtesting_tools import backtesting_engine"""Script for backtesting strategies """if __name__ == '__main__':# Run backtesting enginebacktesting_engine(symbol='AAPL', strategy=LongOnlyReversion,fromdate=datetime(2018, 1, 1), todate=datetime(2019, 1, 1))Here is the output…
這是輸出...
Starting Portfolio Value: 100000.002018-01-30, 160.952018-01-30, BUY CREATE, 160.952018-01-31, 161.4
2018-02-01, 161.74
2018-02-02, 154.72
2018-02-02, BUY CREATE, 154.72
2018-02-05, 150.85
2018-02-05, BUY CREATE, 150.85
2018-02-06, 157.16
2018-02-07, 153.792018-02-08, 149.56
2018-02-09, 151.39
2018-02-12, 157.49
2018-02-13, 159.07
2018-02-14, 162.0
2018-02-15, 167.44
2018-02-16, 166.9
2018-02-20, 166.332018-02-21, 165.58
2018-02-22, 166.96
2018-02-23, 169.87
2018-02-26, 173.23
2018-02-27, 172.66
2018-02-28, 172.42018-03-01, 169.38
2018-03-02, 170.55
2018-03-05, 171.15
2018-03-06, 171.0
2018-03-07, 169.41
2018-03-08, 171.26
2018-03-09, 174.2
2018-03-12, 175.89
2018-03-13, 174.19
2018-03-14, 172.71
2018-03-15, 172.92
2018-03-16, 172.31
2018-03-19, 169.67
2018-03-20, 169.62
2018-03-21, 165.77
2018-03-21, BUY CREATE, 165.77
2018-03-22, 163.43
2018-03-22, BUY CREATE, 163.43
2018-03-23, 159.65
2018-03-23, BUY CREATE, 159.652018-03-26, 167.22
2018-03-27, 162.94
2018-03-28, 161.14
2018-03-29, 162.4
2018-04-02, 161.33
2018-04-03, 162.99
2018-04-04, 166.1
2018-04-05, 167.252018-04-06, 162.98
2018-04-09, 164.59
2018-04-10, 167.69
2018-04-11, 166.91
2018-04-12, 168.55
2018-04-13, 169.12
2018-04-16, 170.18
2018-04-17, 172.522018-04-18, 172.13
2018-04-19, 167.25
2018-04-20, 160.4
2018-04-23, 159.94
2018-04-24, 157.71
2018-04-25, 158.4
2018-04-26, 158.952018-04-27, 157.11
2018-04-30, 159.96
2018-05-01, 163.67
2018-05-02, 170.9
2018-05-03, 171.212018-05-04, 177.93
2018-05-07, 179.22
2018-05-08, 180.08
2018-05-09, 181.352018-05-10, 183.94
2018-05-11, 183.24
2018-05-14, 182.81
2018-05-15, 181.15
2018-05-16, 182.842018-05-17, 181.69
2018-05-18, 181.03
2018-05-21, 182.31
2018-05-22, 181.85
2018-05-23, 183.02
2018-05-24, 182.812018-05-25, 183.23
2018-05-29, 182.57
2018-05-30, 182.18
2018-05-31, 181.57
2018-06-01, 184.84
2018-06-04, 186.392018-06-05, 187.83
2018-06-06, 188.482018-06-07, 187.97
2018-06-08, 186.26
2018-06-11, 185.812018-06-12, 186.83
2018-06-13, 185.29
2018-06-14, 185.39
2018-06-15, 183.48
2018-06-18, 183.392018-06-19, 180.42
2018-06-20, 181.21
2018-06-21, 180.2
2018-06-22, 179.68
2018-06-25, 177.0
2018-06-25, BUY CREATE, 177.002018-06-26, 179.2
2018-06-27, 178.94
2018-06-28, 180.24
2018-06-29, 179.862018-07-02, 181.87
2018-07-03, 178.7
2018-07-05, 180.14
2018-07-06, 182.64
2018-07-09, 185.172018-07-10, 184.95
2018-07-11, 182.55
2018-07-12, 185.61
2018-07-13, 185.9
2018-07-16, 185.5
2018-07-17, 186.022018-07-18, 185.0
2018-07-19, 186.44
2018-07-20, 186.01
2018-07-23, 186.18
2018-07-24, 187.53
2018-07-25, 189.292018-07-26, 188.7
2018-07-27, 185.56
2018-07-30, 184.52
2018-07-31, 184.89
2018-08-01, 195.78
2018-08-02, 201.51
2018-08-03, 202.09
2018-08-06, 203.14
2018-08-07, 201.24
2018-08-08, 201.37
2018-08-09, 202.96
2018-08-10, 202.35
2018-08-13, 203.66
2018-08-14, 204.52
2018-08-15, 204.99
2018-08-16, 208.0
2018-08-17, 212.15
2018-08-20, 210.08
2018-08-21, 209.67
2018-08-22, 209.682018-08-23, 210.11
2018-08-24, 210.77
2018-08-27, 212.5
2018-08-28, 214.22
2018-08-29, 217.42
2018-08-30, 219.41
2018-08-31, 221.952018-09-04, 222.66
2018-09-05, 221.21
2018-09-06, 217.53
2018-09-07, 215.78
2018-09-10, 212.882018-09-11, 218.26
2018-09-12, 215.55
2018-09-13, 220.76
2018-09-14, 218.25
2018-09-17, 212.44
2018-09-18, 212.79
2018-09-19, 212.92
2018-09-20, 214.542018-09-21, 212.23
2018-09-24, 215.28
2018-09-25, 216.65
2018-09-26, 214.92
2018-09-27, 219.34
2018-09-28, 220.112018-10-01, 221.59
2018-10-02, 223.56
2018-10-03, 226.282018-10-04, 222.3
2018-10-05, 218.69
2018-10-08, 218.19
2018-10-09, 221.212018-10-10, 210.96
2018-10-11, 209.1
2018-10-12, 216.57
2018-10-15, 211.94
2018-10-16, 216.612018-10-17, 215.67
2018-10-18, 210.63
2018-10-19, 213.84
2018-10-22, 215.14
2018-10-23, 217.172018-10-24, 209.72
2018-10-25, 214.31
2018-10-26, 210.9
2018-10-29, 206.94
2018-10-30, 207.98
2018-10-31, 213.42018-11-01, 216.67
2018-11-02, 202.3
2018-11-02, BUY CREATE, 202.30
2018-11-05, 196.56
2018-11-05, BUY CREATE, 196.562018-11-06, 198.68
2018-11-06, BUY CREATE, 198.68
2018-11-07, 204.71
2018-11-08, 204.02018-11-09, 200.06
2018-11-12, 189.99
2018-11-12, BUY CREATE, 189.99
2018-11-13, 188.09
2018-11-13, BUY CREATE, 188.092018-11-14, 182.77
2018-11-14, BUY CREATE, 182.77
2018-11-15, 187.28
2018-11-16, 189.362018-11-19, 181.85
2018-11-20, 173.17
2018-11-20, BUY CREATE, 173.17
2018-11-21, 172.972018-11-23, 168.58
2018-11-26, 170.86
2018-11-27, 170.48
2018-11-28, 177.042018-11-29, 175.68
2018-11-30, 174.73
2018-12-03, 180.84
2018-12-04, 172.88
2018-12-06, 170.952018-12-07, 164.86
2018-12-10, 165.94
2018-12-11, 165.0
2018-12-12, 165.46
2018-12-13, 167.27
2018-12-14, 161.91
2018-12-17, 160.41
2018-12-18, 162.49
2018-12-19, 157.42
2018-12-20, 153.45
2018-12-20, BUY CREATE, 153.45
2018-12-21, 147.48
2018-12-21, BUY CREATE, 147.48
2018-12-24, 143.67
2018-12-24, BUY CREATE, 143.67
2018-12-26, 153.78
2018-12-27, 152.78
2018-12-28, 152.86
2018-12-31, 154.34
Final Portfolio Value: 100381.48
Return: OrderedDict([('rtot', 0.0038075421029081335), ('ravg', 1.5169490449833201e-05), ('rnorm', 0.003830027474518453), ('rnorm100', 0.3830027474518453)])
Sharpe Ratio: OrderedDict([('sharperatio', None)])
System Quality Number: AutoOrderedDict([('sqn', 345.9089929588268), ('trades', 2)])
現(xiàn)場(chǎng)實(shí)施 (Live Implementation)
This is less of a section more of a collection of resources that I have for implementing trading strategies. If you want to move forward and implement your strategy in a live market check out these articles…
這不是本節(jié)的更多內(nèi)容,更多的是我用于實(shí)施交易策略的資源集合。 如果您想繼續(xù)前進(jìn)并在實(shí)時(shí)市場(chǎng)中實(shí)施策略,請(qǐng)查看以下文章…
Algorithmic Trading with Python
使用Python進(jìn)行算法交易
Build an AI Stock Trading Bot for Free
免費(fèi)建立AI股票交易機(jī)器人
Algorithmic Trading System Development
算法交易系統(tǒng)開發(fā)
Multithreading in Python for Finance
Python for Finance中的多線程
How to Build a Profitable Stock Trading Bot
如何建立一個(gè)有利可圖的股票交易機(jī)器人
Build a Neural Network to Manage a Stock Portfolio
建立一個(gè)神經(jīng)網(wǎng)絡(luò)來管理股票投資組合
算法交易策略的陷阱 (Algorithmic Trading Strategy Pitfalls)
Not understanding the drivers of profitability in a strategy: There are some that believe, regardless of the financial or economic drivers, if you can get enough data and stir it up in such a way that you can develop a profitable trading strategy. I did too when I was younger, newer to the algorithmic trading, and more naive. The truth is if you can’t understand the nature of your own trading algorithmic it will never be profitable.
不了解策略中獲利能力的驅(qū)動(dòng)因素:有人認(rèn)為,無論財(cái)務(wù)或經(jīng)濟(jì)驅(qū)動(dòng)因素如何,如果您能夠獲取足夠的數(shù)據(jù)并以一種可以制定有利可圖的交易策略的方式進(jìn)行攪動(dòng),便會(huì)認(rèn)為這是可行的。 當(dāng)我還年輕,算法交易較新且天真時(shí),我也這樣做了。 事實(shí)是,如果您不了解自己的交易算法的性質(zhì),它將永遠(yuǎn)不會(huì)盈利。
Not understanding how to split historical or synthetic data to both search for and optimize strategies: This one is big and the consequences are dire. I had a colleague back in college tell me he developed a system with a 300% return trading energy. Naturally, and immediately, I knew he completely overfitted a model to historical data and never actually implemented it in live data. Asking a simple question about his optimization process confirmed my suspicion.
不了解如何拆分歷史數(shù)據(jù)或合成數(shù)據(jù)以同時(shí)搜索和優(yōu)化策略 :這一步很大,后果非常嚴(yán)重。 我上大學(xué)時(shí)曾有一位同事告訴我,他開發(fā)了一種具有300%的收益交易能量的系統(tǒng)。 自然而又立即地,我知道他完全將模型擬合到歷史數(shù)據(jù)中,而從未真正在實(shí)時(shí)數(shù)據(jù)中實(shí)現(xiàn)它。 問一個(gè)關(guān)于他的優(yōu)化過程的簡(jiǎn)單問題證實(shí)了我的懷疑。
Not willing to accept down days: This one is interesting, and seems to have a greater effect on newer traders more than experienced ones. The veterans know there will be down days, losses, but the overarching goal is to have (significantly) more wins than losses. This issue generally arises in deployment — assuming that the other processes
不愿接受低迷的日子:這很有趣,而且似乎對(duì)新手的影響要大于經(jīng)驗(yàn)豐富的人。 退伍軍人知道會(huì)有損失的日子,但是總的目標(biāo)是勝利(多于失敗)。 通常在部署過程中會(huì)出現(xiàn)此問題-假設(shè)其他過程
Not willing to retire a formerly profitable system: Loss control, please understand risk-management and loss control. Your system was successful, and that’s fantastic — that means you understand the design process and can do it again. Don’t get caught up in how well it did look at how well it’s doing. This has overlap with understanding the drivers of profitability in your strategy — you will know when and why it’s time to retire a system if you understand why it’s no longer profitable.
不愿意淘汰以前有利可圖的系統(tǒng):損失控制,請(qǐng)了解風(fēng)險(xiǎn)管理和損失控制。 您的系統(tǒng)成功了,這太棒了-這意味著您了解設(shè)計(jì)過程并可以再次執(zhí)行。 不要被它的表現(xiàn)看得如何。 這與了解戰(zhàn)略中獲利的驅(qū)動(dòng)因素有很多重疊-如果您了解為什么不再有利潤(rùn),您將知道何時(shí)以及為何該退休系統(tǒng)。
翻譯自: https://towardsdatascience.com/a-quick-and-easy-way-to-build-and-test-stock-trading-strategies-bce2b58e6ffe
快速排序簡(jiǎn)便記
總結(jié)
以上是生活随笔為你收集整理的快速排序简便记_建立和测试股票交易策略的快速简便方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到桌子坏了有什么预兆
- 下一篇: 美剧迷失_迷失(机器)翻译