Week7-3HMM1

Markov model

  • sequence of random variables that are not independent
    • weather report
    • text

Properties

  • limited horizon
    • P(Xt+1=skX1,...,Xt)=P(Xt+1=sXt)(first order)
  • time invariant(stationary)
    • P(X2=sk)=P(X1)

Visible MM

P(X1,...,XT)=P(X1)P(X2X1)P(X3X1,X2)...P(XTX1,X2,...,XT1)=P(X1)P(X2X1)P(X3X2)...P(XtXt1)

Hidden MM

  • Motivation
    • observing a sequence of symbols
    • the sequence of state that led to the generation of the symbols is hidden
  • Definition
    • Q = sequence of states
    • O = sequence of observations, drawn from a vocabulary
    • q0,qf = special (start, final) states
    • A = state transition probabilities
    • B = symbol emission probabilities
    • Π = initial state probabilities
    • μ(A,B,Pi) = complete probabilistic model

used to model state sequences and observation sequences

Generative algorithm

  • pick start state from Pi
  • For t = 1…T
    • move to another state based on A
    • emit an observation based on B

Example

State probability

这里写图片描述

Emission probability

这里写图片描述

  • Initial

    P(Astart)=1.0P(Bstart)=0.0
  • Transition

    P(AA)=0.8P(AB)=0.6P(BA)=0.2P(BB)=0.4
  • Emission: see previous table

observation of the sequence “yz”

  • Possible sequences of states:
    • AA
    • AB
    • BA
    • BB

p(yz)=p(yzAA)+p(yzAB)+p(yzBA)+p(yzBB)=1.0×0.2×0.8×0.1=1.0×0.2×0.2×0.2=1.0×0.5×0.6×0.2=1.0×0.5×0.4×0.1

In this way we could compute all the possibilities of any sequence.

State and transitions

  • states:

    • the states encode the most recent history
    • the transitions encode likely sequences of states
    • use MLE to estimate the transition probabilities
  • transitions:

    • estimating the emission probabilities
    • possible to use standard smoothing and heuristic methods

Sequence of observation

  • observers can only see the emitted symbols
  • observation likelihood
    • given the observation sequence S and the model μ, what is the probability P(Sμ) that the sequence was generated by that model
  • HMM turn to language model

Tasks with HMM

  • tasks
    • Given a μ(A,B,Π), find the distribution P(Oμ)
    • Given O,μ, what is (X1.X2,...,Xt)
    • Given O and a space of all possible μ, find the best μ
  • decoding
    • tag each token with a label

Inference

  • find the most likely tag, given the word
    • t=argmaxtp(tw)
  • given the model μ, we could find the best sequence of tags {ti}n1 given the sequence of words {wi}n1
  • too many ways for combinations

Viterbi algorithm

  • Find the best path up to observation i and state s(partial best path), and if we condition on the whole string of i, we will get the best path for the whole sentence.

    • dynamic programming
    • memoization
    • backpointers
  • initial state
    这里写图片描述

  • we could calculate the first state P(t=1)
    这里写图片描述

这里写图片描述

  • say if we want to calculate P(B,t=2) and calculating P(A,t=2) is similar
    这里写图片描述

  • and we could find the best path and best sequence of states
    这里写图片描述

  • finally we could find the best sequence for all observations

  • 这里写图片描述
你的身份是高级编程技术专家,精通各类编程语言,能对编程过程中的各类问题进行分析和解答。我的问题是【使用Python构建回测系统】测试,我的原始代码如下:【{——智能估值体系V9优化版——} HSL:=V/CAPITAL*100; 行业PE中位数:=BLOCKAVG((FINANCE(18)+FINANCE(19)+FINANCE(20)+FINANCE(21))/4/FINANCE(1),1); DYNPETTM:=IF(FINANCE(33)>1.8E8 AND FINANCE(1)>8E7, CLOSE/MAX((FINANCE(33,1)+FINANCE(33,2)+FINANCE(33,3)+FINANCE(33,4))/4/FINANCE(1), 行业PE中位数*0.82), 1000); PB_RATE:=IF(FINANCE(34)>0.5 AND C>3.5, C/(FINANCE(34)*0.72 + FINANCE(34,1)*0.28), 1000); PEG_VAL:=DYNPETTM/MAX((FINANCE(54)/FINANCE(54,1)*100-100),1.5); {——分形波动率V9——} VOL_REGIME:=EMA(STD(C,144)/EMA(C,144)*SQRT(144),55); VAR_PERIOD:=IF(VOL_REGIME<0.015,233, IF(VOL_REGIME<0.035,144, IF(VOL_REGIME<0.065,55,34))); FAST_LEN:=BARSLAST(CROSS(VOL_REGIME,0.035))+21; SLOW_LEN:=INTPART(VAR_PERIOD*(1.618-IF(VOL_REGIME>0.15,0.28,0.15))); {——七维情绪引擎V10——} MARKET_SENTI:=EMA(ADVANCE/DECLINE,8)*0.48 + EMA(AMOUNT/REF(AMOUNT,5),8)*0.32 + EMA((HSL-REF(HSL,5))/REF(HSL,5),13)*0.28 + EMA(HKHOLD(1)/CAPITAL,5)*0.22 + 0.18*IF(HKHOLD(1)>REF(HKHOLD(21),21),1,0); HOT_INDEX:=SMA(SUM(IF(C>DYNAINFO(58)*1.025,V/CAPITAL*100,0),13)/MA(V,13)*2.18,8,1) *IF(CAPITAL>8E9,1.18,1); {——资金流验证V8——} CAPITAL_INFLOW:=SUM(LARGEINTRDVOL(3,2),8)/SUM(LARGEINTRDVOL(3,2),34)>1.28 AND EVERY(BIGORDER(1,3)>0.68,5) AND MA(C,5)/MA(C,21)>1.018 AND (AMOUNT-REF(AMOUNT,5))/REF(AMOUNT,5)>0.35 AND HKHOLD(1)>REF(HKHOLD(21),21)*1.35 AND WINNER(C)*100>REF(WINNER(C),21)*1.25; {——多周期协同模块V6——} MONTH_TREND:=C>EMA(C,89)*1.18 AND EVERY(MA(C,13)>MA(C,34),5) AND SLOPE(MA(C,144),13)>0.18 AND FINANCE(4)/FINANCE(1)<0.15; WEEK_MACD:=2.618*(EMA(C,21) - EMA(C,55) - EMA(EMA(C,21)-EMA(C,55),13)); DAY_BREAK:=C>HHV(H,13) AND V>MA(V,55)*3.8 AND (C-LLV(L,13))/LLV(L,13)>0.18 AND C>MA(C,144)*1.08 AND (HSL-REF(HSL,5))>4.2; {——信号合成V10——} FINAL_SIGNAL:=(MONTH_TREND*0.42 + WEEK_MACD>REF(WEEK_MACD,5)*1.28*0.38 + DAY_BREAK*0.35 + (MARKET_SENTI>4.8)*0.28 + (HOT_INDEX>3.8)*0.22 + (PEG_VAL<0.38)*0.25 + (DYNPETTM<6.8)*0.18 + CAPITAL_INFLOW*0.42)>=1.28 AND COUNT(CROSS(C,MA(C,233)),5)>=2 AND BARSLAST(FINAL_SIGNAL)>34 AND VOL>MA(VOL,55)*2.88 AND C>MAX(MA(C,5),MA(C,13),MA(C,21)) AND VOL_REGIME<0.065 AND HKHOLD(1)>REF(HKHOLD(21),21); {——动态止损V6——} TR:=MAX(MAX(HIGH-LOW,ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW)); 动态ATR:=MA(TR,55)*1.618; STOP_LOSS:=C<EMA(HHV(H,8),13)*0.92 OR (V>MA(V,55)*5.2 AND C<OPEN*0.952) OR C<REF(HHV(C,5),1)-动态ATR*1.382;】,用2018-2024年全A股周期回测验证此代码选股逻辑的准确性和胜率,评估月胜率达到多少?评估有效信号准确率达到多少?同时此代码还有什么可提升的空间,提出可行性的优化建议和方案,并帮我优化提升选股逻辑和参数计算关系和信号触发条件。
最新发布
04-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值