Friday, 27 April 2018

Estratégia dinâmica de negociação em tempo de deformação


Estratégia dinâmica de negociação de distorção do tempo
Por que os períodos durante a noite são mais arriscados? Por um lado, você não pode parar para limitar seu risco. Mas, o que é mais importante, a distribuição dos retornos noturnos tem retornos negativos muito mais extremos do que os períodos intradía ou quase fechados. Deixe-nos dar uma olhada em algumas estatísticas em retornos fechados para abrir, abrir para fechar e fechar para fechar para SPY:
Inclinação: inclinação negativa significa caudas mais longas no lado negativo. Kurtose: maior kurtosis significa caudas mais pesadas (a distribuição normal possui uma curtose de 3).
Em primeiro lugar, os retornos overnight não são tão voláteis. Mas por unidade de volatilidade, eles são muito mais arriscados devido à maior freqüência de retornos extremos. Eu calculo a magnitude dos retornos em termos de desvios padrão (com base na volatilidade realizada de 10 dias), e os retornos overnight têm um desvio padrão de 5 vezes mais do que o dobro do que os retornos próximos ao fechamento. Você pode esperar um movimento nocturno 5SD aproximadamente uma vez por ano.
Aqui é um histograma de retornos fechados para fechar e retornos fechados para abrir. Você pode identificar claramente a afinidade em torno da área de -6% a -3%. O valor na extrema esquerda é de 24 de outubro de 2008. Note também que, apenas porque a desvantagem é negativa, não significa que as posições curtas são seguras: as colas dos retornos noturnos também são pesadas no lado direito.
Os retornos de fechar-abrir foram ajustados para ter a mesma volatilidade que os retornos de fechar-fechar para facilitar a comparação.
Regimes de mercado.
Estes riscos são quase os mesmos nos mercados de touro e urso. Por outro lado, eles parecem ser menores em ambientes de alta volatilidade (possivelmente um efeito colateral da volatilidade reversa média). Quando a volatilidade realizada por SPY & # 8217; 20 dias é superior a 20%, os riscos de cauda dos retornos overnight são aproximadamente os mesmos que os de retornos fechados. Mas isso não é tão útil, porque, afinal, em tempos de alta volatilidade, seu dimensionamento de posição já é limitado.
O fim de semana.
O fim de semana é um caso especial de risco ainda maior; você pode tratá-lo como outros períodos durante a noite. É mais volátil e apresenta perdas extremas ainda mais freqüentes. Na minha própria posição, eu sempre colocava limites adicionais em negociações durante o fim de semana.
Pensamentos finais.
Diferentes instrumentos se comportam de maneiras diferentes, especialmente quando se trata de diferentes classes de ativos. Os perigos durante a noite tendem a ser relativamente maiores para as ações em comparação com os índices. Portanto, certifique-se de que seu dimensionamento esteja adaptado às características únicas dos instrumentos que você está negociando.
Como uma regra geral, eu digo que, dada uma exposição de volatilidade igual, os retornos durante a noite expõem você sobre isso.
1,5-2x risco de retornos negativos extremos, enquanto o fim de semana expõe você ao risco 2-2.5x de retornos negativos extremos. Mas isso significa que você deve reduzir para metade as negociações durante a noite que você entra nas sextas? Não necessariamente. Não há uma resposta perfeita para este dilema: diferentes comerciantes e diferentes estratégias terão diferentes pontos de vista sobre o quanto eles estão dispostos a trocar retornos por movimentos menos extremos. A parte importante é quantificar o trade-off para que você saiba exatamente o quanto você está desistindo e quanto de risco você está assumindo.
Problemas na Otimização de Portfolios Swing.
Suponha que você tenha um monte de sistemas diferentes que negociam ações, ETFs de índice de ações, ETFs de obrigações e alguns outros ativos alternativos, por exemplo, ETFs de commodities. Todos os sistemas tomam posições longas e curtas. Quais são as perguntas que sua abordagem de otimização de portfólio deve responder? Este é um post focado em questões conceituais de alto nível em vez de detalhes de implementação.
Desejo a exposição ao fator de mercado?
Por & # 8220; fator de mercado & # 8221; Refiro-me ao primeiro componente que resulta de PCAing um monte de ações (o que é semelhante, mas não idêntico ao primeiro fator em todos os diferentes modelos de fatores acadêmicos). Em outras palavras, é o processo subjacente que impulsiona o retorno da equidade global como um todo.
Caso A: Seu sistema diz & # 8220; go long SPY & # 8221 ;. Isso é simples: você deseja exposição ao fator do mercado. Esta é basicamente uma estratégia de temporização beta: você está prevendo um retorno positivo no fator do mercado e usando a posição longa do SPY para capturá-lo. A gestão de riscos envolve basicamente diminuir a sua exposição SPY até atingir os níveis de risco desejados.
Caso B: Seu sistema diz & # 8220; vá longo SPY e QQQ curto & # 8221 ;. De repente, esta não é uma estratégia de temporização beta, mas algo muito diferente. Claramente, o que nos interessa neste cenário é o desempenho relativo dos componentes de retorno únicos de SPY e QQQ. Portanto, podemos pensar sobre isso como uma espécie de comércio de arbitragem estatística. A abordagem típica aqui é ir beta neutro ou dólar neutro, mas a paridade de risco ingênua também é razoável.
Eu continuo o mundo todo, e curto NFLX. Isso parece mais um comércio de temporização beta (Caso A) em vez de um comércio de estilo statarb (Caso B), porque o número e a largura dos negócios concentrados no lado longo indicam um retorno positivo no fator do mercado. Provavelmente não quero ser beta neutro neste caso. Nem todas as instâncias de negociações de ações longas / curtas podem ser reduzidas até & # 8220; ir mercado neutro e # 8221 ;. Então, como determinamos se queremos ser expostos ao fator do mercado ou não?
Uma solução intrigante seria criar um modelo de previsão em cima das estratégias: levaria como entrada seus sinais (e talvez outros recursos também) e preveja o retorno do fator do mercado no próximo período. Se o fator do mercado prevê aumento ou queda significativamente, então faça um comércio de temporização beta. Caso contrário, faça um comércio beta neutro. Se essa previsão puder agregar valor, a única desvantagem é a complexidade.
O fator de mercado é suficiente?
Deixe-se dizer que você troca 5 instrumentos: 3 ETFs dos EUA (SPY, QQQ, IWM), um ETF de Hong Kong (EWH) e um ETF da China (FXI). Deixe-nos dar uma olhada em alguns números. Aqui estão as correlações e a trama MDS para que você possa ter uma idéia de como esses instrumentos se relacionam um com o outro:
PCAing seus retornos mostra exatamente o que você esperaria: o primeiro componente é o que você chamou o fator do mercado e todos os ETFs têm um carregamento positivo e similar. O segundo componente é um fator específico da China.
PCA & # 8211; Cargas de fator.
E aqui é o biplot:
Nessa situação, não existe uma maneira prática de ser neutro no fator do mercado global e no fator específico da China. Para ilustrar rapidamente o porquê, considere estes dois cenários de pesos e as cargas de fator resultantes:
Devemos tentar minimizar os dois? Devemos tratar a EWH / FXI como um comércio de statarb independente e neutralizar o fator da China, e então usar nossa posição de SPY para fazer o timing de beta no fator de mercado global? Como sabemos qual opção escolher? Como automatizamos essa decisão?
Um problema semelhante surge se segmentarmos o mercado por setores. É possível que sua estratégia tenha um efeito de seleção que faça com que você esteja sobreponderando certos setores (as estratégias de baixa volatilidade de patrimônio têm esse problema), caso em que pode ser prudente começar com um orçamento de risco por setor e, em seguida, otimize seu portfólio dentro de cada setor separadamente.
Se você estiver executando um portfólio de statarb puro, esta é uma decisão fácil e, dada a grande quantidade de títulos em sua carteira, existe a possibilidade de minimizar a exposição não apenas ao fator do mercado, mas também a muitos outros. Para saber mais sobre como conseguir praticamente isso, confira Valle, Meade & amp; Breve, carteiras neutras de fator.
Desejo a exposição a outros fatores não-equitativos?
Deixe ver o que acontece quando adicionamos TLT (20+ ano tesouros) e GDX (mineradores de ouro) ao nosso universo de ativos. Correlações e MDS:
PCA & # 8211; Cargas de fator.
Algumas coisas a notar: como você espera, precisamos de mais fatores para capturar a maior parte da variância. Além disso, a interpretação do que cada fator & # 8220; significa & # 8221; é mais difícil: o primeiro fator ainda é o fator do mercado, mas depois disso # 8230; meu palpite é que o PC2 está relacionado à taxa de juros e o PC3 parece específico da China? Em qualquer caso, acho que a abordagem correta aqui é ser agnóstico sobre o que esses fatores significam & # 8221; e apenas abordá-lo como um problema puramente estatístico.
Neste ponto, eu também quero notar que esses fatores e suas respectivas cargas de instrumentos não são estáveis ​​ao longo do tempo. A sua escolha do período de lookback influenciará suas previsões.
Mais uma vez, nos deparamos com problemas semelhantes. Se os seus sistemas digam "GDX & # 8221; então, parece ser uma reprodução de tempo beta no PC2 / 3? / 4 ?. Mas vamos dizer que você está executando dois sistemas não relacionados, e eles lhe dão os seguintes sinais:
Devemos tratá-los como dois negócios independentes, ou devemos tratá-lo como um único comércio de estilo statarb? É importante que esses dois instrumentos estejam em classes de ativos completamente diferentes quando suas cargas PC1 e PC2 são tão semelhantes? É um comércio de valor relativo, ou estamos fazendo duas negociações de sincronismo beta separadas (mas na mesma direção) no PC4? Difícil de dizer sem um modelo explícito para prever os retornos dos fatores. Se você não sabe o que está gerando os retornos de suas negociações, não pode otimizar seu portfólio.
Eu tratamento todos os instrumentos por igual?
Depende. Se você seguir a rota agnóstica de fatores e tratar tudo como uma abstração estatística, então talvez seja melhor estar agnóstico sobre os próprios instrumentos. Por outro lado, posso ver alguns bons argumentos para regras feitas à mão que se aplicariam a classes de ativos específicas ou sub-classes. Certamente, quando se trata de gerenciamento de riscos, você não deve tratar as ações individuais da mesma forma que você trata os índices - talvez isso seja ampliado para a otimização do portfólio.
Também depende do que outros instrumentos você inclui no seu universo. Se você apenas negociar um único instrumento em uma classe de ativos, então talvez você possa tratar todos os negócios como um comércio de temporização beta.
Como equilibro os lados longo e curto?
Em um cenário simples, como o caso B (longo SPY / curto QQQ), isso é direto. Você escolhe alguma métrica: beta, $, volatilidade, etc. e apenas equilibre os dois lados.
Mas vamos voltar para o Caso C. mais complexo. A resposta de como equilibrar os lados longo e curto depende da nossa resposta anterior: devemos tratar esse cenário como o timing beta ou statarb? O problema com o último é que qualquer abordagem de gerenciamento de risco sensível irá limitar severamente sua exposição NFLX. E uma vez que você quer ser beta (ou $, ou σ) neutro, isso significa que, por extensão, o lado longo do comércio também será severamente limitado mesmo que ele leve muito menos risco idiossincrático.
Talvez possamos usar os limites de risco para determinar se queremos ser neutros ou não. Se você pode ser neutro devido a limites, então é um comércio de temporização beta. Você pode colocar sua fé em uma heurística tão complicada?
O que fazemos em situações em que estamos tendo que equilibrar um portfólio longo / curto com todos os tipos de classes de ativos diferentes? Nós separamos o portfólio (por classe, por fator de carregamento?) Para equilibrar cada parte separadamente? Como vimos no Caso E, nem sempre é claro quais instrumentos entram em qual grupo.
Como faço para alocar entre estratégias?
Até agora, nós apenas estudamos instrumentos, mas talvez essa seja a abordagem errada. E se usássemos a série de estratégias de retorno? Depois de toda a distribuição de retorno esperada condicional em um sinal que está sendo disparado de uma estratégia específica não é o mesmo que a distribuição de retornos incondicionais esperados do instrumento.
O que fazemos se a Estratégia A quiser colocar 5 negócios e a Estratégia B quiser colocar 1 comércio? Nós nos preocupamos em distribuir o orçamento de risco em todos os instrumentos, ou em estratégias, ou talvez seja um mix de ambos? Como podemos equilibrar isso com os limites de risco? Como equilibramos isso com o fator de carga?
Então, para resumir. O algoritmo ideal de otimização de portfólio equilibra perfeitamente os custos de negociação, os instrumentos, as classes de ativos, a exposição dos fatores (mas somente quando necessário), as estratégias e tudo isso sob as restrições impostas pelo gerenciamento de riscos. No final, não acho que haja boas respostas aqui. Apenas coleções feias de heurísticas.
Os seguidores da tendência fazem previsões como todos os outros.
Este post foi solicitado pela entrevista de Michael Covel & # 8217; Traders & # 8217; Revista na qual ele afirma que os seguidores de tendências não tentam fazer previsões. Essa idéia de que os seguidores da tendência não preveja os retornos é amplamente e freqüentemente repetida. Também é absurdo completo.
Toda estratégia de negociação faz previsões 1. Se essas previsões são explícitas ou escondidas por trás das regras de entrada / saída são irrelevantes. Todos os sistemas padrão de tendência podem ser convertidos trivialmente em um modelo de previsão que prevê retornos, porque eles são fundamentalmente equivalentes.
A formulação específica da tendência seguindo o sistema não importa, então eu continuarei a ser simples. Um indicador de tendência típica é o canal Donchian, que é simplesmente o n-bar mais alto e baixo mais baixo. Considere um sistema que vai por muito tempo quando o preço fecha acima do canal Donchian de 100 dias e sai quando o preço se fecha abaixo do canal Donchian de 50 dias.
Esta é a curva patrimonial do sistema aplicado aos futuros de petróleo bruto:
Este sistema pode ser trivialmente convertido em um modelo de previsão do formulário.
a variável dependente y é retorna e x será uma variável dummy que leva o valor 1 se estivermos em uma tendência e o valor 0 se não estivermos em uma tendência. Como definimos & # 8220; em uma tendência & # 8221 ;? Usando exatamente as mesmas condições que usamos para entradas e saídas, é claro.
Estimamos os parâmetros e descobrimos que α ≃ 0 e β = 0,099% (com p-valor 0,013). Então, usando esta tendência seguindo o modelo de previsão, o retorno esperado quando em uma tendência é de aproximadamente 10bp por dia e o retorno esperado quando não está em uma tendência é zero. Olhe, eu prevejo-me!
Mesmo sem modelar explicitamente essa relação, os seguidores de tendências implicitamente prevêem que as tendências persistam além do ponto de entrada; De outra forma, a tendência não funcionaria. O modelo pode ser facilmente estendido com regras de entrada / saída mais complicadas, venda a descoberto, os efeitos do dimensionamento de posição baseado em volatilidade, etc.
Visualizando a semelhança entre múltiplas séries temporais.
Apresentar a semelhança entre séries temporais múltiplas de forma intuitiva não é um problema fácil. A solução padrão é uma matriz de correlação, mas é uma abordagem problemática. Embora seja fácil verificar a correlação entre as duas séries e (com a ajuda de formatação condicional) a relação entre uma série e todo o resto, é difícil extrair uma compreensão intuitiva de como todas as séries são relacionados uns com os outros. E se você deseja adicionar uma dimensão de tempo para ver como as correlações mudaram, as coisas se tornam ainda mais problemáticas.
A solução é a escala multidimensional (a versão clássica & # 8220 ;, da qual é conhecida como Análise de Coordenadas Principais). É uma maneira de tomar uma matriz de distância e, em seguida, colocar cada objeto em dimensões N, de modo que as distâncias entre cada um deles sejam preservadas o melhor possível. Obviamente, N = 2 é o caso de uso óbvio, pois faz para as visualizações mais simples. O MDS funciona de forma semelhante ao PCA, mas usa a matriz de dissimilaridade como entrada em vez da série. Aqui é uma boa opinião sobre as matemáticas por trás disso.
Deve-se notar que a MDS não se preocupa com a forma como você escolhe medir a distância entre as séries temporais. Enquanto usei correlações neste exemplo, você poderia facilmente usar uma técnica como a distorção do tempo dinâmico.
Abaixo está um exemplo com SPY, TLT, GLD, SLV, IWM, VNQ, VGK, EEM, EMB, usando correlações de 252 dias como medida de distância, calculadas todas as segundas. O gráfico de movimento nos permite ver não apenas as distâncias entre cada ETF em um ponto no tempo, mas também como eles evoluíram.
Algumas coisas interessantes a serem observadas: observe como os REITs (VNQ) se correlacionam mais estreitamente com as ações durante a crise financeira, como a dívida distante do mercado emergente (EMB) é de tudo o resto e a mudança de relacionamento entre prata (SLV) e ouro (GLD) .
Aqui é a mesma coisa com um monte de ETFs setoriais:
Para fazer MDS em casa: em R e MATLAB você pode usar cmdscale (). Posicionei uma implementação C # aqui.
Anunciando QPAS: Análise de desempenho, risco e execução de código aberto.
Quando comecei há alguns anos atrás, na verdade não conheci o meu desempenho além do simples relatório que o IB genera. Eventualmente, eu mudei para excel folhas que cresceu para um tamanho ridículo e incontrolável. Eu examinei o profissional de comércio, mas não era flexível ou profundo o suficiente para os meus requisitos.
Então eu escrevi o meu próprio (eu bloguei sobre isso aqui): por um lado eu me concentrei na flexibilidade em termos de como os dados podem ser divididos (com uma estratégia / sistema de tag / etiqueta muito versátil) e, por outro lado, em produzindo informações relevantes e relevantes que podem ser aplicadas para melhorar sua negociação. Agora eu usei isso para o WPF e removi um monte de componentes proprietários para que ele possa ser aberto. Então, & # 8230;
Estou muito feliz em anunciar que a primeira versão (0.1) do QUSMA Performance Analytics Suite (QPAS) já está disponível. Para obter uma visão geral de seus principais recursos de análise de desempenho, veja a documentação do relatório de desempenho.
A porta ainda está muito fresca, então eu realmente aprecio seus comentários. Para relatórios de erros, solicitações de recursos, etc., você pode usar o rastreador de problemas do GitHub, o grupo do google ou os comentários nesta publicação.
Embora as instruções IB flex forneçam dados suficientes para a maioria das funcionalidades, a QPAS precisa de dados adicionais para coisas como gráficos, análise de execução e benchmarking. Por padrão, ele usa QDMS, mas você pode usar sua própria fonte de dados implementando a interface IExternalDataSource.
Atualmente, o único corretor suportado é Interactive Brokers, mas para aqueles que não os usam, o sistema de importação de declarações é flexível: veja a página Implementar um Parser de Declaração na documentação para mais.
Devo notar que em geral eu projetei o aplicativo para mim e meu próprio estilo de negociação, o que significa que alguns recursos que você pode esperar estão faltando: nenhuma atribuição de setor / fator para classificadores de estoque, sem estatísticas de atribuição para selecionadores de crédito, cálculo de frequência diária de coisas como MAE / MFE (então, quaisquer negociações intradiárias mostrarão zero MAE / MFE) e nenhuma análise específica de opções. Todas essas coisas seriam razoavelmente fáceis de adicionar se você sentir (e conhecer um pouco de C #).
Clique aqui para instalar.
Documentação.
Fonte no GitHub.
Estatísticas de desempenho altamente detalhadas Análise de risco Ex-post Benchmarking Análise de execução Jornal comercial: anote trades com rich text e imagens.
Requisitos:
MySQL, ou MariaDB, ou SQL Server QDMS (Necessário apenas para alguns recursos: benchmarks, análise de execução e gráficos)
Capturas de tela:
Benchmarking Análise de execução Desempenho esperado.
Excursão adversa máxima Uso relativo do capital relativo pela estratégia Anotações comerciais com rich text e imagens.
Retorno cumulativo médio por dia Visão geral do comércio Desempenho por instrumento.
Divergências: Yield Spreads and Size.
E agora para algo completamente diferente. Um pouco de macro e um pouco de desempenho relativo do fator: o que acontece quando os spreads de rendimento e as pequenas capitulares divergem do S & amp; P 500?
Spreads de alto rendimento.
Primeiro, vamos jogar com alguns dados de macro-estilo. Abaixo você encontrará o SPY e BofA Merrill Lynch US High Yield Master II Opcional ajustado Spread (um índice de spread de títulos de alto rendimento) traçado contra SPY.
Obviamente, os dois estão inversamente correlacionados, pois os spreads tendem a se alargar nos mercados de urso. Valores muito baixos são sinais de superaquecimento. Nós ainda estamos a cerca de 130 pb dos mínimos anteriores à crise, então, a esse respeito, a situação atual parece muito boa. Ainda assim, é um pouco mais do que isso.
Primeiro, divergências. Quando os estoques continuam a fazer novos aumentos e se espalham começam a subir, as notícias geralmente ruins. Algumas das áreas mais interessantes a serem vistas são July & # 8217; 98, April & # 8217; 00, July & # 8217; 07 e July & # 8217; 11.
Também é interessante o contra-caso de May & # 8217; 10 que não apresentou tal divergência: o Flash Crash pode ter sido o motorista desse mergulho, e isso é, obviamente, desconectado da situação macro em geral e de alto rendimento se espalha em particular.
Então, vamos tentar quantificar essas divergências e ver se podemos obter algo útil delas # 8230; no gráfico acima, marquei os tempos em que tanto a propagação como o SPY estavam nos 10% superiores dos 100 - intervalo do dia. Como você pode ver, estes foram geralmente tempos próximos do topo, embora houvesse vários sinais falsos # 8221 ;, por exemplo, em novembro & # 8217; 05 e setembro & # 8217; 06. Aqui estão os retornos acumulados nos próximos 50 dias após esse sinal:
Muito desse efeito depende de períodos de sobreposição, no entanto, não é tão bom quanto parece. Ainda assim, acho que é definitivamente algo que vale a pena manter um olho. Claro que agora estamos muito longe desse tipo de sinal que dispara, pois os spreads estão caindo consistentemente.
Tamanho: Quando Pequenas Equidades Divergem.
Ultimamente, vimos o Russell 2000 (e, até certo ponto, o NASDAQ) dar um mergulho enquanto o S & amp; P 500 andou de lado com apenas pequenas retiradas. Existem várias maneiras de formular esta situação quantitativamente. Simplesmente fui com a diferença entre o retorno de 20 dias de SPY e IWM. Os resultados são bastante claros: o grande desempenho da superposição é um sinal (levemente) de alta, tanto para ações grandes quanto pequenas.
Quando a diferença de ROC (20) é maior do que 3%, a SPY tem retornos acima da média das seguintes 2-3 semanas, para melhora de 10 pb por dia (IWM também funciona bem, retornando aproximadamente 16bp por dia nos próximos 10 dias) . O reverso também é útil para analisar: a superação de baixa performance é baixa. Quando a diferença ROC (20) é inferior a -3%, os próximos 10 dias SPY retornam uma média de -5 pb por dia. Obviamente, não é suficiente para ficar curto, mas definitivamente pode ser útil em combinação com outros modelos.
Outra divergência interessante para ver é amplitude. Durante as últimas semanas, enquanto a SPY está pairando em torno dos máximos de todos os tempos, muitas das ações do índice estão abaixo dos SMAs de 50 dias. Eu deixarei a pesquisa de divergência de respiração como um exercício para o leitor, mas observarei que, contrariamente à divergência de tamanho, ela tende a ser descendente.
Em outras novidades, eu comecei a publicar binários do QDMS (o QUSMA Data Management System) à medida que ele está ficando mais maduro. Você pode encontrar o link na página do projeto # 8217 ;. Ele irá solicitar uma atualização quando uma nova versão for lançada.
Algumas notas sobre a permutação do parâmetro do sistema.
O conceito é essencialmente usar todos os resultados de uma otimização de força bruta e escolher a mediana como a melhor estimativa de desempenho fora da amostra. O primeiro passo é:
Os intervalos de varredura de parâmetros para o conceito do sistema são determinados pelo desenvolvedor do sistema.
E aqui reside o principal problema. O alcance da varredura determinará a mediana. Se o intervalo for muito grande, a estimativa será muito baixa e com base em dados que são essencialmente irrelevantes porque o comerciante nunca escolheria essa combinação de parâmetros. Se o alcance é muito estreito, todo o exercício é inútil. Mas o autor não fornece nenhuma maneira de escolher o intervalo ótimo a priori (porque não existe esse método). E, claro, como é mencionado no artigo, as aplicações repetidas do SPP com diferentes intervalos são problemáticas.
Para ilustrar, deixe usar a minha publicação UDIDSRI a partir de outubro de 2012. O período de amostra será o tempo antes dessa postagem e o # 8220; fora da amostra e # 8221; O período será o tempo depois; o instrumento é QQQ, e a estratégia é simplesmente passar muito tempo quando o UDIDSRI está abaixo de X (o valor no eixo x abaixo).
Como você pode ver, a relação entre os retornos do próximo dia e o UDIDSRI é bastante estável. Os retornos fora da amostra são mais altos na maior parte do alcance, mas isso é apenas um artefato do mercado gigante de touro no período de amostragem. Qual seria a melhor linha SPP em outubro de 2012? Qual é o melhor padrão de SPP em retrospectiva? O resultado teria sido útil? Faça-se estas perguntas para cada gráfico abaixo.
Deixe-nos olhar para SPY:
Uau. O melhor foi movido para & lt; 0,05. Dado um alcance muito amplo, a SPP teria feito uma previsão correta neste caso. Mas isso é uma mudança permanente ou apenas um resultado de um pequeno tamanho de amostra? Vamos ver os resultados para 30 ETFs de patrimônio 1:
Bem, isso é isso. E quanto ao SPP em comparação com outros métodos?
O uso de todos os dados de mercado disponíveis permite a melhor aproximação do longo prazo, de modo que, quanto mais dados de mercado disponíveis, mais precisa a estimativa.
Este não é o caso. A crítica do autor ao CV é que ele faz um uso ineficiente dos dados de mercado, mas essa é uma maneira ruim de ver as coisas. O CV usa todos os dados (apenas não em & # 8220; one go & # 8221;) e nos fornece estimativas reais do desempenho fora da amostra, enquanto a SPP apenas faz uma "conclusão educada" # 82221 ;. Um palpite que é 100% dependente de um intervalo de parâmetros arbitrariamente escolhido. Imagine, por exemplo, dois sistemas: um tem parâmetros ótimos estáveis ​​ao longo do tempo, enquanto o outro não. As implicações em termos de desempenho fora da amostra são óbvias. O CV mostrará com precisão a diferença entre os dois, enquanto o SPP não pode. Dependendo do intervalo escolhido, o SPP pode subestimar gravemente o verdadeiro desempenho do sistema estável. Há muita conversa sobre a "regressão para a média" # 8221 ;, mas o que significa é isso?
O SPP minimiza o erro padrão da média (SEM) usando todos os dados de mercado disponíveis na simulação histórica.
Isso é verdade, mas, novamente, o que significa? A verdadeira questão não é o erro da estimativa, é se você está estimando a coisa certa em primeiro lugar. A divisão de dados do CV não é um erro arbitrário feito para aumentar o erro! É um ponto, e isso está medindo o desempenho real da amostra, dado parâmetros que de fato teriam sido escolhidos.
tl; dr: para alguns sistemas SPP é inútil ou simplesmente errado. Para algumas outras classes de sistemas onde o desempenho da amostra pode variar entre uma série de parâmetros, o SPP provavelmente produzirá resultados razoáveis. Mesmo no último caso, acho que você melhorou ficar com CV.
Reverse Engineering DynamicHedge's "Alpha Curves", Parte 2.5 de 3: DTW Barycenter Averaging.
A média de séries financeiras de uma maneira que preserva recursos importantes é um problema interessante e central na busca de criar boas curvas alfa e # 8221 ;. Uma média padrão em várias séries temporais geralmente suaviza os aspectos mais salientes: a magnitude dos extremos e seu tempo. Naturalmente, esses pontos são os mais importantes para os comerciantes, pois fornecem orientação sobre quando e onde negociar.
DTW Barycenter Averaging (ou DBA) é um algoritmo iterativo que usa a distorção de tempo dinâmico para alinhar a série a média com uma média em evolução. Foi introduzido em um método de média global para a distorção de tempo dinâmico, com aplicações para agrupamento por Petitjean, et. al. Como você verá abaixo, o método DBA tem várias vantagens que são bastante importantes quando se trata de combinar séries temporárias financeiras. Observe que também pode ser usado para agrupar séries temporais usando k-means. Aproximadamente, o algoritmo funciona da seguinte forma:
A série n a ser calculada como média é rotulada S 1 & # 8230; S n e tem comprimento T. Comece com uma série média inicial A. Enquanto a média não convergiu: Para cada série S, execute DTW contra A e salve o caminho. Use os caminhos e construa uma nova média A dando a cada ponto um novo valor: a média de cada ponto de S conectado a ele no caminho DTW.
Você pode encontrar instruções passo a passo detalhadas no papel acima.
Um bom processo de inicialização é extremamente importante porque, embora o próprio processo DBA seja determinista, o resultado final depende fortemente da sequência média inicial. Para nossos propósitos, temos 3 objetivos distintos:
Para preservar a forma das entradas. Para preservar a magnitude dos extremos no eixo y. Para preservar o tempo desses extremos no eixo x.
Vamos dar uma olhada em como o DBA se compara à média normal e como a seqüência média inicial afeta o resultado final. Para fins de teste, comecei com esta série:
Em seguida, criou um monte de cópias adicionando alguma variação aleatória e um deslocamento do eixo x:
Para começar, vamos ver o que é uma média simples. Observe a forma, a distância entre o pico eo vale e a magnitude dos valores mínimo e máximo: tudo longe da série original.
A média simples falha em todos os 3 objetivos definidos acima.
Agora, no DBA. Quais são as nossas opções de inicialização? Meu primeiro instinto foi tentar iniciar o processo usando a média simples acima. Enquanto isso atinge o objetivo # 2, a forma geral é obviamente errada.
Petitjean et. al. recomendar escolher uma das séries de entrada aleatoriamente. Por um lado, isso preserva a forma bem, mas o tempo dos extremos depende de qual série foi escolhida. Além disso, um processo determinista é preferível por razões óbvias.
Minha solução era usar uma série de entrada para inicialização, mas escolhê-la através de um processo determinista. Eu primeiro desprendi todos os timeseries, depois registre o valor do eixo x dos valores máximos e mínimos do eixo y para cada série. A série mais próxima da mediana desses valores é escolhida. Isso nos permite preservar a forma, as magnitudes extremas do eixo dos e, e ter uma boa idéia da posição típica do eixo x desses extremos:
Você pode encontrar o código C para fazer o DBA aqui.
Reverse Engineering DynamicHedge & # 8217; s & # 8220; Alpha Curves & # 8221 ;, Parte 2 de 3: Clustering K-Medoids.
Na primeira parte da série, cobrimos a distorção do tempo dinâmico. Aqui nós olhamos para o clustering. O agrupamento de K-means é provavelmente o método mais popular, principalmente devido à sua simplicidade e algoritmo intuitivo. No entanto, tem algumas desvantagens que tornam uma escolha ruim quando se trata de séries temporais de agrupamento. Em vez disso, usaremos agrupamento de K-medoids.
A principal diferença conceitual entre K-means e K-medoids é a distância utilizada no algoritmo de agrupamento. K-means usa a distância de um centróide (uma média dos pontos no cluster), enquanto K-medoids usa distância de um medoide, que é simplesmente um ponto selecionado a partir dos dados. Os algoritmos utilizados para chegar aos clusters finais são bastante diferentes.
O agrupamento de K-medoide depende de distâncias de k (neste caso 2) pontos extraídos dos dados.
As distâncias de K-means são tiradas de um centróide que é criado pela média dos pontos desse cluster.
Como K-medoids se compara com K-means? Tem várias características que o tornam superior para a maioria dos problemas em finanças.
K-medoids não é sensível a outliers que podem & # 8220; puxar & # 8221; o centróide a uma posição desvantajosa. K-medoids pode lidar com funções de distância arbitrárias. Ao contrário de K-means, não há necessidade de um meio a ser definido. Ao contrário de K-means, K-medoids não tem problemas com clusters de tamanho diferente. K-medoids is also potentially less computationally intensive when the distance function is difficult to solve, as distances only need to be computed once for each pair of points.
Note that there’s no guarantee on the size of each cluster. If you want to, it’s trivial to add some sort of penalty function to force similarly-sized clusters.
The algorithm is simple:
Choose k points from the sample to be the initial medoids (see below for specific methods). Give cluster labels to each point in the sample based on the closest medoid. Replace the medoids with some other point in the sample. If the total cost (sum of distances from the closest medoid) decreases, keep this new confirugration. Repeat until there is no further change in medoids.
Initialization, i. e. picking the initial clusters before the algorithm is run, is an important issue. The final result is sensitive to the initial set-up, as the clustering algorithm can get caught in local minimums. It is possible to simply assign labels at random and repeat the algorithm multiple times. I prefer a deterministic initialization method: I use a procedure based on Park et al. , the code for which you can find further down. The gist of it is that it selects the first medoid to be the point with the smallest average distance to all other points, then selects the remaining medoids based on maximum distance from the previous medoids. It works best when k is set to (or at least close to) the number of clusters in the data.
An example, using two distinct groups (and two outliers):
Initial medoids with k=2.
The first medoid is selected due to its closeness to the rest of the points in the lower left cluster, then the second one is selected to be furthest away from the first one, thus “setting up” the two obvious clusters in the data.
In terms of practical applications, clustering can be used to group candlesticks and create a transition matrix (also here), to group and identify trading algorithms, or for clustering returns series for forecasting (also here). I imagine there’s some use in finding groups of similar assets for statistical arbitrage, as well.
Something I haven’t seen done but I suspect has potential is to cluster trades based on return, length, adverse excursion, etc. Then look at the average state of the market (as measured by some indicators) in each cluster, the most common industries of the stocks in each cluster, or perhaps simply the cumulative returns series of each trade at a reasonably high frequency. Differences between the “good trades” cluster(s) and the “bad trades” cluster(s) could then be used to create filters. The reverse, clustering based on conditions and then looking at the average returns in each cluster would achieve the same objective.
I wrote a simple K-medoids class in C#, which can handle arbitrary data types and distance functions. You can find it here. I believe there are packages for R and python if that’s your thing.
2013: Lessons Learned and Revisiting Some Studies.
The year is over in a few hours and I thought it would be nice to do a quick review of the year, revisit some studies and the most popular posts of the year, as well as share some thoughts on my performance in 2013 and my goals for 2014.
Revisiting Old Studies.
IBS did pretty badly in 2012, and didn’t manage to reach the amazing performance of 2007-2010 this year either. However, it still worked reasonably well: IBS < 0.5 led to far higher returns than IBS > 0.5, and the highest quarter had negative returns. It still works amazingly well as a filter. Most importantly the magnitude of the effect has diminished. This is partly due to the low volatility we’ve seen this year. After all IBS does best when movements are large, and SPY’s 10-day realized volatility never even broke 20% this year. Here are the stats:
The original post can be found here. Performance in 2013 hasn’t been as good as in the past, but was still reasonably OK. I think the results are, again, at least partially due to the low volatility environment in equities this year.
UDIDSRI performance, close-to-close returns after a zero reading.
DOTM seasonality.
I’ve done 3 posts on day of the month seasonality (US, EU, Asia), and on average the DOTM effect did its job this year. There are some cases where the top quarter does not have the top returns, but a single year is a relatively small sample so I doubt this has any long-term implications. Here are the stats for 9 major indices:
Day of the month seasonality in 2013.
VIX:VXV Ratio.
My studies on the implied volatility indices ratio turned out to work pretty badly. Returns when the VIX:VXV ratio was 5% above the 10-day SMA were -0.03%. There were no 200-day highs in the ratio in 2013!
Atuação.
Overall I would say it was a mixed bag for me this year. Returns were reasonably good, but a bit below my long-term expectations. It was a very good year for equities, and my results can’t compete with SPY’s 5.12 MAR ratio, which makes me feel pretty bad. Of course I understand that years like this one don’t represent the long-term, but it’s annoying to get beaten by b&h nonetheless.
Some strategies did really well:
Others did really poorly:
Risk was kept under control and entirely within my target range, both in terms of volatility and maximum drawdown. Even when I was at the year’s maximum drawdown I felt comfortable…there is still “psychological room” for more leverage. Daily returns were positively skewed. My biggest success was diversifying across strategies and asset classes. A year ago I was trading few instruments (almost exclusively US equity ETFs) with a limited number of strategies. Combine that with a pretty heavy equity tilt in the GTAA allocation, and my portfolio returns were moving almost in lockstep with the indices (there were very few shorting opportunities in this year’s environment, so the choice was almost always between being long or in cash). Widening my asset universe combined with research into new strategies made a gigantic difference:
I made a series of mistakes that significantly hurt my performance figures this year. Small mistakes pile on top of each other and in the end have a pretty large effect. All in all I lost several hundred bp on these screw-ups. Hopefully you can learn from my errors:
Back in March I forgot the US daylight savings time kicks in earlier than it does here in Europe. I had positions to exit at the open and I got there 45 minutes late. Naturally the market had moved against me. A bug in my software led to incorrectly handling dividends, which led to signals being calculated using incorrect prices, which led to a long position when I should have taken a short. Taught me the importance of testing with extreme caution. Problems with reporting trade executions at an exchange led to an error where I sent the same order twice and it took me a few minutes to close out the position I had inadvertently created. I took delivery on some FX futures when I didn’t want to, cost me commissions and spread to unwind the position. Order entry, sent a buy order when I was trying to sell. Caught it immediately so the cost was only commissions + spread. And of course the biggest one: not following my systems to the letter. A combination of fear, cowardice, over-confidence in my discretion, and under-confidence in my modeling skills led to some instances where I didn’t take trades that I should have. This is the most shameful mistake of all because of its banality. I don’t plan on repeating it in 2014.
Goals for 2014.
Beat my 2013 risk-adjusted returns. Don’t repeat any mistakes. Make new mistakes! But minimize their impact. Every error is a valuable learning experience. Continue on the same path in terms of research. Minimize model implementation risk through better unit testing.
Mais popular.
Finally, the most popular posts of the year:
I want to wish you all a happy and profitable 2014!

Time Series Matching.
THIS IS NOT INVESTMENT ADVICE. The information is provided for informational purposes only.
Do you want to know what S&P 500 will do in the next week, month, quarter? One way to make an educated guess is to find historical periods similar to the current market environment, and examine what happened. I will call this process time series matching, but you could find a similar techniques referred as technical patterns and fractals. To get some flavor about fractals, following are two articles I read recently about fractals:
I recommend reading following article about the time series matching to understand different approaches:
I will use a simple method outlined in the How to Accelerate Model Deployment using Rook by Jean-Robert Avettand-Fenoel article to find time series matches that are similar to the most recent 90 days of SPY.
Following code loads historical prices from Yahoo Fiance, setups the problem and computes Euclidean distance for the historical rolling window using the Systematic Investor Toolbox:
Next, let’s select the best 10 matches to the ‘query’ pattern in the SPY history:
Next, let’s overlay all matches with the ‘query’ pattern and examine their historical performance after the match took place:
Next, let’s summarize all matches performance in a table:
The Time Series Matching analysis can be used to make an educated guess what S&P 500 will do in the next week, month, quarter. This educated guess is based on historical data and there is no guarantees that history will repeat itself.
In the next post I will examine other distance measures for Time Series Matching and I will show an example of Dynamic time warping.
To view the complete source code for this example, please have a look at the bt. matching. test() function in bt. test. r at github.
Comentários estão fechados.
Posts populares recentes.
Artigos mais visitados da semana.
Empregos para usuários R.
É alimentado pelo WordPress usando um design bavotasan.
Direitos autorais e cópia; 2017 R-bloggers. Todos os direitos reservados. Termos e Condições para este site.

Time Series Matching with Dynamic Time Warping.
THIS IS NOT INVESTMENT ADVICE. The information is provided for informational purposes only.
In the Time Series Matching post, I used one to one mapping to the compute distance between the query(current pattern) and reference(historical time series). Following chart visualizes this concept. The distance is the sum of vertical lines.
An alternative way to map one time series to another is Dynamic Time Warping(DTW). DTW algorithm looks for minimum distance mapping between query and reference. Following chart visualizes one to many mapping possible with DTW.
To check if there a difference between simple one to one mapping and DTW, I will search for time series matches that are similar to the most recent 90 days of SPY in the last 10 years of history. Following code loads historical prices from Yahoo Fiance, setups the problem and computes Euclidean distance for the historical rolling window using the Systematic Investor Toolbox:
Next, let’ examine the top 10 matches using Dynamic Time Warping distance. I will use the Dynamic Time Warping implementation from dtw package.
Both algorithms produced very similar matches and very similar predictions. I would use these predictions as an educated guess to market action going forward. So far, it looks like the market will not be going up in full throttle in the next 22 days.

Dynamic Time Warping.
History does not repeat itself, but it often rhymes – Mark Twain.
You certainly wouldn’t know it from a reading of the CBOE S&P500 Volatility Index (CBOE:VIX), which printed a low of 11.44 on Friday, but there is a great deal of uncertainty about the prospects for the market as we move further into the third quarter, traditionally the most challenging period of the year. Reasons for concern are not hard to fathom, with the Fed on hold and poised to start raising rates, despite anemic growth in the economy; gloom over the “earnings recession”; and an abundance of political risk factors in play, not least of which is the upcoming presidential election.
At times like these investors need a little encouragement to stay the course – and where better to look for it than in the history books. More specifically, the question is whether the past has anything to teach us about the prospects for the market, going forward. Academic theory says no; but Wall Street traders controlling trillions of dollars of investments believe that, on the contrary, history contains valuable information that can be helpful in predicting the likely future outcome for the market.
Correlation, Drift and Volatility.
There are several difficulties in making historical comparisons. Firstly, while it maybe intuitively obvious what one means when speaking about a “comparable” historical period, it is not as easy as one might think to translate that concept into mathematical form. And it does need to be translated, because unless you plan to study market history comprising tens or hundreds of thousands of historical patterns by hand (eye), you are going to have to rely on computers to do the heavy lifting.
Perhaps the most well-known measure of “similarity” is correlation; but this is entirely unsuited to the task at hand. The reason is that correlation removes the very thing that traders are most interested in: the trend, or drift. Let me illustrate the point with a simple example. The following chart illustrates two, perfectly correlated series (technically, Wiener processes) that simulate the evolution of returns in two stocks.
Source: Wolfram Research.
Even though the processes are perfectly correlated, they end up producing very different outcomes, chiefly because the red process has a strongly positive drift, or trend, while the green process has a strongly negative drift. It is highly implausible that the path realized by the green process would be regarded as similar to that of the red process, despite their correlation. The moral is simple: whatever else we mean by “similar”, it must entail a comparable result in terms of the overall appreciation (or depreciation) of the stock; i. e. the two periods must show a similar degree of trending behavior.
Now let’s consider a second illustrative example. Here, not only are the two processes perfectly correlated, they also have an identical drift (14%).
Source: Wolfram Research.
Despite their commonalities, it is again very unlikely that we would regard the behavior of the green process as being sufficiently “similar” to that of the red process. Here the problem is not the difference in drift, but in volatility, which is ten times higher for the green process than for the red process. Even though both processes are expected to appreciate at the same average rate, the high volatility of the green process means that it may appreciate at a much faster, or slower, rate than the mean. We say that the volatility “drowns out” the drift in the process, at least over the short term.
So, in conclusion, what we are looking for in our quest for “similarity” is a period in which the process has displayed, not only a similar trend, but also a comparable level of volatility.
The challenges don’t end there, however. Let’s say we find a period in history in which the overall appreciation and volatility of the process is “similar” to that of the period of interest, but the historical period is shorter, or longer, than the period we are evaluating. Does that matter? Well to some degree, it must: if during the historical period the stock appreciated by 50% in 3 days, vs the same percentage over a term of 3 months during the current period, it is again unlikely that we would regard the historical period as similar. On the other hand, if the two periods differed in length by, say, only 4-5 days out of a total of 30, would that be enough to make you discard the historical precedent? Probably not, other things being equal. So there has to be scope for some, but not unlimited, flexibility in making historical comparisons using periods of slightly differing durations.
Solving the Correspondence Problem with Dynamic Time Warping.
Having presented the problem, let me now turn to the solution.
Dynamic Time Warping (DTW) is a machine learning algorithm originally developed for speech recognition that aims two align two sequences by warping the time axis iteratively until a match is found between the two sequences.
Consider two sequences.
The two sequences can be arranged on the sides of a grid, with one on the top and the other up the left hand side. Both sequences start on the bottom left of the grid.
Inside each cell a distance measure is used to compare the corresponding elements of the two sequences. To find the best match or alignment between these two sequences one needs to find a path through the grid which minimizes the total distance between them. The procedure for computing this overall distance involves finding all possible routes through the grid and computing the overall distance for each one. The overall distance is the minimum of the sum of the distances between the individual elements on the path divided by the sum of the weighting function.
A great many measures of “distance” (the inverse of “similarity”) have been developed over the years, in fields as disparate as image analysis, signal processing and machine learning. In what follows we shall be using Euclidean Distance as our preferred distance metric, but there are a large number of alternative options:
The DTW algorithm optimizes the distance, constrained by limits on acceptable paths through the grid:
Monotonic condition : the path will not turn back on itself, both the i and j indexes either stay the same or increase, they never decrease. Continuity condition : the path advances one step at a time. Both i and j can only increase by at most 1 on each step along the path. Boundary condition : the path starts at the bottom left and ends at the top right. Warping window condition : a good path is unlikely to wander very far from the diagonal. The distance that the path is allowed to wander is the window width. Slope constraint condition : The path should not be too steep or too shallow. This prevents short sequences matching too long ones. The condition is expressed as a ratio p/q where p is the number of steps allowed in the same (horizontal or vertical) direction. After p steps in the same direction is not allowed to step further in the same direction before stepping at least q time in the diagonal direction.
These constraints allow to restrict the moves that can be made from any point in the path and so limit the number of paths that need to be considered. The power of the DTW algorithm lies in that instead finding all possible routes through the grid which satisfy the above conditions, it works by keeping track of the cost of the best path to each point in the grid. During the calculation process of the DTW grid it is not known which path is minimum overall distance path, but this can be traced back when the end point is reached.
Market Outlook Using Dynamic Time Warping.
Let’s apply the DTW approach to find a similar period in the history of the SPDR S&P 500 ETF (NYSEArca:SPY).
We download data for the SPY ETF and look for periods in the history of the series from 1995 that are similar to how the process has evolved in Q3 2016. Note that we are using log-returns rather than raw prices. This is because what we care about is that the rate at which the ETF has appreciated relative to its initial starting value should be comparable for both periods.
The algorithm picks out a 21-day period from 3/6/1995 to 4/7/1995 as being the most similar to the way the SPY ETF has progressed in Q3 2016. Let’s take a look at the two periods and assess their similarity. Note that we set the initial starting price at 100 in each case.
It is clear that the SPY appreciates by approximately the same percentage over the two periods, but the way in which it evolves looks rather different in each case. That’s because the earlier period covers only 25 business days, compared to the 51 days from the start of Q3 2016 period. If you can imagine dilating the shorter time span of the orange line in the above chart to cover the same span as the blue line, the patterns look very similar indeed.
We are going to use the historical period to forecast how the ETF is likely to evolve of the next 35 days to the end of Q3. We do this by mapping the evolution of the ETF over the 35 days following the end of the historical period on 4/7/95 and projecting that pattern onto the end of the current period, from 8/12/16. The result is as follows.
In other words, if the closely parallel history of the series from 1995 were to repeat itself in 2016, we might expect a further gain of perhaps 3.5% to 4% in the SPY ETF between now and the end of September.
Whether you hold this approach as valid or not depends largely on how credible you regard the thesis that history is inclined to repeat itself. There are significant differences in fundamental factors that are likely to affect the outcome over the next several months, compared to the similar period in 1995.
The early part of 1995 marked the beginning of a powerful market surge driven by an economic boom that lasted until late 1999. By contrast, in the more recent period, the economy has been emerging very slowly from the long-running credit crisis commencing in 2008. Likewise, in contrast to 1995 when the Fed was at the early stage of reducing interest rates, the Fed is now more likely to start raising rates at some point before the end of 2016.
While these and other aspects of the economic landscape are fundamentally different, there are parallels. The recent slowdown in productivity, for example, often cited as a cause for concern, mirrors a similar slowdown in 1995. As Bloomberg points out, such pauses are not uncommon and in fact the plateaus in 1993-1996 and 2003-2005 occurred at a time when the economy was pretty healthy. Conversely, several of the biggest productivity jumps have happened during recessions, in 2001 and 2009.
Conclusão.
Doom-mongering is at record levels these days, as the market continues to make new highs. The Wall Street Journal, for example, recently ran a piece entitled “This Tech Bubble Is Bursting”, drawing parallels with the dot-com bust of 2000.
They could be right.
On the other hand, if history repeats itself we could see the market 4% higher going into the final quarter of 2016.
Referências.
Sakoe, H. and Chiba, S. Dynamic programming algorithm optimization for spoken word recognition. IEEE Trans. on Acoust., Speech, and Signal Process., ASSP 26, 43-49 (1978).
Artigos relacionados.
A Comparison of Programming Languages.
Capitalizing on the Coming Market Crash.
The Swan of Deadwood.
1 comment. Leave new.
[…] Dynamic Time Warping [Jonathan Kinlay] History does not repeat itself, but it often rhymes Mark Twain You certainly wouldnt know it from a reading of the CBOE S&P500 Volatility Index (CBOE:VIX), which printed a low of 11.44 on Friday, but there is a great deal of uncertainty about the prospects for the market as we move further into the third quarter, traditionally the most challenging period of the year. Reasons for concern […]

Subsequence dynamic time warping for charting: Bullish and bearish class predictions for NYSE stocks.
Destaques.
We formally state and justify a set of five common characteristics of charting.
We propose an algorithmic scheme that captures these characteristics.
The proposed algorithm is primarily based on subsequence Dynamic Time Warping.
The proposed algorithm performs significantly in predicting bearish classes.
Bearish class predictions generate on average significant maximum potential profits.
Advanced pattern recognition algorithms have been historically designed in order to mitigate the problem of subjectivity that characterises technical analysis (also known as ‘charting’). However, although such methods allow to approach technical analysis scientifically, they mainly focus on automating the identification of specific technical patterns. In this paper, we approach the assessment of charting from a more generic point of view, by proposing an algorithmic approach using mainly the dynamic time warping (DTW) algorithm and two of its modifications; subsequence DTW and derivative DTW. Our method captures common characteristics of the entire family of technical patterns and is free of technical descriptions and/or guidelines for the identification of specific technical patterns. The algorithm assigns bullish and bearish classes to a set of query patterns by looking the price behaviour that follows the realisation of similar, in terms of price and volume, historical subsequences to these queries. A large number of stocks listed on NYSE from 2006 to 2015 is considered to statistically evaluate the ability of the algorithm to predict classes and resulting maximum potential profits within a test period that spans from 2010 to 2015. We find statistically significant bearish class predictions that generate on average significant maximum potential profits. However, bullish performance measures are not significant.
Escolha uma opção para localizar / acessar este artigo:
Verifique se você tem acesso através de suas credenciais de login ou sua instituição.

Reverse Engineering DynamicHedge’s Alpha Curves, Part 1 of 3: Dynamic Time Warping.
DynamicHedge recently introduced a new service called “alpha curves”: the main idea is to find patterns in returns after certain events, and present the most frequently occurring patterns. In their own words, alpha curves “represent a special blend of uniqueness and repeatability”. Here’s what they look like, ranked in order of “pattern dominance”. According to them, they “use different factors other than just returns”. We can speculate about what other factors go into it, possibly something like maximum extension or the timing of maxima and minima, but I’ll keep it simple and only use returns.
In this post I’ll do a short presentation of dynamic time warping, a method of measuring the similarity between time series. In part 2 we will look at a clustering method called K-medoids. Finally in part 3 we will put the two together and generate charts similar to the alpha curves. The terminology might be a bit intimidating, but the ideas are fundamentally highly intuitive. As long as you can grasp the concepts, the implementation details are easy to figure out.
To be honest I’m not so sure about the practical value of this concept, and I have no clue how to quantify its performance. Still, it’s an interesting idea and the concepts that go into it are useful in other areas as well, so this is not an entirely pointless endeavor. My backtesting platform still can’t handle intraday data properly, so I’ll be using daily bars instead, but the ideas are the same no matter the frequency.
So, let’s begin with why we need DTW at all in the first place. What can it do that other measures of similarity, such as Euclidean distance and correlation can not? Starting with correlation: one must keep in mind that it is a measure of similarity based on the difference between means. Significantly different means can lead to high correlation, yet strikingly different price series. For example, the returns of these two series have a correlation of 0.81, despite being quite dissimilar.
A second issue, comes up in the case of slightly out of phase series, which are very similar but can have low correlations and high Euclidean distances. The returns of these two curves have a correlation of .14:
So, what is the solution to these issues? Dynamic Time Warping. The main idea behind DTW is to “warp” the time series so that the distance measurement between each point does not necessarily require both points to have the same x-axis value. Instead, the points further away can be selected, so as to minimize the total distance between the series. The algorithm (the original 1987 paper by Sakoe & Chiba can be found here) restricts the first and last points to be the beginning and end of each series. From there, the matching of points can be visualized as a path on an n by m grid, where n and m are the number of points in each time series.
Source: Elena Tsiporkova, Dynamic Time Warping Algorithm for Gene Expression Time Series.
The algorithm finds the path through this grid that minimizes the total distance. The function that measures the distance between each set of points can be anything we want. To restrict the number of possible paths, we restrict the possible points that can be connected, by requiring the path to be monotonically increasing, limiting the slope, and restricting how far away from a straight line the path can stray. The difference between standard Euclidean distance and DTW can be demonstrated graphically. In this case I use two sin curves. The gray lines between the series show which points the distance measurements are done between.
Notice the warping at the start and end of the series, and how the points in the middle have identical y-values, thus minimizing the total distance.
What are the practical applications of DTW in trading? As we’ll see in the next parts, it can be used to cluster time series. It can also be used to average time series, with the DBA algorithm. Another potential use is k-nn pattern matching strategies, which I have experimented with a bit…some quick tests showed small but persistent improvements in performance over Euclidean distance.
If you want to test it out yourselves, there are plenty of tools out there. I’m using the NDTW library. There are libraries available for R and python as well.
Compartilhar isso:
Obrigado por este post. Muito interessante. I have been looking at Dynamic Hedge articles when he mentioned Alpha Curves for quite some time. And then I spotted your questin below the blog post and no answer from him and was just waiting for your blog post on the topic… 🙂
But please, don’t keep it simple (as you are saying: “We can speculate about what other factors go into it, possibly something like maximum extension or the timing of maxima and minima, but I’ll keep it simple and only use returns.”). Can you please explain what you mean by “…maximum extension or the timing of maxima and minima…” and possibly give an example in future posts. Obrigado.
There are nice posts on tye topic here:
Those are some great links, thanks. I really like the color-coded graphs that show the matched sequences. This one is good, too: etfprophet/mrkt_analogues-model/
For practical trading purposes the two most important points of an “alpha curve” are the points of maximum drawdown and maximum run-up. Any price targets or stops would presumably be based on the magnitude of those two, and time-based exits would be based on when they occur. So I think it might make sense to use these numbers when it comes to computing the distance between two series (and thus when it comes to clustering). The more similar the extremes, the smaller the distance.
Is the Dynamic Time Warping just a way of working around the artifact of calendar time? I have had good results by normalizing time according to tick count/volume as a method of reconstituting normality of returns (somewhat), but inhomogeneous delta-T increments makes many cointegration tests much more challenging, a problem I am still working on.
It can be used to work around the issue of calendar time, but it also has many other uses. Beyond the issue of similar series that are slightly out of phase, it can also be used to “work around” pattern similarity when the two series are at different speeds (the algorithm handles series of different lengths transparently, ej. iop/images/0957-0233/23/5/055601/Full/mst411675f1_online. jpg ), or the patterns exist on different scales.
The cointegration application seems interesting…I don’t think there’s any literature on the combination of DTW and cointegration tests but I think it could be a good match: use DTW to align the series and then run the ADF test (or whatever you use) on the aligned data…
these links are excellent. I thank the information.

No comments:

Post a Comment