Skip to content

hajaja/ThaiExpress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ThaiExpress

ThaiExpress is a framework for data processing, back test, paramter review, and real time monitor. ThaiExpress is the Chain of Thai Restaurants.

Future works:

  1. Only three indicator are supported 1 long, 0 no position, -1 short. No numerical position is supported, such as buy 3 contracts of cu.shf today, and close 1 contract tomorrow.
  2. Calendar spread arbitrage, inter-product arbitrage, inter-market arbitrage are not supported. Only trend following strategy is supported.

Prerequisite Packages

  • annaconda (including pandas, numpy, scipy)
  • memory_profiler
  • talib
  • RoyalMoutain
  • CommodityDataBase
  • Dumpling

Package Structure

Common

Utils.py: This contains ALL the parameter, directory, common functions that are used by this package.
Strategy.py: This is the file for back test. Stoploss function is supported.
ParamRange.py: This provides the parametr sweeping range for different strategies.
DumpExcel.py: This defines the file to dump excel with friendly format.

Config

Configurations of logics of different strategies. The most important directory of the package.

TSM

TSM is short for Time Series Momentum. This strategy is following the movement of the market usage:

  • python Config/TSM/TopTSM.py TSM
  • python Weight/TopPortSync.py TSM
  • in ipython, df,s = Utils.funcCalcPort(['TSM'])

TS (More accurate name is XSC, Cross Section Carry)

Carry strategy on commodity trading. TS is short for Term Structure (More accurate name is XSC), because here the contract with the highest discount rate is viewed as the currency with the highest interest rate. usage: python Config/TS/TopTS.py TS

Tech

Tech is short for Technical Analysis. This is in fact a framework for strategies based on technical indicators, such as the DualThrust, DynamicBreakOut, R-Break, etc. UtilsTech.py is a wrapper for different technical analysis models

usage: python Config/Tech/TopTech.py HLMonitor

ML

Config/Tech/ML is a wrapper for the package Dumpling, which defines general wrapper of popular machine learning tools for prediction. SVM, support vector machine
Logistic Regression
Decision Tree

UtilsInterDay.py

MA: moving average crossing signal
BTBreak: bottom/top breaking signal
HL: secondary high/low breaking signal
TSC: time series carry strategy MARUBOZU: sharpe rise/plunge in single day as indicator

UtilsIntraDay.py

DualThrust, DynamicBreakOut, R-Break, FD, Frequency Domain Analysis As ThaiExpress is largely designed for 1day frequency strategies, this type of intra-day strategies are not supported quite well, especially in Weight/TopPortAsync.py

Prepdata

concat.py: This helps to concat the dominant contract from .xlsx file. The .xslx file is stored in /Data.

Data

dailyAll.xlsx: This has two sheets two sheets "ALL" and "Contract".
dailyAll.sql: This is used to query the dailyAll.xlsx from database (provided by WIND)
dailyAllSplit*: These files are splited version of the 10 year data for all commodities. They are splited for size constraint reason. The command to concat these files is "cat Data/dailyAllSplit* >dailyAll10Y.xlsx".

note please remove the '' in the command

SecuDetail.xlsx: This contains the detailed information for each product, such as multiplier, commission, etc.

dfTrendTS_TS2_Max10Min10.pickle: This is for the TS strategy. It contains whether a secu is in the top 10% most discount/premium products. TS2 represents the method to use near contract and dominant contract to determine the discount rate. This file is generated by Config/UtilsTS.py

dfTrendTS_TS3_Quant20.pickle: This is for the TS strategy. It contains whether a secu is in the top 10% most discount/premium products. TS3 represents the method to use near contract and deferred contract to determine the discount rate. This file is generated by Config/Utils.py

1day

This directory contains the pickle file generated by Prepdata/concat.py. It is read in Common/Utils.py

Weight

This directory contains files for attributing weights for different contracts when entering. Currently, two weights-determine modes are supported, including Synchronous and Asynchronous.

Synchronous

TopPortSync.py The weights of all products are adjusted simultaneously in a periodic way. The rebalancing dates are generated in Utils.generateDTTestStartCalendarDay (for TSM) and Utils.generateNthFriday (for TS). Other methods on determining rebalancing dates deserve more efforts.

Asynchronous

TopPortAsync.py
The weights of all products are adjusted separately. Whether cu.shf is rebalanced is only dependent on the price of itself. The principle is to make sure 1 sigma of change of cu.shf only results in 1% change of the portfolio.

Review

TopModelReview.py

A lot parameters are set for each strategy (Detailed parameters can be found in Common/ParamRange.py). As a result, how/when to update these parameters is also important.

Inevitablly, other parameters are used to determine when/how to update the original parameters. Here several new parameters are introduced, including strColumnToSelect, NMonthModelReview, NMonthLookBack.

  1. NMonthModelReview, on 20100101, how many months are used to evaluate different param sets.
  2. NMonthLookBack, after param update in 20100101, how many months before the next update.
  3. strColumnToSelect, what is the desired metric to evaluate a param set is good or not.

Monitor

This directory contains the files for generating real-time monitor based on Excel Wind options. Only TS and TSM are supported.

Example

TSM

  1. Utils.boolMonitor = False
  2. cd TEDir/Data, read sql server by calling daily.sql, the results should be manually written in daily.xlsx
  3. cd TEDir/Prepdata, python concat.py, the generated ExeCommodityFuture.pickle would be dumped into TEDir/Prepdata/1day/
  4. cd TEDir/Config/TSM, python TopTSM.py TSM, the temporary results would be saved in Utils.dirResultPerCase
  5. cd TEDir/Weight/, python TopPortSync.py TSM, the portfolio results would be saved in Utils.dirResultPerCase/strParamSweep/

TS

similar with TSM, except for cd TEDir/Config/TS/ for python TopTS.py TS

Tech

  1. Utils.boolMonitor = False
  2. cd TEDir/Data, read sql server by calling daily.sql, the results should be manually written in daily.xlsx
  3. cd TEDir/Prepdata, python concat.py, the generated ExeCommodityFuture.pickle would be dumped into TEDir/Prepdata/1day/
  4. cd TEDir/Config/Tech, python TopTech.py Dochian, the temporary results would be saved in Utils.dirResultPerCase
  5. cd TEDir/Weight/, python TopPortAsync.py TSM, the portfolio results would be saved in Utils.dirResultPerCase/strParamSweep/

Monitor

  1. set Utils.boolMonitor = True
  2. copy the latest dailyAll.xlsx file to TEDir/Data/dailyAll.xlsx
  3. cd TEDir/Monitor/TSTSM4/, python TopTSTSM4.py, the monitor results would be dumped in TEDir/Monitor/TSTSM4/ . TopTSTSM4.py is actually a script which will complete TSM and TS procedures.

Review

  1. Utils.boolMonitor = False
  2. cd TEDir/Config/TSM, python TopTSM.py TSM_Review, the temporary results would be saved in Utils.dirResultPerCase
  3. cd TEDir/Weight/, python TopPortSync.py TSM_Review, the portfolio results would be saved in Utils.dirResultPerCase/strParamSweep/
  4. cd TEDir/Review/, python TopModelReview.py TSM_Review, result is TSM_Review.xlsx

About

CTA research tools

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages