The document discusses trading strategies using open source tools. It presents a trading system called OSDC Trading System that uses random numbers generated by rolling dice to determine trading signals. Backtesting results of two strategies are shown, with the second strategy implementing a stop loss that performs better by reducing losses. However, both strategies resulted in overall negative returns compared to a buy and hold strategy.
21. 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
-----------------------------------------------------
Performance : -199.1 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by year
MaxDrawDown : 201.6% B&H MaxDrawDown : 44.8%
Best performance : 3.3% Worst performance : -204.9
Net gain : -19910.00 Gross gain : -2590.00
Trades statistics :
Number of trades : 1732 Trades/Year : 247.97
Number of gains : 698 Number of losses : 1034 Win. ratio : 40.3%
Max consec. win : 7 Max consec. loss : 13 Expectancy : -0.00
Average gain : 0.87% Average loss : -0.94% Avg. perf : nan%
Biggest gain : 6.44% Biggest loss : -6.65% Profit fac : 0.92
Sum of gains : 36090.00 Sum of losses : -56000.00 Risk of ruin : 100.0
22. 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
-----------------------------------------------------
Performance : -199.1 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by year
MaxDrawDown : 201.6% B&H MaxDrawDown : 44.8%
Best performance : 3.3% Worst performance : -204.9
Net gain : -19910.00 Gross gain : -2590.00
Trades statistics :
Number of trades : 1732 Trades/Year : 247.97
Number of gains : 698 Number of losses : 1034 Win. ratio : 40.3%
Max consec. win : 7 Max consec. loss : 13 Expectancy : -0.00
Average gain : 0.87% Average loss : -0.94% Avg. perf : nan%
Biggest gain : 6.44% Biggest loss : -6.65% Profit fac : 0.92
Sum of gains : 36090.00 Sum of losses : -56000.00 Risk of ruin : 100.0
23. 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
-----------------------------------------------------
Performance : -199.1 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by year
MaxDrawDown : 201.6% B&H MaxDrawDown : 44.8%
Best performance : 3.3% Worst performance : -204.9
-NT$3,982,000
Net gain : -19910.00 Gross gain : -2590.00
Trades statistics :
Number of trades : 1732 Trades/Year : 247.97
Number of gains : 698 Number of losses : 1034 Win. ratio : 40.3%
Max consec. win : 7 Max consec. loss : 13 Expectancy : -0.00
Average gain : 0.87% Average loss : -0.94% Avg. perf : nan%
Biggest gain : 6.44% Biggest loss : -6.65% Profit fac : 0.92
Sum of gains : 36090.00 Sum of losses : -56000.00 Risk of ruin : 100.0
24. 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
-----------------------------------------------------
Performance : -199.1 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by year
MaxDrawDown : 201.6% B&H MaxDrawDown : 44.8%
Best performance : 3.3% Worst performance : -204.9
-NT$3,982,000
Net gain : -19910.00 Gross gain : -2590.00
Trades statistics :
Number of trades : 1732 Trades/Year : 247.97
Number of gains : 698 Number of losses : 1034 Win. ratio : 40.3%
Max consec. win : 7 Max consec. loss : 13 Expectancy : -0.00
Average gain : 0.87% Average loss : -0.94% Avg. perf : nan%
Biggest gain : 6.44% Biggest loss : -6.65% Profit fac : 0.92
Sum of gains : 36090.00 Sum of losses : -56000.00 Risk of ruin : 100.0
DOOMED!!
28. 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
-----------------------------------------------------
Performance : -124.4 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by year
MaxDrawDown : 136.8% B&H MaxDrawDown : 44.8%
Best performance : 2.0% Worst performance : -137.5
Net gain : -12442.13 Gross gain : 4877.87
Trades statistics :
Number of trades : 1732 Trades/Year : 247.97
Number of gains : 715 Number of losses : 1017 Win. ratio : 41.3%
Max consec. win : 11 Max consec. loss : 16 Expectancy : -0.00
Average gain : 0.88% Average loss : -0.83% Avg. perf : nan%
Biggest gain : 5.67% Biggest loss : -1.79% Profit fac : 1.05
Sum of gains : 37037.00 Sum of losses : -49479.13 Risk of ruin : 100.0
29. 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
-----------------------------------------------------
Performance : -124.4 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by year
MaxDrawDown : 136.8% B&H MaxDrawDown : 44.8%
Best performance : 2.0% Worst performance : -137.5
-NT$2,488,426
Net gain : -12442.13 Gross gain : 4877.87
Trades statistics :
Number of trades : 1732 Trades/Year : 247.97
Number of gains : 715 Number of losses : 1017 Win. ratio : 41.3%
Max consec. win : 11 Max consec. loss : 16 Expectancy : -0.00
Average gain : 0.88% Average loss : -0.83% Avg. perf : nan%
Biggest gain : 5.67% Biggest loss : -1.79% Profit fac : 1.05
Sum of gains : 37037.00 Sum of losses : -49479.13 Risk of ruin : 100.0
30. 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
-----------------------------------------------------
Performance : -124.4 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by year
MaxDrawDown : 136.8% B&H MaxDrawDown : 44.8%
Best performance : 2.0% Worst performance : -137.5
-NT$2,488,426
Net gain : -12442.13 Gross gain : 4877.87
Trades statistics :
Number of trades : 1732 Trades/Year : 247.97
Number of gains : 715 Number of losses : 1017 Win. ratio : 41.3%
Max consec. win : 11 Max consec. loss : 16 Expectancy : -0.00
Average gain : 0.88% Average loss : -0.83% Avg. perf : nan%
Biggest gain : 5.67% Biggest loss : -1.79% Profit fac : 1.05
Sum of gains : 37037.00 Sum of losses : -49479.13 Risk of ruin : 100.0
Much better, but still negative
34. 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
-----------------------------------------------------
Performance : -149.8 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by year
MaxDrawDown : 155.0% B&H MaxDrawDown : 44.8%
Best performance : 0.0% Worst performance : -155.0
Net gain : -14977.47 Gross gain : 2342.53
Trades statistics :
Number of trades : 1732 Trades/Year : 247.97
Number of gains : 706 Number of losses : 1026 Win. ratio : 40.8%
Max consec. win : 8 Max consec. loss : 14 Expectancy : -0.00
Average gain : 0.91% Average loss : -0.87% Avg. perf : nan%
Biggest gain : 6.29% Biggest loss : -2.78% Profit fac : 1.05
Sum of gains : 37749.00 Sum of losses : -52726.47 Risk of ruin : 100.0
35. 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
-----------------------------------------------------
Performance : -149.8 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by year
MaxDrawDown : 155.0% B&H MaxDrawDown : 44.8%
Best performance : 0.0% Worst performance : -155.0
-NT$2,995,494
Net gain : -14977.47 Gross gain : 2342.53
Trades statistics :
Number of trades : 1732 Trades/Year : 247.97
Number of gains : 706 Number of losses : 1026 Win. ratio : 40.8%
Max consec. win : 8 Max consec. loss : 14 Expectancy : -0.00
Average gain : 0.91% Average loss : -0.87% Avg. perf : nan%
Biggest gain : 6.29% Biggest loss : -2.78% Profit fac : 1.05
Sum of gains : 37749.00 Sum of losses : -52726.47 Risk of ruin : 100.0
36. 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
-----------------------------------------------------
Performance : -149.8 ( nan%) Buy & Hold : 77.5% ( 14.2%) () => by year
MaxDrawDown : 155.0% B&H MaxDrawDown : 44.8%
Best performance : 0.0% Worst performance : -155.0
-NT$2,995,494
Net gain : -14977.47 Gross gain : 2342.53
Trades statistics :
Number of trades : 1732 Trades/Year : 247.97
Number of gains : 706 Number of losses : 1026 Win. ratio : 40.8%
Max consec. win : 8 Max consec. loss : 14 Expectancy : -0.00
Average gain : 0.91% Average loss : -0.87% Avg. perf : nan%
Biggest gain : 6.29% Biggest loss : -2.78% Profit fac : 1.05
Sum of gains : 37749.00 Sum of losses : -52726.47 Risk of ruin : 100.0
Not better after increase the stop threshold
40. 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
-----------------------------------------------------
Performance : 29.2% ( 6.1%) Buy & Hold : 77.5% ( 14.2%) () => by year
MaxDrawDown : 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.60
Number of gains : 32 Number of losses : 49 Win. ratio : 39.5%
Max consec. win : 4 Max consec. loss : 8 Expectancy : 0.01
Average gain : 9.92% Average loss : -5.43% Avg. perf : 0.32%
Biggest gain : 11.50% Biggest loss : -9.73% Profit fac : 1.83
Sum of gains : 18313.10 Sum of losses : -15392.45 Risk of ruin : 21.3%
41. 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
-----------------------------------------------------
Performance : 29.2% ( 6.1%) Buy & Hold : 77.5% ( 14.2%) () => by year
MaxDrawDown : 24.9% B&H MaxDrawDown : 44.8%
Best performance : 49.7% Worst performance : -1.2%
NT$584,130
Net gain : 2920.65 Gross gain : 3730.65
Trades statistics :
Number of trades : 81 Trades/Year : 11.60
Number of gains : 32 Number of losses : 49 Win. ratio : 39.5%
Max consec. win : 4 Max consec. loss : 8 Expectancy : 0.01
Average gain : 9.92% Average loss : -5.43% Avg. perf : 0.32%
Biggest gain : 11.50% Biggest loss : -9.73% Profit fac : 1.83
Sum of gains : 18313.10 Sum of losses : -15392.45 Risk of ruin : 21.3%
42. 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
-----------------------------------------------------
Performance : 29.2% ( 6.1%) Buy & Hold : 77.5% ( 14.2%) () => by year
MaxDrawDown : 24.9% B&H MaxDrawDown : 44.8%
Best performance : 49.7% Worst performance : -1.2%
NT$584,130
Net gain : 2920.65 Gross gain : 3730.65
Trades statistics :
Number of trades : 81 Trades/Year : 11.60
PROFIT!!
Number of gains : 32 Number of losses : 49 Win. ratio : 39.5%
Max consec. win : 4 Max consec. loss : 8 Expectancy : 0.01
Average gain : 9.92% Average loss : -5.43% Avg. perf : 0.32%
Biggest gain : 11.50% Biggest loss : -9.73% Profit fac : 1.83
Sum of gains : 18313.10 Sum of losses : -15392.45 Risk of ruin : 21.3%
53. 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
54. 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
55. Analysis
• Where are all the loss coming from?
• Any interesting correlation with technical
indicators?
• (Be curious and ask yourself questions about your
results)
56. R is a programming language and software environment for
statistical computing and graphics. It is an implementation
of the S programming language with lexical scoping
semantics inspired by Scheme.
57. R is a programming language and software environment for
statistical computing and graphics. It is an implementation
of the S programming language with lexical scoping
semantics inspired by Scheme.
to work with numbers, vectors efficiently
75. Backtesting
• If you want to write a strategy (which
might not be using dice), you want to test it
for historical data
76. 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”
77. 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?
84. live trading
• Data feed
• Strategy / System runner
• Broker API
• Infrastructure
• Monitor
• Scale and redundancy!
85. 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
88. Strategy runner
• genius trader, available for back test
• GT::Stream, accept streaming data and
applies trading system to generate real time
signals
89. Strategy runner
• genius trader, available for back test
• GT::Stream, accept streaming data and
applies trading system to generate real time
signals
• available at: ????