Saturday, May 27, 2023

Short term Trading

In short-term trading take what the market gives. Sometimes it's small profits or losses. Occasionally, few windfall trades make a difference. Strategy automatioensures consistent execution and helps capture those opportunities. Stay disciplined, manage risk. #TradingStrategies

When engaging in short-term trading or applying mean reversion setups, it is common to take what the market gives, which can result in small profits or losses. However, occasionally, you may experience windfall profits that can make a significant difference to your overall trading performance.

Consistency is indeed key when trading these strategies, and many traders opt to automate their strategies to ensure consistent execution. Automating your trading system allows you to remove emotional biases and ensures that your strategy is executed according to pre-defined rules. It also enables you to take advantage of opportunities in the market even when you are not actively monitoring it.

By consistently trading your automated strategy, you increase your chances of capturing those few very good trades that can significantly impact your profitability. These trades can help offset smaller losses and generate overall positive returns. However, it's important to note that no trading strategy can guarantee profits, and risk management and thorough backtesting are essential to evaluate the viability of any trading approach.

@QuantScraper

Wednesday, May 24, 2023

Backtesting Strategies

The Emini S&P Future has printed 5 consecutive times a Down day on Tuesday.  Does it have statistical relevance?

Since 2000 following are results selling the next day:




Not very good......
Regardless the result what are considerations to make sure you are following a reasonable process to assess the relevance of your findings? Let's see how chatgpt answers to the question.

"Determining the statistical relevance of a pattern, such as five consecutive down Tuesdays in the stock market, requires a rigorous statistical analysis. It involves examining historical data, conducting hypothesis testing, and considering various factors such as sample size, significance levels, and the presence of confounding variables".

"It's important to note that isolated patterns or observations, without a solid statistical analysis, may not have significant predictive power. Stock market movements are influenced by a wide range of complex factors, including economic indicators, market sentiment, geopolitical events, and investor behavior. Therefore, relying solely on a short-term pattern like consecutive down Tuesdays may not provide reliable predictions or trading strategies".

"To determine the statistical relevance of a pattern like five consecutive down Tuesdays in the stock market, we need to conduct a hypothesis test. Here's a step-by-step approach:
- Formulate the null hypothesis (H0): The occurrence of 5 consecutive down
   Tuesdays in the stock market is due to random chance and has no predictive
    significance.
 - Collect historical data: Gather a dataset containing historical stock market returns
    for Tuesdays over a significant period. Ensure the data is reliable, consistent,
    and covers various market conditions.
- Define the statistical test: Select an appropriate statistical test based on the
   characteristics of the data. One potential test could be a binomial test or a runs
   test, depending on the specific nature of the data.
- Set the significance level (alpha): Determine the acceptable level of risk for
    rejecting the null hypothesis. Commonly used values are 0.05 or 0.01,
    representing a 5% or 1% chance of making a Type I error, respectively.
- Calculate the p-value: Perform the statistical test using the collected data and
   calculate the p-value. The p-value represents the probability of observing the
   pattern (or a more extreme one) assuming the null hypothesis is true.
 - Evaluate the results: Compare the calculated p-value with the significance level. If
   the p-value is smaller than the significance level, we reject the null hypothesis,
   indicating that the pattern is statistically significant. If the p-value is larger than the
   significance level, we fail to reject the null hypothesis, suggesting the pattern may
   be due to chance.
- Consider additional factors: It's crucial to consider the broader context and avoid
   overfitting. Assess whether other variables, such as economic indicators or
   seasonal effects, may be influencing the observed pattern".

Remember, statistical significance does not guarantee practical significance or future predictive power. Even if the pattern is statistically significant, it's essential to conduct further analysis, validate results using out-of-sample data, and consider the limitations and assumptions of the statistical test. These considerations make sense and actually the result provided by my test have no significance in my view mainly because they are based on a very limited number of observations, p-value and T-test are not good and I have not considered using out of sample data.


Tuesday, May 23, 2023

Software Tool: Python

Backtesting: building your tool offers flexibility and it is cost-effective. You're in control, learning valuable skills. Instead commercial platforms bring efficiency, support, and data integration. It's a trade-off based on goals, expertise, and resources. #Backtesting #Python @QuantScraper

Sunday, May 21, 2023

Tradestation: Workspace


I am thrilled with my TradeStation desktop setup!
💻📈 Advanced charting tools, lightning-fast order execution, and a personalized workspace for conquering the futures market. Ready to trade with precision and confidence! 🚀 #TradeStation #TradingTools #FuturesTrader @QuantScraper

I have been using Tradestation for many years now. It has a user friendly environment. The programming language (EasyLanguage) is quite simple to learn. Some advantages of TradeStation desktop setup:

  1. TradeStation's desktop platform offers robust charting capabilities with numerous technical indicators, drawing tools, and analytical features. Traders can perform in-depth market analysis.

  2. The platform allows you to customize your workspace according to your preferences, including layout, colors, and tool placement, enabling you to create a personalized environment.

  3. TradeStation supports automated trading through its proprietary EasyLanguage programming language. You can develop and implement complex trading strategies, backtest them using historical data, and execute trades automatically.

  4. It provides fast and reliable order execution, ensuring that trades are executed swiftly to suit your specific trading strategies.

  5. TradeStation offers access to extensive market data, including real-time quotes, historical data, and market depth information. This wealth of data empowers you to make trading decisions based on up-to-date information.

At QuantScraper we have developed our own tool in Python to backtest strategies at daily and intraday level. We are continuing to work on our sw because it is perfectly customized for our own needs. It can work with any type of data (including alternative data)nand it fits with our trading style. However, I like Tradestation because it is quite reliable, it has decent fees, you have great access to market data (for us mainly futures), it has a nice programming language, you can manage portfolios or scan the market according to specific filters or indicators.


Saturday, May 20, 2023

Again About Discipline and Backtesting

Trading discipline is key! Ignoring rules can lead to costly mistakes. Backtesting is crucial to identify statistically significant patterns and regularities. Stay disciplined, stick to your strategy, and let numbers guide decisions. #Trading #Backtesting @QuantScraper


Thursday, May 18, 2023

Intermarket Pattern - Gold

When Gold Future prints a 10-Days Low and the Emini S&P prints a 10-Days High, since 2019 it has been positive for Gold selling after 1-5 days. See results in the Figure.​


Quantifying intermarket relationships through counting is a valuable approach in the field of quantitative finance. By systematically analyzing and counting certain market phenomena, patterns, or events across different asset classes or markets, traders can gain insights into the interconnectedness and potential dependencies among various markets. This allows for a more comprehensive understanding of market dynamics and can aid in developing effective trading strategies.

Counting techniques can be applied to a wide range of intermarket relationships. For instance, one common application is counting the occurrences of specific price patterns or technical indicators across different markets. By tracking the frequency of these patterns or indicators, traders can identify potential correlations or divergences between markets.

@QuantScraper


Tuesday, May 16, 2023

Small Wins and Trading

 In trading, remember that many small wins are more than often overshadowed by a single big loss that wipes out all the gains. Risk management and discipline are key to long-term success. Don't let short-term victories lull you into complacency. #TradingTips #RiskManagement @QuantScraper

Monday, May 15, 2023

Python: datatable

"Datatable is a Python package for manipulating 2-dimensional tabular data structures (aka data frames). It is close in spirit to pandas or SFrame; however we put specific emphasis on speed and big data support. As the name suggests, the package is closely related to R’s data.table and attempts to mimic its core algorithms and API."

See https://github.com/h2oai/datatable for more details.

Link to website:

datatable 1.0.0



Here is a code snippet often used to load large .CSV files and work in Pandas:

import datatable as dt

df = dt.fread("my_large_file.csv").to_pandas()


5 Signs You’ve Become an Advanced Pandas User Without Even Realizing It



Find below an example of difference in execution time to read a .CSV file using pd.read

and the datatable library:










The datatable library is known for its speed and efficiency in handling large datasets. It provides an alternative to pandas for manipulating tabular data structures while emphasizing speed and big data support. The code snippet provided demonstrates how to load a large CSV file using the datatable library and convert it to a pandas DataFrame.

The advantage of using the datatable library is its optimized algorithms and efficient memory usage, which can significantly reduce the execution time when working with large datasets compared to pandas. This can be particularly beneficial when dealing with big data scenarios where memory constraints and processing speed are crucial.

In the example, the execution time difference between pd.read (pandas) and datatable can be quite remarkable, showcasing the performance advantage of the datatable library for large dataset operations.

It's worth noting that while the datatable library shares similarities with pandas and R's data.table, it may have some differences in terms of syntax and functionality. Therefore, it's important to consult the official documentation and familiarize yourself with the library's specific API when using datatable in your projects.

If you're working with large datasets and performance is a critical factor, exploring the datatable library can be a valuable option. It's recommended to refer to the official documentation and examples provided by the datatable project to leverage its full capabilities.

Sunday, May 14, 2023

Initial Jobless Claims

 Buying the Emini S&P 4 days before the Initial Jobless Claims when the Forecast < Previous data since 2020 has been positive selling after 1-5 days. See results in the Figure.​


          @QuantScraper

Saturday, May 13, 2023

Overfitting

Frustration sets in when overfitting provides results promising on historical data, but that fail in real world. The right balance between complexity and simplicity is key to robust and reliable models. Avoid falling into the trap of over-optimization. #Trading #Backtesting @QuantScraper

Python: cProfile

The cProfile module in Python is used to obtain detailed information about the execution time of different parts of your code. This helps you identify the code portions that consume more time and resources, guiding you in finding potential optimizations.

Here are the steps to use cProfile for code profiling:

  1. Import the cProfile module in your script:
python
import cProfile
  1. Identify the specific part of your code that you want to profile. You can encapsulate the code block within a function to simplify the profiling process.
python
def my_function(): # Code to profile # ...
  1. Wrap the code block you want to profile inside the cProfile.run() function, passing the function name as an argument:
python
def my_function(): # Code to profile # ... cProfile.run('my_function()')
  1. Run your script. Upon execution, cProfile will gather information about the execution time of each function call within my_function().

  2. After execution, a detailed output will be printed, showing the execution time of each called function, the number of calls, and other useful information.

Here's a complete example of using cProfile:

python
import cProfile def my_function(): for i in range(1000000): result = i * 2 print(result) cProfile.run('my_function()')

After running the script, you will see an output similar to this:

sql
4 function calls in 0.058 seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.058 0.058 0.058 0.058 script.py:4(my_function) 1 0.000 0.000 0.058 0.058 {built-in method builtins.exec} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} 1 0.000 0.000 0.000 0.000 {method 'print' of 'builtins.PyCapsule' objects}

The output provides information such as the number of function calls, total execution time (tottime), cumulative execution time (cumtime), and more.

Note that cProfile can provide very detailed and complex output, so it may require some time to analyze and understand the returned information. This helps you identify the code parts that consume the most execution time and focus on areas that may require optimization.

Yahoo Finance Futures Contracts Historical Data

Futures data downloaded from yahoo finance are not adjusted as continuous contracts. When you download futures data from Yahoo Finance or ma...