跳转至

abm

产品如何定价的模型讨论

昨天跟人聊到这个问题,但是从经验上说,定价似乎需要考虑很多,但也好像不需要考虑一样。定价格有一些已有的规律,比如产品独领风骚然后按毛利去定的、红海市场跟随友商打价格的、为了扩张亏本卖的等等。经验这种东西会很有效,但它也是阻止破圈的罪魁祸首。所以这篇文章尝试建立一个代理人模型从尽可能多的角度去探索,毕竟这是一个系统性的问题,我们不讲经验,一两条经验不足以适配所有问题,干了40年的老板也不一定解决新场景遇到的问题,要不然百年老店不是又比现在多了一些。

当然,我仍然会建立一个合适的动态模型来模拟尽可能多的情况,如果是沙盘推演也没有问题,只是可能局限性比较大,不能把一些极端的变量组合考虑进去。设计的时候尽量遵循ODD原则(overview, design, detail),以保证覆盖现实情况的同时模拟出更多意外。

这里我们抛开单个产品差异化定价策略,即可以把产品拆成很细的定价策略,比如一块盘按照不同iops和容量租出去最大化利益,只讨论一块固有iops和容量的情况,因为这种拆分算利益的话,更适合用最优解公式而不是建模分析,况且现在差异化定价你会别人也会,最后难免都是同质竞争。

设计

以我熟悉的云计算为例,首先我们尽可能多的列出agent,最明显的就是产品、客户、厂商、供应商,但是这还不够,有些过度抽象了。(我们暂且忽略渠道,主要是因为渠道与云厂商体量在实际情况中基本保持一致,所以这点确实可以忽略)

那接下来我们加入更多agent,产品嘛单纯一些只有一类,客户这一类金融行业客户、游戏行业客户、制造行业客户,厂商的话主要考虑外部竞争和内部团队(云计算部门的集团投入政策、销售体系等),即会有几个体量、质量、策略等不同的厂商agent,厂商除了考虑同类供应商,也要考虑它的上下游,比如代工厂、圆晶厂、渠道商这些(方便实现简化保留下游,仅为防止泰国又洪水产品生命周期有影响)。

梗概

至此,我们已经在这个世界里已经可以描述一个完整的故事了,某个客户(可控数量)向某个云厂商(可控数量)购买最多N个产品(有生命周期),客户会根据自己的偏好选择厂商,厂商提供的产品受限于供应商(价格极低),如果客户技术能力强或者价格敏感度高可能会直接向供应商下单(供应商参与竞争,适用于OEM产品),最后我们的输出是某个厂商在未来一段时间内的市场表现变化,包括收益和客户占有率。

属性与动作

客户

列出尽可能多的agent以后,我们开始构建每个agent的属性和行为。由于我不想写那么多一个个解释,所以列几个意思一下,以金融客户为例(属性值和动作来源于市场销售记录统计,无法确定的值没关系,模拟的时候机器可以范围内随机探索)。

1
2
3
4
5
6
7
产品价格敏感性:低(0.2)
产品质量要求:中(0.5)
服务质量要求:高(0.8)
客户直销忠诚度:中(0.0-1)
客户渠道销售忠诚度:中(0.0-1)
IT技术能力:中(0.5)
受他人影响程度:高(0.7)

然后是动作,这些动作暂且适用于所有客户agent。

- 客户的属性随着时间的增长保持不变 - 客户会根据自己的属性偏好选择厂商产品,各个属性加权值决定产品,比如质量要求高的会喜欢产品综合质量好一些的、渠道忠诚度高的会喜欢渠道多的、IT技术能力低的会喜欢厂商服务好的 - 客户的购买行为除了在与云厂商直接,也可以发生在与供应商之间
- 客户的某属性超过一定阈值的时候(比如忠诚度),虽然所有属性加权值不是最佳,但会导致其这次仍然选择上一家
- 客户的忠诚度会随着历年选择厂商的变化而变化

产品

列出产品的属性,这里可以先定义这么几个。

1
2
3
4
5
6
7
8
9
产品价格:可控变量,即客户每天使用需要付出的价格  
产品状态:在厂、待售、使用、结束(这里假设每个产品从售出便不会再次回到产品池)  
产品用户:产品用户
已经销售:是否已经销售到客户
产品成本:与供应链相关
产品质量:随时间、客户增加而增加,有一个逐步完善的过程
产品销售厂商:产品销售厂商  
产品生产厂商:产品生产厂商
生命周期:产品从售出开始则开始消耗

厂商

然后是厂商的属性。

1
2
3
销售策略:盈利、求同、激进  
产品最大数量:对应厂商体量  
产品成本:与供应商有关

供应商

最后就是供应商的属性,为了减少复杂度,这里我们只有两类供应商,即可直接面向客户以及不可直接面向客户。

1
2
3
4
销售策略:盈利(供应商不赚就是亏)  
产品供应周期:每天能够生产的产品数量  
产品生产成本:可变量  
可直销:是、否

再加一些全局变量进去,比如从Gartner的趋势报告里把云计算、各类产品的每年增长也算进去,主要操控的变量是某个或多个厂商的定价范围(0-100)。

周期事件

TBD 一个周期内,会发生哪些事件呢?

产品:
客户:
厂商:
供应商:

模拟

预期

在开始之前,我们根据经验应该是对这个世界有一些经验预期的,包括:

1
2
3
4
5
6
7
8
一定范围内,定价不能直接决定市场占有率;  
产品做的晚的厂商即使定价再低也只能抢得一定份额的市场;  
供应商供货不足时,体量大的厂商更能抗住黑天鹅事件从而保证客户产品交付,从而获得更高的客户忠诚度;  
动态选择灵活的定价(销售)策略即使起步晚,也可以抢夺一部分可观的市场;  
价格敏感、技术能力强、忠诚度低的客户更容易从供应商处买;  
集团策略影响云厂商定价策略选择;  
在没被针对的情况下,小厂商初期可以打价格战争夺部分客户后,不会赚甚至是亏,但获取一定客户后再改变价格策略是可以盈利的;  
因为不同阶段采取不同的定价策略会影响市场表现,那么作为云厂商在期间的前端销售和供应商谈判策略也不尽相同,比如产品初期的时候很难从供应商要低价,平价甚至亏本抢占市场后可以再向供应商谈判出更低成本价;

行为空间模拟

最后我们来看看模拟的动态情况。

tbd model simulation

tbd 由结果我们先看到几种现象。。。

tbd 然后我们把自己的实际情况带入进去。。。

tbd

tbd 看的多了,再结合dikw模型,结论就是直觉可能就是对的。但是要给人展示数字,我们可以从各种渠道快速填充数字,从数字到推论,只是让人觉得你可信,至于你自己信或不信,就是另外一码事儿了。。。最后我们要把数字与经验结合起来,就是出几个概率数字,即未来几年内我们应该采取怎样的定价策略(保持毛利、争夺市场、自动动态调整)然后有百分之多少的概率占去多少这个产品的市场获得多少利益,根据概率做选择,虽然无法确信,但也不会犯错,平平淡淡才是真。

Agent based modeling相关


TensorFlow in NetLogo, Make Your Agent More Intelligent

0. Background

NetLogo is a very useful tools for ABM, and Python is also a handful language for building proof of concept.

In this post I will show you how to call python language in NetLogo. For more information please follow here.

1. NetLogo version

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
breed [data-points data-point]
breed [centroids centroid]

globals [
  any-centroids-moved?
]

to setup
  clear-all
  set-default-shape data-points "circle"
  set-default-shape centroids "x"
  generate-clusters
  reset-centroids
end

to generate-clusters
  let cluster-std-dev 20 - num-clusters
  let cluster-size num-data-points / num-clusters
  repeat num-clusters [
    let center-x random-xcor / 1.5
    let center-y random-ycor / 1.5
    create-data-points cluster-size [
      setxy center-x center-y
      set heading random 360
      fd abs random-normal 0 (cluster-std-dev / 2) ;; Divide by two because abs doubles the width
    ]
  ]
end

to reset-centroids
  set any-centroids-moved? true
  ask data-points [ set color grey ]

  let colors base-colors
  ask centroids [die]
  create-centroids num-centroids [
    move-to one-of data-points
    set size 5
    set color last colors + 1
    set colors butlast colors
  ]
  clear-all-plots
  reset-ticks
end

to go
  if not any-centroids-moved? [stop]
  set any-centroids-moved? false
  assign-clusters
  update-clusters
  tick
end

to assign-clusters
  ask data-points [set color [color] of closest-centroid - 2]
end

to update-clusters
  let movement-threshold 0.1
  ask centroids [
    let my-points data-points with [ shade-of? color [ color ] of myself ]
    if any? my-points [
      let new-xcor mean [ xcor ] of my-points
      let new-ycor mean [ ycor ] of my-points
      if distancexy new-xcor new-ycor > movement-threshold [
        set any-centroids-moved? true
      ]
      setxy new-xcor new-ycor
    ]
  ]
  update-plots
end

to-report closest-centroid
  report min-one-of centroids [ distance myself ]
end

to-report square-deviation
  report sum [ (distance myself) ^ 2 ] of data-points with [ closest-centroid = myself ]
end

; Copyright 2014 Uri Wilensky.
; See Info tab for full copyright and license.

2. TensorFlow version

TensorFlow version: 1.14

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import numpy as np
import tensorflow as tf

num-points = 100
dimensions = 2
points = np.random.uniform(0, 1000, [num-points, dimensions])

def input-fn():
  return tf.compat.v1.train.limit-epochs(
      tf.convert-to-tensor(points, dtype=tf.float32), num-epochs=1)

num-clusters = 5
kmeans = tf.contrib.factorization.KMeansClustering(
    num-clusters=num-clusters, use-mini-batch=False)

# train
num-iterations = 10
previous-centers = None
for - in xrange(num-iterations):
  kmeans.train(input-fn)
  cluster-centers = kmeans.cluster-centers()
  if previous-centers is not None:
    print 'delta:', cluster-centers - previous-centers
  previous-centers = cluster-centers
  print 'score:', kmeans.score(input-fn)
print 'cluster centers:', cluster-centers

# map the input points to their clusters
cluster-indices = list(kmeans.predict-cluster-index(input-fn))
for i, point in enumerate(points):
  cluster-index = cluster-indices[i]
  center = cluster-centers[cluster-index]
  print 'point:', point, 'is in cluster', cluster-index, 'centered at', center

3. NetLogo with Python Extension version

Here's the snapshot.

And here's the code.

extensions [ py ]

breed [data-points data-point] breed [centroids centroid]

data-points-own [ cluster-id ]

centroids-own [ cluster-id centx centy ]

globals [ testoutput centroid-list ]

to setup clear-all py:setup py:python (py:run "import tensorflow as tf" "import numpy as np" ) set testoutput py:runresult "1" py:set "testoutput" testoutput set-default-shape data-points "circle" set-default-shape centroids "x" generate-clusters ; For python py:set "num-points" num-clusters py:set "points" [list xcor ycor] of data-points py:set "num-clusters" num-clusters py:set "num-round" num-round if debug = True [ py:run "print('Points Cordinates:', points)" ;for debug ] ;reset-centroids end

to generate-clusters set testoutput py:runresult "testoutput + 1" let cluster-std-dev cluster-range let cluster-size num-data-points / num-clusters repeat num-clusters [ let center-x random-xcor / 1.5 let center-y random-ycor / 1.5 create-data-points cluster-size [ setxy center-x center-y set heading random 360 fd abs random-normal 0 (cluster-std-dev / 2) ] ] end

to train ; Cluster center (py:run "points = np.asarray(points)" "def input-fn():" " return tf.compat.v1.train.limit-epochs(tf.convert-to-tensor(points, dtype=tf.float32), num-epochs=1)" "kmeans = tf.contrib.factorization.KMeansClustering(num-clusters=num-clusters, use-mini-batch=False)" "num-iterations = num-round" "previous-centers = None" "for - in range(num-iterations):" " kmeans.train(input-fn)" " cluster-centers = kmeans.cluster-centers()" " if previous-centers is not None:" " print(('delta:', cluster-centers - previous-centers))" " previous-centers = cluster-centers" " print(('score:', kmeans.score(input-fn)))" "print(('cluster centers:', cluster-centers))" "# map the input points to their clusters" "cluster-indices = list(kmeans.predict-cluster-index(input-fn))" "print('cluster indices: ', cluster-indices)" "for i, point in enumerate(points):" " cluster-index = cluster-indices[i]" " center = cluster-centers[cluster-index]" " print(('point:', point, 'is in cluster', cluster-index, 'centered at', center))" ) end

to show-shape set centroid-list py:runresult "cluster-centers" foreach centroid-list [ x -> create-centroids 1 [ set xcor ( item 0 x ) set ycor ( item 1 x ) set size 3 set color white ] ] end

Ref:

[1] https://www.altoros.com/blog/using-k-means-clustering-in-tensorflow/

[2] https://www.tensorflow.org/api-docs/python/tf/contrib/factorization/KMeansClustering

外汇学习笔记

早先把书的内容过了一遍,现在打算把书中的模型统统实现并做相应介绍。

Agent based modeling Strategy in forex trading market

PREFACE

Since I've tested S1, S2, and S3 from the DATANOTE. However, it was not so good or in other words, identical with expectation. It's time to make a change.

BASIC MODEL AND ARCHITECTURE

As you can see from my last articles, the architecture's infrastructure is about to go and the agent's protocol is well defined. Now what we should do is to combine them together.

In the first phase, the simulation will JUST be a Netlogo program. If the performance is just like S1-3, then it goes to phase 2 ---- treating the agents as the real from the data gained and strategy trained from the real world. And if NOT, less probable, the program must be corrected.

PRACTICAL GUIDE

1. FAKE WORLD, FAKE AGENT
2. REAL WORLD, FAKE AGENT
3. REAL WORLD, REAL AGENT

World3 Model is a choice.(System Dynamics)

https://insightmaker.com/insight/1954/The-World3-Model-A-Detailed-World-Forecaster

title: "Forex data collection and backtesting with python/netlogo" date: 2017-03-13 categories: - "signal-system"


These two sites provides free forex tick/time data. So before getting into backtesting, we must get data.

I provide two scripts for you to download and update these data daily.

OK, it's boring...

http://github.com/lofyer/forex-data

However, there's still some work to update our data every day/week.

Like this:

TBD

For the next, we'll try to apply basic strategy to backtest our data.

Like this:

Forex Data ML Relationship

Data Processing with ML

Data Overview: 1. Forex Index <-> Currency Rate Change 2. News -> Classification -> Weight <-> Currency Rate Change

Caution: Strict Time Based Data pipeline.

外汇常用技术指标算法(附Python量化分析教程)

公式不好写,写到DataNote里吧。

Bill Williams Indicators

Accelerator/Decelerator oscillator(AC)

Acceleration/Deceleration (AC) technical indicator signals the acceleration or deceleration of the current market driving force.

How to Use Acceleration/Deceleration

The indicator is fluctuating around a median 0.00 (zero) level which corresponds to a relative balance of the market driving force with the acceleration. Positive values signal a growing bullish trend, while negative values may be qualified as a bearish trend development. The indicator changes its direction before any actual trend reversals take place in the market therefore it serves as an early warning sign of probable trend direction changes. The indicator color changes alone are very important as the current green line (irrespectively of the value) warns against long positions the same way as the red one would against selling. To enter the market along with its driving force one needs to watch for both value and color. Two consecutive green columns above the zero level would suggest you to enter the market with a long position while at least two red columns below the zero level might be taken for a command to go short. Fake signals prevail in timeframes smaller than 4 hours.

Acceleration/Deceleration Oscillator Formula (Calculation)

AC bar chart is the difference between the value of 5/34 of the driving force bar chart and 5-period simple moving average, taken from that bar chart.

AO = SMA(median price, 5)-SMA(median price, 34) AC = AO-SMA(AO, 5)

--------------------------------------------------------------------------- Alligator

Alligator is an indicator designed to signal a trend absence, formation and direction. Bill Williams saw the alligator's behavior as an allegory of the market's one: the resting phase is turning into the price-hunting as the alligator awakes so that to come back to sleep after the feeding is over. The longer the alligator is sleeping the hungrier it gets and the stronger the market move will be.

How to Use Alligator Indicator

The Alligator indicator consists of 13-, 8- and 5-period smoothed moving averages shifted into the future by 8, 5 and 3 bars respectively which are colored blue, red and green representing the alligator’s jaw, teeth and lips. The Alligator is resting when the three averages are twisted together progressing in a narrow range. The more distant the averages become, the sooner the price move will happen. The averages continuing in an upward direction (green followed by red and blue) suggest an emerging uptrend which we interpret as a signal to buy. The averages following each other in the reversed order down the slope are a strong signal of an unfolding downtrend so selling at this point would be more than appropriate.

Alligator Indicator Formula (Calculation)

MEDIAN PRICE = (HIGH + LOW) / 2 ALLIGATORS JAW = SMMA (MEDEAN PRICE, 13, 8) ALLIGATORS TEETH = SMMA (MEDEAN PRICE, 8, 5) ALLIGATORS LIPS = SMMA (MEDEAN PRICE, 5, 3)

--------------------------------------------------------------------------- Awesome oscillator(AO)

Awesome Oscillator (AO) is a momentum indicator reflecting the precise changes in the market driving force which helps to identify the trend’s strength up to the points of formation and reversal.

How to Use Awesome Oscillator

There are three main signals which may be seen: Saucer - three consecutive columns above the nought line the first two of which must be colored red (the second one is lower than the first one) while the third one is colored green and higher than the previous (second) one. Such a formation would be a clear Buy signal whilst inverted and vertically flipped formation would serve as a Sell signal. Nought line crossing - the histogram crosses the naught line in an upward direction changing its values from negative to that of positive ones. In this situation we have a Buy signal. The Sell signal would be a reversed pattern. Two pikes - the indicator displays a Buy signal when the figure is formed by two consecutive pikes both of which are below the naught line and the later-formed pike is closer to the zero level than the earlier-formed one. The Sell signal would be given by the reverse formation.

Awesome Oscillator Trading Strategy

Awesome Oscillator Strategy includes 3 ways of trading. The first way is to open a sell position when the oscillator is below the zero line forming a peak, and open a buy position when the oscillator is above the zero line forming a gap. Another way is to open a sell position when the oscillator forms two peaks above the zero line, where the second high is lower than the previous one. And, conversely, traders watch to open a buy position when the oscillator forms to lows below the zero line with the last one not as low as the previous one. The third way is to account crossing the zero line. When the oscillator crosses it from up to down, it is time to open a sell position and when it crosses from down to up, it is time to open a buy position.

Awesome Oscillator Formula (Calculation)

Awesome Oscillator is a 34-period simple moving average, plotted through the central points of the bars (H+L)/2, and subtracted from the 5-period simple moving average, graphed across the central points of the bars (H+L)/2. MEDIAN PRICE = (HIGH+LOW)/2 AO = SMA(MEDIAN PRICE, 5)-SMA(MEDIAN PRICE, 34) where SMA — Simple Moving Average.

--------------------------------------------------------------------------- Fractal Indicator Definition

Fractals is an indicator highlighting the chart’s local heights and lows where the price movement had stopped and reversed. These reversal points are called respectively Highs and Lows. How to Use Fractal Indicator

Bill Williams' Fractals are formed around a group of five consecutive bars the first two of which are successively reaching higher (or diving deeper) and the last two descending lower (or growing higher) with the middle one being the highest (or the lowest) result in the group accordingly. Buy fractal is an arrow pointing to the top Sell fractal is an arrow pointing to the bottom -------------------------------------------------------------------------- Gator Oscillator Definition

The Gator Oscillator (GO) is a supplement to the Alligator indicator and is used alongside with it showing the absolute degree of convergence/divergence of the Alligator's three SMAs pointing at the Alligator's periods of slumber and awakeness (i.e. trending and non-trending market phases). How to Use Gator Oscillator

Being an oscillator in the form of two histograms built on either side of the naught line, the Gator Oscillator plots the absolute difference between the Alligator’s Jaw and Teeth (blue and red lines) in the positive area and the absolute difference between the Alligator’s Teeth and Lips (red and green lines) in the negative area. The histogram’s bars are colored green if exceeding the previous bar’s volume or red if falling short. The bars of the extreme values are in tune with the strong trend forces. The Alligator's activity periods are divided into the following four: Gator awakes - the bars on different sides of the naught line are colored differently. Gator eats - green bars on both sides of the naught line. Gator fills out - single red bar during the "eating" phase. Gator sleeps - the bars on both sides are red -------------------------------------------------------------------------- Market Facilitation Index Definition

The Market Facilitation Index is designed for evaluation the willingness of the market to move the price. The indicator's absolute values alone cannot provide any trading signals unlike it's dynamics in relation to the dynamics of the volume. How to Use Market Facilitation Index

The absolute values of the index are represented by the histogram's bars while the comparison of the index and volume dynamics are given in colors which are vital in terms of reading the indicator signs. Green bar - both MFI and volume are up. Increasing trading activity means market movement acceleration. We may join the trend. Blue bar - MFI indicator is up, volume is down. The movement is continuing although the volume has dropped. The trend will soon be reversing. Pink bar - MFI indicator is down, volume is up. The slowing down movement while volume is raising may indicate a possible break through, often a U-turn. Brown bar - both MFI and volume are down. The market is no longer interested in the current direction and is looking for signs of a future development. Market Facilitation Index Market Facilitation Index (BW MFI) Market Facilitation Index Formula (Calculation)

BW MFI = (HIGH-LOW)/VOLUME --------------------------------------------------------------------------

Oscilators

Trend Indicators

Volume Indicators

Accumulation/Distribution(AD)

Accumulation/Distribution is a volume-based technical analysis indicator designed to reflect cumulative inflows and outflows of money for an asset by comparing close prices with highs and lows and weighting the relation by trading volumes.

How to Use Accumulation/Distribution

The Accumulation/Distribution line is used for trend confirmation or possible turning points identification purposes. Trend confirmation: An uptrend in prices is confirmed if A/D line is rising; A downtrend in prices is confirmed if A/D line is falling. Divergence pattern analysis: Rising A/D line along with decreasing prices indicates the downtrend may be weakening to a bullish reversal; Falling A/D along with rising prices indicates the uptrend may be weakening to a bearish reversal.

Accumulation/Distribution Indicator Formula (Calculation)

A/D(t) = [((C – L) – (H – C)) / (H – L)] x Vol + A/D(t-1), where: A/D(t) – current Accumulation/Distribution value; A/D(t-1) – previous Accumulation/Distribution value; H – current high; L – current low; C – close price; Vol – volume.

---------------------------------------------------------------------------

Average Directional Movement Index(ADX)

Average Directional Index (ADX) is a technical indicator developed by Welles Wilder to estimate trend strength and determine probable further price movements by comparing the difference between two consecutive lows with the difference between the highs.

How to Use ADX Indicator

ADX is a complex indicator, which results from calculation of the Plus Directional Indicator (+DI – green line) and the Minus Directional Indicator (-DI – red line), but all of them may be used for trend analysis.

In general the indicator (bold line) move is believed to reflect current trend strength: Rising ADX (usually climbing above 25) suggests strengthening market trend – trend following indicators are becoming more useful; Falling ADX suggests the trend development is doubtful. ADX values below 20 may indicate neutral trend is present – oscillators are becoming more useful. Use of complex ADX trading system may require additional confirmation signals: Normally if +DI (green line) climbs above -DI (red line), a buy signal is generated; Normally if -DI climbs above +DI, a sell signal is generated. Average Directional Index Indicator - ADX Indicator Average Directional Index (ADX) Indicator

ADX Trading Strategy

ADX trading strategy aims to identify the strongest trends and distinguish between trending and non-trending conditions. ADX reading above 25 indicates trend strength, while when ADX is below 25, this shows trend weakness. Breakouts, which are not difficult to spot, also help to identify whether ADX is strong enough for the price to trend or not. Thus, when ADX rises from below 25 to above 25, trend is considered strong enough to continue in the direction of the breakout. It’s a common misperception that when ADX line starts falling this is a sign of trend reversal. Whereas, it only means that the trend strength is weakening. As long as ADX is above 25, it should be considered that a falling ADX line is simply less strong.

ADX Formula (Calculation)

ADX = MA [((+DI) – (-DI)) / ((+DI) + (-DI))] x 100; where: +DI – Plus Directional Indicator; -DI – Minus Directional Indicator.

---------------------------------------------------------------------------

Average True Range(ATR) --------------------------------------------------------------------------- Bears Power --------------------------------------------------------------------------- Bollinger Bands --------------------------------------------------------------------------- Bulls Power --------------------------------------------------------------------------- Commodity Channel Index(CCI) --------------------------------------------------------------------------- DeMarker --------------------------------------------------------------------------- Envelopes --------------------------------------------------------------------------- Force --------------------------------------------------------------------------- Fractals --------------------------------------------------------------------------- Gator oscillator --------------------------------------------------------------------------- Ichimoku Kinko Hyo --------------------------------------------------------------------------- Market Facilitation Index(BWMFI) --------------------------------------------------------------------------- Momentum --------------------------------------------------------------------------- Money Flow Index --------------------------------------------------------------------------- 移动平均线(Moving Average,MA)

MA=N日收市价之和/N 一般N可取短期5或10天,也可是30、65、200、280等中长期。

Moving Average is a technical analysis tool that shows average price over a given period of time, which is used to smoothen price fluctuations and therefore to determine trend direction and strength. Depending of the method of averaging, distinguish between simple moving average (SMA), smoothed moving average (SMMA) and exponential moving average (EMA).

Moving Average Trading Strategy

Moving average strategy is essentially a trend following means. Its objective is to signal the beginning of a new trend or a trend reversal. Herein, its main purpose is to track the progress of the trend and not to predict market action in the same sense that technical analysis attempts to do. By its nature, Moving Average is a follower; it follows the market telling that a new trend has begun or reversed only after the fact.

Moving Average Formula (Calculation)

SMA = Sum (Close (i), N) / N, where: Close (i) – current close price; N – period of averaging. EMA(t) = EMA(t-1) + (K x [Close(t) – EMA(t-1)]), where: t – current period; K = 2 / (N + 1), N – period of averaging.

How to Use Moving Average

Generally moving average curves analysis includes the following principles: Direction of moving average curve reflects prevailing trend over a period; Low-period averaging may give more false signals, while large-period averaging tend to be lagging; To increase (decrease) sensitivity of the curve one should decrease (increase) the period of averaging; Average curves are more useful in trending environment.

Comparing moving average with price movements: A strong buy (sell) signal arise if price crosses from below (from above) its rising (falling) moving average curve; A weak buy (sell) signal arise if price crosses from below (from above) its falling (rising) moving average curve. Comparing moving average curves of different periods: A rising (falling) lower-period curve crossing from below (above) another rising (falling) longer-period curve gives a strong buy (sell) signal; A rising (falling) lower-period curve crossing from below (above) another falling (rising) longer-period curve gives a weak buy (sell) signal. --------------------------------------------------------------------------- Moving Average of Oscillator --------------------------------------------------------------------------- 抛物线转向(Stop And Reverse)

SAR(n)=SAR(n-1)+AF*[EP(n-1)-SAR(n-1)]

其中:SAR(n)为第n日的SAR值,SAR(n-1)为第(n-1)日的值;AF为加速因子(或叫加速系数),EP为极点价(最高价或最低价)。

-*- coding: utf-8 -*-

""" http://virtualizedfrog.wordpress.com/ 2014

Translated from http://www.amibroker.com/library/detail.php?id=268 Requires pandas to load csv files, and matplotlib to chart the data

The main expects table.csv file. Valid files can be downloaded on Yahoo Finance eg: http://real-chart.finance.yahoo.com/table.csv?s=%5EGSPC&ignore=.csv """

import pandas as pd from datetime import datetime import matplotlib.pyplot as plt

def psar(barsdata, iaf = 0.02, maxaf = 0.2): length = len(barsdata) dates = list(barsdata['Date']) high = list(barsdata['High']) low = list(barsdata['Low']) close = list(barsdata['Close']) psar = close[0:len(close)] psarbull = [None] * length psarbear = [None] * length bull = True af = iaf ep = low[0] hp = high[0] lp = low[0]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
for i in range(2,length):
    if bull:
        psar\[i\] = psar\[i - 1\] + af \* (hp - psar\[i - 1\])
    else:
        psar\[i\] = psar\[i - 1\] + af \* (lp - psar\[i - 1\])

    reverse = False

    if bull:
        if low\[i\] < psar\[i\]:
            bull = False
            reverse = True
            psar\[i\] = hp
            lp = low\[i\]
            af = iaf
    else:
        if high\[i\] > psar\[i\]:
            bull = True
            reverse = True
            psar\[i\] = lp
            hp = high\[i\]
            af = iaf

    if not reverse:
        if bull:
            if high\[i\] > hp:
                hp = high\[i\]
                af = min(af + iaf, maxaf)
            if low\[i - 1\] < psar\[i\]:
                psar\[i\] = low\[i - 1\]
            if low\[i - 2\] < psar\[i\]:
                psar\[i\] = low\[i - 2\]
        else:
            if low\[i\] < lp:
                lp = low\[i\]
                af = min(af + iaf, maxaf)
            if high\[i - 1\] > psar\[i\]:
                psar\[i\] = high\[i - 1\]
            if high\[i - 2\] > psar\[i\]:
                psar\[i\] = high\[i - 2\]

    if bull:
        psarbull\[i\] = psar\[i\]
    else:
        psarbear\[i\] = psar\[i\]

return {dates:dates, high:high, low:low, close:close, psar:psar, psarbear:psarbear, psarbull:psarbull}

if __name__ == "__main__": import sys import os

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
if len(sys.argv) < 2:
    sys.exit("Usage: %s datafile.csv" % sys.argv\[0\])
if not os.path.exists(sys.argv\[1\]):
    sys.exit("Error: can't open file '%s': No such file" % sys.argv\[1\])

barsdata = pd.read\_csv(sys.argv\[1\])
#Reindex the data: ascending dates are expected in the function
barsdata = barsdata.reindex(index=barsdata.index\[::-1\])
#Convert strings to actual timestamps
barsdata\['Date'\] = \[datetime.strptime(x, '%Y-%m-%d') for x in barsdata\['Date'\]\]

startidx = 0
endidx = len(barsdata)

result = psar(barsdata)
dates = result\['dates'\]\[startidx:endidx\]
close = result\['close'\]\[startidx:endidx\]
psarbear = result\['psarbear'\]\[startidx:endidx\]
psarbull = result\['psarbull'\]\[startidx:endidx\]

plt.plot(dates, close)
plt.plot(dates, psarbull)
plt.plot(dates, psarbear)
plt.grid()
plt.show()

动向指标(DMI) --------------------------------------------------------------------------- Moving Averages Convergence/Divergence(MACD) --------------------------------------------------------------------------- On Balance Volume(OBV) --------------------------------------------------------------------------- 相对强弱指标(Relative Strength Index,RSI) --------------------------------------------------------------------------- Relative Vigor Index(RVI) --------------------------------------------------------------------------- 漫步随机指标(Random Walk Index,RWI) --------------------------------------------------------------------------- Standard Deviation(StdDev) --------------------------------------------------------------------------- Stochastic Oscillator --------------------------------------------------------------------------- Larry Williams' Percent Range(WPR) --------------------------------------------------------------------------- Python量化分析中文

Get ready for forex

这个月书的样章要完结,还有一篇稿要写。

偶然看到高频交易,加上之前对股市的自动交易感兴趣,然后偶然看到外汇交易,metatrader,看到他们的交易策略,我就燃了。(亏)新手轻虐。

Scott E.Page是个好老师。

节奏要加快,再快,再快点。

基于外汇市场技术指标的ABM建模

本模型的最终模拟期望是随机,我想试试。

货币对作为agent,这样仅需要个位数以内;

货币对本身不拥有市场价值,初始值为此货币对相对于eurusd的比值;

agent拥有自己的技术指标,这个指标尽量在一定范围内震荡;

agent行动时,随之变化的指标会影响其他agent的行动;

patch横向分层,高中低区,agent的行动只在patch间行动;

未名

学习,有工具,有过程,当然也有目的。

早先学习Linux,当工具,也当目的,心想好好学学它在IT行业遇到什么心里有底都不怕。后来,接触的越来越多,Linux已经成为工具箱中的一员了。

云计算、数据挖掘是现阶段的工具,把目的设为金融中的某一项(套利、交易),我目前对这个设定很满意。

人总要向前,为什么要着急地不明就里。

Agent Based Modeling学习笔记合集

最小增长模型

这个模型可以简单解释GDP增长、公司状况等等增长模型,比较实用。

基本条件: 100个工人操作1个生产豆子的机器,生产出的豆子可以用来消费、购买机器(一个豆子)、储蓄,每个机器的产出为 100*机器数量^0.5 个豆子,机器第二年的报废率为10%,每年总产出的20%用于投资,其他用于消费。

计算:

总产出 = 100 * 机器数量^0.5

储蓄 = 储蓄率s * 总产出

总产出 = 消费 + 投资

下一年机器数量 = 当年机器数量 + 投资机器数量 - 报废率d * 当年机器数量

可知,报废的机器数量总有与投资机器数量相等的时候。

此时我们应有储蓄保证每年消费最大,即将储蓄用于报废机器的增补投资。

s * 100 * 机器数量^0.5 = d * 机器数量

此时机器数量维持在 10000s/d

消费 = 10000 * s * (1-s)/d

为使消费最大,s在此场景中取0.5

基于ABM的云平台控制器

这篇文章可以写一篇论文。

注意,这里的controller不是指OpenStack的controller,而是整个平台过程控制的controller,也就是Automatic System。

好吧,这个问题不大,但也不小。好在我会建模会模拟,嘿哈。(这里不用EBM建模的原因是这个系统有些复杂,公式不足以直观发现问题,但为了提升一下本文的友好度,所以我会加几个公式_

如果你不熟悉ABM建模可以参考我之前的文档,DataNote

那么首先我们要确认模型的目的,即是控制整个虚拟化(容器)在一定条件下的行为,这些条件有存储、网络、计算等资源,直观的条件简单来说就是用户需求(杂项比较多)。然后确定代理人(agent, turtles)、关系连接(link)、控制规则(rules)、代理人行为(actions)等。

在公交车上想出了一个模型,factory-server-client模型,可以的,然后我再收集点主流平台的规则就可以模拟了,非常容易唬人。

最近改为了网格-细菌-食物模型。

先来个粗犷的图吧。

图中,细菌代表虚拟机,食物代表负载,网格代表物理机,食物会一直生成,其速度可控,也就是可以控制负载的变化速度。比如,当负载变化加快时,即食物增长,虚拟机的平均负载会增高,甚至会增加新的虚拟机(也就是细菌繁殖),当然,物理机总数保持不变。

那么这个模型中我们可以得到什么信息,从而达到最高的性价比呢,即虚拟机的变化量最小?

1. 选择合适的繁殖参数(什么时候创建新虚拟机);

2. 可以尝试将细菌固定在一个或者一些网格中,即虚拟机的亲和性,可以观察影响;

3. 课以观察物理机宕机状态下的虚拟机承载与变化能力;

基于这个模型,我们可以搞个controller独立运行,会通过平台API获取资源的即时信息,然后再去做优化动作。

ABM建模导读

本文算是一个读书笔记吧,就是最近刚买的那几本书,相较于之前Scott的几本,这几本学术意味比较浓。中间发现这些作者确实有比较有意思的观点和坚实的理论基础,在此记录以用来随时回忆。

1. Introduction to Agent Based Modeling

c0. & c1. 简介

反正ABM应用范围与可观察性相比EBM(基于公式,也就是我们常说的数学建模)更好,但EBM更容易系统集成。

c2. 入门

蚂蚁模型(也就是寻食模型)、网格自动机(复杂科学,在Wolfram之前就有人总结了相当一部分,另外它与有限状态机都属于自动机的一个特例)、英雄与懦夫模型(如果再加上人可以受他人感染的属性那就可以解释为什么某些人领袖特征还有人买账)、简单经济模型(只要人人都奉献,那么穷的越来越穷,富的越来越富,真不是正态分布,开源届或许也是如此_

c3. 继续入门

四个特性:简单规则组成复杂现象,个体随机性导致一致行为,复杂模式可以“自组织”(飞鸟群、大雁群),不同模型反应世界的不同方面;森林大火模型(即渗透模型,可以用来测试系统的鲁棒性,能适用于很多领域,比如IT、经济、社会等);有限分形聚合模型(化学与自然物理模型);谢林模型(求同存异,人以群分啊);EL Farol模型(学习并预测去酒馆)

c4. 进入正题

开篇就遇到一个我十分认同并曾经也说过(哈哈)的话,来自物理学家费曼先生。 我不能理解我造不出来的东西。 OK进入正题,本章是将如何创建模型,有基于现象(模拟)和探索型(比如网格自动机)两种基本模型,但没有明显边界。然后接下来为了让我们快速上手ABM,作者一步步地使用NetLogo构建出了草-羊-狼模型,从而让你理解ABM建模的一般思路。建模运行以后,为了发现或验证规律,我们需要多次运行这个模型,为此NetLogo提供了行为空间(Behavior Space)方便我们多次运行并收集数据。本章末尾,作者提出了ABM与面向对象编程(OOP)异同点的思考,刚接触这个ABM的时候我就发现它俩很像,但以我短浅的经验来看,两者区别不太大,因为它俩的历史出处有非常惊人的相似或相同,要说有的话,ABM是一种思考方法,即一切从代理出发(agent),不必关心代理之间的复杂影响关系(说实话作者这个描述我是反对的,但作为一种思想而言细想又是对的,复杂的模型,复杂的关系,提纲挈领后也非常简单),而OOP。。OK我编不下去了。

c5. 哈哈,实践篇

这章终于讲了个正经模型,红绿灯模型。这不是重点,重点是为了节省汽油,作者引入了最佳速度,并且为控制这个最佳速度,使用了简单的比例控制,然后又说了一下机器学习的作用。敢情我大学几年都在学习机器学习啊。。本章结尾也较为系统地介绍了NetLogo的特性,比如3D、GIS等,其中这个GIS我在建模世界历史时应该会用到。总之本章非常精彩,至少我很满意。

后面6789章就不写出来了,速读了一下,暂时用不到,但很快就用到。

Compell's law

IMG_1824

Markov model

马尔可夫模型是个很有意思的模型,记住两个示例。 学生上课注意力:Alert:Bored 国家体制:Free:Partly Free:Not Free

1
      Alert(t)  Bored(t)

Alert(t+1) 0.8 0.25 P P X = Bored(t+1) 0.2 0.75 (1-P) (1-P)

So 0.8xP + 0.25x(1-P) = P, we got P=5/9, finally 5/9 of the students will be alert.

模型思考汇总

我们生活在一个繁杂的世界里,形形色色的人、企业和政府交织在一起,产生了各种 新奇、意想不到的现象。我们看到政治冲突、市场崩盘和不断更迭的社会趋势。该如何去理解呢?运用模型。证据表明,具备模型思维的人要优于没有这种思维的人。此外,运用大量模型进行思考的人要优于只运用一种模型思考的人。为什么模型会使我们成为更好的思考者呢?模型有助于我们更好地组织信息,理清互联网上乱成一团麻或者一锅粥(选择你认为合适的比喻说法)的数据。模型有助于我们提高准确预测的能力,还有助于我们做出更好的决策并采取更有效的策略,甚至可以提高我们的机构和流程设计能力。

第1单元:简介:为什么要运用模型?

在这些课程视频中,我会解释为什么我们需要学习模型。这些原因可分为四大类:

成为睿智的世界公民 成为逻辑清晰的思考者 了解并使用数据 更好地制定决策、战略和设计

本单元有两个阅读材料。可以在第一个视频结束后,或在观看完所有视频后阅读这些材料。

《模型思考者》序言、导论和第1章

《为什么要运用模型?》 乔舒亚·爱普斯坦 著

第2单元:分类和同群效应

我们现在直接跳转到一些模型。我们对解释同一个现象(即,人们更喜欢与那些和自己外形、思想和行为相似的人生活和交流)的两种模型进行对比。入门课程视频后,我们将介绍解释这些现象的谢林(Schelling)和格兰诺维特(Granovetter)的著名模型。然后我们会介绍一个有趣的有关起立鼓掌的模型,这个模型是由我和我的朋友约翰·米勒(John Miller)共同编写的。

在第2单元中,我将会使用NetLogo软件展示一个计算版本的谢林的隔离模型。Netlogo是一款由乌里·威伦斯基(Uri Wilensky)或美国西北大学编写的免费软件。在本课程中我会多次用到NetLogo软件。可以通过以下地址下载该软件:

NetLogo

通过单击“文件”(file)选项,然后进入“模型库”(Models Library)可以找到我使用的谢林模型。在“模型库”目录中,单击“社会科学”(Social Science)文件夹旁边的箭头并向下滚动,然后单击名为“隔离”(Segregation)的模型。

本单元的阅读材料包括谢林模型的一些简要说明,以及格兰诺维特、米勒和佩吉的 学术论文。通读这些论文不是必须的,但是我强烈建议你们这么做,以了解社会科学家是如何搭建和解释这些模型的。

谢林模型说明

格兰诺维特模型

米勒和佩吉模型

第 3 单元:聚合

在本单元中,我们将了解聚合,即事件累计的秘密。我们先从数字合计方式开始, 重点介绍中心极限定理。然后了解合计规则。并讲解生命游戏和一维细胞自动机模型。 这两种模型都展示了如何将简单的规则组合在一起来产生有趣的现象。最后,我们会讲解聚合偏好。在这里,我们看到个人偏好可以是合理的,但聚合偏好无需如此。

网上有很多有关中心极限定理、二项分布、六西格玛、生命游戏等内容的资料。我提供了一些链接以便于你入门。细胞自动机和多元化偏好的阅读材料分别来自我所著的《复杂自适应社会系统》和《区别》这两本书中的简短摘录。

中心极限定理

二项分布

六西格玛

细胞自动机1

细胞自动机2

多元化偏好

第4单元:决策模型

在本单元中,我们将研究人们如何制定决策的一些模型。我们先从多准则决策开始。然后介绍决策空间模型和决策树。最后讨论信息的价值。

多准则决策阅读材料是我讲解密歇根州民权提案的指导材料。它为如何使用这个技巧提供了案例研究。关于空间投票和决策模型,网上有很多很棒的PPT演示和论文。决策树资料源自亚利桑那州立大学克雷格·柯克伍德(Craig Kirkwood)的著作。

多准则决策案例研究

空间模型

决策理论

第5单元:人类模型:电子思维

在本单元中,我们将介绍社会科学家塑造人类模型的不同方法。我们会介绍并对比三种不同的模型。理性行为者方法、行为模型以及规则模型。这些课程视频为许多后续模型提供了相应的背景知识。这些课程视频没有具体的阅读材料,但是我在课程中提及的行为经济学的一些相关书籍可用作参考。此外,如果你觉得竞次游戏很有趣,那么可以在搜索引擎中键入“罗丝玛丽·纳格尔竞次理论”("Rosemary Nagel Race to the Bottom")便可以得到多个相关链接。你还可以采用同样的方法找到“零智能交易者”(Zero Intelligence Traders)的相关介绍。

通过此处提供的链接可以获得行为经济学的初级读物,这里面有更多的参考资料。

《行为经济学初级读物》

第6单元:线性模型

在本单元中,主要介绍了线性模型。我们先从分类模型开始,该模型中的数据分为多类。我们使用这个简单的框架介绍一些度量值,如平均值、方差、决定系数。然后进入线性模型主题,讲解线性模型的作用、介绍如何读取回归输出(宝贵技能!) 以及如何用线性模型匹配非线性数据。这些课程视频旨在介绍如何使用线性模型,由此可能激励你参加这些主题相关课程。本单元最后会重点介绍我称为大系数思维和新现实思维之间的区别。本单元的阅读材料包括我编写的2篇短论文,但是你可以在网上找到有关线性模型、决定系数、回归和循证思维的更多资料。

分类模型

线性模型

第7单元:临界点

在本单元中,我们会介绍临界点。我们重点介绍两种模型。一种是银行使用的物理学上的渗流模型,另一种是疾病传播模型。由于疾病模型比较复杂,因此我分为两部分进行 讲解。第一部分重点介绍扩散。第二部分介绍恢复。本单元的阅读材料是我编写的有 关模型的书籍中的两篇摘录。一篇关于扩散。另一篇关于临界点。此外,我还提供了一个链接,由此可以找到一篇关于临界点的技术论文。这是我和PJ·兰伯森(PJ Lamberson)共同编著的,并将在《政治学季刊》(Quarterly Journal of Political Science)上发表。由此你可以大概了解技术型社会学论文的一些基本情况。无需全篇阅读,但我强烈建议你仔细阅读简介部分。其中包含了非常有用的参考文献列表。

临界点

扩散和SIS

兰伯森和佩吉:临界点(只阅读导论部分)

第8单元:经济增长

在本单元中,我们将介绍几种增长模型。首先介绍指数增长的一个简单模型,然后是经济学模型,并重点阐述索洛的基本增长模型。我将模型进行了简化,去除了劳动力部分。 这些模型有助于我们区分两种增长方式:资本积累增长和创新增长。

增长模型

第9单元:多样性和创新

在本单元中,我们介绍了解决问题的几种模型,以展示多样性对创新的重要性。我们将了解到不同的观点(问题表征)和启发法如何使问题解决者团队的表现胜过个人。此外, 我们还会引入一些新概念,如“崎岖的风景”和“局部最优”。在最后的课程视频中, 我们将见识重组的威力及其如何促进经济增长。本章节的阅读材料包括普林斯顿大学出版社出版的由我编著的书籍《区别》的摘录。

多样性和问题解决

第10单元:马尔可夫过程

在本单元中,主要介绍了马尔可夫过程(Markov Processes)。马尔可夫过程指的是一组固定状态之间的动态过程。例如,我们将讨论有些国家在民主制度和专制制度之间过渡的过程。作为马尔可夫过程,必须要能从任意一种状态转换为另一种状态,且状态之间转换的可能性必须随着时间的推移保持不变。如果这些假设成立,那么这种过程将存在唯一的均衡。换句话说,历史将变得无关紧要。这种结果称为马尔可夫收敛定理。除了马尔可夫过程之外,我们还将了解如何将这个基本框架用于其他用途,如确定文本的著作权以及药物协议的有效性等。

马尔可夫过程

第11单元:李雅普诺夫函数

模型可以帮助我们确定系统产生结果的性质:系统是否会产生平衡、循环、随机性或复杂性? 在本节课程视频中,我们将介绍李雅普诺夫函数。这种技术有助于我们识别哪些系统可以达到平衡。此外,我们还可以限制达到平衡的速度。在本课程视频中,我们将介绍李雅普诺夫函数(Lyapunov Functions)的形式定义,并了解如何在多种情境中应用它们。我们还会研究其不适用的范围,甚至研究使人们不能判断系统是否达到平衡的问题。

李雅普诺夫函数

第12单元:协调和文化

在本课程视频中,我们将介绍几个有关文化的模型。首先从文化是什么以及文化对社会科学家比较重要的原因开始。在分析部分,我们先从一个非常简单的,称为纯协调博弈的游戏开始。在该博弈中,局中人只有选择相同的行动才算赢。不管他们选择哪个行动,只要他们选择相同的行动便会赢。例如,你选择在公路的左侧开车还是右侧开车并不重要,重要的是你和其他人是否在同一侧开车。随后我们会介绍多人协调博弈的情景并研究文化的出现。在最后的模型中,我们将介绍模型中的一致性和协调性,这些文化同样会出现在现实世界数据中。本单元的阅读材料包括我对协调博弈的说明,以及贝德纳(Bednar)等人的学术论文。在该论文中,你将了解到我们如何使用马尔可夫过程研究模型。本课程还提供了阿克塞尔罗德(Axelrod)的Net Logo模型的链接。

协调博弈

贝德纳等人 2010年

Netlogo中的阿克斯德罗文化模型

第13单元:路径依赖

在本课程视频中,我们介绍了路径依赖。我们将用到一些简单的瓮模型。其中最著名的是波利亚过程(Polya Process)。这些模型尽管简单,却可以帮助我们剖析路径依赖背后的逻辑。我们还会将路径依赖与递增收益、临界点联系在一起。本单元的阅读材料是我在《政治科学季刊》上发表的论文。

路径依赖

第14单元:网络

在本单元中,我们会介绍网络。我们会讨论网络的形成方式、结构(尤其是网络的一些通用度量)及其功能。我们通常会说网络功能自然生成,这意味着由于网络的自身结构会出现意想不到的功能。本单元的阅读材料是史蒂夫·斯托加茨(Steven Strogatz)的一篇小论文。

斯托加茨

第15单元:随机性和随机游走

在本单元,我们会讨论随机性及其各种来源。接下来会讨论成绩与技能和运气的依赖关系,其中将运气建模为随机性。然后了解基本随机游走模型,该模型应用于有效市场假说,此假说认为市场价格涵盖了所有相关信息,余下的就是随机性。最后,我们将讨论可用于创建竞争模型的有限存储器随机游走模型。本单元的阅读材料是迈克尔·莫布森(Michael Mauboussin)的一篇有关区分技能和运气的论文。

莫布森:技能与运气

第16单元:上校赛局

在本单元中,我们将介绍上校赛局。这最早用于战争中研究多线作战。如今被广泛应用于运动、法律、恐怖主义等。我们先讨论上校赛局的基础,进行更深入的分析,然后将上校赛局与上一单元技能运气模型进行对比。本单元的阅读材料是我的一本名为《差异》的书籍的节选以及我跟卡内基梅隆大学的拉塞尔·戈尔曼(Russell Golman)合作编写的一篇论文。你只需要阅读戈尔曼论文的前四页即可。

《差异》中的上校赛局

戈尔曼的论文:上校赛局

第17单元:囚徒困境和集体行动

在本单元中,我们将会介绍囚徒困境、集体行动和公共池塘资源问题。我们会先讨论囚徒困境,并演示个体激励如何催生不良社会后果。然后我们会介绍产生合作的七种方式。瓦克(Nowak)和西格蒙德(Sigmund)的下列论文涵盖了其中的五种。最后,我们将讨论集体行动和公共池塘资源问题,以及如何通过深入仔细的思考来解决这些问题。诺贝尔奖获得者埃莉诺·奥斯特罗姆(Elinor Ostrom)就此著有一篇精彩的文章。

《斯坦福哲学百科全书》中的囚徒困境

《合作的五种方式》瓦克和西格蒙德 著

《超越万灵之方》奥斯特罗姆 著

第18单元:机制设计:拍卖

在本单元中,我们将会介绍机制设计。我们先研究一些基本问题:如何克服隐藏行动和隐藏信息的问题。然后转到更广泛应用的问题:如何设计拍卖。最后,我们将讨论如何运用机制对公共项目作出决策。本单元的阅读材料包括埃里克·马金斯(Eric Maskin)的一篇文章(他因在机制设计方面的贡献而获得诺贝尔奖)和V.S.撒布汉曼尼(V.S. Subrahmanian)的一些有关拍卖的幻灯片。马金斯的论文读到最后会有些困难。无需深入理解全部内容。掌握大意即可。

马金斯:《机制设计》

V.S.撒布汉曼尼的拍卖幻灯片

第19单元:学习:模仿者动态

在本单元中,我们将介绍模仿者动态以及费希尔基本定理。模仿者动态已被用于解释学习和演变。费希尔定理演示了适应速度是如何随变动幅度增加的。最后,我们将介绍如何用六西格玛和偏差缩减来解释费希尔定理和我们得出的结果。本单元的阅读材料很短。费希尔定理的第二篇材料更侧重于技术性。文章均摘自《多样性和复杂性》

《模仿者方程式》

费希尔基本定理

第20单元:众多模型思考者:多样性和预测

在最后一个单元中,我们将介绍进行预测时创建智慧人群所用到的能力和多样性的价值。我们会先介绍分类模型和线性模型,以及如何将其用于预测。然后我们会介绍多样性预测定理,该定理提供了有关集体预测工作方式的基本知识。最后,我们会讨论使用多种模型的价值。本单元的阅读材料为多样性预测定理的简短说明。

多样性预测定理

先修知识 学生需要能够熟练使用基本代数。不需要微积分方面的知识,但是如果能从概念上理解导数是如何表示某点斜率的话,会对课程的学习非常有帮助。

参考资料 《差异:多元化的力量如何建立更好的团体、企业、学校和社会(新版)》 斯科特·E·佩吉 著

The Difference: How the Power of Diversity Creates Better Groups, Firms, Schools, and Societies (New Edition), Scott Page

《复杂适应系统:社会生活的计算模型简介(普林斯顿复杂性研究)》 约翰·米勒和斯科特·佩吉 著

Complex Adaptive Systems: An Introduction to Computational Models of Social Life (Princeton Studies in Complexity), John Miller and Scott Page

《社会科学模型简介》 珍妮·拉弗和詹姆斯·马奇 著

An Introduction to Models in the Social Sciences, Jean Lave and James March

模型分类

Scale Model

Simple Model

Equation Model

Agents-based Model |_ Micro-simulation(Individual based) |_ System Dynamics(System view)

Monty Hall Problem

这是一个令直觉犯错误的问题,我们试图将其用贝叶斯理论解释。

A,B,C三个门,其中只有一个门后有奖品——奥迪S8一辆。我们在第一次选择时,主持人会打开你选中之外的门的其中一扇空门,然后问你要不要更改你的选择。

直觉可能告诉我们:“你选哪个得奖的概率都有1/3,换了也一样,咱不换了。”

嗯,这样不对。

这样想:“假如坚持第一次的选择,那我得奖的概率就是三分之一;如果我没选中,然后我换了,那我一定得奖。我第一次选中的概率是三分之一,没选中的概 率就是三分之二,所以这样就相当于我要是换那个剩着的门那我获奖的概率就是三分之二了。”

对的,把你的选择分成两组,比如D、E,其中D是你选择的门,E是你没选择的那俩门。D后有奖品的概率是1/3,E后有奖品的概率是2/3。当主持人开空门的时候,E组有奖品概率不变,但只剩下一个选择了,岂不很好,然后这两组门后有奖的概率不变,仍然是1/3和2/3。

每次选择都是独立事件,我们用基础概率表示一下: 第一次选择:1/3中,2/3不中; 第二次选择:1/2中,1/2不中; 坚持选择:(1/3)*(1/2)=1/6中; 更改选择:(2/3)*(1/2)=2/6中; 然后坚持和更改的分别中的概率为1/(1+2)和2/(1+2),就是1/3和2/3。

所以,还是换吧。

用代码看看:

!/usr/bin/env python

import random

match_first = 0.00 match_second = 0.00

for i in range(1,1000): print "Game round %i" % i door = ['a', 'b', 'c'] # We choose a random door with prize. prize = door[random.randint(0,2)] # Now player's turn player_choice = door[random.randint(0,2)] # If player choose the right one at first if player_choice == prize: # If player sticks to his/her choice match_first += 1 # If he change hist mind and we can be sure that player is lost print "Stick to the first: %i\nChange to the second: %i\nWin on the second thought: %.2f" %(match_first, match_second, match_second/i) continue # If player choose the wrong one at first else: # We open a blank door and player changes his mind, then player wins match_second += 1 print "Stick to the first: %i\nChange to the second: %i\nWin on the second thought: %.2f" %(match_first, match_second, match_second/i) continue

输出结果:

Game round 999 Stick to the first: 347 Change to the second: 652 Win on the second thought: 0.65

TBD

开源交易平台

tradelink http://code.google.com/p/tradelink/ Write automated trading systems, connect with 17+ broker APIs

AIOTrade http://sourceforge.net/projects/humaitrader AIOTrade (formerly Humai Trader Platform) is a free, open source stock technical analysis platform built on pure java. manticore-trader http://www.manticore-projects.com/ manticore-trader is a free and open java software for day trading warants on stocks, currencies and comodities. It includes modules for charting, position and risk management, automatic ordering and system trading. Instruments and quotes of the main financial markets are provided daily

G-BOT http://www.datatime.eu/public/gbot/ G-BOT is a public academic project, headed by Prof. Tom Gastaldi (first University of Rome "La Sapienza"). The project is about the study of trading algorithms and fully automated strategies for systematic profitability. Marketcetera http://trac.marketcetera.org/ http://www.marketcetera.com/ Marketcetera focuses on building the key trading functions that are common to all organizations, thus freeing our clients to concentrate on proprietary trading algorithms and other specialized software that provide a competitive advantage.

Merchant of Venice http://sourceforge.net/projects/mov http://mov.sourceforge.net/ MOV is a stock market trading programme that supports portfolio management, charting, technical analysis, paper trading and genetic programming. Venice runs in a graphical user interface with online help and has full documentation.

EclipseTrader http://sourceforge.net/projects/eclipsetrader/ http://eclipsetrader.sourceforge.net/ Eclipse Rich Client Platform (RCP) application featuring shares pricing watch, intraday and history charts with technical analysis indicators, level II/market depth view, news watching, and integrated trading.

JBookTrader http://code.google.com/p/jbooktrader/ All aspects of trading, such as obtaining market prices, analyzing price patterns, making trading decisions, placing orders, monitoring order executions, and controlling the risk are automated according to the user preferences. JBookTrader is a "sister" project to JSystemTrader.

Matrex http://sourceforge.net/projects/matrex/ http://matrex.sourceforge.net/ The perfect desktop tool for mathematical, statistical models and complex calculations. Adapters to matlab, scilab, octave, R.

OpenGamma http://www.opengamma.com/ OpenGamma provides technology for financial institutions to improve analytics calculation and delivery to front-office and risk users. Open Java Trading System (Last Update 2010-08-14) http://sourceforge.net/projects/ojts/ http://ojts.sourceforge.net/ The Open Java Trading System (OJTS) is meant to be a common infrastructure to develop (stock) trading systems. There are four parts: gathering of raw data over the internet, recognition of trading signals, a visualization module and trading with banks.

Joone http://sourceforge.net/projects/joone/ Joone is a neural net framework written in Java(tm). It's composed by a core engine, a GUI editor and a distributed training environment and can be extended by writing new modules to implement new algorithms or architectures starting from base component Data Visualizer (Last Update 2009-07-17) http://sourceforge.net/projects/dataviews http://dataviews.sourceforge.net/

Modular environment for graphical visualization of stock market type data SFL Java Trading System Enviroment (Last Update 2009-07-17) http://sourceforge.net/projects/sfljtse http://www.sflweb.org/index.php?blog=sfljtse Java application built on KISS principle ( Keep It Simple,Stupid ) and its aim is to provide a fast and platform indipendent infrastructure to develop and execute trading systems.

ActiveQuant (Last Update 2009) http://www.activequant.org/ Somewhat heavy stuff, for proficient programmers only JSystemTrader (Last Update 2009) Developed to work with Interactive Broker’s API, fully automated trading system (ATS) that can trade various types of market securities during the trading day without user monitoring.

Market Analysis System (Last Update 2009-07-17) http://sourceforge.net/projects/eiffel-mas http://eiffel-mas.sourceforge.net/ System for analysis of financial markets using technical analysis. Includes facilities for stock charting and futures charting, as well as automated generation of trading signals based on user-selected criteria. Operates on both daily and intraday data.

Oropuro trading system (Last Update 2009) http://sourceforge.net/projects/oropuro http://www.oropuro.org Complete technical analysis & trading system, full set of features: retrieve, analyze EOD stocks data; manage multiple portfolios; technical analysis & graphical rendering; neural networks for generation of trading signals; support trader community,

AlgoTrader http://code.google.com/p/algo-trader/ AlgoTrader is an automated trading system (ATS) that can trade any type of security on any market available through InteractiveBrokers or FIX. All aspects of trading like getting market data, analyzing prices, taking trade decisions, placing orders & tracking executions can be automated. Encog Encog Java and DotNet Neural Network Framework | Heaton Research Encog Ninjatrader Getting Started - Encog Machine Learning Framework Encog is an advanced neural network and machine learning framework. Encog contains classes to create a wide variety of networks, as well as support classes to normalize and process data for these neural networks. Encog trains using multithreaded resilient propagation. Encog can also make use of a GPU to further speed processing time. A GUI based workbench is also provided to help model and train neural networks.

The first attempt to build an automated trading and signal system

Here's the sketch. tm

Source code. https://github.com/lofyer/trade-model-01

目前新闻收集已经OK,搜索也已OK,趋势关键字尚未完成。

交易算法学习中,外汇历史收集中,学习策略未完成。

已升级为quantum-trade-model

对应文章为数据笔记

媒体发布-筛选服务 官网

公众号

策略研究-会员服务

趋势总结(新闻关键字,暗网关键字,地图,pdf报告)

世界指标(政治稳定度,经济稳定度,社会指标)

交易模型(算法实现,托管交易,代码托管PaaS)

技术博客

平台文章

Timeline: 2016-7 模型学习、算法学习、平台构建、渠道收集 2016-8 算法学习、平台构建、趋势输出

示例站点

信号交易系统

tbd

国家、行业、人物、现象与总结的历史知识降维方法

知识太多,如何归纳。

有行业历史、人物历史、世界(国家)历史,统统降维划到世界历史中,降级元素视作代理,尝试使用ABM建模。

降至平面图形中,形似“蝌蚪头(蝌蚪头(蝌蚪头拖着长长的尾巴)拖着长长的尾巴)拖着长长的尾巴”,蝌蚪头是领域,尾巴是历史,蝌蚪头可以是另一个蝌蚪头的拷贝,蝌蚪头的扩展可以向大可以向小。当遇到这些元素的交集再升维至球形,往中心聚拢。

笔者以国家为最外层蝌蚪头,假如发现外星文化,同样可以再加蝌蚪头将其吃掉。