IBKR Quant Blog


1 2 3 4 5 2 59


Quant

How can you work faster in R Studio? Do you really want to know? - Part II


By Krzysztof Sprycha,  Appsilon Data Science
 

Code completion

A suggestion list will pop up as you type or can be accessed manually by either pressing Tab or Ctrl + Space. You can adjust those settings in Global Options ->  Code -> Completion.  To fill in the suggested phrase, you have to press either Tab or Enter, pressing Ctrl + Space with auto-completion list open will close it. You can navigate through the suggestion list with arrows or just hover over the item before filling in.

R Studio

Note: Screenshot of Screencast. Visit Appsilon to see the full demo in R Studio  https://appsilon.com/r-studio-shortcuts-and-tips/

 

Paths

If you need to type a path, you can use file path auto-complete, which can be brought up by pressing the auto-completion shortcut (Tab or Ctrl + Space) from a pair of double or single quotes. 

By default, it starts in your working directory. You can navigate from the root location like in shell console starting with “/”, or step up levels in the directory tree by stacking “../”

 

R Studio

Note: Screenshot of Screencast. Visit Appsilon to see the full demo in R Studio  https://appsilon.com/r-studio-shortcuts-and-tips/

 

In the next installment, Krzysztof will show us how to execute and format the code.

For part I, click here: https://www.interactivebrokers.com/en/index.php?f=25244&vid=23346

 

 

-------------------------------------------

Visit Appsilon Data Science Blog to learn more about R: https://appsilon.com/r-studio-shortcuts-and-tips/

 

About Appsilon  

Our Vision: To discover tomorrow’s applications of data & apply them today. We constantly improve how data is acquired, processed and used. We are driven by using Data Science at the forefront of business, leveraging the potential of the ever increasing amount of data. https://appsilon.com/

 This material is from Appsilon and is being posted with Appsilon’s permission. The views expressed in this material are solely those of the author and/or Appsilon and IBKR is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation to buy, sell or hold such security. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.


23574




Quant

Momentum Factor Investing in 19th Century Imperial Russia


Is momentum data-mined? Why does momentum exist?
Read this research paper review by Wesley Gray, PhD to learn more!

The post ‘Momentum Factor Investing in 19th Century Imperial Russia?’ first appeared on the Alpha Architect Blog 

 

Momentum Factor Investing in 19th Century Imperial Russia

  • William Goetzmann and Siman Huang
  • JFE, forthcoming.
  • A version of this paper can be found here.
     

What are the research questions?

Momentum is often considered the “premier anomaly” because of the large historical excess returns generated by the process.(1) For efficient market hypothesis proponents, momentum has a problem — deriving an exclusively risk-based foundation for momentum is difficult, if not impossible (discussion here). Without a purely risk-based hypothesis, one needs to rely on behavioral theories to understand why momentum returns exist in equilibrium. Of course, with additional theories comes additional problems. First, when one relies on multiple theories, the ability to fit a theory to data is much higher, and researchers often worry that the empirical results from momentum might just be an exceptional case of data-mining. Second, with more theories comes more predictions (often in conflict), which need to be assessed and tested using data.

The authors seeks to address the following questions:

  1. Is momentum data-mined? This paper addresses the data-mining issue by testing a truly unique out-of-sample test of the traditional cross-sectional momentum effect.
  2. Why does momentum exist? The paper addresses alternative theories for “why momentum exists” using a unique laboratory of the St. Petersburg Stock Exchange from January 1865 to July 1914.

 

What are the Academic Insights?

  1. Yes. Momentum effects are very strong in the author’s sample suggesting that prior results are unlikely to be attributable to “data-mining.”
  2. Overreaction.  There is little evidence that momentum effects are driven by the institutional theory (covered here), “crash risk”, or macro-economic sensitivity. The evidence from the paper supports the behavioral theory of overreaction and not underreaction to positive news.

 

Why does it matter?

Momentum is one of the more hotly debated factor anomalies. This paper allows the authors to test competing theories. Visit Alpha Architect to read more about the results.

 


 

  • The views and opinions expressed herein are those of the author and do not necessarily reflect the views of Alpha Architect, its affiliates or its employees. Our full disclosures are available here. Definitions of common statistics used in our analysis are available here (towards the bottom).
  • Join thousands of other readers and subscribe to our blog.
  • This site provides NO information on our value ETFs or our momentum ETFs. Please refer to this site.

 

Alpha Architect empowers investors through education. The company designs affordable active management strategies for Exchange-Traded Funds and Separately Managed Accounts. Visit their website to learn more: https://alphaarchitect.com

This material is from Alpha Architect and is being posted with Alpha Architect 's permission. The views expressed in this material are solely those of the author and/or Alpha Architect and IBKR is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation to buy, sell or hold such security. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.


23600




Quant

Random Forest Algorithm In Trading Using Python - Part I


In this blog, we will be covering:

  • What are Decision Trees?
  • What is a Random Forest?
  • Working of Random Forest
  • Python Code for Random Forest
  • Advantages and Disadvantages of Random Forest

 

Before jumping directly to Random Forests, let’s first get a brief idea about decision trees and how they work.

What are Decision Trees?

Decision trees, as the name suggests, have a hierarchical or tree-like structure with branches that act as nodes. We can arrive at a certain decision by traversing through these nodes, which are based on the responses garnered from to the parameters related to the nodes.

However, decision trees tend to suffer from a problem of “overfitting”. Overfitting is increasing the specificity within the tree so that one can reach a certain conclusion by adding more and more nodes in the tree. This increases the depth of the tree and makes it more complex.

What is a Random Forest?

A Random Forest is a supervised classification machine learning algorithm which uses ensemble method. Simply put, a Random Forest is made up of numerous decision trees and helps to tackle the problem of overfitting in decision trees. These decision trees are randomly constructed by selecting random features from the given dataset.

A Random Forest arrives at a decision or prediction based on the maximum number of votes received from the decision trees.

Working of Random Forest

Random forests are based on ensemble learning techniques. Ensemble simply means a group or a collection. In this case, a collection of decision treesis referred to as Random Forest. The accuracy of ensemble models is better than the accuracy of individual models, as it compiles the results from the individual models and provides a final outcome.

How to select features from the dataset to construct decision trees for the Random Forest?

Features are selected randomly using a method known as bootstrap aggregating or bagging. From the set of features available in the dataset, a number of training subsets are created by choosing random features with replacement. What this means is that one feature may be repeated in different training subsets at the same time.

For example, if a dataset contains 20 features, and subsets of 5 features are to be selected to construct different decision trees, then these 5 features will be selected randomly, and any feature can be a part of more than one subset. This ensures randomness, making fewer correlations between the trees, thus overcoming the problem of overfitting.

Once the features are selected, the trees are constructed based on the best split. Each tree gives an output, which is considered as a ‘vote’ from that tree to the given output. The output that receives the maximum ‘votes’ is chosen by the Random Forest as the final output/result, or in case of continuous variables, the average of all the outputs is considered as the final output.

Quant

 

For example, in the above diagram, we can observe that each decision tree has voted or predicted a specific class. The final output or class selected by the Random Forest will be the Class N, as it has majority votes or is the predicted output by two out of the four decision trees.

Stay tuned for the next installment in this series, in which Shagufta demonstrates the Python Code For Random Forest!

 

Learn more QuantInsti here https://www.quantinsti.com

To learn more about Python and R, visit QuantInsti website and their educational offerings at their Executive Programme in Algorithmic Trading (EPAT™).

This material is from QuantInsti and is being posted with QuantInsti’s permission. The views expressed in this material are solely those of the author and/or QuantInsti and IBKR is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation to buy, sell or hold such security. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.


23422




Quant

Intro To Hidden Markov Chains - Part I


The Hidden Markov model is a process consisting of two components: an observable component and an unobservable or ‘hidden’ component (van Handel, 2008). Nevertheless, from the observable process, we can extract information about the “hidden” processes. As such, our task is to determine the unobserved process from the observed one.

The Hidden Markov Models (HMM) have two defining properties. (i) It assumes that the observation at the time was generated by some process whose state is hidden from the observer and (ii) it assumes the state of this hidden process satisfies the Markov property. Complex as it may seem to some, one comes naturally to understand HMMs, once one understands what a Markov Model is. We will look into these two model components, then consider advanced techniques that help construct these HMMs.

Constructing A Hidden Markov Model

 

The “Hidden Process”

A process is said to have the Markov property if:

For any A S, any value n and for any time value t< t2 < … < tn < tn+1 it is true that

Quant

 

This means that to determine the next state of the process, one can just consider the current state the process is in and ignore everything that has occurred before, as this information is already included in the current state.

We need some properties and definitions that will allow us to help eventually grasp the concept of HMM

  1. Time Homogeneity: this occurs when the probability of moving from a to b is independent of time, i.e., it does not matter how far you are in the process; as long as the processes are going to move from a to b in one step, the probability will be the same throughout. When a process has this property, we say this process is Time Homogenous and if not, time non-homogenous
  2. Though possible to work with infinite states, in our financial context, it suffices to work with a finite amount of states, which are irreducible.
  3. Irreducible States: It is possible to move from any one state to another over a certain number of steps.

 

Quant

 

This probability matrix is such that:

Quant

 

n.b.: these emission probabilities are the main drivers of where next the process may go. From our time homogeneity assumption, we can calculate the probability that the process is in state j after t steps, given it started at I, we multiply the matrix P with itself t times then read off the ijth element of P

Example:

Let us consider two probability transition matrices each with two transition states, one that is Time-Homogeneous and one that is not.

The non-Time-Homogeneous case

Quant

 

Then       Quant   and

 

Quant

 

Here the probability of changing state depends on where you are in time. Contrary to this procedure, a time-homogenous matrix gives constant probabilities that are independent of time.

Quant   On this case  Quant

 

 

In the next post, Bonolo Molopyane will demonstrate a two-state time homogeneous probability matrix.

 

Learn more QuantInsti here https://www.quantinsti.com

To learn more about Python and R, visit QuantInsti website and their educational offerings at their Executive Programme in Algorithmic Trading (EPAT™).

Trading on margin is only for sophisticated investors with high risk tolerance. You may lose more than your initial investment.


This material is from QuantInsti and is being posted with QuantInsti’s permission. The views expressed in this material are solely those of the author and/or QuantInsti and IBKR is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation to buy, sell or hold such security. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.


23517




Quant

qplum - Comparing alpha extraction in ETFs vs individual stocks


In case you missed this presentation on Alpha Generation!, the webinar recording is available on IBKR’s YouTube Channel!

https://youtu.be/U-iL_S1L4ZA

 

Single stocks are often traded based on technical and fundamental analysis. ETFs, on the other hand, are often used for passively following an index. In this webinar, we explore how certain changes in the markets have led to a world where traditional conceptions of passive and active are being turned on their head. We challenge the assumption that ETFs are for passive followers and discuss how the grab for alpha in single stocks is getting more difficult for traditional players.

 

Sponsored by qplum

Speaker: Gaurav Chakravorty, Founder qplum

Trading on margin is only for sophisticated investors with high risk tolerance. You may lose more than your initial investment.

 

The analysis in this material is provided for information only and is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad-based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation by IBKR to buy, sell or hold such investments. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.


23496




1 2 3 4 5 2 59

Disclosures

We appreciate your feedback. If you have any questions or comments about IBKR Quant Blog please contact ibkrquant@ibkr.com.

The material (including articles and commentary) provided on IBKR Quant Blog is offered for informational purposes only. The posted material is NOT a recommendation by Interactive Brokers (IB) that you or your clients should contract for the services of or invest with any of the independent advisors or hedge funds or others who may post on IBKR Quant Blog or invest with any advisors or hedge funds. The advisors, hedge funds and other analysts who may post on IBKR Quant Blog are independent of IB and IB does not make any representations or warranties concerning the past or future performance of these advisors, hedge funds and others or the accuracy of the information they provide. Interactive Brokers does not conduct a "suitability review" to make sure the trading of any advisor or hedge fund or other party is suitable for you.

Securities or other financial instruments mentioned in the material posted are not suitable for all investors. The material posted does not take into account your particular investment objectives, financial situations or needs and is not intended as a recommendation to you of any particular securities, financial instruments or strategies. Before making any investment or trade, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice. Past performance is no guarantee of future results.

Any information provided by third parties has been obtained from sources believed to be reliable and accurate; however, IB does not warrant its accuracy and assumes no responsibility for any errors or omissions.

Any information posted by employees of IB or an affiliated company is based upon information that is believed to be reliable. However, neither IB nor its affiliates warrant its completeness, accuracy or adequacy. IB does not make any representations or warranties concerning the past or future performance of any financial instrument. By posting material on IB Quant Blog, IB is not representing that any particular financial instrument or trading strategy is appropriate for you.