Trading With Open Source Tools

Post on 17-Aug-2014

14544 Views

Category:

Economy & Finance

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

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.

Transcript

Tradingwith open source tools

Chia-liang Kaoclkao@clkao.org

OSDC.TW 2009 Taipei

Caution

CautionThere is

ABSOLUTELY NO WARRANTYif you use any of the code or

strategy mentioned in this talk.

Presenting.......

Presenting.......

The OSDC Trading System

Presenting.......

The OSDC Trading System

using dice!

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

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

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)

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

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

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

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

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

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

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

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

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

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

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!!

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

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%

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

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

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

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

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

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%

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

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

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

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

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

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%

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

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%

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

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!!

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

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

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

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%

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

The OSDC Trading System

Got your dice?

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%

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%

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%

Outline

• trading system

• analysis

• backtesting

• live trading

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

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

Analysis

• Where are all the loss coming from?

• Any interesting correlation with technical indicators?

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

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

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

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

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

Was 5699

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

R also supports nice plotting

Backtesting

Backtesting

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

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”

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?

Genius Trader

• 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

live trading

live trading

• Data feed

live trading

• Data feed

• Strategy / System runner

live trading

• Data feed

• Strategy / System runner

• Broker API

live trading

• Data feed

• Strategy / System runner

• Broker API

• Infrastructure

• Monitor

• Scale and redundancy!

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

Strategy runner

Strategy runner

• genius trader, available for back test

Strategy runner

• genius trader, available for back test

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

Strategy runner

• genius trader, available for back test

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

• available at: ????

Infrastructure

• VirtualBox headless & MicroXP

• memcached

• gearman

• nagios

Trading platforms

• http://geniustrade.org/

• Trade Station (proprietary)

• http://ojts.sourceforge.net/

• http://www.marketcetera.org/

Library

• quantlib

• ta-lib

R tutorials

• Econometrics in R (Grant V. Farnsworth)

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

Conclusion

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

感覺炒股票?

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

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

At 11:45:20

At 11:45:20

At 11:45:20

At 11:45:20

At 11:45:20

At 11:45:20

At 11:45:20

At 11:45:20

PROFIT!!

PROFIT!!

Questions?

clkao@clkao.org

謝謝!

top related