At SQL Bits the wonders of networking in the SQL community showed it benefits, in a conversation with Jen Stirrup and Chris Testa-O’Neill mentioned that I was a math expert (his words not mine); later on Jen was talking to Chris Webb and he mentioned a problem he was with the performance of a recursive formula in Analysis Services and she then pointed him in my direction.

I was able to transform the recursive formula to one just based on Product and Sum of the values. Since I believe that a lot of Analytic systems start life in an excel spread sheet, so I decided to write-up some of the steps in the process of analysing and transforming these formulas.

The recursive formula in question is where is either 1 for a Long Position or -1 for a Short Position for the period t and is the percentage Profit or Loss for the period t.

Before I start the analysis it going to be helpful to give some examples of the values

Example 1: Long Position with 10% growth per period

Period | 1 | 2 | 3 | 4 |

LS | 1 | 1 | 1 | 1 |

RoR | 0.1 | 0.1 | 0.1 | 0.1 |

CRoR | 0.1 | 0.21 | 0.331 | 0.4641 |

Example 2: Short Position with 10% profit per period

Period | 1 | 2 | 3 | 4 |

LS | -1 | -1 | -1 | -1 |

RoR | 0.1 | 0.1 | 0.1 | 0.1 |

CRoR | 0.1 | 0.19 | 0.271 | 0.3439 |

Example 3: Swapping Long and Short Positions

Period | 1 | 2 | 3 | 4 |

LS | 1 | -1 | 1 | -1 |

RoR | 0.1 | 0.1 | 0.1 | 0.1 |

CRoR | 0.1 | 0.19 | 0.309 | 0.3781 |

Period | 1 | 2 | 3 | 4 |

LS | -1 | 1 | -1 | 1 |

RoR | 0.1 | 0.1 | 0.1 | 0.1 |

CRoR | 0.1 | 0.21 | 0.289 | 0.4179 |

As with all recursive formulas the end points have to be defined and they’re .

The first step was to factor the formula to reduce the number of terms giving

The next step is to shorten the names of the terms to save space when expanding the formulas.

Now we will look at the expansion of the first couple of terms to get an idea of the shape of the formula.

A pattern has emerged so it easy to see that for we will have followed by until which will have the term from 3 to 5.

This is starting to look like the expansion of a simple series since the common term is a good place to start finding solution will be to set to allow the analysis on the simplified formula.

The product of our simplified term for period 4 is expanding and collecting the terms gives us substituting the approximated gives us back which is the same pattern as the formula for except for the 1 at the start of the formula and the fact that we’ve ignored by setting it to 1 for all values.

Since the full definition for means that there will be no terms with without a matching . We will need to find a function to apply to the generated formula to remove the leading 1 and the where required.

There are two methods we can use either we choose simple values to place in the formula which would be the numerical analysis of the formula or we can perform the same algebraic analysis we have used to get to this point.

Using the function for the first couple of terms gives us

To get we need to divide by itself and times by which is

## Leave a Reply