benchmark

Report 3 Downloads 254 Views
Introduction to a new strategy

Strategy Logic As discussed in the previous chapter Input

Comparison Difference in prices >= parameter

Signal buy

sell

parameter Difference in prices < parameter

No change

New Strategy Logic (create an indicator) Input

Parameters:

box size reversal size

Create an Indicator (call it benchmark)

Using box size update benchmark

Comparison

Signal

Diff in Price & benchmark meets reversal size criterion

Buy

Not met reversal size criterion

sell

No change

Why: The trading idea* *Based on Point & Figure charts • Trend following strategy: It tries to predict when prices will begin to rise or fall. • If prices are going up consistently, update the benchmark. Don’t sell. Wait for a movement in downward direction. If the movement is significant (>= reversal size), SELL. Else hold on to your position, the prices are simply re-adjusting.

• Same logic in other direction

Trending data We make money when we can buy/sell at the bottom/top of an upward/downward movement

Trending data Track when price movement has crossed a minimum pre-defined amount called ‘reversal size’ to generate buy/sell orders Use an indicator called ‘benchmark’ which gets updated as per the ‘box size’

Indicator: benchmark Logic for creating/updating benchmark Greater than or equal to box size

Change

Less than box size

No change

Greater than or equal to reversal size

Change

Less than reversal size

No change

Movement in same direction

Start with a benchmark value Movement in opposite direction

Input parameters • Using which an indicator is created • On which trading signals & strategy output depends • Based on which a strategy can be optimized Movement in same direction Start with a benchmark value Movement in opposite direction

Greater than or equal to box size

Change

Less than box size

No change

Greater than or equal to reversal size

Change

Less than reversal size

No change

BOX SIZE

REVERSAL SIZE

Initialize input parameters in R • Tick size is the minimum amount of movement in prices reported by the exchange. It is usually fixed at 0.05. • Box size in prices is a multiple of tick size • Reversal size in prices is a multiple of box size #initialize ticksize ticksize = 0.05 #initialize box size in terms of number of boxes INPUT PARAMETERS bsiz_box = 4 #number of boxes for reversal brev_box = 12 # Find box size in terms of prices. This number would be used in price comparisons: bsiz = bsiz_box*ticksize # Find reversal size in terms of prices. This number would be used in price comparisons: brev = brev_box*bsiz

Example of input parameters ticksize = 0.05 bsiz_box = 4 brev_box = 12 bsiz = bsiz_box*ticksize = 0.2 brev = brev_box*bsiz = 2.4 E.g. Case 1: P(1) = 1.2, P(2) = 1.5 P(2) – P(1) > 0.2 && curposs = 1 => update benchmark Case 2: P(1) = 2.1, P(2) = 4.5 P(2) – P(1) = 2.4 && currpos = -1 => generate signal

Signal Generation logic

Example with sample data We will work with the sample data of simple numbers to understand the logic. ticksize = 1, bsiz_box = 4, brev_box = 2 bsiz = 4 & brev = 8 (in prices)

S. No. 1 2 3 4 5 6 7 8 9 10

Closing Price Benchmark 100 109 117 105 90 81 85 84 90 100

----

Signal ----

Signal generation logic Start from row 2. Initialize bench as first closing price. Benchmark[2] = bench = closing price[1]

Start with new row (i)

Set benchmark[i] as equal to bench

Comparison

Signal

Use updated current position

Bench

Box size criterion

Update bench

Buy Reversal size criterion

Sell No change

Example with sample data bsiz = 4 (in prices) brev = 8 (in prices)

S. No. 1 2 3 4 5 6 7 8 9 10

Closing Price Benchmark 100 109 117 105 90 81 85 84 90 100

---100 108 116 108 92 84 84 84 84 100

Signal ---buy no change sell no change no change no change no change no change buy

Box size= 4 Reversal size = 8 120 116 112 108

104 100 96 92 88 84

80 76

Benchmark Closing Price

Running the strategy bsiz = 4 & brev = 8 (in prices) S. No.

Closing Price

Benchmark

1

100

----

Signal

Explanation for signal

initialize value to closing price in first row 109 - 100 > 8, first signal

2

109

100

3

117

108

4

105

116

5

90

108

2-box increase from 108 to 116 2-box decrease to from 116 to no change 108

6

81

92

no change 4-box decrease from 108 to 92

7

85

84

8

84

84

9

90

84

10

100

84 100

buy

Explanation for benchmark

no change 2-box increase from 100 to 108 sell

same direction 116 - 105 > 8, opposite signal same direction

same direction reversal size criteria not no change 2-box decrease to from 92 to 84 met (84, 85) reversal size not met (85, 84), no change no change No change in price reversal size criteria not no change No change in price met (84, 90) reversal size not met (84, 90), 100 - 84 >8, opposite buy no change signal 4-box increase from 84 to 100

120 116 112 108

104 100 96 92 88 84

80 76

Benchmark changes with large price movements Benchmark

Prices move in large amounts or in same direction so benchmark changes

Closing Price

120 116 112

Benchmark static due to small price movements Benchmark Closing Price

108

104 100 96 92 88 84

80 76

Prices move in small amounts so benchmark remains the same

Generating trading signals: Meeting reversal size criterion

120

Benchmark

116

Closing Price

112 108

BUY

Trading Signal

SELL

104 100 96 92 88 84

80 76

BUY

Coding in R

Parts of the code Upload data file

Initialize input parameters & counters for the loop

Initialize output variables

Print strategy output

for-loop

• Traded lots • Mtm in last row

• Signal generation code • Benchmark update code • Update tprofit & mtm

Conditions for signal generation If(currpos >-1 && (benchmark – Price >= brev)): SELL If(currpos = brev)): BUY benchmark – Price >= brev

SELL

Else

No change

Price - benchmark >= brev

BUY

Else

No change

currpos >-1 or NOT SOLD Depends on currpos AND Reversal Size Criterion currpos < 1 or NOT BOUGHT

Within the for() loop Iterate to next row (i) Save bench as benchmark[i]

SIGNAL GENERATION Update tprofit, mtm

UPDATE counter BENCH UPWARDS: If(currpos =1 && (Price[i] – bench >= bsiz)) DOWNWARDS: If(currpos = -1 && (bench – Price[i] >= bsiz))

If(currpos = brev)): BUY If(currpos >-1 && (benchmark[i] – Price[i] >= brev)): SELL

Update currpos & output variables

Bench Change Conditions UPWARDS: If(currpos =1 && (Price - benchmark >= bsiz)) DOWNWARDS: If(currpos = -1 && (benchmark – Price >= bsiz))

currpos = 1 Start with a benchmark value currpos = -1

Price – benchmark >= bsiz

Change

benchmark – Price >= brev

Change

benchmark – Price >= bsiz

Change

Price – benchmark >= brev

Change

This is already checked in signal generation code. Hence, currpos = -1

Summarize Signal Generation Conditions If((currpos = brev)) is TRUE: BUY If((currpos >-1) && (benchmark – Price >= brev)) is TRUE: SELL

Benchmark Conditions If((currpos =1) && (Price - benchmark >= bsiz)) is TRUE: CHANGE If((currpos = -1) && (benchmark – Price >= bsiz)) is TRUE: CHANGE

Upload data file

Initialize input parameters & counters & output variables

for-loop

• Signal generation code • Benchmark update code • Update tprofit & mtm

Print strategy output • Traded lots • Mtm in last row