Top Banner
Trading with open source tools Chia-liang Kao [email protected] OSDC.TW 2009 Taipei
110

Trading With Open Source Tools

Aug 17, 2014

Download

Economy & Finance

clkao

April 18, 2009 OSDC Taipei.

This talk gives an introduction about trading systems. We will walk through the basic concepts by examples. we will also cover various open source tools that you can use for market data analysis, writing strategy, back testing, and finally live trading and system monitoring.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Trading With Open Source Tools

Tradingwith open source tools

Chia-liang [email protected]

OSDC.TW 2009 Taipei

Page 2: Trading With Open Source Tools
Page 3: Trading With Open Source Tools
Page 4: Trading With Open Source Tools
Page 5: Trading With Open Source Tools
Page 6: Trading With Open Source Tools

Caution

Page 7: Trading With Open Source Tools

CautionThere is

ABSOLUTELY NO WARRANTYif you use any of the code or

strategy mentioned in this talk.

Page 8: Trading With Open Source Tools

Presenting.......

Page 9: Trading With Open Source Tools

Presenting.......

The OSDC Trading System

Page 10: Trading With Open Source Tools

Presenting.......

The OSDC Trading System

using dice!

Page 11: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade

Take #1

Page 12: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade

Long Signal

Take #1

Page 13: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade

Long Signal

Take #1 (Random returns 0..5)

Page 14: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade

Long Signal

Take #1

Page 15: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade

Short Signal

Take #1

Page 16: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade

Enters at 08:50

Take #1

Page 17: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade

Take #1

Page 18: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade

Take #1

% perl backtest.pl --start=2001-01-01 --end=2007-12-31 --timeframe 5min --money-management='FixedShares 1'

OSDC1 TX

Page 19: Trading With Open Source Tools

Taiwan Weighted Futures1 point = nt$200

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade

Take #1

% perl backtest.pl --start=2001-01-01 --end=2007-12-31 --timeframe 5min --money-management='FixedShares 1'

OSDC1 TX

Page 20: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade

Take #1

Page 21: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade

Take #1

-----------------------------------------------------Performance : -199.1 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 201.6% B&H MaxDrawDown : 44.8%Best performance : 3.3% Worst performance : -204.9Net gain : -19910.00 Gross gain : -2590.00

Trades statistics :Number of trades : 1732 Trades/Year : 247.97Number of gains : 698 Number of losses : 1034 Win. ratio : 40.3%Max consec. win : 7 Max consec. loss : 13 Expectancy : -0.00Average gain : 0.87% Average loss : -0.94% Avg. perf : nan%Biggest gain : 6.44% Biggest loss : -6.65% Profit fac : 0.92Sum of gains : 36090.00 Sum of losses : -56000.00 Risk of ruin : 100.0

Page 22: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade

Take #1

-----------------------------------------------------Performance : -199.1 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 201.6% B&H MaxDrawDown : 44.8%Best performance : 3.3% Worst performance : -204.9Net gain : -19910.00 Gross gain : -2590.00

Trades statistics :Number of trades : 1732 Trades/Year : 247.97Number of gains : 698 Number of losses : 1034 Win. ratio : 40.3%Max consec. win : 7 Max consec. loss : 13 Expectancy : -0.00Average gain : 0.87% Average loss : -0.94% Avg. perf : nan%Biggest gain : 6.44% Biggest loss : -6.65% Profit fac : 0.92Sum of gains : 36090.00 Sum of losses : -56000.00 Risk of ruin : 100.0

Page 23: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade

Take #1

-----------------------------------------------------Performance : -199.1 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 201.6% B&H MaxDrawDown : 44.8%Best performance : 3.3% Worst performance : -204.9Net gain : -19910.00 Gross gain : -2590.00

Trades statistics :Number of trades : 1732 Trades/Year : 247.97Number of gains : 698 Number of losses : 1034 Win. ratio : 40.3%Max consec. win : 7 Max consec. loss : 13 Expectancy : -0.00Average gain : 0.87% Average loss : -0.94% Avg. perf : nan%Biggest gain : 6.44% Biggest loss : -6.65% Profit fac : 0.92Sum of gains : 36090.00 Sum of losses : -56000.00 Risk of ruin : 100.0

-NT$3,982,000

Page 24: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade

Take #1

-----------------------------------------------------Performance : -199.1 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 201.6% B&H MaxDrawDown : 44.8%Best performance : 3.3% Worst performance : -204.9Net gain : -19910.00 Gross gain : -2590.00

Trades statistics :Number of trades : 1732 Trades/Year : 247.97Number of gains : 698 Number of losses : 1034 Win. ratio : 40.3%Max consec. win : 7 Max consec. loss : 13 Expectancy : -0.00Average gain : 0.87% Average loss : -0.94% Avg. perf : nan%Biggest gain : 6.44% Biggest loss : -6.65% Profit fac : 0.92Sum of gains : 36090.00 Sum of losses : -56000.00 Risk of ruin : 100.0

-NT$3,982,000

DOOMED!!

Page 25: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade \ |CS:Stop:Fixed 1.5

Take #2

Page 26: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade \ |CS:Stop:Fixed 1.5

Take #2

Stop when losing 1.5%

Page 27: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade \ |CS:Stop:Fixed 1.5

Take #2

Page 28: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade \ |CS:Stop:Fixed 1.5

Take #2

-----------------------------------------------------Performance : -124.4 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 136.8% B&H MaxDrawDown : 44.8%Best performance : 2.0% Worst performance : -137.5Net gain : -12442.13 Gross gain : 4877.87

Trades statistics :Number of trades : 1732 Trades/Year : 247.97Number of gains : 715 Number of losses : 1017 Win. ratio : 41.3%Max consec. win : 11 Max consec. loss : 16 Expectancy : -0.00Average gain : 0.88% Average loss : -0.83% Avg. perf : nan%Biggest gain : 5.67% Biggest loss : -1.79% Profit fac : 1.05Sum of gains : 37037.00 Sum of losses : -49479.13 Risk of ruin : 100.0

Page 29: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade \ |CS:Stop:Fixed 1.5

Take #2

-----------------------------------------------------Performance : -124.4 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 136.8% B&H MaxDrawDown : 44.8%Best performance : 2.0% Worst performance : -137.5Net gain : -12442.13 Gross gain : 4877.87

Trades statistics :Number of trades : 1732 Trades/Year : 247.97Number of gains : 715 Number of losses : 1017 Win. ratio : 41.3%Max consec. win : 11 Max consec. loss : 16 Expectancy : -0.00Average gain : 0.88% Average loss : -0.83% Avg. perf : nan%Biggest gain : 5.67% Biggest loss : -1.79% Profit fac : 1.05Sum of gains : 37037.00 Sum of losses : -49479.13 Risk of ruin : 100.0

-NT$2,488,426

Page 30: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade \ |CS:Stop:Fixed 1.5

Take #2

-----------------------------------------------------Performance : -124.4 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 136.8% B&H MaxDrawDown : 44.8%Best performance : 2.0% Worst performance : -137.5Net gain : -12442.13 Gross gain : 4877.87

Trades statistics :Number of trades : 1732 Trades/Year : 247.97Number of gains : 715 Number of losses : 1017 Win. ratio : 41.3%Max consec. win : 11 Max consec. loss : 16 Expectancy : -0.00Average gain : 0.88% Average loss : -0.83% Avg. perf : nan%Biggest gain : 5.67% Biggest loss : -1.79% Profit fac : 1.05Sum of gains : 37037.00 Sum of losses : -49479.13 Risk of ruin : 100.0

-NT$2,488,426

Much better, but still negative

Page 31: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade \ |CS:Stop:Fixed 2.5

Take #3

Page 32: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade \ |CS:Stop:Fixed 2.5

Take #3

Stop when losing 2.5%

Page 33: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade \ |CS:Stop:Fixed 2.5

Take #3

Page 34: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade \ |CS:Stop:Fixed 2.5

Take #3

-----------------------------------------------------Performance : -149.8 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 155.0% B&H MaxDrawDown : 44.8%Best performance : 0.0% Worst performance : -155.0Net gain : -14977.47 Gross gain : 2342.53

Trades statistics :Number of trades : 1732 Trades/Year : 247.97Number of gains : 706 Number of losses : 1026 Win. ratio : 40.8%Max consec. win : 8 Max consec. loss : 14 Expectancy : -0.00Average gain : 0.91% Average loss : -0.87% Avg. perf : nan%Biggest gain : 6.29% Biggest loss : -2.78% Profit fac : 1.05Sum of gains : 37749.00 Sum of losses : -52726.47 Risk of ruin : 100.0

Page 35: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade \ |CS:Stop:Fixed 2.5

Take #3

-----------------------------------------------------Performance : -149.8 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 155.0% B&H MaxDrawDown : 44.8%Best performance : 0.0% Worst performance : -155.0Net gain : -14977.47 Gross gain : 2342.53

Trades statistics :Number of trades : 1732 Trades/Year : 247.97Number of gains : 706 Number of losses : 1026 Win. ratio : 40.8%Max consec. win : 8 Max consec. loss : 14 Expectancy : -0.00Average gain : 0.91% Average loss : -0.87% Avg. perf : nan%Biggest gain : 6.29% Biggest loss : -2.78% Profit fac : 1.05Sum of gains : 37749.00 Sum of losses : -52726.47 Risk of ruin : 100.0

-NT$2,995,494

Page 36: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:DayTrade \ |CS:Stop:Fixed 2.5

Take #3

-----------------------------------------------------Performance : -149.8 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 155.0% B&H MaxDrawDown : 44.8%Best performance : 0.0% Worst performance : -155.0Net gain : -14977.47 Gross gain : 2342.53

Trades statistics :Number of trades : 1732 Trades/Year : 247.97Number of gains : 706 Number of losses : 1026 Win. ratio : 40.8%Max consec. win : 8 Max consec. loss : 14 Expectancy : -0.00Average gain : 0.91% Average loss : -0.87% Avg. perf : nan%Biggest gain : 6.29% Biggest loss : -2.78% Profit fac : 1.05Sum of gains : 37749.00 Sum of losses : -52726.47 Risk of ruin : 100.0

-NT$2,995,494

Not better after increase the stop threshold

Page 37: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:Stop:Fixed 5 \ |CS:CloseGain 10

Take #4

Page 38: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:Stop:Fixed 5 \ |CS:CloseGain 10

Take #4

Stop when winning 10%

Page 39: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:Stop:Fixed 5 \ |CS:CloseGain 10

Take #4

Page 40: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:Stop:Fixed 5 \ |CS:CloseGain 10

Take #4

-----------------------------------------------------Performance : 29.2% ( 6.1%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 24.9% B&H MaxDrawDown : 44.8%Best performance : 49.7% Worst performance : -1.2%Net gain : 2920.65 Gross gain : 3730.65

Trades statistics :Number of trades : 81 Trades/Year : 11.60Number of gains : 32 Number of losses : 49 Win. ratio : 39.5%Max consec. win : 4 Max consec. loss : 8 Expectancy : 0.01Average gain : 9.92% Average loss : -5.43% Avg. perf : 0.32%Biggest gain : 11.50% Biggest loss : -9.73% Profit fac : 1.83Sum of gains : 18313.10 Sum of losses : -15392.45 Risk of ruin : 21.3%

Page 41: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:Stop:Fixed 5 \ |CS:CloseGain 10

Take #4

-----------------------------------------------------Performance : 29.2% ( 6.1%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 24.9% B&H MaxDrawDown : 44.8%Best performance : 49.7% Worst performance : -1.2%Net gain : 2920.65 Gross gain : 3730.65

Trades statistics :Number of trades : 81 Trades/Year : 11.60Number of gains : 32 Number of losses : 49 Win. ratio : 39.5%Max consec. win : 4 Max consec. loss : 8 Expectancy : 0.01Average gain : 9.92% Average loss : -5.43% Avg. perf : 0.32%Biggest gain : 11.50% Biggest loss : -9.73% Profit fac : 1.83Sum of gains : 18313.10 Sum of losses : -15392.45 Risk of ruin : 21.3%

NT$584,130

Page 42: Trading With Open Source Tools

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:Stop:Fixed 5 \ |CS:CloseGain 10

Take #4

-----------------------------------------------------Performance : 29.2% ( 6.1%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 24.9% B&H MaxDrawDown : 44.8%Best performance : 49.7% Worst performance : -1.2%Net gain : 2920.65 Gross gain : 3730.65

Trades statistics :Number of trades : 81 Trades/Year : 11.60Number of gains : 32 Number of losses : 49 Win. ratio : 39.5%Max consec. win : 4 Max consec. loss : 8 Expectancy : 0.01Average gain : 9.92% Average loss : -5.43% Avg. perf : 0.32%Biggest gain : 11.50% Biggest loss : -9.73% Profit fac : 1.83Sum of gains : 18313.10 Sum of losses : -15392.45 Risk of ruin : 21.3%

NT$584,130

PROFIT!!

Page 43: Trading With Open Source Tools

SY:Generic \ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==1 : {S:G:Above {I:Random 6} 2})}\ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==-1 : {S:G:Below {I:Random 6} 3})}\ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:Stop:Fixed 5 \ |CS:CloseGain 10

Take #5

Page 44: Trading With Open Source Tools

SY:Generic \ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==1 : {S:G:Above {I:Random 6} 2})}\ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==-1 : {S:G:Below {I:Random 6} 3})}\ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:Stop:Fixed 5 \ |CS:CloseGain 10

Take #5

Following results from last trade

Page 45: Trading With Open Source Tools

SY:Generic \ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==1 : {S:G:Above {I:Random 6} 2})}\ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==-1 : {S:G:Below {I:Random 6} 3})}\ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:Stop:Fixed 5 \ |CS:CloseGain 10

Take #5

Page 46: Trading With Open Source Tools

SY:Generic \ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==1 : {S:G:Above {I:Random 6} 2})}\ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==-1 : {S:G:Below {I:Random 6} 3})}\ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:Stop:Fixed 5 \ |CS:CloseGain 10

Take #5

-----------------------------------------------------Performance : 48.4% ( 9.5%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 19.8% B&H MaxDrawDown : 44.8%Best performance : 49.5% Worst performance : 0.0%Net gain : 4839.75 Gross gain : 5699.75

Trades statistics :Number of trades : 86 Trades/Year : 12.31Number of gains : 36 Number of losses : 50 Win. ratio : 41.9%Max consec. win : 4 Max consec. loss : 8 Expectancy : 0.01Average gain : 9.72% Average loss : -5.48% Avg. perf : 0.46%Biggest gain : 10.71% Biggest loss : -11.33% Profit fac : 1.77Sum of gains : 20674.70 Sum of losses : -15834.95 Risk of ruin : 9.9%

Page 47: Trading With Open Source Tools

SY:Generic \ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==1 : {S:G:Above {I:Random 6} 2})}\ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==-1 : {S:G:Below {I:Random 6} 3})}\ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:Stop:Fixed 5 \ |CS:CloseGain 10

Take #5

-----------------------------------------------------Performance : 48.4% ( 9.5%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 19.8% B&H MaxDrawDown : 44.8%Best performance : 49.5% Worst performance : 0.0%Net gain : 4839.75 Gross gain : 5699.75

Trades statistics :Number of trades : 86 Trades/Year : 12.31Number of gains : 36 Number of losses : 50 Win. ratio : 41.9%Max consec. win : 4 Max consec. loss : 8 Expectancy : 0.01Average gain : 9.72% Average loss : -5.48% Avg. perf : 0.46%Biggest gain : 10.71% Biggest loss : -11.33% Profit fac : 1.77Sum of gains : 20674.70 Sum of losses : -15834.95 Risk of ruin : 9.9%

NT$967,950

Page 48: Trading With Open Source Tools

The OSDC Trading System

Got your dice?

Page 49: Trading With Open Source Tools

SY:Generic \ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==1 : {S:G:Above {I:Random 6} 2})}\ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==-1 : {S:G:Below {I:Random 6} 3})}\ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:Stop:Fixed 5 \ |CS:CloseGain 10-----------------------------------------------------Performance : 48.4% ( 9.5%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 19.8% B&H MaxDrawDown : 44.8%Best performance : 49.5% Worst performance : 0.0%Net gain : 4839.75 Gross gain : 5699.75

Trades statistics :Number of trades : 86 Trades/Year : 12.31Number of gains : 36 Number of losses : 50 Win. ratio : 41.9%Max consec. win : 4 Max consec. loss : 8 Expectancy : 0.01Average gain : 9.72% Average loss : -5.48% Avg. perf : 0.46%Biggest gain : 10.71% Biggest loss : -11.33% Profit fac : 1.77Sum of gains : 20674.70 Sum of losses : -15834.95 Risk of ruin : 9.9%

Page 50: Trading With Open Source Tools

SY:Generic \ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==1 : {S:G:Above {I:Random 6} 2})}\ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==-1 : {S:G:Below {I:Random 6} 3})}\ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:Stop:Fixed 5 \ |CS:CloseGain 10-----------------------------------------------------Performance : 48.4% ( 9.5%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 19.8% B&H MaxDrawDown : 44.8%Best performance : 49.5% Worst performance : 0.0%Net gain : 4839.75 Gross gain : 5699.75

Trades statistics :Number of trades : 86 Trades/Year : 12.31Number of gains : 36 Number of losses : 50 Win. ratio : 41.9%Max consec. win : 4 Max consec. loss : 8 Expectancy : 0.01Average gain : 9.72% Average loss : -5.48% Avg. perf : 0.46%Biggest gain : 10.71% Biggest loss : -11.33% Profit fac : 1.77Sum of gains : 20674.70 Sum of losses : -15834.95 Risk of ruin : 9.9%

Page 51: Trading With Open Source Tools

SY:Generic \ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==1 : {S:G:Above {I:Random 6} 2})}\ {I:G:Eval ( {I:LastTrade} ? {I:LastTrade}==-1 : {S:G:Below {I:Random 6} 3})}\ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:Stop:Fixed 5 \ |CS:CloseGain 10-----------------------------------------------------Performance : 48.4% ( 9.5%) Buy & Hold : 77.5% ( 14.2%) () => by yearMaxDrawDown : 19.8% B&H MaxDrawDown : 44.8%Best performance : 49.5% Worst performance : 0.0%Net gain : 4839.75 Gross gain : 5699.75

Trades statistics :Number of trades : 86 Trades/Year : 12.31Number of gains : 36 Number of losses : 50 Win. ratio : 41.9%Max consec. win : 4 Max consec. loss : 8 Expectancy : 0.01Average gain : 9.72% Average loss : -5.48% Avg. perf : 0.46%Biggest gain : 10.71% Biggest loss : -11.33% Profit fac : 1.77Sum of gains : 20674.70 Sum of losses : -15834.95 Risk of ruin : 9.9%

Page 52: Trading With Open Source Tools

Outline

• trading system

• analysis

• backtesting

• live trading

Page 53: Trading With Open Source Tools

Trading System

Trading system, also known as algorithmic trading, is the use of computer programs for entering trading orders with the computer algorithm deciding on certain aspects of the order such as the timing, price, quantity of order

Page 54: Trading With Open Source Tools

Trading System

Trading system, also known as algorithmic trading, is the use of computer programs for entering trading orders with the computer algorithm deciding on certain aspects of the order such as the timing, price, quantity of order

Even with dice

Page 55: Trading With Open Source Tools

Analysis

• Where are all the loss coming from?

• Any interesting correlation with technical indicators?

• (Be curious and ask yourself questions about your results)

Page 58: Trading With Open Source Tools
Page 59: Trading With Open Source Tools
Page 60: Trading With Open Source Tools

winamount <- xtabs(paste("profit~", rhs, sep=""), data=data[data$profit>0,])

loseamount <- xtabs(paste("profit~", rhs, sep=""), data=data[data$profit<=0,]);

x$netgain <- winamount+loseamount;

x$avgnet <- x$netgain/trade

Page 61: Trading With Open Source Tools

winamount <- xtabs(paste("profit~", rhs, sep=""), data=data[data$profit>0,])

loseamount <- xtabs(paste("profit~", rhs, sep=""), data=data[data$profit<=0,]);

x$netgain <- winamount+loseamount;

x$avgnet <- x$netgain/trade

Page 62: Trading With Open Source Tools

winamount <- xtabs(paste("profit~", rhs, sep=""), data=data[data$profit>0,])

loseamount <- xtabs(paste("profit~", rhs, sep=""), data=data[data$profit<=0,]);

x$netgain <- winamount+loseamount;

x$avgnet <- x$netgain/trade

Page 63: Trading With Open Source Tools
Page 64: Trading With Open Source Tools
Page 65: Trading With Open Source Tools
Page 66: Trading With Open Source Tools
Page 67: Trading With Open Source Tools
Page 68: Trading With Open Source Tools
Page 69: Trading With Open Source Tools
Page 70: Trading With Open Source Tools
Page 71: Trading With Open Source Tools

Now if we don’t short when we are above the open price....

Page 72: Trading With Open Source Tools

Was 5699

Now if we don’t short when we are above the open price....

Page 73: Trading With Open Source Tools

R also supports nice plotting

Page 74: Trading With Open Source Tools

Backtesting

Page 75: Trading With Open Source Tools

Backtesting

• If you want to write a strategy (which might not be using dice), you want to test it for historical data

Page 76: Trading With Open Source Tools

Backtesting

• If you want to write a strategy (which might not be using dice), you want to test it for historical data

• “past performance does not guarantee future results”

Page 77: Trading With Open Source Tools

Backtesting

• If you want to write a strategy (which might not be using dice), you want to test it for historical data

• “past performance does not guarantee future results”

• But if your past performance is bad, do you dare to use the system?

Page 78: Trading With Open Source Tools

Genius Trader

Page 79: Trading With Open Source Tools

• Modular

• Flexible

• Open source

• does backtesting, charting

SY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} \ |TF:Generic {S:G:CrossOverUp {I:Hour} 850} \ {S:G:CrossOverUp {I:Hour} 850} \ |TF:MaxOpenTrades 1 \ |CS:Stop:Fixed 5 \ |CS:CloseGain 10

Page 80: Trading With Open Source Tools

live trading

Page 81: Trading With Open Source Tools

live trading

• Data feed

Page 82: Trading With Open Source Tools

live trading

• Data feed

• Strategy / System runner

Page 83: Trading With Open Source Tools

live trading

• Data feed

• Strategy / System runner

• Broker API

Page 84: Trading With Open Source Tools

live trading

• Data feed

• Strategy / System runner

• Broker API

• Infrastructure

• Monitor

• Scale and redundancy!

Page 85: Trading With Open Source Tools

Data feed

• free: DDE from broker’s software

• Win32::DDE (polling)

• publish to memcached (or more appropriate message queues)

• 10 lines of code

• 20 lines for reconnect and robustness

Page 86: Trading With Open Source Tools

Strategy runner

Page 87: Trading With Open Source Tools

Strategy runner

• genius trader, available for back test

Page 88: Trading With Open Source Tools

Strategy runner

• genius trader, available for back test

• GT::Stream, accept streaming data and applies trading system to generate real time signals

Page 89: Trading With Open Source Tools

Strategy runner

• genius trader, available for back test

• GT::Stream, accept streaming data and applies trading system to generate real time signals

• available at: ????

Page 90: Trading With Open Source Tools

Infrastructure

• VirtualBox headless & MicroXP

• memcached

• gearman

• nagios

Page 91: Trading With Open Source Tools

Trading platforms

• http://geniustrade.org/

• Trade Station (proprietary)

• http://ojts.sourceforge.net/

• http://www.marketcetera.org/

Page 92: Trading With Open Source Tools

Library

• quantlib

• ta-lib

Page 93: Trading With Open Source Tools

R tutorials

• Econometrics in R (Grant V. Farnsworth)

• Practical Regression and Anova using R (Julian J. Faraway)

Page 94: Trading With Open Source Tools

Conclusion

Page 95: Trading With Open Source Tools
Page 96: Trading With Open Source Tools
Page 97: Trading With Open Source Tools

已經 2009 年了,還在看報紙、看電視、聽明牌、憑

感覺炒股票?

Page 98: Trading With Open Source Tools

Yesterday... I went to hotsprings in the morning..

Page 99: Trading With Open Source Tools

Yesterday... I went to hotsprings in the morning..

Page 100: Trading With Open Source Tools

At 11:45:20

Page 101: Trading With Open Source Tools

At 11:45:20

Page 102: Trading With Open Source Tools

At 11:45:20

Page 103: Trading With Open Source Tools

At 11:45:20

Page 104: Trading With Open Source Tools

At 11:45:20

Page 105: Trading With Open Source Tools

At 11:45:20

Page 106: Trading With Open Source Tools

At 11:45:20

Page 107: Trading With Open Source Tools

At 11:45:20

PROFIT!!

Page 108: Trading With Open Source Tools

PROFIT!!

Page 110: Trading With Open Source Tools

謝謝!