+ Analyzing a company’s fundamentals is a method of trading that doesn’t
+ rely purely on price and volume data. We will apply the use of computers to automate
+ the analysis of this data, and we will do so using a method of
+ Factor Investing,
+ the process of using different attributes, in this case, fundamental data, to choose
+ stocks to purchase. More specifically, we will use G-Score investing, and evaluate companies
+ on seven factors that we will detail later. We specifically choose companies with Book-to-Market
+ due to abnormal returns as a result of the Risk Premium Effect.
+
+ We first sort all companies that have fundamental data by their Book-to-Market ratio, and narrow our universe to the
+ bottom quartile. We measure the Book-to-Market ratio using
+ fine.FinancialStatements.BalanceSheet.NetTangibleAssets.TwelveMonths divided by
+ fine.MarketCap. In this strategy, we will use Technology as the industry of choice, thus, we further
+ narrow this universe to Technology stocks only.
+
+
+
+ For each of the conditions that are described below, if met, one point will be added to the G-Score.
+ Thus, with seven factors, our G-Score can range from 0 to 7. We evaluate a company based on the following:
+
+
+
+
+
+ The Return on Assets (ROA) is greater than the contemporaneous industry median. In other words, the ROA for
+ the analyzed company is greater than the median of the ROAs of all companies in the same industry
+ We measure this value using fine.OperationRatios.ROA.OneYear
+
+
+ The Cash Flow Return on Assets (CFROA) is greater than the contemporaneous industry median
+ We measure this value using fine.FinancialStatements.CashFlowStatement.OperatingCashFlow.TwelveMonths
+ divided by fine.FinancialStatements.BalanceSheet.TotalAssets.TwelveMonths
+
+
+ The CFROA is greater than the ROA
+
+
+ The Variance of the ROA (VARROA) is lower than the contemporaneous industry median
+ We measure this by storing the past twelve values of fine.OperationRatios.ROA.ThreeMonths in a
+ RollingWindow and computing the variance of the values in the RollingWindow
+
+
+ The Research and Development Expenditure (R&D) is higher than the contemporaneous industry median
+ We measure this using fine.FinancialStatements.IncomeStatement.ResearchAndDevelopment.TwelveMonths
+
+
+ The Capital Expenditure (CapEx) is higher than the contemporaneous industry median
+ We measure this using fine.FinancialStatements.CashFlowStatement.CapExReported.TwelveMonths
+
+
+ The Advertisement Expenditure (Ad) is higher than the contemporaneous industry median
+ We measure this using fine.FinancialStatements.IncomeStatement.SellingGeneralAndAdministration.TwelveMonths
+
+
+
+
+ The fundamental data used in our algorithms is sourced from MorningStar, and to read more about our fundamental data,
+ please visit the Fundamentals section of our
+ documentation.
+
+
+
+ Once we have computed the G-Scores for each of the securities, we long the securities with G-Scores of 5 or higher
+
+ Since we use Technology as the industry, we decided to use Nasdaq-100, or ^NDX, as the benchmark, which we track
+ using the QQQ ETF. Our algorithm achieves a Sharpe Ratio of 0.713 from April 2016 to September 2020, and so it is
+ outperformed by simply holding QQQ, which yielded a Sharpe Ratio of 1.22 over the same period.
+
\ No newline at end of file
diff --git a/04 Strategy Library/1030 G-Score Investing/06 References.html b/04 Strategy Library/1030 G-Score Investing/06 References.html
new file mode 100644
index 0000000..f21473a
--- /dev/null
+++ b/04 Strategy Library/1030 G-Score Investing/06 References.html
@@ -0,0 +1,6 @@
+
+
+ Mohanram, Partha S., Separating Winners from Losers Among Low Book-to-Market Stocks Using Financial Statement
+ nalysis (April 2004). Online Copy.
+
Since we use Technology as the industry, we decided to use Nasdaq-100, or ^NDX, as the benchmark, which we track
- using the QQQ ETF. Our algorithm achieves a Sharpe Ratio of 0.713 from April 2016 to September 2020, and so it is
+ using the QQQ ETF. Our algorithm achieves a Sharpe Ratio of 0.5 from April 2016 to September 2020, and so it is
outperformed by simply holding QQQ, which yielded a Sharpe Ratio of 1.22 over the same period.
Since we use Technology as the industry, we decided to use Nasdaq-100, or ^NDX, as the benchmark, which we track
- using the QQQ ETF. Our algorithm achieves a Sharpe Ratio of 0.5 from April 2016 to September 2020, and so it is
+ using the QQQ ETF. Our algorithm achieves a Sharpe Ratio of 0.491 from April 2016 to September 2020, and so it is
outperformed by simply holding QQQ, which yielded a Sharpe Ratio of 1.22 over the same period.
- Once we have computed the G-Scores for each of the securities, we long the securities with G-Scores of 5 or higher
+ Once we have computed the G-Scores for each of the securities, we long the securities with G-Scores of 5 or higher.
From ce40497bbf02d5587fe1229e825e93752c43adeb Mon Sep 17 00:00:00 2001
From: Derek Melchin
Date: Fri, 23 Oct 2020 18:15:01 -0600
Subject: [PATCH 05/27] Make relative tables mobile friendly
---
.../05 Relative Performance.html | 2 ++
.../1026 Intraday ETF Momentum/05 Conclusion.html | 2 ++
.../05 Relative Performance.html | 2 ++
.../1033 Gradient Boosting Model/05 Relative Performance.html | 3 +++
4 files changed, 9 insertions(+)
diff --git a/04 Strategy Library/1023 Intraday Arbitrage Between Index ETFs/05 Relative Performance.html b/04 Strategy Library/1023 Intraday Arbitrage Between Index ETFs/05 Relative Performance.html
index fd71509..2d3e6c9 100644
--- a/04 Strategy Library/1023 Intraday Arbitrage Between Index ETFs/05 Relative Performance.html
+++ b/04 Strategy Library/1023 Intraday Arbitrage Between Index ETFs/05 Relative Performance.html
@@ -6,6 +6,7 @@
across all our testing periods is displayed in the table below.
+
@@ -72,6 +73,7 @@
+
diff --git a/04 Strategy Library/1026 Intraday ETF Momentum/05 Conclusion.html b/04 Strategy Library/1026 Intraday ETF Momentum/05 Conclusion.html
index ff087ea..bad583b 100644
--- a/04 Strategy Library/1026 Intraday ETF Momentum/05 Conclusion.html
+++ b/04 Strategy Library/1026 Intraday ETF Momentum/05 Conclusion.html
@@ -7,6 +7,7 @@
A breakdown of the results from all of the testing periods can be seen in the table below.
+
@@ -73,6 +74,7 @@
+
diff --git a/04 Strategy Library/1028 Ichimoku Clouds in the Energy Sector/05 Relative Performance.html b/04 Strategy Library/1028 Ichimoku Clouds in the Energy Sector/05 Relative Performance.html
index a1d1610..07a20e4 100644
--- a/04 Strategy Library/1028 Ichimoku Clouds in the Energy Sector/05 Relative Performance.html
+++ b/04 Strategy Library/1028 Ichimoku Clouds in the Energy Sector/05 Relative Performance.html
@@ -17,6 +17,7 @@
frames, implying that the strategy has more consistent returns than the benchmark.
+
@@ -83,6 +84,7 @@
+
We find the lack of performance for this strategy is not largely attributed to the transaction costs. After
diff --git a/04 Strategy Library/1033 Gradient Boosting Model/05 Relative Performance.html b/04 Strategy Library/1033 Gradient Boosting Model/05 Relative Performance.html
index 88d08bf..415eea9 100644
--- a/04 Strategy Library/1033 Gradient Boosting Model/05 Relative Performance.html
+++ b/04 Strategy Library/1033 Gradient Boosting Model/05 Relative Performance.html
@@ -1,3 +1,4 @@
+
Since we use Technology as the industry, we decided to use Nasdaq-100, or ^NDX, as the benchmark, which we track
- using the QQQ ETF. Our algorithm achieves a Sharpe Ratio of 0.491 from April 2016 to September 2020, and so it is
+ using the QQQ ETF. Our algorithm achieves a Sharpe Ratio of 0.778 from April 2016 to September 2020, and so it is
outperformed by simply holding QQQ, which yielded a Sharpe Ratio of 1.22 over the same period.
\ No newline at end of file
From 9f30601e58cecd646ecd46f69cce5a57b8750c3a Mon Sep 17 00:00:00 2001
From: Shile Wen
Date: Thu, 5 Nov 2020 17:36:42 -0800
Subject: [PATCH 07/27] fixed algorithm
---
.../04 Algorithm.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/04 Algorithm.html b/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/04 Algorithm.html
index bcf0bc2..60c8e6c 100755
--- a/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/04 Algorithm.html
+++ b/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/04 Algorithm.html
@@ -1,6 +1,6 @@
-
+
From 9ef83b5ff7ad231b106bff7e7c0130719d0e3e94 Mon Sep 17 00:00:00 2001
From: Shile Wen
Date: Fri, 6 Nov 2020 15:42:22 -0800
Subject: [PATCH 08/27] fixed algorithm
---
.../04 Algorithm.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/04 Algorithm.html b/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/04 Algorithm.html
index 60c8e6c..8586edb 100755
--- a/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/04 Algorithm.html
+++ b/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/04 Algorithm.html
@@ -1,6 +1,6 @@
+ Naïve Bayes models have become popular for their success in spam email filtering. In this tutorial, we train
+ Gaussian Naïve Bayes (GNB) classifiers to forecast the daily returns of stocks in the technology sector given the
+ historical returns of the sector. Our implementation shows the strategy has a greater Sharpe and lower variance
+ than the SPY ETF over a 5 year backtest and during the 2020 stock market crash. The algorithm we build here follows
+ the research done by Lu (2016) and Imandoust & Bolandraftar (2014).
+
+ In our use case, the classes in the model are: positive, negative, or flat future return for a security. The features
+ are the last 4 daily returns of the universe constituents. Since we are dealing with continuous data, we extend the
+ model to a GNB model by replacing \(P(x_j|c_i)\) in the equation above. First, we find the mean \(\mu_j\) and standard
+ deviation \(\sigma_j^2\) of the \(x_j\) feature vector in the training set labeled class \(c_i\). A normal distribution
+ parameterized by \(\mu_j\) and \(\sigma_j^2\) is then used to determine the likelihood of the observations. If \(o\) is the
+ observation for the \(j\)th feature. The likelihood of the observation given the class \(c_i\) is
+
+ The mechanics of the GNB model can be seen visually in
+ this video. Note that the GNB model has 2 underlying
+ assumptions: the feature vectors are independent and normally distributed. We do not test for these properties, but
+ rather leave it as an area of future research.
+
\ No newline at end of file
diff --git a/04 Strategy Library/1036 Gaussian Naive Bayes Model/03 Method.html b/04 Strategy Library/1036 Gaussian Naive Bayes Model/03 Method.html
new file mode 100644
index 0000000..8ef11c2
--- /dev/null
+++ b/04 Strategy Library/1036 Gaussian Naive Bayes Model/03 Method.html
@@ -0,0 +1,223 @@
+
Universe Selection
+
+ Following Lu (2016), we implement a custom universe selection model to select the largest stocks from the technology
+ sector. We restrict our universe to have a size of 10, but this can be easily customized via the `fine_size`
+ parameter in the constructor.
+
+
+
+class BigTechUniverseSelectionModel(FundamentalUniverseSelectionModel):
+ def __init__(self, fine_size=10):
+ self.fine_size = fine_size
+ self.month = -1
+ super().__init__(True)
+
+ def SelectCoarse(self, algorithm, coarse):
+ if algorithm.Time.month == self.month:
+ return Universe.Unchanged
+ return [ x.Symbol for x in coarse if x.HasFundamentalData ]
+
+ def SelectFine(self, algorithm, fine):
+ self.month = algorithm.Time.month
+
+ tech_stocks = [ f for f in fine if f.AssetClassification.MorningstarSectorCode == MorningstarSectorCode.Technology ]
+ sorted_by_market_cap = sorted(tech_stocks, key=lambda x: x.MarketCap, reverse=True)
+ return [ x.Symbol for x in sorted_by_market_cap[:self.fine_size] ]
+
+
+
+
+
Alpha Construction
+
+ The GaussianNaiveBayesAlphaModel predicts the direction each security will move from a given day’s open to the next
+ day’s open. When constructing this alpha model, we set up a dictionary to hold a SymbolData object for each symbol
+ in the universe and a flag to show the universe has changed.
+
+ When a new security is added to the universe, we create a SymbolData object for it to store information unique to
+ the security. The management of the SymbolData objects occurs in the alpha model's OnSecuritiesChanged method. In
+ this algorithm, since we train the Gaussian Naive Bayes classifier using the historical returns of the securities
+ in the universe, we flag to train the model every time the universe changes.
+
+
+
+class GaussianNaiveBayesAlphaModel(AlphaModel):
+ ...
+
+ def OnSecuritiesChanged(self, algorithm, changes):
+ for security in changes.AddedSecurities:
+ self.symbol_data_by_symbol[security.Symbol] = SymbolData(security, algorithm)
+
+ for security in changes.RemovedSecurities:
+ symbol_data = self.symbol_data_by_symbol.pop(security.Symbol, None)
+ if symbol_data:
+ symbol_data.dispose()
+
+ self.new_securities = True
+
+
+
+
+
SymbolData Class
+
+ The SymbolData class is used to store training data for the GaussianNaiveBayesAlphaModel and manage a consolidator
+ subscription. In the constructor, we specify the training parameters, setup the consolidator, and warm up the
+ training data.
+
+
+
+class SymbolData:
+ def __init__(self, security, algorithm, num_days_per_sample=4, num_samples=100):
+ self.exchange = security.Exchange
+ self.symbol = security.Symbol
+ self.algorithm = algorithm
+ self.num_days_per_sample = num_days_per_sample
+ self.num_samples = num_samples
+ self.previous_open = 0
+ self.model = None
+
+ # Setup consolidators
+ self.consolidator = TradeBarConsolidator(timedelta(days=1))
+ self.consolidator.DataConsolidated += self.CustomDailyHandler
+ algorithm.SubscriptionManager.AddConsolidator(self.symbol, self.consolidator)
+
+ # Warm up ROC lookback
+ self.roc_window = np.array([])
+ self.labels_by_day = pd.Series()
+
+ data = {f'{self.symbol.ID}_(t-{i})' : [] for i in range(1, num_days_per_sample + 1)}
+ self.features_by_day = pd.DataFrame(data)
+
+ lookback = num_days_per_sample + num_samples + 1
+ history = algorithm.History(self.symbol, lookback, Resolution.Daily)
+ if history.empty or 'close' not in history:
+ algorithm.Log(f"Not enough history for {self.symbol} yet")
+ return
+
+ history = history.loc[self.symbol]
+ history['open_close_return'] = (history.close - history.open) / history.open
+
+ start = history.shift(-1).open
+ end = history.shift(-2).open
+ history['future_return'] = (end - start) / start
+
+ for day, row in history.iterrows():
+ self.previous_open = row.open
+ if self.update_features(day, row.open_close_return) and not pd.isnull(row.future_return):
+ row = pd.Series([np.sign(row.future_return)], index=[day])
+ self.labels_by_day = self.labels_by_day.append(row)[-self.num_samples:]
+
+
+
+
+ The update_features method is called to update our training features with the latest data passed to the algorithm.
+ It returns True/False, representing if the features are in place to start updating the training labels.
+
+ The GNB model is trained each day the universe has changed. By default, it uses 100 samples to train. The features
+ are the historical open-to-close returns of the universe constituents. The labels are the returns from the open at
+ T+1 to the open at T+2 at each time step for each security.
+
+
+
+class GaussianNaiveBayesAlphaModel(AlphaModel):
+ ...
+
+ def train(self):
+ features = pd.DataFrame()
+ labels_by_symbol = {}
+
+ # Gather training data
+ for symbol, symbol_data in self.symbol_data_by_symbol.items():
+ if symbol_data.IsReady:
+ features = pd.concat([features, symbol_data.features_by_day], axis=1)
+ labels_by_symbol[symbol] = symbol_data.labels_by_day
+
+ # Train the GNB model
+ for symbol, symbol_data in self.symbol_data_by_symbol.items():
+ if symbol_data.IsReady:
+ symbol_data.model = GaussianNB().fit(features.iloc[:-2], labels_by_symbol[symbol])
+
+
+
+
+
Alpha Update
+
+ As new TradeBars are provided to the alpha model's Update method, we collect the latest TradeBar’s open-to-close
+ return for each security in the universe. We then predict the direction of each security using the security’s
+ corresponding GNB model, and return insights accordingly.
+
+
+
+class GaussianNaiveBayesAlphaModel(AlphaModel):
+ ...
+
+ def Update(self, algorithm, data):
+ if self.new_securities:
+ self.train()
+ self.new_securities = False
+
+ tradable_symbols = {}
+ features = [[]]
+
+ for symbol, symbol_data in self.symbol_data_by_symbol.items():
+ if data.ContainsKey(symbol) and data[symbol] is not None and symbol_data.IsReady:
+ tradable_symbols[symbol] = symbol_data
+ features[0].extend(symbol_data.features_by_day.iloc[-1].values)
+
+ insights = []
+ if len(tradable_symbols) == 0:
+ return []
+ weight = 1 / len(tradable_symbols)
+ for symbol, symbol_data in tradable_symbols.items():
+ direction = symbol_data.model.predict(features)
+ if direction:
+ insights.append(Insight.Price(symbol, data.Time + timedelta(days=1, seconds=-1),
+ direction, None, None, None, weight))
+
+ return insights
+
+ Although this strategy passes several of the
+ metrics required for Alpha Streams
+ and the Quant League competition, it requires further work to pass the following requirements:
+
+ The GNB model strategy implemented in this tutorial produced a greater Sharpe ratio and lower annual variance than
+ buying and holding the S&P 500 index ETF benchmark over the backtesting period. In addition to outperforming during
+ the entire backtest, the strategy also outperformed during the 2020 stock market crash.
+
+
+
+ To continue the development of this strategy, future areas of research include:
+
+
+
+
Adjusting parameters in the SymbolData class
+
Trying other features and labels for the GNB model
+
Adjusting the universe parameters and targeted sector
+
Adding handlers for corporate actions
+
Filter for stocks with independent and normal returns
+
\ No newline at end of file
diff --git a/04 Strategy Library/1036 Gaussian Naive Bayes Model/08 References.html b/04 Strategy Library/1036 Gaussian Naive Bayes Model/08 References.html
new file mode 100644
index 0000000..0320284
--- /dev/null
+++ b/04 Strategy Library/1036 Gaussian Naive Bayes Model/08 References.html
@@ -0,0 +1,12 @@
+
+
+ Imandoust, S. B., & Mohammad, B. (2014). Forecasting the direction of stock market index movement using three
+ data mining techniques: the case of Tehran Stock Exchange. Journal of Engineering Research and Applications,
+ 6(2), 106-117.
+ Online copy
+
+
+ Lu, N. (2016). A Machine Learning Approach to Automated Trading.
+ Online copy
+
+
\ No newline at end of file
From 93cfc1f62b1904001eb57a767e167956284b646b Mon Sep 17 00:00:00 2001
From: Derek Melchin
Date: Thu, 19 Nov 2020 18:39:43 -0700
Subject: [PATCH 11/27] Fix description
---
04 Strategy Library/00 Strategy Library/01 Strategy Library.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/04 Strategy Library/00 Strategy Library/01 Strategy Library.php b/04 Strategy Library/00 Strategy Library/01 Strategy Library.php
index 9fdb414..9fc944f 100644
--- a/04 Strategy Library/00 Strategy Library/01 Strategy Library.php
+++ b/04 Strategy Library/00 Strategy Library/01 Strategy Library.php
@@ -721,7 +721,7 @@
'sources' => [
'Academia' => 'https://www.academia.edu/7677227/Forecasting_the_direction_of_stock_market_index_movement_using_three_data_mining_techniques_the_case_of_Tehran_Stock_Exchange'
],
- 'description' => "Analyzes the news releases of drug manufacturers and places intraday trades for the stocks with positive news.",
+ 'description' => "Forecasts the next day's return of technology stocks by fitting a gaussian naive bayes model to the historical returns of the technology sector constituents.",
'tags'=>'Equities, Machine Learning, Naive Bayes, Gaussian'
]
];
From 28e73de28c4e10b564278a805f5b34dc8ec725c8 Mon Sep 17 00:00:00 2001
From: Derek Melchin
Date: Thu, 19 Nov 2020 20:56:41 -0700
Subject: [PATCH 12/27] Fix latex error
---
.../1036 Gaussian Naive Bayes Model/02 Background.html | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/04 Strategy Library/1036 Gaussian Naive Bayes Model/02 Background.html b/04 Strategy Library/1036 Gaussian Naive Bayes Model/02 Background.html
index 2643372..f576900 100644
--- a/04 Strategy Library/1036 Gaussian Naive Bayes Model/02 Background.html
+++ b/04 Strategy Library/1036 Gaussian Naive Bayes Model/02 Background.html
@@ -10,7 +10,10 @@
\[P(c_i | x_1, ..., x_n) = \frac{P(c_i)P(x_1, ..., x_n | c_i)}{P(x_1, ..., x_n)}\]
-where \(c_i\) represents one of the \(m\) classes and \(x_1, ..., x_n\) are the features.
+
+
+ where \(c_i\) represents one of the \(m\) classes and \(x_1, ..., x_n\) are the features.
+
The Naïve Bayes model assumes the features are independent, so that
@@ -34,7 +37,7 @@
observation for the \(j\)th feature. The likelihood of the observation given the class \(c_i\) is
- Factor Based Stock Selection Model for Turkish Equities, 2015, Ayhan Yüksel Online Copy
+ Factor Based Stock Selection Model for Turkish Equities, 2015, Ayhan Yüksel Online Copy
From d204c4e0e21e02048a61ae7b4363b4c1234641bb Mon Sep 17 00:00:00 2001
From: Alexandre Catarino
Date: Tue, 8 Dec 2020 21:49:01 +0000
Subject: [PATCH 15/27] Update Reference in Chinese Version
Using https://www.dropbox.com/s/bfkvrggydf06rxq/Factor%20Based%20Stock%20Selection%20Model.pdf
---
...05 \345\217\202\350\200\203\346\226\207\347\214\256.cn.html" | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git "a/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/05 \345\217\202\350\200\203\346\226\207\347\214\256.cn.html" "b/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/05 \345\217\202\350\200\203\346\226\207\347\214\256.cn.html"
index 145c7bf..4d6f9c3 100644
--- "a/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/05 \345\217\202\350\200\203\346\226\207\347\214\256.cn.html"
+++ "b/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/05 \345\217\202\350\200\203\346\226\207\347\214\256.cn.html"
@@ -1,5 +1,5 @@
- Factor Based Stock Selection Model for Turkish Equities, 2015, Ayhan Yüksel Online Copy
+ Factor Based Stock Selection Model for Turkish Equities, 2015, Ayhan Yüksel Online Copy
- This strategy is called Short-Term Reversal Strategy which is discussed in detail in the paper written by Wilma de Groot, Joop Huij and Weili Zhou (2011) titled "Another look at trading costs and short-term reversal profits". The standard reversal strategy takes the whole universe of stocks into consideration, while this paper limits the stock universe only to large cap stocks so that trading costs could be significantly reduced.
-
-
- One simple version of this strategy could be described like this: The investment universe consists of 100 biggest companies by market capitalization. We go long on the 10% stocks which have the lowest performances in the last month while going short on the 10% stocks with the highest ones. The portfolio is rebalanced weekly.
- In the paper, however, strategies with different investment universes and different rebalancing frequencies are all backtested. The results show that, the larger the size of the investment universe, the larger the trading costs caused by extensively trading in small cap stocks which are less liquid; and trading costs become substantially lower when the rebalancing frequency is decreased from daily to weekly, but so do gross returns.
- In this tutorial, we only use 100 stocks with weekly rebalancing for illustration.
+ In this tutorial, we implement a version of the short-term reversal strategy published by De Groot, Huij, & Zhou
+ (2012). The strategy works by observing the returns of each security in the universe over the previous month. Every
+ week, the algorithm longs the worst performers and shorts the top performers. The original strategy outlined in the
+ literature considers the entire universe of stocks when trading. To reduce trading costs, we limit our universe to
+ the most liquid large cap stocks. Our analysis shows the strategy underperforms the S&P 500 index during all our
+ backtest periods except the 2020 market crash.
diff --git a/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/02 Method.html b/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/02 Method.html
index a666b03..8b9f021 100755
--- a/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/02 Method.html
+++ b/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/02 Method.html
@@ -1,103 +1,141 @@
- The strategy code mainly consists of three parts: Initialization, Warm Up, and Weekly Rebalancing.
+ The strategy code mainly consists of four parts: Initialization, Universe Selection, OnData, and OnSecuritiesChanged.
-
Step 1: Initialization
+
Algorithm Initialization
- In the Initialize function, we set up look-back period, beginning cash balance, the size of the investment universe, the number of traded stocks, etc. We use self._numOfWeeks to count?the number of weeks that have passed since the start date, and self._LastDay to indicate whether it is a new week. self._ifWarmUp is true when the self._numOfWeeks is 3, which means as long as next week's data come, we can make our investment decisions.??self._stocks is a list containing all the symbols of the 100 stocks that are taken into consideration. self._values is a dictionary with keys the stock symbols and values the lists containing the prices of stock each week since 4 weeks ago.
+ When initializing the algorithm, we add a coarse universe selection method and specify several parameters to use
+ when selecting securities.
- Also, we need to use?CoarseSelectionFunction to select 100 qualified stocks from the total stock universe. Here, we sort the total stock universe by each stock's DollarVolume in decreasing order. Then, we select the first 100 stocks that have the largest DollarVolume among all the stocks in the universe.
-
-
-
-def CoarseSelectionFunction(self, coarse):
- sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
- top100 = sortedByDollarVolume[:self._numberOfSymbols]
- return [i.Symbol for i in top100]
-
-
-
Step 2:Warm Up
+
+
Universe Selection
- Before we are able to make our investment decisions, we must have at least 4 weeks' data to calculate the performance, i.e. the monthly return, of each stock. Hence, we need a warm up period as long as 3 weeks to accumulate price series, so that once the fourth week's data come we can calculate?the return of the whole month.
+ The coarse universe selection method creates a RateOfChange
+ indicator for each of the top 100
+ most liquid securities in the market. Upon creation, the indicator is manually warmed-up with historical closing
+ prices. After the indicators are ready, the universe selects the securities with the 10 best and 10 worst
+ RateOfChange values.
+
+class ShortTimeReversal(QCAlgorithm):
+ # ...
+
+ def SelectCoarse(self, coarse):
+
+ # We should keep a dictionary for all securities that have been selected
+ for cf in coarse:
+ symbol = cf.Symbol
+ if symbol in self.roc_by_symbol:
+ self.roc_by_symbol[symbol].Update(cf.EndTime, cf.AdjustedPrice)
+
+ # Refresh universe each week
+ week_number = self.Time.date().isocalendar()[1]
+ if week_number == self.week:
+ return Universe.Unchanged
+ self.week = week_number
+
+ # sort and select by dollar volume
+ sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
+ selected = {cf.Symbol: cf for cf in sortedByDollarVolume[:self.dollar_volume_selection_size]}
+
+ # New selections need a history request to warm up the indicator
+ symbols = [k for k in selected.keys()
+ if k not in self.roc_by_symbol or not self.roc_by_symbol[k].IsReady]
+
+ if symbols:
+ history = self.History(symbols, self.lookback, Resolution.Daily)
+ if history.empty:
+ self.Log(f'No history for {", ".join([x.Value for x in symbols])}')
+ history = history.close.unstack(0)
+
+ for symbol in symbols:
-
self._stocks = []
-self.uni_symbol = None
-symbols = self.UniverseManager.Keys
-for i in symbols:
- if str(i.Value) == "QC-UNIVERSE-COARSE-USA":
- self.uni_symbol = i
- for i in self.UniverseManager[self.uni_symbol].Members:
- self._stocks.append(i.Value.Symbol)
- self._values[i.Value.Symbol] = [self.Securities[i.Value.Symbol].Price]
+ if symbol not in history:
+ continue
+ # Create and warm-up the RateOfChange indicator
+ roc = RateOfChange(self.lookback)
+ for time, price in history[symbol].dropna().iteritems():
+ roc.Update(time, price)
+
+ if roc.IsReady:
+ self.roc_by_symbol[symbol] = roc
+
+ # Sort the symbols by their ROC values
+ selectedRateOfChange = {}
+ for symbol in selected.keys():
+ if symbol in self.roc_by_symbol:
+ selectedRateOfChange[symbol] = self.roc_by_symbol[symbol]
+ sortedByRateOfChange = sorted(selectedRateOfChange.items(), key=lambda kv: kv[1], reverse=True)
+
+ # Define the top and the bottom to buy and sell
+ self.rocTop = [x[0] for x in sortedByRateOfChange[:self.roc_selection_size]]
+ self.rocBottom = [x[0] for x in sortedByRateOfChange[-self.roc_selection_size:]]
+
+ return self.rocTop + self.rocBottom
-
- We get all the symbols of qualified stocks from UniverseManager and keep them in self._stocks which is a list. Then we create for each key in the dictionary self._values a list where its first week's price is stored. And every time new data come, we append the new price to the end of the list of each stock.
-
-
-
for stock in self._stocks:
- self._values[stock].append(self.Securities[stock].Price)
-
-
Step 3:Weekly Rebalancing
+
The OnData Method
- After the warm-up period, we calculate monthly returns every week and based on the returns, we make our investment decisions.
+ As new data is passed to the OnData method, we issue orders to form a long-short portfolio. We long the securities
+ with the lowest RateOfChange values and short those with the largest values. After rebalancing, we clear the
+ `rocTop` and `rocBottom` lists to ensure we don’t trade again until the universe is refreshed.
-
+
+class ShortTimeReversal(QCAlgorithm):
+ # ...
-
returns = {}
-for stock in self._stocks:
- newPrice = self.Securities[stock].Price
- oldPrice = self._values[stock].pop(0)
- self._values[stock].append(newPrice)
- returns[stock] = newPrice/oldPrice
+ def OnData(self, data):
+ # Rebalance
+ for symbol in self.rocTop:
+ self.SetHoldings(symbol, -0.5/len(self.rocTop))
+ for symbol in self.rocBottom:
+ self.SetHoldings(symbol, 0.5/len(self.rocBottom))
+
+ # Clear the list of securities we have placed orders for
+ # to avoid new trades before the next universe selection
+ self.rocTop.clear()
+ self.rocBottom.clear()
+
+
The OnSecuritiesChanged Method
- Every week when new data come, we use them along with the data four weeks ago to calculate the monthly returns. At the same time, we remove the oldest data from our lists. This step is essential to prevent memory size exceeding the limit.
+ We are rebalancing the portfolio on a weekly basis, but securities can leave our defined universe between rebalance
+ days. To accommodate this, we liquidate any securities that are removed from the universe in the
+ OnSecuritiesChanged method.
-
+
+class ShortTimeReversal(QCAlgorithm):
+ # ...
-
newArr = [(v,k) for k,v in returns.items()]
-newArr.sort()
-for ret, stock in newArr[self._numberOfTradings:-self._numberOfTradings]:
- self.SetHoldings(stock, 0)
-for ret, stock in newArr[0:self._numberOfTradings]:
- self.SetHoldings(stock, 0.5/self._numberOfTradings)
-for ret, stock in newArr[-self._numberOfTradings:]:
- self.SetHoldings(stock, -0.5/self._numberOfTradings)
+ def OnSecuritiesChanged(self, changes):
+ for security in changes.RemovedSecurities:
+ self.Liquidate(security.Symbol, 'Removed from Universe')
-
-
- Finally, we sort the returns in increasing order. For the stocks whose monthly returns fall into the first 10% (performed badly in last month), we long them; For those fall into the last 10% (performed well in last month), we short them. Others (between 10% and 90%) will be set to 0.
-
+
\ No newline at end of file
diff --git a/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/03 Summary.html b/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/03 Summary.html
deleted file mode 100755
index 0c2b46e..0000000
--- a/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/03 Summary.html
+++ /dev/null
@@ -1,5 +0,0 @@
-
- In the paper, the look-back period is from 1990 to 2009. However, we want to test whether the strategy is still profitable in the new time period. Hence we use different look-back periods instead.
- If we begin from 2005 and end in 2017, there will be a total return of 131.50%. Although to some extent the performance of this strategy is dependent on different market situations,?nevertheless, in either situation mentioned above, this strategy could significantly beat the S&P 500 benchmark.
- Further research and backtesting could be done on different look-back periods, rebalancing frequencies, investment universes, numbers of traded stocks, etc.
-
diff --git a/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/04 Algorithm.html b/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/04 Algorithm.html
index 009e778..c2e37d5 100755
--- a/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/04 Algorithm.html
+++ b/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/04 Algorithm.html
@@ -1,6 +1,6 @@
+ Although this strategy passes several of the
+ metrics required for Alpha Streams
+ and the Quant League competition, it requires further work to pass the following requirements:
+
+
+
+
PSR >= 80%
+
Emits insights
+
Max drawdown <= 10%
+
Handles dividends and splits
+
Minute or second data resolution
+
diff --git a/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/08 Conclusion.html b/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/08 Conclusion.html
new file mode 100644
index 0000000..ae81428
--- /dev/null
+++ b/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/08 Conclusion.html
@@ -0,0 +1,16 @@
+
+ The short-term reversal strategy implemented in this tutorial produced a lower Sharpe ratio than the S&P
+ 500 index ETF benchmark over all our testing periods except during the 2020 market crash. To continue the
+ development of this strategy, future areas of research include:
+
+
+
+ To continue the development of this strategy, future areas of research include:
+
+
+
+
Increasing the data resolution and adding risk management logic.
+
Applying the strategy to a different universe of securities.
+
Testing other lookback periods for the RateOfChange indicator. Some researchers exclude the most-recent month’s price action from the indicator’s calculation.
+
Adjusting the weight for each insight emitted from the alpha model. Perhaps the most extreme performer of all the securities the alpha model is about to long (short) should be given the largest weight of all the securities the model is about to long (short).
+
\ No newline at end of file
diff --git a/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/09 References.html b/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/09 References.html
new file mode 100644
index 0000000..2a52089
--- /dev/null
+++ b/04 Strategy Library/10 Short-Term Reversal Strategy in Stocks/09 References.html
@@ -0,0 +1,6 @@
+
+
+ de Groot, Wilma and Huij, Joop and Zhou, Weili, Another Look at Trading Costs and Short-Term Reversal
+ Profits (July 1, 2011). Online copy
+
- This model was proposed in 1993 by Eugene Fama and Kenneth French to describe stock returns.[ref] Fama, E F; French, K R (1993). Common risk factors in the returns on stocks and bonds. Journal of Financial Economics. 33: 3. CiteSeerX 10.1.1.139.5892 Freely accessible. doi:10.1016/0304-405X(93)90023-5[/ref]
-
-
- The 3-factor model is
+ This model was proposed in 1993 by Eugene Fama and Kenneth French to describe stock returns. The 3-factor model is
MKT is the excess return of the market. It's the value-weighted return of all CRSP firms incorporated in the US and listed on the NYSE, AMEX, or NASDAQ minus the 1-month Treasury Bill rate.
SMB (Small Minus Big) measures the excess return of stocks with small market cap over those with larger market cap.
-
HML (High Minus Low) measures the excess return of value stocks over growth stocks. Value stocks have high book to price ratio (B/P) than growth stocks.
+
HML (High Minus Low) measures the excess return of value stocks over growth stocks. Value stocks have a higher book to price ratio (B/P) than growth stocks.
diff --git a/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/05 Other Factors.html b/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/05 Other Factors.html
deleted file mode 100755
index 510c436..0000000
--- a/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/05 Other Factors.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
- The Fama-French 5-Factor model comprises two more factors:
-
-
-
RMW (Robust Minus Weak) measures the excess returns of firms with high operating profit margins over those with lower profits.
-
CMA (Conservative Minus Aggressive) measures the excess returns of firms investing less over those investing more.
-
-
-
- RMW was proposed by Novy-Marx (2013) who wrote that:
- "Controlling for gross profitability explains most earnings related anomalies, and a wide range of seemingly unrelated profitable trading strategies." CMA was proposed by Fama and French (2014) who pointed out that: A five-factor model directed at capturing the size, value, profitability, and investment patterns in average stock returns is rejected on the GRS test, but for applied purposes it provides an acceptable description of average returns. Finally, momentum is another commonly used factor. It captures excess returns of stocks with highest returns over those with lowest returns
-
diff --git a/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/06 Summary.html b/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/05 Summary.html
old mode 100755
new mode 100644
similarity index 98%
rename from 05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/06 Summary.html
rename to 05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/05 Summary.html
index 549200f..d2b7e7a
--- a/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/06 Summary.html
+++ b/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/05 Summary.html
@@ -1,3 +1,3 @@
-
- In this chapter we expand Capital Asset Pricing Model (CAPM) into multi-factor models: the Fama-French factor models in particular. They are the most empirically successful multi-factor models by far, and are commonly used in practice.
-
+
+ In this chapter we expand Capital Asset Pricing Model (CAPM) into multi-factor models: the Fama-French factor models in particular. They are the most empirically successful multi-factor models by far, and are commonly used in practice.
+
diff --git a/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/07 Algorithm.html b/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/06 Algorithm.html
old mode 100755
new mode 100644
similarity index 78%
rename from 05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/07 Algorithm.html
rename to 05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/06 Algorithm.html
index e3c69c8..2fd2fa2
--- a/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/07 Algorithm.html
+++ b/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/06 Algorithm.html
@@ -1,15 +1,15 @@
-
- Multi-factor strategies are stock picking strategies. Here we try to implement a 2013 paper published by AQR Capital Management.
- The paper recommends picking stocks by their value, quality (profitability) and momentum.
- The empirically successful measure of value is book-to-price ratio (B/P), but other measures can be used simultaneously to form a more robust and reliable view of a stock's value. The paper uses 5 measures: book-to-price, earnings-to-price ratio (EPS), forecasted EPS, cash flow-to-enterprise value and sales-to-enterprise value.
- The paper suggested a few quality measures: total profit over assets, gross margin and free cash flow over assets. There are also various measures of momentum. 1-year momentum, fundamental momentum and returns around earnings announcement are good choices.
-
-
- In our backtested strategy, we used operating profit margin to measure quality, P/B value to measure value, and 1-month momentum. The portfolio was rebalanced every 2 months and our backtest period runs from Jan 2012 to Jan 2015. You can build your own version by changing the factor, the weight of each factor, and the rebalance period based on the backtested strategy.
-
-
-
-
-
-
-
+
+ Multi-factor strategies are stock picking strategies. Here we try to implement a 2013 paper published by AQR Capital Management.
+ The paper recommends picking stocks by their value, quality (profitability) and momentum.
+ The empirically successful measure of value is book-to-price ratio (B/P), but other measures can be used simultaneously to form a more robust and reliable view of a stock's value. The paper uses 5 measures: book-to-price, earnings-to-price ratio (EPS), forecasted EPS, cash flow-to-enterprise value and sales-to-enterprise value.
+ The paper suggested a few quality measures: total profit over assets, gross margin and free cash flow over assets. There are also various measures of momentum. 1-year momentum, fundamental momentum and returns around earnings announcement are good choices.
+
+
+ In our backtested strategy, we used operating profit margin to measure quality, P/B value to measure value, and 1-month momentum. The portfolio was rebalanced every month. You can build your own version by changing the factor, the weight of each factor, and the rebalance period based on the backtested strategy.
+
+
+
+
+
+
+
diff --git a/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/08 References.html b/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/07 References.html
similarity index 81%
rename from 05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/08 References.html
rename to 05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/07 References.html
index 79b3bcb..eb7216e 100644
--- a/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/08 References.html
+++ b/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/07 References.html
@@ -14,4 +14,7 @@
Robert Novy-Marx (2013). The Other Side of Value: The Gross Profitability Premium Journal of Financial Economics 108 (1), 1-28. Retrieved from rnm.simon.rochester.edu/research/OSoV.pdf
+
+ Fama, E. F. & French, K. R. (1993). Common risk factors in the returns on stocks and bonds. Journal of Financial Economics, 33, 3-56. doi: 10.1016/0304-405X(93)90023-5. Retrieved from rady.ucsd.edu.
+
From 304f01fe6fa9e01d15c3155cab4f3b03d5e251fc Mon Sep 17 00:00:00 2001
From: Derek Melchin
Date: Fri, 5 Mar 2021 11:44:46 -0700
Subject: [PATCH 18/27] Update value factor definition to match algo
---
.../14 Fama-French Multi-Factor Models/06 Algorithm.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/06 Algorithm.html b/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/06 Algorithm.html
index 2fd2fa2..3eb4334 100644
--- a/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/06 Algorithm.html
+++ b/05 Introduction to Financial Python[]/14 Fama-French Multi-Factor Models/06 Algorithm.html
@@ -5,7 +5,7 @@
The paper suggested a few quality measures: total profit over assets, gross margin and free cash flow over assets. There are also various measures of momentum. 1-year momentum, fundamental momentum and returns around earnings announcement are good choices.
- In our backtested strategy, we used operating profit margin to measure quality, P/B value to measure value, and 1-month momentum. The portfolio was rebalanced every month. You can build your own version by changing the factor, the weight of each factor, and the rebalance period based on the backtested strategy.
+ In our backtested strategy, we used operating profit margin to measure quality, book value per share to measure value, and 1-month momentum. The portfolio was rebalanced every month. You can build your own version by changing the factor, the weight of each factor, and the rebalance period based on the backtested strategy.
From b1fc9c2bb99abb67fdf008e118597f55bab491ba Mon Sep 17 00:00:00 2001
From: Jared
Date: Wed, 17 Mar 2021 10:17:08 -0700
Subject: [PATCH 19/27] Update 01 Definition.html
---
07 Applied Options[]/02 Bull Call Spread/01 Definition.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/07 Applied Options[]/02 Bull Call Spread/01 Definition.html b/07 Applied Options[]/02 Bull Call Spread/01 Definition.html
index 0418abb..c361521 100755
--- a/07 Applied Options[]/02 Bull Call Spread/01 Definition.html
+++ b/07 Applied Options[]/02 Bull Call Spread/01 Definition.html
@@ -5,7 +5,7 @@
This strategy creates a ceiling and floor for the profit. By purchasing a call and selling a call with higher strike simultaneously, traders can reduce the cost of just one long call option with the premium of a short call option. But the premium of ITM call is more expensive than the OTM call. The strategy limits the loss resulting from a drop in the price of the underlying stock but still creates a ceiling to the profit while the underlying price is increasing.
- Take GOOG as an example. If the share price of GOOG is $950 at time 0, the premium of ITM call option is 20 with strike 900 and the premium of OTM call option is 2 with strike 1000. If we ignore the commission, dividends and other transaction fees, the payoff of Bull Call Spread strategy is as follows:
+ Take GOOG as an example. If the share price of GOOG is $950 at time 0, the premium of ITM call option is 50 with strike 900 and the premium of OTM call option is 2 with strike 1000. If we ignore the commission, dividends and other transaction fees, the payoff of Bull Call Spread strategy is as follows:
From 6750665e5c3f051e4ab37bbafb7835d1bed848b3 Mon Sep 17 00:00:00 2001
From: Web Editor
Date: Mon, 11 Oct 2021 16:34:56 -0400
Subject: [PATCH 20/27] Automated push from server made by Alexandre Catarino
---
.../02 Fetching Data.html | 196 +++++++++---------
1 file changed, 98 insertions(+), 98 deletions(-)
diff --git a/05 Introduction to Financial Python[]/05 Pandas-Resampling and DataFrame/02 Fetching Data.html b/05 Introduction to Financial Python[]/05 Pandas-Resampling and DataFrame/02 Fetching Data.html
index 325ecd6..181f0fc 100755
--- a/05 Introduction to Financial Python[]/05 Pandas-Resampling and DataFrame/02 Fetching Data.html
+++ b/05 Introduction to Financial Python[]/05 Pandas-Resampling and DataFrame/02 Fetching Data.html
@@ -1,98 +1,98 @@
-
From eb15f94de0868141eb5bb55909c4e7ead648f79f Mon Sep 17 00:00:00 2001
From: Web Editor
Date: Fri, 11 Mar 2022 01:59:09 -0500
Subject: [PATCH 21/27] Automated push from server made by Louis Szeto
---
.../02 QuantConnect Options API/04 Select Contracts.html | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/06 Introduction to Options[]/02 QuantConnect Options API/04 Select Contracts.html b/06 Introduction to Options[]/02 QuantConnect Options API/04 Select Contracts.html
index 54084fb..e9ca2d1 100755
--- a/06 Introduction to Options[]/02 QuantConnect Options API/04 Select Contracts.html
+++ b/06 Introduction to Options[]/02 QuantConnect Options API/04 Select Contracts.html
@@ -65,12 +65,12 @@
def OnData(self,slice):
for i in slice.OptionChains:
if i.Key != self.symbol: continue
- optionchain = i.Value
- self.Log("underlying price:" + str(optionchain.Underlying.Price))
- df = pd.DataFrame([[x.Right,float(x.Strike),x.Expiry,float(x.BidPrice),float(x.AskPrice)] for x in optionchain],
+ optionchain = i.Value
+ self.Log("underlying price:" + str(optionchain.Underlying.Price))
+ df = pd.DataFrame([[x.Right,float(x.Strike),x.Expiry,float(x.BidPrice),float(x.AskPrice)] for x in optionchain],
index=[x.Symbol.Value for x in optionchain],
columns=['type(call 0, put 1)', 'strike', 'expiry', 'ask price', 'bid price'])
- self.Log(str(df))
+ self.Log(str(df))
def OnData(self,slice):
for i in slice.OptionChains:
if i.Key != self.symbol: continue
- optionchain = i.Value
- self.Log("underlying price:" + str(optionchain.Underlying.Price))
- df = pd.DataFrame([[x.Right,float(x.Strike),x.Expiry,float(x.BidPrice),float(x.AskPrice)] for x in optionchain],
- index=[x.Symbol.Value for x in optionchain],
- columns=['type(call 0, put 1)', 'strike', 'expiry', 'ask price', 'bid price'])
- self.Log(str(df))
+ optionchain = i.Value
+ self.Log("underlying price:" + str(optionchain.Underlying.Price))
+ df = pd.DataFrame([[x.Right,float(x.Strike),x.Expiry,float(x.BidPrice),float(x.AskPrice)] for x in optionchain],
+ index=[x.Symbol.Value for x in optionchain],
+ columns=['type(call 0, put 1)', 'strike', 'expiry', 'ask price', 'bid price'])
+ self.Log(str(df))
for i in slice.OptionChains:
if i.Key != self.symbol: continue
- chain = i.Value
-# differentiate the call and put options
-call = [x for x in optionchain if chain.Right == 0]
-put = [x for x in optionchain if chain.Right == 1]
-# choose ITM contracts
-contracts = [x for x in call if call.UnderlyingLastPrice - x.Strike > 0]
-# or choose ATM contracts
-contracts = sorted(optionchain, key = lambda x: abs(optionchain.Underlying.Price - x.Strike))[0]
-# or choose OTM contracts
-contracts = [x for x in call if call.UnderlyingLastPrice - x.Strike < 0]
-# sort the contracts by their expiration dates
-contracts = sorted(contracts, key = lambda x:x.Expiry, reverse = True)
+ optionchain = i.Value
+ # differentiate the call and put options
+ call = [x for x in optionchain if x.Right == 0]
+ put = [x for x in optionchain if x.Right == 1]
+ # choose ITM call contracts
+ contracts = [x for x in call if x.UnderlyingLastPrice - x.Strike > 0]
+ # or choose ATM contracts
+ contracts = sorted(optionchain, key = lambda x: abs(x.UnderlyingLastPrice - x.Strike))[0]
+ # or choose OTM call contracts
+ contracts = [x for x in call if x.UnderlyingLastPrice - x.Strike < 0]
+ # sort the contracts by their expiration dates
+ contracts = sorted(contracts, key = lambda x: x.Expiry, reverse = True)
def Initialize(self):
- self.SetStartDate(2017, 01, 01) #Set Start Date
- self.SetEndDate(2017, 06, 30) #Set End Date
+ self.SetStartDate(2017, 1, 1) #Set Start Date
+ self.SetEndDate(2017, 6, 30) #Set End Date
self.SetCash(50000) #Set Strategy Cash
equity = self.AddEquity("GOOG", Resolution.Minute) # Add the underlying stock: Google
option = self.AddOption("GOOG", Resolution.Minute) # Add the option corresponding to underlying stock
From 25963e427c4cee06d7778fecca635126745242cf Mon Sep 17 00:00:00 2001
From: Alexandre Catarino
Date: Thu, 19 May 2022 23:54:45 +0100
Subject: [PATCH 25/27] Move Workflow to Documentation Page
---
README.md | 30 ++++++------------------------
1 file changed, 6 insertions(+), 24 deletions(-)
diff --git a/README.md b/README.md
index 5e2fd23..c9846d7 100644
--- a/README.md
+++ b/README.md
@@ -8,40 +8,22 @@ This repository is a collection of WordPress and Jupyter notebook tutorials for
Lean Engine is an open-source fully managed C# algorithmic trading engine built for desktop and cloud usage. It was designed in Mono and operates in Windows, Linux and Mac platforms. For more information about the LEAN Algorithmic Trading engine see the [Lean][4] Engine repository.
-
-## New Tutorial Requests and Edits ##
-
-Please submit new tutorial requests as an issue to the [Tutorials][5] repository. Before submitting an issue please read others to ensure it is not a duplicate. Edits and fixes for clarity are warmly welcomed!
-
-## Mailing List ##
-
-The mailing list for the project can be found on [Google Groups][6]
-
## Contributors and Pull Requests ##
Contributions are warmly very welcomed but we ask you read the existing code to see how it is formatted, commented and ensure contributions match the existing style. All code submissions must include accompanying tests. Please see the [contributor guide lines][7].
## Strategy Library Development Workflow ##
-To publish a strategy to our [Strategy Library](https://www.quantconnect.com/tutorials/strategy-library/strategy-library), follow these steps:
-1. Review filtered sources like SSRN, arxiv, and other academic journals/papers for a strategy to implement. Try to adhere to the [Quant League competition](https://www.quantconnect.com/competitions/quant-league-1) criteria and the Alpha Streams [minimum criteria](https://www.quantconnect.com/docs/alpha-streams/submitting-an-alpha#Submitting-an-Alpha-Minimum-Criteria) and [review process](https://www.quantconnect.com/docs/alpha-streams/submitting-an-alpha#Submitting-an-Alpha-Subsequent-Review-Process).
-2. Post a 3-point development plan to [our Slack channel](https://www.quantconnect.com/slack) and wait for approval by @jaredbroad or @alexcatarino. See an example [here](https://cdn.quantconnect.com/i/tu/development-plan-example.png).
-3. Develop the strategy (add [license and imports](https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/BasicTemplateAlgorithm.py#L1) to main.py).
-4. Add an Issue to the [Tutorials repo](https://github.com/QuantConnect/Tutorials/issues) ([example](https://github.com/QuantConnect/Tutorials/issues/277)).
-5. Add @alexcatarino as a [collaborator](https://www.quantconnect.com/blog/collaborating-in-quantconnect/) to the project.
-6. Publish a strategy write-up in the Slack channel and wait for approval (see [Strategy Library](https://www.quantconnect.com/tutorials/strategy-library/strategy-library) for examples).
-7. Convert the strategy write-up to HTML form ([examples](https://github.com/QuantConnect/Tutorials/tree/master/04%20Strategy%20Library)).
-8. Make PR (following the [Contributor's Guidelines](https://github.com/QuantConnect/Lean/blob/master/CONTRIBUTING.md)):
- - If the write-up includes images, upload them [here](https://www.quantconnect.com/admin/cdnUpload).
- - Add summary HTML files to [Strategy Library directory](https://github.com/QuantConnect/Tutorials/tree/master/04%20Strategy%20Library). If it's a non-Quantpedia strategy, set the ID number (in the directory name) to the next available after 1023.
- - If the strategy is from Quantpedia, add strategy ID and backtest ID to [quantpedia.json](https://github.com/QuantConnect/Tutorials/blob/master/quantpedia.json).
- - Add strategy metadata to [this file](https://github.com/QuantConnect/Tutorials/blob/master/04%20Strategy%20Library/00%20Strategy%20Library/01%20Strategy%20Library.php) (Currently semi-sorted by Quantpedia strategy ID).
-9. After the PR is merged, send @jaredbroad the URL and a 1-sentence summary of what the paper/strategy is about and post the strategy to the forum with the backtest of the algorithm and a short summary of the project ([example](https://www.quantconnect.com/forum/discussion/8608/strategy-library-addition-residual-momentum/p1)).
+
+To publish a strategy to our [Strategy Library](https://www.quantconnect.com/tutorials/strategy-library/strategy-library), follow the steps on the [documentation page](https://www.quantconnect.com/docs/v2/writing-algorithms/strategy-library#03-Contribute-Tutorials)
+
+## New Tutorial Requests and Edits ##
+
+Please submit new tutorial requests as an issue to the [Tutorials][5] repository. Before submitting an issue please read others to ensure it is not a duplicate. Edits and fixes for clarity are warmly welcomed!
[1]: https://www.quantconnect.com/tutorials "Tutorials Viewer"
[2]: https://www.quantconnect.com/lean/docs "Lean Documentation"
[3]: https://github.com/QuantConnect/Lean/archive/master.zip
[4]: https://github.com/QuantConnect/Lean
[5]: https://github.com/QuantConnect/Tutorials/issues
-[6]: https://groups.google.com/forum/#!forum/lean-engine
[7]: https://github.com/QuantConnect/Lean/blob/master/CONTRIBUTING.md
[8]: https://www.quantconnect.com/slack
From 67580984b715b02d829840831b8bc487f29c7213 Mon Sep 17 00:00:00 2001
From: Gustavo Aviles
Date: Wed, 15 Jun 2022 17:35:12 -0700
Subject: [PATCH 26/27] Update backtest embed url.
---
.../05 \347\256\227\346\263\225.cn.html" | 2 +-
.../06 Algorithm.html | 2 +-
.../06 \347\256\227\346\263\225.cn.html" | 4 +--
.../04 Algorithm.html | 4 +--
.../05 Algorithm.html | 2 +-
.../06 Algorithm.html | 2 +-
.../06 \347\256\227\346\263\225.cn.html" | 2 +-
.../05 Algorithm.html | 2 +-
.../04 \347\256\227\346\263\225.cn.html" | 2 +-
.../03 Algorithm.html | 2 +-
.../03 \347\256\227\346\263\225.cn.html" | 2 +-
.../03 Algorithm.html | 2 +-
.../04 Algorithm.html | 2 +-
.../113 January Barometer/03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../13 Asset Class Momentum/03 Algorithm.html | 2 +-
.../14 Sector Momentum/03 Algorithm.html | 2 +-
.../15 Short Term Reversal/03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../16 Overnight Anomaly/03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 \347\256\227\346\263\225.cn.html" | 2 +-
.../17 Forex Momentum/03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../20 Forex Carry Trade/03 Algorithm.html | 2 +-
.../03 \347\256\227\346\263\225.cn.html" | 2 +-
.../03 Algorithm.html | 2 +-
.../04 Algorithm.html | 4 +--
.../04 \347\256\227\346\263\225.cn.html" | 4 +--
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 4 +--
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../32 Gold Market Timing/03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 \347\256\227\346\263\225.cn.html" | 2 +-
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../03 Algorithm.html | 2 +-
.../83 Pre-Holiday Effect/03 Algorithm.html | 2 +-
.../06 Algorithm.html | 18 ++++++-------
.../13 Market Risk/06 Algorithm.html | 26 +++++++++----------
.../05 Algorithm.html | 2 +-
.../05 Algorithm.html | 2 +-
.../01 Covered Call/04 Algorithm.html | 4 +--
.../02 Bull Call Spread/04 Algorithm.html | 4 +--
.../03 Long Straddle/04 Algorithm.html | 4 +--
.../04 Long Strangle/04 Algorithm.html | 4 +--
.../05 Butterfly Spread/04 Algorithm.html | 4 +--
.../06 Iron Condor/04 Algorithm.html | 4 +--
.../07 Iron Butterfly/04 Algorithm.html | 4 +--
.../08 Protective Collar/04 Algorithm.html | 4 +--
65 files changed, 98 insertions(+), 98 deletions(-)
diff --git "a/04 Strategy Library/01 CAPM Alpha Ranking Strategy on Dow 30 Companies/05 \347\256\227\346\263\225.cn.html" "b/04 Strategy Library/01 CAPM Alpha Ranking Strategy on Dow 30 Companies/05 \347\256\227\346\263\225.cn.html"
index 1f296ed..4a79e84 100644
--- "a/04 Strategy Library/01 CAPM Alpha Ranking Strategy on Dow 30 Companies/05 \347\256\227\346\263\225.cn.html"
+++ "b/04 Strategy Library/01 CAPM Alpha Ranking Strategy on Dow 30 Companies/05 \347\256\227\346\263\225.cn.html"
@@ -4,6 +4,6 @@
-
+
diff --git a/04 Strategy Library/02 Combining Mean Reversion and Momentum in Forex Market/06 Algorithm.html b/04 Strategy Library/02 Combining Mean Reversion and Momentum in Forex Market/06 Algorithm.html
index 5c357f4..9717146 100755
--- a/04 Strategy Library/02 Combining Mean Reversion and Momentum in Forex Market/06 Algorithm.html
+++ b/04 Strategy Library/02 Combining Mean Reversion and Momentum in Forex Market/06 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git "a/04 Strategy Library/03 Pairs Trading-Copula vs Cointegration/06 \347\256\227\346\263\225.cn.html" "b/04 Strategy Library/03 Pairs Trading-Copula vs Cointegration/06 \347\256\227\346\263\225.cn.html"
index 932854a..c5d9f52 100644
--- "a/04 Strategy Library/03 Pairs Trading-Copula vs Cointegration/06 \347\256\227\346\263\225.cn.html"
+++ "b/04 Strategy Library/03 Pairs Trading-Copula vs Cointegration/06 \347\256\227\346\263\225.cn.html"
@@ -4,7 +4,7 @@
-
+
@@ -14,6 +14,6 @@
-
+
diff --git a/04 Strategy Library/04 The Dynamic Breakout II Strategy/04 Algorithm.html b/04 Strategy Library/04 The Dynamic Breakout II Strategy/04 Algorithm.html
index 58173b8..3358861 100755
--- a/04 Strategy Library/04 The Dynamic Breakout II Strategy/04 Algorithm.html
+++ b/04 Strategy Library/04 The Dynamic Breakout II Strategy/04 Algorithm.html
@@ -4,7 +4,7 @@
diff --git a/04 Strategy Library/07 Intraday Dynamic Pairs Trading using Correlation and Cointegration Approach/06 Algorithm.html b/04 Strategy Library/07 Intraday Dynamic Pairs Trading using Correlation and Cointegration Approach/06 Algorithm.html
index 69b6365..3d55776 100755
--- a/04 Strategy Library/07 Intraday Dynamic Pairs Trading using Correlation and Cointegration Approach/06 Algorithm.html
+++ b/04 Strategy Library/07 Intraday Dynamic Pairs Trading using Correlation and Cointegration Approach/06 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git "a/04 Strategy Library/07 Intraday Dynamic Pairs Trading using Correlation and Cointegration Approach/06 \347\256\227\346\263\225.cn.html" "b/04 Strategy Library/07 Intraday Dynamic Pairs Trading using Correlation and Cointegration Approach/06 \347\256\227\346\263\225.cn.html"
index 69b6365..3d55776 100644
--- "a/04 Strategy Library/07 Intraday Dynamic Pairs Trading using Correlation and Cointegration Approach/06 \347\256\227\346\263\225.cn.html"
+++ "b/04 Strategy Library/07 Intraday Dynamic Pairs Trading using Correlation and Cointegration Approach/06 \347\256\227\346\263\225.cn.html"
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/08 The Momentum Strategy Based on the Low Frequency Component of Forex Market/05 Algorithm.html b/04 Strategy Library/08 The Momentum Strategy Based on the Low Frequency Component of Forex Market/05 Algorithm.html
index 03b3ba2..f9505bd 100755
--- a/04 Strategy Library/08 The Momentum Strategy Based on the Low Frequency Component of Forex Market/05 Algorithm.html
+++ b/04 Strategy Library/08 The Momentum Strategy Based on the Low Frequency Component of Forex Market/05 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git "a/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/04 \347\256\227\346\263\225.cn.html" "b/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/04 \347\256\227\346\263\225.cn.html"
index bcf0bc2..d1a72fa 100644
--- "a/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/04 \347\256\227\346\263\225.cn.html"
+++ "b/04 Strategy Library/09 Stock Selection Strategy Based on Fundamental Factors/04 \347\256\227\346\263\225.cn.html"
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/100 Trading with WTI BRENT Spread/03 Algorithm.html b/04 Strategy Library/100 Trading with WTI BRENT Spread/03 Algorithm.html
index 15151d8..ccc8b22 100644
--- a/04 Strategy Library/100 Trading with WTI BRENT Spread/03 Algorithm.html
+++ b/04 Strategy Library/100 Trading with WTI BRENT Spread/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git "a/04 Strategy Library/100 Trading with WTI BRENT Spread/03 \347\256\227\346\263\225.cn.html" "b/04 Strategy Library/100 Trading with WTI BRENT Spread/03 \347\256\227\346\263\225.cn.html"
index 15151d8..ccc8b22 100644
--- "a/04 Strategy Library/100 Trading with WTI BRENT Spread/03 \347\256\227\346\263\225.cn.html"
+++ "b/04 Strategy Library/100 Trading with WTI BRENT Spread/03 \347\256\227\346\263\225.cn.html"
@@ -1,6 +1,6 @@
diff --git a/04 Strategy Library/11 Fundamental Factor Long Short Strategy/04 Algorithm.html b/04 Strategy Library/11 Fundamental Factor Long Short Strategy/04 Algorithm.html
index 53170f5..b8d9c7d 100755
--- a/04 Strategy Library/11 Fundamental Factor Long Short Strategy/04 Algorithm.html
+++ b/04 Strategy Library/11 Fundamental Factor Long Short Strategy/04 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/113 January Barometer/03 Algorithm.html b/04 Strategy Library/113 January Barometer/03 Algorithm.html
index be69ba3..e85f53d 100644
--- a/04 Strategy Library/113 January Barometer/03 Algorithm.html
+++ b/04 Strategy Library/113 January Barometer/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/114 January Effect in Stocks/03 Algorithm.html b/04 Strategy Library/114 January Effect in Stocks/03 Algorithm.html
index f94dcba..6dc92eb 100644
--- a/04 Strategy Library/114 January Effect in Stocks/03 Algorithm.html
+++ b/04 Strategy Library/114 January Effect in Stocks/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/12 Asset Class Trend Following/03 Algorithm.html b/04 Strategy Library/12 Asset Class Trend Following/03 Algorithm.html
index ca04542..77b7892 100644
--- a/04 Strategy Library/12 Asset Class Trend Following/03 Algorithm.html
+++ b/04 Strategy Library/12 Asset Class Trend Following/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/125 12 Month Cycle in Cross-Section of Stocks Returns/03 Algorithm.html b/04 Strategy Library/125 12 Month Cycle in Cross-Section of Stocks Returns/03 Algorithm.html
index 6189f9c..e7aa2b2 100644
--- a/04 Strategy Library/125 12 Month Cycle in Cross-Section of Stocks Returns/03 Algorithm.html
+++ b/04 Strategy Library/125 12 Month Cycle in Cross-Section of Stocks Returns/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/13 Asset Class Momentum/03 Algorithm.html b/04 Strategy Library/13 Asset Class Momentum/03 Algorithm.html
index 0e5258c..d001aad 100644
--- a/04 Strategy Library/13 Asset Class Momentum/03 Algorithm.html
+++ b/04 Strategy Library/13 Asset Class Momentum/03 Algorithm.html
@@ -1,6 +1,6 @@
diff --git a/04 Strategy Library/15 Short Term Reversal/03 Algorithm.html b/04 Strategy Library/15 Short Term Reversal/03 Algorithm.html
index 09e4c6f..1970b93 100644
--- a/04 Strategy Library/15 Short Term Reversal/03 Algorithm.html
+++ b/04 Strategy Library/15 Short Term Reversal/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/155 Momentum and Reversal Combined with Volatility Effect in Stocks/03 Algorithm.html b/04 Strategy Library/155 Momentum and Reversal Combined with Volatility Effect in Stocks/03 Algorithm.html
index e3a87f0..41faf63 100644
--- a/04 Strategy Library/155 Momentum and Reversal Combined with Volatility Effect in Stocks/03 Algorithm.html
+++ b/04 Strategy Library/155 Momentum and Reversal Combined with Volatility Effect in Stocks/03 Algorithm.html
@@ -1,6 +1,6 @@
diff --git a/04 Strategy Library/162 Momentum Effect in Stocks in Small Portfolios/03 Algorithm.html b/04 Strategy Library/162 Momentum Effect in Stocks in Small Portfolios/03 Algorithm.html
index 6bbcd8e..219c782 100644
--- a/04 Strategy Library/162 Momentum Effect in Stocks in Small Portfolios/03 Algorithm.html
+++ b/04 Strategy Library/162 Momentum Effect in Stocks in Small Portfolios/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git "a/04 Strategy Library/162 Momentum Effect in Stocks in Small Portfolios/03 \347\256\227\346\263\225.cn.html" "b/04 Strategy Library/162 Momentum Effect in Stocks in Small Portfolios/03 \347\256\227\346\263\225.cn.html"
index 6bbcd8e..219c782 100644
--- "a/04 Strategy Library/162 Momentum Effect in Stocks in Small Portfolios/03 \347\256\227\346\263\225.cn.html"
+++ "b/04 Strategy Library/162 Momentum Effect in Stocks in Small Portfolios/03 \347\256\227\346\263\225.cn.html"
@@ -1,6 +1,6 @@
diff --git a/04 Strategy Library/207 Value Effect within Countries/03 Algorithm.html b/04 Strategy Library/207 Value Effect within Countries/03 Algorithm.html
index b581b49..f2180a0 100644
--- a/04 Strategy Library/207 Value Effect within Countries/03 Algorithm.html
+++ b/04 Strategy Library/207 Value Effect within Countries/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/22 Momentum Effect in Country Equity Indexes/04 Algorithm.html b/04 Strategy Library/22 Momentum Effect in Country Equity Indexes/04 Algorithm.html
index 37631d8..1f5050c 100644
--- a/04 Strategy Library/22 Momentum Effect in Country Equity Indexes/04 Algorithm.html
+++ b/04 Strategy Library/22 Momentum Effect in Country Equity Indexes/04 Algorithm.html
@@ -2,13 +2,13 @@
The Momentum Effect
-
+
Equal Weighted Benchmark
-
+
diff --git "a/04 Strategy Library/22 Momentum Effect in Country Equity Indexes/04 \347\256\227\346\263\225.cn.html" "b/04 Strategy Library/22 Momentum Effect in Country Equity Indexes/04 \347\256\227\346\263\225.cn.html"
index cd34f0c..7078bbf 100644
--- "a/04 Strategy Library/22 Momentum Effect in Country Equity Indexes/04 \347\256\227\346\263\225.cn.html"
+++ "b/04 Strategy Library/22 Momentum Effect in Country Equity Indexes/04 \347\256\227\346\263\225.cn.html"
@@ -2,13 +2,13 @@
diff --git a/04 Strategy Library/23 Mean Reversion Effect in Country Equity Indexes/03 Algorithm.html b/04 Strategy Library/23 Mean Reversion Effect in Country Equity Indexes/03 Algorithm.html
index 547579a..2b216a7 100644
--- a/04 Strategy Library/23 Mean Reversion Effect in Country Equity Indexes/03 Algorithm.html
+++ b/04 Strategy Library/23 Mean Reversion Effect in Country Equity Indexes/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/24 Liquidity Effect in Stocks/03 Algorithm.html b/04 Strategy Library/24 Liquidity Effect in Stocks/03 Algorithm.html
index 5041f10..15edb83 100644
--- a/04 Strategy Library/24 Liquidity Effect in Stocks/03 Algorithm.html
+++ b/04 Strategy Library/24 Liquidity Effect in Stocks/03 Algorithm.html
@@ -1,6 +1,6 @@
diff --git a/04 Strategy Library/29 Term Structure Effect in Commodities/03 Algorithm.html b/04 Strategy Library/29 Term Structure Effect in Commodities/03 Algorithm.html
index ada8627..f820ca9 100644
--- a/04 Strategy Library/29 Term Structure Effect in Commodities/03 Algorithm.html
+++ b/04 Strategy Library/29 Term Structure Effect in Commodities/03 Algorithm.html
@@ -3,7 +3,7 @@
-
+
@@ -11,7 +11,7 @@
-
+
diff --git a/04 Strategy Library/30 Momentum Effect Combined with Term Structure in Commodities/03 Algorithm.html b/04 Strategy Library/30 Momentum Effect Combined with Term Structure in Commodities/03 Algorithm.html
index 91052ac..b781228 100644
--- a/04 Strategy Library/30 Momentum Effect Combined with Term Structure in Commodities/03 Algorithm.html
+++ b/04 Strategy Library/30 Momentum Effect Combined with Term Structure in Commodities/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/31 Book-to-Market Value Anomaly/03 Algorithm.html b/04 Strategy Library/31 Book-to-Market Value Anomaly/03 Algorithm.html
index e0ed93e..9029e2c 100644
--- a/04 Strategy Library/31 Book-to-Market Value Anomaly/03 Algorithm.html
+++ b/04 Strategy Library/31 Book-to-Market Value Anomaly/03 Algorithm.html
@@ -1,6 +1,6 @@
diff --git a/04 Strategy Library/34 Momentum-Short Term Reversal Strategy/03 Algorithm.html b/04 Strategy Library/34 Momentum-Short Term Reversal Strategy/03 Algorithm.html
index a38d444..b3b0694 100644
--- a/04 Strategy Library/34 Momentum-Short Term Reversal Strategy/03 Algorithm.html
+++ b/04 Strategy Library/34 Momentum-Short Term Reversal Strategy/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/36 Sentiment and Style Rotation Effect in Stocks/03 Algorithm.html b/04 Strategy Library/36 Sentiment and Style Rotation Effect in Stocks/03 Algorithm.html
index 9af8464..cff2414 100644
--- a/04 Strategy Library/36 Sentiment and Style Rotation Effect in Stocks/03 Algorithm.html
+++ b/04 Strategy Library/36 Sentiment and Style Rotation Effect in Stocks/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git "a/04 Strategy Library/36 Sentiment and Style Rotation Effect in Stocks/03 \347\256\227\346\263\225.cn.html" "b/04 Strategy Library/36 Sentiment and Style Rotation Effect in Stocks/03 \347\256\227\346\263\225.cn.html"
index 9af8464..cff2414 100644
--- "a/04 Strategy Library/36 Sentiment and Style Rotation Effect in Stocks/03 \347\256\227\346\263\225.cn.html"
+++ "b/04 Strategy Library/36 Sentiment and Style Rotation Effect in Stocks/03 \347\256\227\346\263\225.cn.html"
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/37 Momentum and State of Market Filters/03 Algorithm.html b/04 Strategy Library/37 Momentum and State of Market Filters/03 Algorithm.html
index c07b1c7..926770b 100644
--- a/04 Strategy Library/37 Momentum and State of Market Filters/03 Algorithm.html
+++ b/04 Strategy Library/37 Momentum and State of Market Filters/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/40 Pairs Trading with Country ETFs/03 Algorithm.html b/04 Strategy Library/40 Pairs Trading with Country ETFs/03 Algorithm.html
index 7cf2e86..36343ed 100644
--- a/04 Strategy Library/40 Pairs Trading with Country ETFs/03 Algorithm.html
+++ b/04 Strategy Library/40 Pairs Trading with Country ETFs/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/58 VIX Predicts Stock Index Returns/03 Algorithm.html b/04 Strategy Library/58 VIX Predicts Stock Index Returns/03 Algorithm.html
index f8ca3b6..529a2d1 100644
--- a/04 Strategy Library/58 VIX Predicts Stock Index Returns/03 Algorithm.html
+++ b/04 Strategy Library/58 VIX Predicts Stock Index Returns/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/61 Lunar Cycle in Equity Market/03 Algorithm.html b/04 Strategy Library/61 Lunar Cycle in Equity Market/03 Algorithm.html
index 55f69ca..8caed63 100644
--- a/04 Strategy Library/61 Lunar Cycle in Equity Market/03 Algorithm.html
+++ b/04 Strategy Library/61 Lunar Cycle in Equity Market/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/66 Combining Momentum Effect with Volume/03 Algorithm.html b/04 Strategy Library/66 Combining Momentum Effect with Volume/03 Algorithm.html
index 3956745..57f98de 100644
--- a/04 Strategy Library/66 Combining Momentum Effect with Volume/03 Algorithm.html
+++ b/04 Strategy Library/66 Combining Momentum Effect with Volume/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/71 Short Term Reversal with Futures/03 Algorithm.html b/04 Strategy Library/71 Short Term Reversal with Futures/03 Algorithm.html
index 430008f..d3f5c48 100644
--- a/04 Strategy Library/71 Short Term Reversal with Futures/03 Algorithm.html
+++ b/04 Strategy Library/71 Short Term Reversal with Futures/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/77 Beta Factors in Stocks/03 Algorithm.html b/04 Strategy Library/77 Beta Factors in Stocks/03 Algorithm.html
index c9839cd..91f1e5a 100644
--- a/04 Strategy Library/77 Beta Factors in Stocks/03 Algorithm.html
+++ b/04 Strategy Library/77 Beta Factors in Stocks/03 Algorithm.html
@@ -1,6 +1,6 @@
-
+
diff --git a/04 Strategy Library/78 Beta Factor in Country Equity Indexes/03 Algorithm.html b/04 Strategy Library/78 Beta Factor in Country Equity Indexes/03 Algorithm.html
index 36e3092..0447f1a 100644
--- a/04 Strategy Library/78 Beta Factor in Country Equity Indexes/03 Algorithm.html
+++ b/04 Strategy Library/78 Beta Factor in Country Equity Indexes/03 Algorithm.html
@@ -1,6 +1,6 @@
diff --git a/05 Introduction to Financial Python[]/12 Modern Portfolio Theory/06 Algorithm.html b/05 Introduction to Financial Python[]/12 Modern Portfolio Theory/06 Algorithm.html
index 8d6082c..309e3c2 100755
--- a/05 Introduction to Financial Python[]/12 Modern Portfolio Theory/06 Algorithm.html
+++ b/05 Introduction to Financial Python[]/12 Modern Portfolio Theory/06 Algorithm.html
@@ -1,9 +1,9 @@
-
- Mean-variance analysis is used to optimize portfolios with several strategies. Here we treat Dow 30 stocks as strategy and designed an algorithm to test mean-variance analysis:
-
-
-
-
-
-
-
+
+ Mean-variance analysis is used to optimize portfolios with several strategies. Here we treat Dow 30 stocks as strategy and designed an algorithm to test mean-variance analysis:
+
+
+
+
+
+
+
diff --git a/05 Introduction to Financial Python[]/13 Market Risk/06 Algorithm.html b/05 Introduction to Financial Python[]/13 Market Risk/06 Algorithm.html
index 3069322..64474c1 100755
--- a/05 Introduction to Financial Python[]/13 Market Risk/06 Algorithm.html
+++ b/05 Introduction to Financial Python[]/13 Market Risk/06 Algorithm.html
@@ -1,13 +1,13 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/06 Introduction to Options[]/02 QuantConnect Options API/05 Algorithm.html b/06 Introduction to Options[]/02 QuantConnect Options API/05 Algorithm.html
index 64b1d35..e485feb 100755
--- a/06 Introduction to Options[]/02 QuantConnect Options API/05 Algorithm.html
+++ b/06 Introduction to Options[]/02 QuantConnect Options API/05 Algorithm.html
@@ -4,6 +4,6 @@
-
+
diff --git a/06 Introduction to Options[]/03 Put-Call Parity and Arbitrage Strategies/05 Algorithm.html b/06 Introduction to Options[]/03 Put-Call Parity and Arbitrage Strategies/05 Algorithm.html
index 12d6ce9..b196a80 100755
--- a/06 Introduction to Options[]/03 Put-Call Parity and Arbitrage Strategies/05 Algorithm.html
+++ b/06 Introduction to Options[]/03 Put-Call Parity and Arbitrage Strategies/05 Algorithm.html
@@ -1,6 +1,6 @@
From 144ea92bd184b1cd91f0af35c8aa288e97d1ed5f Mon Sep 17 00:00:00 2001
From: avorobiev
Date: Mon, 28 Jul 2025 17:58:07 +0300
Subject: [PATCH 27/27] Correct intrinsic and time value calculation in AAPL
example
---
.../01 General Features of Options/04 The Value of Options.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/06 Introduction to Options[]/01 General Features of Options/04 The Value of Options.html b/06 Introduction to Options[]/01 General Features of Options/04 The Value of Options.html
index f0877cc..b392bbd 100755
--- a/06 Introduction to Options[]/01 General Features of Options/04 The Value of Options.html
+++ b/06 Introduction to Options[]/01 General Features of Options/04 The Value of Options.html
@@ -12,5 +12,5 @@
\[Time Value= Premium-Intrinsic Value\]
-For example, an AAPL call option contract which expires after 10 days has strike $143 and premium $10. now the market price of AAPL is $160. The intrinsic value of this contract is 160-143=$17, the time value is 17-10=$7. Although the intrinsic value of OTM and ATM options is zero, they have time values if they still have a certain amount of time until the option expires so for OTM and ATM options, their premiums equal their time values.
+For example, an AAPL call option contract which expires after 10 days has strike $143 and premium $10. now the market price of AAPL is $150. The intrinsic value of this contract is 150-143=$7, the time value is 10-7=$3. Although the intrinsic value of OTM and ATM options is zero, they have time values if they still have a certain amount of time until the option expires so for OTM and ATM options, their premiums equal their time values.