John Ehlers' Fischer Transform

Hello All,

This is very much a 'work in progress'. In 'Cybernetic Analysis for Stocks and Futures' John Ehlers used the Fischer transform (p.1 - p.10) to convert non-Gaussian stock prices to a nearly Gaussian probability distribution.

I'm playing here. I think I need to calculate Relative Strength (RS) first, then RSI, then apply the Fischer transform. (See:http://blog.traderslibrary.com/sylvain_vervoort/2010/09/smoothed-rsi-inverse-fisher-transform-excerpt-from-sc-magazine.html)

Regards,

Peter

140
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
 Returns 1 Month 3 Month 6 Month 12 Month
 Alpha 1 Month 3 Month 6 Month 12 Month
 Beta 1 Month 3 Month 6 Month 12 Month
 Sharpe 1 Month 3 Month 6 Month 12 Month
 Sortino 1 Month 3 Month 6 Month 12 Month
 Volatility 1 Month 3 Month 6 Month 12 Month
 Max Drawdown 1 Month 3 Month 6 Month 12 Month
import pandas
import math

Stock1 = 0

def initialize(context):
global Stock1
context.Stock1 = sid(24)
context.qty = 100
Stock1 = int(str(context.Stock1)[9:-1])

@batch_transform(window_length=20)
def get_MinMax(datapanel):
global Stock1
prices=datapanel['price']
prices['Min'] = pandas.stats.moments.rolling_min(prices[Stock1],20)
prices['Max'] = pandas.stats.moments.rolling_max(prices[Stock1],20)
return prices

def handle_data(context, data):
result = get_MinMax(data)
if result is None:
return
min = result['Min'][19]
max = result['Max'][19]
mid = min + (max - min) / 2
diff = data[context.Stock1].price - mid
transform = (2 * math.exp(diff) - 1) / (2 * math.exp(diff) + 1)
if transform > 0.9999:
transform = 1
elif transform < -0.9999:
transform = -1
record(Transform=transform)
order_handling(context, data, transform)

def order_handling(context, data, transform):
if transform == -1:
# Are we long or neutral?
if context.portfolio.positions[context.Stock1].amount >= 0:
# Close our long position if we have one
close_position(context, data)
order(context.Stock1, -context.qty)
if transform == 1:
# Are we short or neutral?
if context.portfolio.positions[context.Stock1].amount <= 0:
# Close our short position if we have one
close_position(context, data)
order(context.Stock1, context.qty)
return

def close_position(context, result):
# Open position?
if  context.portfolio.positions[context.Stock1].amount > 0:
order(context.Stock1, -context.qty)
elif context.portfolio.positions[context.Stock1].amount < 0:
order(context.Stock1, context.qty)
return

This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.
1 response

any idea... on the Roofing filter... of John Ehlers mate. thanks....